| 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_SERVICE_LOADER_H_ | 5 #ifndef MOJO_SERVICE_MANAGER_BACKGROUND_SERVICE_LOADER_H_ |
| 6 #define MOJO_SERVICE_MANAGER_BACKGROUND_SERVICE_LOADER_H_ | 6 #define MOJO_SERVICE_MANAGER_BACKGROUND_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/threading/thread.h" | 10 #include "base/threading/thread.h" |
| 10 #include "mojo/service_manager/service_loader.h" | 11 #include "mojo/service_manager/service_loader.h" |
| 11 | 12 |
| 12 namespace mojo { | 13 namespace mojo { |
| 13 | 14 |
| 14 class ServiceManager; | 15 class ServiceManager; |
| 15 | 16 |
| 16 // ServiceLoader implementation that creates a background thread and issues load | 17 // ServiceLoader implementation that creates a background thread and issues load |
| 17 // requests there. | 18 // requests there. |
| 18 class MOJO_SERVICE_MANAGER_EXPORT BackgroundServiceLoader | 19 class MOJO_SERVICE_MANAGER_EXPORT BackgroundServiceLoader |
| 19 : public ServiceLoader { | 20 : public ServiceLoader { |
| 20 public: | 21 public: |
| 21 BackgroundServiceLoader(scoped_ptr<ServiceLoader> real_loader, | 22 BackgroundServiceLoader(scoped_ptr<ServiceLoader> real_loader, |
| 22 const char* thread_name); | 23 const char* thread_name, |
| 24 base::MessageLoop::Type message_loop_type); |
| 23 virtual ~BackgroundServiceLoader(); | 25 virtual ~BackgroundServiceLoader(); |
| 24 | 26 |
| 25 // ServiceLoader overrides: | 27 // ServiceLoader overrides: |
| 26 virtual void LoadService(ServiceManager* manager, | 28 virtual void LoadService(ServiceManager* manager, |
| 27 const GURL& url, | 29 const GURL& url, |
| 28 ScopedMessagePipeHandle service_handle) OVERRIDE; | 30 ScopedMessagePipeHandle service_handle) OVERRIDE; |
| 29 virtual void OnServiceError(ServiceManager* manager, | 31 virtual void OnServiceError(ServiceManager* manager, |
| 30 const GURL& url) OVERRIDE; | 32 const GURL& url) OVERRIDE; |
| 31 | 33 |
| 32 private: | 34 private: |
| 33 class BackgroundLoader; | 35 class BackgroundLoader; |
| 34 | 36 |
| 35 // These functions are exected on the background thread. They call through | 37 // These functions are exected on the background thread. They call through |
| 36 // to |background_loader_| to do the actual loading. | 38 // to |background_loader_| to do the actual loading. |
| 37 // TODO: having this code take a |manager| is fragile (as ServiceManager isn't | 39 // TODO: having this code take a |manager| is fragile (as ServiceManager isn't |
| 38 // thread safe). | 40 // thread safe). |
| 39 void LoadServiceOnBackgroundThread(ServiceManager* manager, | 41 void LoadServiceOnBackgroundThread(ServiceManager* manager, |
| 40 const GURL& url, | 42 const GURL& url, |
| 41 ScopedMessagePipeHandle* shell_handle); | 43 ScopedMessagePipeHandle* shell_handle); |
| 42 void OnServiceErrorOnBackgroundThread(ServiceManager* manager, | 44 void OnServiceErrorOnBackgroundThread(ServiceManager* manager, |
| 43 const GURL& url); | 45 const GURL& url); |
| 44 void ShutdownOnBackgroundThread(); | 46 void ShutdownOnBackgroundThread(); |
| 45 | 47 |
| 46 scoped_ptr<ServiceLoader> loader_; | 48 scoped_ptr<ServiceLoader> loader_; |
| 47 base::Thread thread_; | 49 base::Thread thread_; |
| 50 base::MessageLoop::Type message_loop_type_; |
| 48 | 51 |
| 49 // Lives on |thread_|. Trivial interface that calls through to |loader_|. | 52 // Lives on |thread_|. Trivial interface that calls through to |loader_|. |
| 50 BackgroundLoader* background_loader_; | 53 BackgroundLoader* background_loader_; |
| 51 | 54 |
| 52 DISALLOW_COPY_AND_ASSIGN(BackgroundServiceLoader); | 55 DISALLOW_COPY_AND_ASSIGN(BackgroundServiceLoader); |
| 53 }; | 56 }; |
| 54 | 57 |
| 55 } // namespace mojo | 58 } // namespace mojo |
| 56 | 59 |
| 57 #endif // MOJO_SERVICE_MANAGER_BACKGROUND_SERVICE_LOADER_H_ | 60 #endif // MOJO_SERVICE_MANAGER_BACKGROUND_SERVICE_LOADER_H_ |
| OLD | NEW |