Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(978)

Unified Diff: content/renderer/mojo/blink_connector_impl.h

Issue 2643063002: Refactor Blink's ServiceConnector and add ability to mock in layout tests (Closed)
Patch Set: Fix build Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/renderer/BUILD.gn ('k') | content/renderer/mojo/blink_connector_impl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/mojo/blink_connector_impl.h
diff --git a/content/renderer/mojo/blink_connector_impl.h b/content/renderer/mojo/blink_connector_impl.h
new file mode 100644
index 0000000000000000000000000000000000000000..7b35ee5388b8e16f3dabc29d7645ab6b84d3e0f6
--- /dev/null
+++ b/content/renderer/mojo/blink_connector_impl.h
@@ -0,0 +1,73 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_RENDERER_MOJO_BLINK_CONNECTOR_IMPL_H_
+#define CONTENT_RENDERER_MOJO_BLINK_CONNECTOR_IMPL_H_
+
+#include "base/macros.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/weak_ptr.h"
+#include "content/common/content_export.h"
+#include "mojo/public/cpp/system/message_pipe.h"
+#include "services/service_manager/public/cpp/connector.h"
+#include "third_party/WebKit/public/platform/Connector.h"
+
+namespace base {
+class SingleThreadTaskRunner;
+}
+
+namespace content {
+
+// An implementation of blink::Connector that forwards to a
+// service_manager::Connector.
+class CONTENT_EXPORT BlinkConnectorImpl : public blink::Connector {
+ public:
+ explicit BlinkConnectorImpl(
+ std::unique_ptr<service_manager::Connector> connector);
+ ~BlinkConnectorImpl();
+
+ // blink::Connector override.
+ void bindInterface(const char* service_name,
+ const char* interface_name,
+ mojo::ScopedMessagePipeHandle handle) override;
+
+ void AddOverrideForTesting(
+ const std::string& service_name,
+ const std::string& interface_name,
+ const base::Callback<void(mojo::ScopedMessagePipeHandle)>& binder);
+
+ void ClearOverridesForTesting();
+
+ void SetConnector(std::unique_ptr<service_manager::Connector> connector) {
+ connector_ = std::move(connector);
+ }
+
+ base::WeakPtr<BlinkConnectorImpl> GetWeakPtr();
+
+ private:
+ using Binder = base::Callback<void(mojo::ScopedMessagePipeHandle)>;
+ using InterfaceBinderMap = std::map<std::string, Binder>;
+ using ServiceBinderMap =
+ std::map<std::string, std::unique_ptr<InterfaceBinderMap>>;
+
+ // Returns a pointer to the InterfaceBinderMap in action for |service_name|,
+ // or nullptr if |service_name| has no overrides in action.
+ InterfaceBinderMap* GetOverridesForService(const char* service_name);
+
+ // Maps service names to the per-interface overrides that have been set for
+ // that service.
+ ServiceBinderMap service_binders_;
+
+ std::unique_ptr<service_manager::Connector> connector_;
+
+ scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_;
+
+ base::WeakPtrFactory<BlinkConnectorImpl> weak_ptr_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(BlinkConnectorImpl);
+};
+
+} // namespace content
+
+#endif // CONTENT_RENDERER_MOJO_BLINK_CONNECTOR_IMPL_H_
« no previous file with comments | « content/renderer/BUILD.gn ('k') | content/renderer/mojo/blink_connector_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698