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