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

Unified Diff: chrome/browser/sync/util/weak_handle.h

Issue 8568041: [Sync] Add type conversion constructor for WeakHandle (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Clean up tests a bit Created 9 years, 1 month 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 | « chrome/browser/sync/sync_js_controller.cc ('k') | chrome/browser/sync/util/weak_handle_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/sync/util/weak_handle.h
diff --git a/chrome/browser/sync/util/weak_handle.h b/chrome/browser/sync/util/weak_handle.h
index 2ce3d8092c1763f06d4dadfcd437c0c02b524a14..3c9269782682350f74379b81bf14b4a10b25c0e0 100644
--- a/chrome/browser/sync/util/weak_handle.h
+++ b/chrome/browser/sync/util/weak_handle.h
@@ -54,6 +54,7 @@
#include "base/bind.h"
#include "base/callback.h"
#include "base/compiler_specific.h"
+#include "base/gtest_prod_util.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/memory/ref_counted.h"
@@ -280,6 +281,17 @@ class WeakHandle {
explicit WeakHandle(const base::WeakPtr<T>& ptr)
: core_(new internal::WeakHandleCore<T>(ptr)) {}
+ // Allow conversion from WeakHandle<U> to WeakHandle<T> if U is
+ // convertible to T, but we *must* be on |other|'s owner thread.
+ // Note that this doesn't override the regular copy constructor, so
+ // that one can be called on any thread.
+ template <typename U>
+ WeakHandle(const browser_sync::WeakHandle<U>& other) // NOLINT
+ : core_(
+ other.IsInitialized() ?
+ new internal::WeakHandleCore<T>(other.Get()) :
+ NULL) {}
+
// Returns true iff this WeakHandle is initialized. Note that being
// initialized isn't a guarantee that the underlying object is still
// alive.
@@ -348,6 +360,11 @@ class WeakHandle {
}
private:
+ FRIEND_TEST_ALL_PREFIXES(WeakHandleTest,
+ TypeConversionConstructor);
+ FRIEND_TEST_ALL_PREFIXES(WeakHandleTest,
+ TypeConversionConstructorAssignment);
+
scoped_refptr<internal::WeakHandleCore<T> > core_;
};
« no previous file with comments | « chrome/browser/sync/sync_js_controller.cc ('k') | chrome/browser/sync/util/weak_handle_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698