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 SHELL_ANDROID_BACKGROUND_APPLICATION_LOADER_H_ | 5 #ifndef SHELL_ANDROID_BACKGROUND_APPLICATION_LOADER_H_ |
6 #define SHELL_ANDROID_BACKGROUND_APPLICATION_LOADER_H_ | 6 #define SHELL_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 "shell/application_manager/application_loader.h" | 13 #include "shell/application_manager/application_loader.h" |
14 | 14 |
15 namespace mojo { | 15 namespace mojo { |
16 | 16 |
17 class MOJO_APPLICATION_MANAGER_EXPORT BackgroundApplicationLoader | 17 class MOJO_APPLICATION_MANAGER_EXPORT BackgroundApplicationLoader |
18 : public ApplicationLoader, | 18 : public ApplicationLoader, |
19 public base::DelegateSimpleThread::Delegate { | 19 public base::DelegateSimpleThread::Delegate { |
20 public: | 20 public: |
21 BackgroundApplicationLoader(scoped_ptr<ApplicationLoader> real_loader, | 21 BackgroundApplicationLoader(scoped_ptr<ApplicationLoader> real_loader, |
22 const std::string& thread_name, | 22 const std::string& thread_name, |
23 base::MessageLoop::Type message_loop_type); | 23 base::MessageLoop::Type message_loop_type); |
24 ~BackgroundApplicationLoader() override; | 24 ~BackgroundApplicationLoader() override; |
25 | 25 |
26 // ApplicationLoader overrides: | 26 // ApplicationLoader overrides: |
27 void Load(ApplicationManager* manager, | 27 void Load(ApplicationManager* manager, |
28 const GURL& url, | 28 const GURL& url, |
29 ShellPtr shell, | 29 InterfaceRequest<Application> application_request, |
30 LoadCallback callback) override; | 30 LoadCallback callback) override; |
31 void OnApplicationError(ApplicationManager* manager, | 31 void OnApplicationError(ApplicationManager* manager, |
32 const GURL& url) override; | 32 const GURL& url) override; |
33 | 33 |
34 private: | 34 private: |
35 // |base::DelegateSimpleThread::Delegate| method: | 35 // |base::DelegateSimpleThread::Delegate| method: |
36 void Run() override; | 36 void Run() override; |
37 | 37 |
38 // These functions are exected on the background thread. They call through | 38 // These functions are exected on the background thread. They call through |
39 // to |background_loader_| to do the actual loading. | 39 // to |background_loader_| to do the actual loading. |
40 // TODO: having this code take a |manager| is fragile (as ApplicationManager | 40 // TODO: having this code take a |manager| is fragile (as ApplicationManager |
41 // isn't thread safe). | 41 // isn't thread safe). |
42 void LoadOnBackgroundThread(ApplicationManager* manager, | 42 void LoadOnBackgroundThread( |
43 const GURL& url, | 43 ApplicationManager* manager, |
44 ShellPtr shell); | 44 const GURL& url, |
| 45 InterfaceRequest<Application> application_request); |
45 void OnApplicationErrorOnBackgroundThread(ApplicationManager* manager, | 46 void OnApplicationErrorOnBackgroundThread(ApplicationManager* manager, |
46 const GURL& url); | 47 const GURL& url); |
47 bool quit_on_shutdown_; | 48 bool quit_on_shutdown_; |
48 scoped_ptr<ApplicationLoader> loader_; | 49 scoped_ptr<ApplicationLoader> loader_; |
49 | 50 |
50 const base::MessageLoop::Type message_loop_type_; | 51 const base::MessageLoop::Type message_loop_type_; |
51 const std::string thread_name_; | 52 const std::string thread_name_; |
52 | 53 |
53 // Created on |thread_| during construction of |this|. Protected against | 54 // Created on |thread_| during construction of |this|. Protected against |
54 // uninitialized use by |message_loop_created_|, and protected against | 55 // uninitialized use by |message_loop_created_|, and protected against |
55 // use-after-free by holding a reference to the thread-safe object. Note | 56 // use-after-free by holding a reference to the thread-safe object. Note |
56 // that holding a reference won't hold |thread_| from exiting. | 57 // that holding a reference won't hold |thread_| from exiting. |
57 scoped_refptr<base::TaskRunner> task_runner_; | 58 scoped_refptr<base::TaskRunner> task_runner_; |
58 base::WaitableEvent message_loop_created_; | 59 base::WaitableEvent message_loop_created_; |
59 | 60 |
60 // Lives on |thread_|. | 61 // Lives on |thread_|. |
61 base::Closure quit_closure_; | 62 base::Closure quit_closure_; |
62 | 63 |
63 scoped_ptr<base::DelegateSimpleThread> thread_; | 64 scoped_ptr<base::DelegateSimpleThread> thread_; |
64 | 65 |
65 DISALLOW_COPY_AND_ASSIGN(BackgroundApplicationLoader); | 66 DISALLOW_COPY_AND_ASSIGN(BackgroundApplicationLoader); |
66 }; | 67 }; |
67 | 68 |
68 } // namespace mojo | 69 } // namespace mojo |
69 | 70 |
70 #endif // SHELL_ANDROID_BACKGROUND_APPLICATION_LOADER_H_ | 71 #endif // SHELL_ANDROID_BACKGROUND_APPLICATION_LOADER_H_ |
OLD | NEW |