#ifndef MOJO_SERVICE_MANAGER_SERVICE_MANAGER_H_
#define MOJO_SERVICE_MANAGER_SERVICE_MANAGER_H_
#include <map>
#include "base/basictypes.h"
#include "base/callback.h"
#include "base/gtest_prod_util.h"
#include "mojo/public/interfaces/shell/shell.mojom.h"
#include "mojo/service_manager/service_manager_export.h"
#include "url/gurl.h"
namespace content {
class MojoTest;
}
namespace mojo {
class ServiceLoader;
class MOJO_SERVICE_MANAGER_EXPORT ServiceManager {
public:
class MOJO_SERVICE_MANAGER_EXPORT TestAPI {
private:
friend class ServiceManagerTest;
friend class content::MojoTest;
explicit TestAPI(ServiceManager* manager) : manager_(manager) {}
static bool HasCreatedInstance();
bool HasFactoryForURL(const GURL& url) const;
ServiceManager* manager_;
};
ServiceManager();
~ServiceManager();
static ServiceManager* GetInstance();
void Connect(const GURL& url, ScopedMessagePipeHandle client_handle);
void set_default_loader(ServiceLoader* loader) { default_loader_ = loader; }
void SetLoaderForURL(ServiceLoader* loader, const GURL& url);
void SetLoaderForScheme(ServiceLoader* loader, const std::string& scheme);
private:
class ServiceFactory;
typedef std::map<std::string, ServiceLoader*> SchemeToLoaderMap;
typedef std::map<GURL, ServiceLoader*> URLToLoaderMap;
typedef std::map<GURL, ServiceFactory*> URLToServiceFactoryMap;
ServiceLoader* GetLoaderForURL(const GURL& url);
void OnServiceFactoryError(ServiceFactory* service_factory);
URLToLoaderMap url_to_loader_;
SchemeToLoaderMap scheme_to_loader_;
ServiceLoader* default_loader_;
URLToServiceFactoryMap url_to_service_factory_;
DISALLOW_COPY_AND_ASSIGN(ServiceManager);
};
}
#endif