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_
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "mojo/public/system/core_cpp.h"
13 #include "mojom/shell.h"
19 class ServiceManager
{
21 // Interface to allowing default loading behavior to be overridden for a
26 virtual void Load(const GURL
& url
,
27 ScopedShellHandle service_handle
) = 0;
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_
;
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
);
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
);
74 #endif // MOJO_SHELL_service_manager_H_