rAc - revert invalid suggestions to edit mode
[chromium-blink-merge.git] / mojo / shell / service_manager.h
blobb21393ad167443ca843c1e22cc08ee27e116de6a
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
3 // found in the LICENSE file.
5 #ifndef MOJO_SHELL_service_manager_H_
6 #define MOJO_SHELL_service_manager_H_
8 #include <map>
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "mojo/public/system/core_cpp.h"
13 #include "mojom/shell.h"
14 #include "url/gurl.h"
16 namespace mojo {
17 namespace shell {
19 class ServiceManager {
20 public:
21 // Interface to allowing default loading behavior to be overridden for a
22 // specific url.
23 class Loader {
24 public:
25 virtual ~Loader();
26 virtual void Load(const GURL& url,
27 ScopedShellHandle service_handle) = 0;
28 protected:
29 Loader();
32 // API for testing.
33 class TestAPI {
34 private:
35 friend class ServiceManagerTest;
36 explicit TestAPI(ServiceManager* manager) : manager_(manager) {}
37 // Returns true if there is a ServiceFactory for this URL.
38 bool HasFactoryForURL(const GURL& url) const;
40 ServiceManager* manager_;
43 ServiceManager();
44 ~ServiceManager();
46 // Sets the default Loader to be used if not overridden by SetLoaderForURL().
47 // Does not take ownership of |loader|.
48 void set_default_loader(Loader* loader) { default_loader_ = loader; }
49 // Sets a Loader to be used for a specific url.
50 // Does not take ownership of |loader|.
51 void SetLoaderForURL(Loader* loader, const GURL& gurl);
52 // Returns the Loader to use for a url (using default if not overridden.)
53 Loader* GetLoaderForURL(const GURL& gurl);
54 // Loads a service if necessary and establishes a new client connection.
55 void Connect(const GURL& url, ScopedMessagePipeHandle client_handle);
57 private:
58 class ServiceFactory;
60 // Removes a ServiceFactory when it no longer has any connections.
61 void RemoveServiceFactory(ServiceFactory* service_factory);
63 Loader* default_loader_;
64 typedef std::map<GURL, ServiceFactory*> ServiceFactoryMap;
65 ServiceFactoryMap url_to_service_factory_;
66 typedef std::map<GURL, Loader*> LoaderMap;
67 LoaderMap url_to_loader_;
68 DISALLOW_COPY_AND_ASSIGN(ServiceManager);
71 } // namespace shell
72 } // namespace mojo
74 #endif // MOJO_SHELL_service_manager_H_