| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef MOJO_SHELL_STANDALONE_ANDROID_BACKGROUND_APPLICATION_LOADER_H_ | 5 #ifndef MOJO_SHELL_STANDALONE_ANDROID_BACKGROUND_APPLICATION_LOADER_H_ |
| 6 #define MOJO_SHELL_STANDALONE_ANDROID_BACKGROUND_APPLICATION_LOADER_H_ | 6 #define MOJO_SHELL_STANDALONE_ANDROID_BACKGROUND_APPLICATION_LOADER_H_ |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/synchronization/waitable_event.h" | 11 #include "base/synchronization/waitable_event.h" |
| 12 #include "base/threading/simple_thread.h" | 12 #include "base/threading/simple_thread.h" |
| 13 #include "mojo/shell/application_loader.h" | 13 #include "mojo/shell/application_loader.h" |
| 14 | 14 |
| 15 namespace mojo { | 15 namespace mojo { |
| 16 namespace shell { | 16 namespace shell { |
| 17 | 17 |
| 18 class BackgroundApplicationLoader | 18 class BackgroundApplicationLoader |
| 19 : public ApplicationLoader, | 19 : public ApplicationLoader, |
| 20 public base::DelegateSimpleThread::Delegate { | 20 public base::DelegateSimpleThread::Delegate { |
| 21 public: | 21 public: |
| 22 BackgroundApplicationLoader(scoped_ptr<ApplicationLoader> real_loader, | 22 BackgroundApplicationLoader(scoped_ptr<ApplicationLoader> real_loader, |
| 23 const std::string& thread_name, | 23 const std::string& thread_name, |
| 24 base::MessageLoop::Type message_loop_type); | 24 base::MessageLoop::Type message_loop_type); |
| 25 ~BackgroundApplicationLoader() override; | 25 ~BackgroundApplicationLoader() override; |
| 26 | 26 |
| 27 // ApplicationLoader overrides: | 27 // ApplicationLoader overrides: |
| 28 void Load(const GURL& url, | 28 void Load(const GURL& url, |
| 29 InterfaceRequest<mojom::Application> application_request) override; | 29 InterfaceRequest<mojom::ShellClient> request) override; |
| 30 | 30 |
| 31 private: | 31 private: |
| 32 // |base::DelegateSimpleThread::Delegate| method: | 32 // |base::DelegateSimpleThread::Delegate| method: |
| 33 void Run() override; | 33 void Run() override; |
| 34 | 34 |
| 35 // These functions are exected on the background thread. They call through | 35 // These functions are exected on the background thread. They call through |
| 36 // to |background_loader_| to do the actual loading. | 36 // to |background_loader_| to do the actual loading. |
| 37 void LoadOnBackgroundThread( | 37 void LoadOnBackgroundThread(const GURL& url, |
| 38 const GURL& url, | 38 InterfaceRequest<mojom::ShellClient> request); |
| 39 InterfaceRequest<mojom::Application> application_request); | |
| 40 bool quit_on_shutdown_; | 39 bool quit_on_shutdown_; |
| 41 scoped_ptr<ApplicationLoader> loader_; | 40 scoped_ptr<ApplicationLoader> loader_; |
| 42 | 41 |
| 43 const base::MessageLoop::Type message_loop_type_; | 42 const base::MessageLoop::Type message_loop_type_; |
| 44 const std::string thread_name_; | 43 const std::string thread_name_; |
| 45 | 44 |
| 46 // Created on |thread_| during construction of |this|. Protected against | 45 // Created on |thread_| during construction of |this|. Protected against |
| 47 // uninitialized use by |message_loop_created_|, and protected against | 46 // uninitialized use by |message_loop_created_|, and protected against |
| 48 // use-after-free by holding a reference to the thread-safe object. Note | 47 // use-after-free by holding a reference to the thread-safe object. Note |
| 49 // that holding a reference won't hold |thread_| from exiting. | 48 // that holding a reference won't hold |thread_| from exiting. |
| 50 scoped_refptr<base::TaskRunner> task_runner_; | 49 scoped_refptr<base::TaskRunner> task_runner_; |
| 51 base::WaitableEvent message_loop_created_; | 50 base::WaitableEvent message_loop_created_; |
| 52 | 51 |
| 53 // Lives on |thread_|. | 52 // Lives on |thread_|. |
| 54 base::Closure quit_closure_; | 53 base::Closure quit_closure_; |
| 55 | 54 |
| 56 scoped_ptr<base::DelegateSimpleThread> thread_; | 55 scoped_ptr<base::DelegateSimpleThread> thread_; |
| 57 | 56 |
| 58 DISALLOW_COPY_AND_ASSIGN(BackgroundApplicationLoader); | 57 DISALLOW_COPY_AND_ASSIGN(BackgroundApplicationLoader); |
| 59 }; | 58 }; |
| 60 | 59 |
| 61 } // namespace shell | 60 } // namespace shell |
| 62 } // namespace mojo | 61 } // namespace mojo |
| 63 | 62 |
| 64 #endif // MOJO_SHELL_STANDALONE_ANDROID_BACKGROUND_APPLICATION_LOADER_H_ | 63 #endif // MOJO_SHELL_STANDALONE_ANDROID_BACKGROUND_APPLICATION_LOADER_H_ |
| OLD | NEW |