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_SERVICE_MANAGER_BACKGROUND_SHELL_SERVICE_LOADER_H_ | 5 #ifndef MOJO_SERVICE_MANAGER_BACKGROUND_SHELL_SERVICE_LOADER_H_ |
6 #define MOJO_SERVICE_MANAGER_BACKGROUND_SHELL_SERVICE_LOADER_H_ | 6 #define MOJO_SERVICE_MANAGER_BACKGROUND_SHELL_SERVICE_LOADER_H_ |
7 | 7 |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/synchronization/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
11 #include "base/threading/simple_thread.h" | 11 #include "base/threading/simple_thread.h" |
12 #include "mojo/service_manager/service_loader.h" | 12 #include "mojo/service_manager/service_loader.h" |
13 | 13 |
14 namespace mojo { | 14 namespace mojo { |
15 | 15 |
16 // TODO(tim): Eventually this should be Android-only to support services | 16 // TODO(tim): Eventually this should be Android-only to support services |
17 // that we need to bundle with the shell (such as NetworkService). Perhaps | 17 // that we need to bundle with the shell (such as NetworkService). Perhaps |
18 // we should move it to shell/ as well. | 18 // we should move it to shell/ as well. |
19 class MOJO_SERVICE_MANAGER_EXPORT BackgroundShellServiceLoader : | 19 class MOJO_SERVICE_MANAGER_EXPORT BackgroundShellServiceLoader : |
20 public ServiceLoader, | 20 public ServiceLoader, |
21 public base::DelegateSimpleThread::Delegate { | 21 public base::DelegateSimpleThread::Delegate { |
22 public: | 22 public: |
23 BackgroundShellServiceLoader(scoped_ptr<ServiceLoader> real_loader, | 23 BackgroundShellServiceLoader(scoped_ptr<ServiceLoader> real_loader, |
24 const std::string& thread_name, | 24 const std::string& thread_name, |
25 base::MessageLoop::Type message_loop_type); | 25 base::MessageLoop::Type message_loop_type); |
26 virtual ~BackgroundShellServiceLoader(); | 26 virtual ~BackgroundShellServiceLoader(); |
27 | 27 |
28 // ServiceLoader overrides: | 28 // ServiceLoader overrides: |
29 virtual void LoadService(ServiceManager* manager, | 29 virtual void Load(ServiceManager* manager, |
30 const GURL& url, | 30 const GURL& url, |
31 ScopedMessagePipeHandle shell_handle) OVERRIDE; | 31 scoped_refptr<LoadCallbacks> callbacks) OVERRIDE; |
32 virtual void OnServiceError(ServiceManager* manager, | 32 virtual void OnServiceError(ServiceManager* manager, |
33 const GURL& url) OVERRIDE; | 33 const GURL& url) OVERRIDE; |
34 | 34 |
35 private: | 35 private: |
36 class BackgroundLoader; | 36 class BackgroundLoader; |
37 | 37 |
38 // |base::DelegateSimpleThread::Delegate| method: | 38 // |base::DelegateSimpleThread::Delegate| method: |
39 virtual void Run() OVERRIDE; | 39 virtual void Run() OVERRIDE; |
40 | 40 |
41 // These functions are exected on the background thread. They call through | 41 // These functions are exected on the background thread. They call through |
42 // to |background_loader_| to do the actual loading. | 42 // to |background_loader_| to do the actual loading. |
43 // TODO: having this code take a |manager| is fragile (as ServiceManager isn't | 43 // TODO: having this code take a |manager| is fragile (as ServiceManager isn't |
44 // thread safe). | 44 // thread safe). |
45 void LoadServiceOnBackgroundThread( | 45 void LoadOnBackgroundThread(ServiceManager* manager, |
46 ServiceManager* manager, | 46 const GURL& url, |
47 const GURL& url, | 47 ScopedMessagePipeHandle* shell_handle); |
48 ScopedMessagePipeHandle* shell_handle); | |
49 void OnServiceErrorOnBackgroundThread(ServiceManager* manager, | 48 void OnServiceErrorOnBackgroundThread(ServiceManager* manager, |
50 const GURL& url); | 49 const GURL& url); |
51 bool quit_on_shutdown_; | 50 bool quit_on_shutdown_; |
52 scoped_ptr<ServiceLoader> loader_; | 51 scoped_ptr<ServiceLoader> loader_; |
53 | 52 |
54 const base::MessageLoop::Type message_loop_type_; | 53 const base::MessageLoop::Type message_loop_type_; |
55 const std::string thread_name_; | 54 const std::string thread_name_; |
56 | 55 |
57 // Created on |thread_| during construction of |this|. Protected against | 56 // Created on |thread_| during construction of |this|. Protected against |
58 // uninitialized use by |message_loop_created_|, and protected against | 57 // uninitialized use by |message_loop_created_|, and protected against |
59 // use-after-free by holding a reference to the thread-safe object. Note | 58 // use-after-free by holding a reference to the thread-safe object. Note |
60 // that holding a reference won't hold |thread_| from exiting. | 59 // that holding a reference won't hold |thread_| from exiting. |
61 scoped_refptr<base::TaskRunner> task_runner_; | 60 scoped_refptr<base::TaskRunner> task_runner_; |
62 base::WaitableEvent message_loop_created_; | 61 base::WaitableEvent message_loop_created_; |
63 | 62 |
64 // Lives on |thread_|. | 63 // Lives on |thread_|. |
65 base::Closure quit_closure_; | 64 base::Closure quit_closure_; |
66 | 65 |
67 scoped_ptr<base::DelegateSimpleThread> thread_; | 66 scoped_ptr<base::DelegateSimpleThread> thread_; |
68 | 67 |
69 // Lives on |thread_|. Trivial interface that calls through to |loader_|. | 68 // Lives on |thread_|. Trivial interface that calls through to |loader_|. |
70 BackgroundLoader* background_loader_; | 69 BackgroundLoader* background_loader_; |
71 | 70 |
72 DISALLOW_COPY_AND_ASSIGN(BackgroundShellServiceLoader); | 71 DISALLOW_COPY_AND_ASSIGN(BackgroundShellServiceLoader); |
73 }; | 72 }; |
74 | 73 |
75 } // namespace mojo | 74 } // namespace mojo |
76 | 75 |
77 #endif // MOJO_SERVICE_MANAGER_BACKGROUND_SHELL_SERVICE_LOADER_H_ | 76 #endif // MOJO_SERVICE_MANAGER_BACKGROUND_SHELL_SERVICE_LOADER_H_ |
OLD | NEW |