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/callback.h" | 10 #include "base/callback.h" |
11 #include "mojo/public/system/core_cpp.h" | 11 #include "mojo/public/system/core_cpp.h" |
12 #include "url/gurl.h" | 12 #include "url/gurl.h" |
13 | 13 |
14 namespace mojo { | 14 namespace mojo { |
15 namespace shell { | 15 namespace shell { |
16 | 16 |
17 class Context; | |
18 | |
19 class ServiceManager { | 17 class ServiceManager { |
20 public: | 18 public: |
19 // Interface to allowing default loading behavior to be overridden for a | |
20 // specific url. | |
21 class Loader { | 21 class Loader { |
22 public: | 22 public: |
23 virtual ~Loader(); | 23 virtual ~Loader(); |
24 virtual void Load(const GURL& url, | 24 virtual void Load(const GURL& url, |
25 ServiceManager* manager, | |
26 ScopedMessagePipeHandle service_handle) = 0; | 25 ScopedMessagePipeHandle service_handle) = 0; |
27 protected: | 26 protected: |
28 Loader(); | 27 Loader(); |
29 }; | 28 }; |
30 | 29 |
31 explicit ServiceManager(Context* context); | 30 ServiceManager(); |
32 ~ServiceManager(); | 31 ~ServiceManager(); |
33 | 32 |
33 // Sets the default Loader to be used if not overridden by SetLoaderForURL(). | |
34 void set_default_loader(Loader* loader) { default_loader_ = loader; } | |
viettrungluu
2014/01/03 17:44:49
Who owns the default loader? (Someone else.)
And w
DaveMoore
2014/01/03 18:05:49
I thought it would be cleaner to have the Loaders
viettrungluu
2014/01/03 18:23:14
I don't feel strongly, but then you should probabl
| |
35 // Sets a Loader to be used for a specific url. | |
34 void SetLoaderForURL(Loader* loader, const GURL& gurl); | 36 void SetLoaderForURL(Loader* loader, const GURL& gurl); |
37 // Returns the Loader to use for a url (using default if not overridden.) | |
35 Loader* GetLoaderForURL(const GURL& gurl); | 38 Loader* GetLoaderForURL(const GURL& gurl); |
39 // Loads a service if necessary and establishes a new client connection. | |
36 void Connect(const GURL& url, ScopedMessagePipeHandle client_handle); | 40 void Connect(const GURL& url, ScopedMessagePipeHandle client_handle); |
37 | 41 |
38 private: | 42 private: |
39 class Service; | 43 class Service; |
40 class DynamicLoader; | |
41 | 44 |
42 Context* context_; | 45 Loader* default_loader_; |
43 scoped_ptr<Loader> default_loader_; | |
44 typedef std::map<GURL, Service*> ServiceMap; | 46 typedef std::map<GURL, Service*> ServiceMap; |
45 ServiceMap url_to_service_; | 47 ServiceMap url_to_service_; |
46 typedef std::map<GURL, Loader*> LoaderMap; | 48 typedef std::map<GURL, Loader*> LoaderMap; |
47 LoaderMap url_to_loader_; | 49 LoaderMap url_to_loader_; |
48 DISALLOW_COPY_AND_ASSIGN(ServiceManager); | 50 DISALLOW_COPY_AND_ASSIGN(ServiceManager); |
viettrungluu
2014/01/03 17:44:49
nit: #include "base/basictypes.h", while you're at
DaveMoore
2014/01/03 18:05:49
Done.
| |
49 }; | 51 }; |
50 | 52 |
51 } // namespace shell | 53 } // namespace shell |
52 } // namespace mojo | 54 } // namespace mojo |
53 | 55 |
54 #endif // MOJO_SHELL_SERVICE_MANAGER_H_ | 56 #endif // MOJO_SHELL_SERVICE_MANAGER_H_ |
OLD | NEW |