Chromium Code Reviews| Index: mojo/service_manager/background_shell_service_loader.h |
| diff --git a/mojo/service_manager/background_service_loader.h b/mojo/service_manager/background_shell_service_loader.h |
| similarity index 42% |
| rename from mojo/service_manager/background_service_loader.h |
| rename to mojo/service_manager/background_shell_service_loader.h |
| index 253637adb6cfefb487ebce1db7fee5276561e98b..624ccb23dc36f717c873bef9014cd64406ac0c04 100644 |
| --- a/mojo/service_manager/background_service_loader.h |
| +++ b/mojo/service_manager/background_shell_service_loader.h |
| @@ -2,27 +2,28 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#ifndef MOJO_SERVICE_MANAGER_BACKGROUND_SERVICE_LOADER_H_ |
| -#define MOJO_SERVICE_MANAGER_BACKGROUND_SERVICE_LOADER_H_ |
| +#ifndef MOJO_SERVICE_MANAGER_BACKGROUND_SHELL_SERVICE_LOADER_H_ |
| +#define MOJO_SERVICE_MANAGER_BACKGROUND_SHELL_SERVICE_LOADER_H_ |
| #include "base/memory/scoped_ptr.h" |
| #include "base/message_loop/message_loop.h" |
| -#include "base/threading/thread.h" |
| +#include "base/synchronization/waitable_event.h" |
| +#include "base/threading/simple_thread.h" |
| #include "mojo/service_manager/service_loader.h" |
| namespace mojo { |
| -class ServiceManager; |
| - |
| -// ServiceLoader implementation that creates a background thread and issues load |
| -// requests there. |
| -class MOJO_SERVICE_MANAGER_EXPORT BackgroundServiceLoader |
| - : public ServiceLoader { |
| +// TODO(tim): Eventually this should be Android-only to support services |
| +// that we need to bundle with the shell (such as NetworkService). Perhaps |
| +// we should move it to shell/ as well. |
| +class MOJO_SERVICE_MANAGER_EXPORT BackgroundShellServiceLoader : |
| + public ServiceLoader, |
| + public base::DelegateSimpleThread::Delegate { |
| public: |
| - BackgroundServiceLoader(scoped_ptr<ServiceLoader> real_loader, |
| - const char* thread_name, |
| - base::MessageLoop::Type message_loop_type); |
| - virtual ~BackgroundServiceLoader(); |
| + BackgroundShellServiceLoader(scoped_ptr<ServiceLoader> real_loader, |
| + const std::string& thread_name, |
| + base::MessageLoop::Type message_loop_type); |
| + virtual ~BackgroundShellServiceLoader(); |
| // ServiceLoader overrides: |
| virtual void LoadService(ServiceManager* manager, |
| @@ -31,9 +32,17 @@ class MOJO_SERVICE_MANAGER_EXPORT BackgroundServiceLoader |
| virtual void OnServiceError(ServiceManager* manager, |
| const GURL& url) OVERRIDE; |
| + // Post a task to quit the MessageLoop we are running for the app when we |
| + // are destroyed. Most apps should quit themselves and not need this. |
| + // TODO(tim): Remove this method once applications are smart enough |
| + // to quit themselves. Bug 394477. |
| + void set_quit_on_shutdown() { quit_on_shutdown_ = true; } |
| private: |
|
sky
2014/07/31 20:59:33
nit: newline between 39 and 40.
tim (not reviewing)
2014/07/31 22:17:28
Done.
|
| class BackgroundLoader; |
| + // |base::DelegateSimpleThread::Delegate| method: |
| + virtual void Run() OVERRIDE; |
| + |
| // These functions are exected on the background thread. They call through |
| // to |background_loader_| to do the actual loading. |
| // TODO: having this code take a |manager| is fragile (as ServiceManager isn't |
| @@ -44,18 +53,27 @@ class MOJO_SERVICE_MANAGER_EXPORT BackgroundServiceLoader |
| ScopedMessagePipeHandle* shell_handle); |
| void OnServiceErrorOnBackgroundThread(ServiceManager* manager, |
| const GURL& url); |
| - void ShutdownOnBackgroundThread(); |
| - |
| + bool quit_on_shutdown_; |
| + bool loaded_service_; |
| scoped_ptr<ServiceLoader> loader_; |
| - base::Thread thread_; |
| - base::MessageLoop::Type message_loop_type_; |
| + |
| + const base::MessageLoop::Type message_loop_type_; |
| + |
| + // Created on |thread_| during construction of |this|. Protected against |
| + // uninitialized use by |message_loop_created_|, and protected against |
| + // use-after-free by holding a reference to the thread-safe object. Note |
| + // that holding a reference won't hold |thread_| from exiting. |
| + scoped_refptr<base::TaskRunner> task_runner_; |
| + base::WaitableEvent message_loop_created_; |
| + |
| + base::DelegateSimpleThread thread_; |
| // Lives on |thread_|. Trivial interface that calls through to |loader_|. |
| BackgroundLoader* background_loader_; |
| - DISALLOW_COPY_AND_ASSIGN(BackgroundServiceLoader); |
| + DISALLOW_COPY_AND_ASSIGN(BackgroundShellServiceLoader); |
| }; |
| } // namespace mojo |
| -#endif // MOJO_SERVICE_MANAGER_BACKGROUND_SERVICE_LOADER_H_ |
| +#endif // MOJO_SERVICE_MANAGER_BACKGROUND_SHELL_SERVICE_LOADER_H_ |