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

Unified Diff: content/common/possibly_associated_interface_ptr.h

Issue 2858503002: Stop having two URLLoaderFactories in RendererBlinkPlatformImpl (Closed)
Patch Set: fix Created 3 years, 8 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/common/BUILD.gn ('k') | content/renderer/renderer_blink_platform_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/common/possibly_associated_interface_ptr.h
diff --git a/content/common/possibly_associated_interface_ptr.h b/content/common/possibly_associated_interface_ptr.h
new file mode 100644
index 0000000000000000000000000000000000000000..4d1bf57e8190f95a3c7eb2fc0ad16e3376ca1f2a
--- /dev/null
+++ b/content/common/possibly_associated_interface_ptr.h
@@ -0,0 +1,57 @@
+// 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_COMMON_POSSIBLY_ASSOCIATED_INTERFACE_PTR_H_
+#define CONTENT_COMMON_POSSIBLY_ASSOCIATED_INTERFACE_PTR_H_
kinuko 2017/05/02 08:29:20 I imagine/expect this'd be a temporary thing, does
yhirano 2017/05/02 08:53:40 Done.
+
+#include "base/macros.h"
+#include "mojo/public/cpp/bindings/associated_interface_ptr.h"
+#include "mojo/public/cpp/bindings/interface_ptr.h"
+
+namespace content {
+
+// PossiblyAssociatedInterfacePtr<T> contains mojo::InterfacePtr<T> or
+// mojo::AssociatedInterfacePtr<T>, but not both. Mojo-related functions in
+// mojo::InterfacePtr<T> and mojo::AssociatedInterfacePtr<T> are not accessible,
+// but a user can access the raw pointer to the interface.
+template <typename T>
+class PossiblyAssociatedInterfacePtr final {
+ public:
+ PossiblyAssociatedInterfacePtr() {}
+ PossiblyAssociatedInterfacePtr(std::nullptr_t) {}
+ PossiblyAssociatedInterfacePtr(mojo::InterfacePtr<T> independent_ptr)
+ : independent_ptr_(std::move(independent_ptr)) {}
+ PossiblyAssociatedInterfacePtr(mojo::AssociatedInterfacePtr<T> associated_ptr)
+ : associated_ptr_(std::move(associated_ptr)) {}
+
+ PossiblyAssociatedInterfacePtr(PossiblyAssociatedInterfacePtr&& other) {
+ independent_ptr_ = std::move(other.independent_ptr_);
+ associated_ptr_ = std::move(other.associated_ptr_);
+ }
+ ~PossiblyAssociatedInterfacePtr() {}
+
+ PossiblyAssociatedInterfacePtr& operator=(
+ PossiblyAssociatedInterfacePtr&& other) {
+ independent_ptr_ = std::move(other.independent_ptr_);
+ associated_ptr_ = std::move(other.associated_ptr_);
+ return *this;
+ }
+
+ T* get() const {
+ return independent_ptr_ ? independent_ptr_.get() : associated_ptr_.get();
+ }
+ T* operator->() const { return get(); }
+ T& operator*() const { return *get(); }
+ explicit operator bool() const { return get(); }
+
+ private:
+ mojo::InterfacePtr<T> independent_ptr_;
+ mojo::AssociatedInterfacePtr<T> associated_ptr_;
+
+ DISALLOW_COPY_AND_ASSIGN(PossiblyAssociatedInterfacePtr);
+};
+
+} // namespace content
+
+#endif // CONTENT_COMMON_POSSIBLY_ASSOCIATED_INTERFACE_PTR_H_
« no previous file with comments | « content/common/BUILD.gn ('k') | content/renderer/renderer_blink_platform_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698