| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_SHELL_SERVICE_MANAGER_H_ | 5 #ifndef MOJO_SHELL_SERVICE_MANAGER_H_ |
| 6 #define MOJO_SHELL_SERVICE_MANAGER_H_ | 6 #define MOJO_SHELL_SERVICE_MANAGER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/basictypes.h" |
| 10 #include "base/callback.h" | 11 #include "base/callback.h" |
| 11 #include "mojo/public/system/core_cpp.h" | 12 #include "mojo/public/system/core_cpp.h" |
| 12 #include "url/gurl.h" | 13 #include "url/gurl.h" |
| 13 | 14 |
| 14 namespace mojo { | 15 namespace mojo { |
| 15 namespace shell { | 16 namespace shell { |
| 16 | 17 |
| 17 class Context; | |
| 18 | |
| 19 class ServiceManager { | 18 class ServiceManager { |
| 20 public: | 19 public: |
| 20 // Interface to allowing default loading behavior to be overridden for a |
| 21 // specific url. |
| 21 class Loader { | 22 class Loader { |
| 22 public: | 23 public: |
| 23 virtual ~Loader(); | 24 virtual ~Loader(); |
| 24 virtual void Load(const GURL& url, | 25 virtual void Load(const GURL& url, |
| 25 ServiceManager* manager, | |
| 26 ScopedMessagePipeHandle service_handle) = 0; | 26 ScopedMessagePipeHandle service_handle) = 0; |
| 27 protected: | 27 protected: |
| 28 Loader(); | 28 Loader(); |
| 29 }; | 29 }; |
| 30 | 30 |
| 31 explicit ServiceManager(Context* context); | 31 ServiceManager(); |
| 32 ~ServiceManager(); | 32 ~ServiceManager(); |
| 33 | 33 |
| 34 // Sets the default Loader to be used if not overridden by SetLoaderForURL(). |
| 35 // Does not take ownership of |loader|. |
| 36 void set_default_loader(Loader* loader) { default_loader_ = loader; } |
| 37 // Sets a Loader to be used for a specific url. |
| 38 // Does not take ownership of |loader|. |
| 34 void SetLoaderForURL(Loader* loader, const GURL& gurl); | 39 void SetLoaderForURL(Loader* loader, const GURL& gurl); |
| 40 // Returns the Loader to use for a url (using default if not overridden.) |
| 35 Loader* GetLoaderForURL(const GURL& gurl); | 41 Loader* GetLoaderForURL(const GURL& gurl); |
| 42 // Loads a service if necessary and establishes a new client connection. |
| 36 void Connect(const GURL& url, ScopedMessagePipeHandle client_handle); | 43 void Connect(const GURL& url, ScopedMessagePipeHandle client_handle); |
| 37 | 44 |
| 38 private: | 45 private: |
| 39 class Service; | 46 class Service; |
| 40 class DynamicLoader; | |
| 41 | 47 |
| 42 Context* context_; | 48 Loader* default_loader_; |
| 43 scoped_ptr<Loader> default_loader_; | |
| 44 typedef std::map<GURL, Service*> ServiceMap; | 49 typedef std::map<GURL, Service*> ServiceMap; |
| 45 ServiceMap url_to_service_; | 50 ServiceMap url_to_service_; |
| 46 typedef std::map<GURL, Loader*> LoaderMap; | 51 typedef std::map<GURL, Loader*> LoaderMap; |
| 47 LoaderMap url_to_loader_; | 52 LoaderMap url_to_loader_; |
| 48 DISALLOW_COPY_AND_ASSIGN(ServiceManager); | 53 DISALLOW_COPY_AND_ASSIGN(ServiceManager); |
| 49 }; | 54 }; |
| 50 | 55 |
| 51 } // namespace shell | 56 } // namespace shell |
| 52 } // namespace mojo | 57 } // namespace mojo |
| 53 | 58 |
| 54 #endif // MOJO_SHELL_SERVICE_MANAGER_H_ | 59 #endif // MOJO_SHELL_SERVICE_MANAGER_H_ |
| OLD | NEW |