Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / mojo / service_manager / service_manager.h
index 513c792..81e129a 100644 (file)
@@ -8,35 +8,47 @@
 #include <map>
 
 #include "base/basictypes.h"
-#include "base/callback.h"
 #include "base/gtest_prod_util.h"
-#include "mojo/public/shell/shell.mojom.h"
+#include "base/memory/scoped_ptr.h"
+#include "mojo/public/interfaces/shell/shell.mojom.h"
+#include "mojo/service_manager/service_loader.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:
   // API for testing.
   class MOJO_SERVICE_MANAGER_EXPORT TestAPI {
-   private:
-    friend class ServiceManagerTest;
-    friend class content::MojoTest;
+   public:
+    explicit TestAPI(ServiceManager* manager);
+    ~TestAPI();
+
+    // Returns a handle to a unique shell instance.
+    ScopedMessagePipeHandle GetShellHandle();
 
-    explicit TestAPI(ServiceManager* manager) : manager_(manager) {}
     // Returns true if the shared instance has been created.
     static bool HasCreatedInstance();
     // Returns true if there is a ServiceFactory for this URL.
     bool HasFactoryForURL(const GURL& url) const;
 
+   private:
+    class TestShellConnection;
+
     ServiceManager* manager_;
+    scoped_ptr<TestShellConnection> shell_;
+
+    DISALLOW_COPY_AND_ASSIGN(TestAPI);
+  };
+
+  // Interface class for debugging only.
+  class Interceptor {
+   public:
+    virtual ~Interceptor() {}
+    // Called when ServiceManager::Connect is called.
+    virtual ScopedMessagePipeHandle OnConnectToClient(
+        const GURL& url, ScopedMessagePipeHandle handle) = 0;
   };
 
   ServiceManager();
@@ -48,16 +60,18 @@ class MOJO_SERVICE_MANAGER_EXPORT ServiceManager {
   // Loads a service if necessary and establishes a new client connection.
   void Connect(const GURL& url, ScopedMessagePipeHandle client_handle);
 
-  // Sets the default Loader to be used if not overridden by
-  // SetLoaderForURL() or SetLoaderForScheme().
-  // Does not take ownership of |loader|.
-  void set_default_loader(ServiceLoader* loader) { default_loader_ = loader; }
+  // Sets the default Loader to be used if not overridden by SetLoaderForURL()
+  // or SetLoaderForScheme().
+  void set_default_loader(scoped_ptr<ServiceLoader> loader) {
+    default_loader_ = loader.Pass();
+  }
   // Sets a Loader to be used for a specific url.
-  // Does not take ownership of |loader|.
-  void SetLoaderForURL(ServiceLoader* loader, const GURL& url);
+  void SetLoaderForURL(scoped_ptr<ServiceLoader> loader, const GURL& url);
   // Sets a Loader to be used for a specific url scheme.
-  // Does not take ownership of |loader|.
-  void SetLoaderForScheme(ServiceLoader* loader, const std::string& scheme);
+  void SetLoaderForScheme(scoped_ptr<ServiceLoader> loader,
+                          const std::string& scheme);
+  // Allows to interpose a debugger to service connections.
+  void SetInterceptor(Interceptor* interceptor);
 
  private:
   class ServiceFactory;
@@ -70,13 +84,14 @@ class MOJO_SERVICE_MANAGER_EXPORT ServiceManager {
   // then one that's been specified for a scheme, then the default.
   ServiceLoader* GetLoaderForURL(const GURL& url);
 
-  // Removes a ServiceFactory when it no longer has any connections.
+  // Removes a ServiceFactory when it encounters an error.
   void OnServiceFactoryError(ServiceFactory* service_factory);
 
   // Loader management.
   URLToLoaderMap url_to_loader_;
   SchemeToLoaderMap scheme_to_loader_;
-  ServiceLoader* default_loader_;
+  scoped_ptr<ServiceLoader> default_loader_;
+  Interceptor* interceptor_;
 
   URLToServiceFactoryMap url_to_service_factory_;
   DISALLOW_COPY_AND_ASSIGN(ServiceManager);