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

Unified Diff: content/public/browser/remote_frame_interface.h

Issue 2310563002: Adds routed interface support between RenderFrameHost and RenderFrame (Closed)
Patch Set: Created 4 years, 3 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
Index: content/public/browser/remote_frame_interface.h
diff --git a/content/public/browser/remote_frame_interface.h b/content/public/browser/remote_frame_interface.h
new file mode 100644
index 0000000000000000000000000000000000000000..2b39694819069a82fe52eb3184dd6f354362603c
--- /dev/null
+++ b/content/public/browser/remote_frame_interface.h
@@ -0,0 +1,47 @@
+// Copyright 2016 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_PUBLIC_BROWSER_REMOTE_FRAME_INTERFACE_H_
+#define CONTENT_PUBLIC_BROWSER_REMOTE_FRAME_INTERFACE_H_
+
+#include <unordered_map>
+#include <utility>
+
+#include "base/macros.h"
+#include "content/public/browser/render_frame_host.h"
+#include "mojo/public/cpp/bindings/associated_interface_ptr.h"
+
+namespace content {
+
+// A helper class which caches associated interface proxies per RenderFrameHost.
+template <typename Interface>
+class RemoteFrameInterface {
+ public:
+ RemoteFrameInterface() = default;
+ ~RemoteFrameInterface() = default;
+
+ Interface* ForFrame(RenderFrameHost* render_frame_host) {
+ auto it = frame_proxies_.find(render_frame_host);
+ if (it == frame_proxies_.end()) {
+ ProxyType proxy;
+ render_frame_host->GetRemoteRoutedInterface(&proxy);
+ auto result = frame_proxies_.insert(
+ std::make_pair(render_frame_host, std::move(proxy)));
+ DCHECK(result.second);
+ it = result.first;
+ }
+ return it->second.get();
+ }
+
+ private:
+ using ProxyType = mojo::AssociatedInterfacePtr<Interface>;
+
+ std::unordered_map<RenderFrameHost*, ProxyType> frame_proxies_;
+
+ DISALLOW_COPY_AND_ASSIGN(RemoteFrameInterface);
+};
+
+} // namespace content
+
+#endif // CONTENT_PUBLIC_BROWSER_REMOTE_FRAME_INTERFACE_H_

Powered by Google App Engine
This is Rietveld 408576698