James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Benjamin Lerman | 5d429aa | 2015-05-07 16:21:00 +0200 | [diff] [blame] | 5 | #ifndef SHELL_BACKGROUND_APPLICATION_LOADER_H_ |
| 6 | #define SHELL_BACKGROUND_APPLICATION_LOADER_H_ |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 7 | |
| 8 | #include "base/macros.h" |
| 9 | #include "base/memory/scoped_ptr.h" |
| 10 | #include "base/message_loop/message_loop.h" |
| 11 | #include "base/synchronization/waitable_event.h" |
| 12 | #include "base/threading/simple_thread.h" |
Przemysław Pietrzkiewicz | 6384d09 | 2015-01-15 16:03:17 -0800 | [diff] [blame] | 13 | #include "shell/application_manager/application_loader.h" |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 14 | |
Viet-Trung Luu | 36faa4d | 2015-03-04 18:08:18 -0800 | [diff] [blame] | 15 | namespace shell { |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 16 | |
Viet-Trung Luu | 1649201 | 2015-03-03 15:18:32 -0800 | [diff] [blame] | 17 | class BackgroundApplicationLoader |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 18 | : public ApplicationLoader, |
| 19 | public base::DelegateSimpleThread::Delegate { |
| 20 | public: |
Scott Violet | f0ef082 | 2014-12-18 08:55:12 -0800 | [diff] [blame] | 21 | BackgroundApplicationLoader(scoped_ptr<ApplicationLoader> real_loader, |
| 22 | const std::string& thread_name, |
| 23 | base::MessageLoop::Type message_loop_type); |
| 24 | ~BackgroundApplicationLoader() override; |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 25 | |
| 26 | // ApplicationLoader overrides: |
Viet-Trung Luu | bd07e3a | 2015-04-09 12:43:29 -0700 | [diff] [blame] | 27 | void Load( |
| 28 | const GURL& url, |
| 29 | mojo::InterfaceRequest<mojo::Application> application_request) override; |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 30 | |
| 31 | private: |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 32 | // |base::DelegateSimpleThread::Delegate| method: |
James Robinson | e1b30cf | 2014-10-21 12:25:40 -0700 | [diff] [blame] | 33 | void Run() override; |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 34 | |
| 35 | // These functions are exected on the background thread. They call through |
| 36 | // to |background_loader_| to do the actual loading. |
James Robinson | e5ae9e4 | 2015-01-26 17:53:08 -0800 | [diff] [blame] | 37 | void LoadOnBackgroundThread( |
James Robinson | e5ae9e4 | 2015-01-26 17:53:08 -0800 | [diff] [blame] | 38 | const GURL& url, |
Viet-Trung Luu | bd07e3a | 2015-04-09 12:43:29 -0700 | [diff] [blame] | 39 | mojo::InterfaceRequest<mojo::Application> application_request); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 40 | bool quit_on_shutdown_; |
| 41 | scoped_ptr<ApplicationLoader> loader_; |
| 42 | |
| 43 | const base::MessageLoop::Type message_loop_type_; |
| 44 | const std::string thread_name_; |
| 45 | |
| 46 | // Created on |thread_| during construction of |this|. Protected against |
| 47 | // uninitialized use by |message_loop_created_|, and protected against |
| 48 | // use-after-free by holding a reference to the thread-safe object. Note |
| 49 | // that holding a reference won't hold |thread_| from exiting. |
| 50 | scoped_refptr<base::TaskRunner> task_runner_; |
| 51 | base::WaitableEvent message_loop_created_; |
| 52 | |
| 53 | // Lives on |thread_|. |
| 54 | base::Closure quit_closure_; |
| 55 | |
| 56 | scoped_ptr<base::DelegateSimpleThread> thread_; |
| 57 | |
Scott Violet | f0ef082 | 2014-12-18 08:55:12 -0800 | [diff] [blame] | 58 | DISALLOW_COPY_AND_ASSIGN(BackgroundApplicationLoader); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 59 | }; |
| 60 | |
Viet-Trung Luu | 36faa4d | 2015-03-04 18:08:18 -0800 | [diff] [blame] | 61 | } // namespace shell |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 62 | |
Benjamin Lerman | 5d429aa | 2015-05-07 16:21:00 +0200 | [diff] [blame] | 63 | #endif // SHELL_BACKGROUND_APPLICATION_LOADER_H_ |