From b5d1f3f32f08c4d58e58a3214e527e2a3e191d43 Mon Sep 17 00:00:00 2001 From: "akalin@chromium.org" Date: Fri, 20 Jan 2012 09:51:42 +0000 Subject: Summary of changes to cacheinvalidation client: - adds ResourceComponent and BasicSystemResources - adds unit tests for ProtocolHandler - adds delay before sending first message after restart, to avoid unnecessary and expensive invocation of registration sync protocol - adds a check to prevent Start() from being called multiple times - deletes all v1 code and overrides - various internal cleanups and minor refactorings Review URL: https://chromiumcodereview.appspot.com/9185038 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@118425 0039d316-1c4b-4281-b951-d872f2087c98 --- .../cacheinvalidation/cacheinvalidation.gyp | 31 +++-- .../overrides/google/cacheinvalidation/callback.h | 126 --------------------- .../google/cacheinvalidation/compiler-specific.h | 10 -- .../overrides/google/cacheinvalidation/gmock.h | 10 -- .../google/cacheinvalidation/googletest.h | 10 -- .../overrides/google/cacheinvalidation/hash_map.h | 16 --- .../overrides/google/cacheinvalidation/logging.h | 16 --- .../overrides/google/cacheinvalidation/md5.h | 18 --- .../overrides/google/cacheinvalidation/mutex.h | 26 ----- .../overrides/google/cacheinvalidation/random.h | 25 ---- .../google/cacheinvalidation/scoped_ptr.h | 16 --- .../google/cacheinvalidation/stl-namespace.h | 10 -- .../google/cacheinvalidation/string_util.h | 16 --- .../overrides/google/cacheinvalidation/time.h | 16 --- .../google/cacheinvalidation/v2/callback.h | 126 +++++++++++++++++++++ .../overrides/google/cacheinvalidation/v2/gmock.h | 91 +++++++++++++++ .../google/cacheinvalidation/v2/googletest.h | 10 ++ .../overrides/google/cacheinvalidation/v2/random.h | 25 ++++ .../cacheinvalidation/v2/sha1-digest-function.h | 4 +- .../google/cacheinvalidation/v2/stl-namespace.h | 10 ++ 20 files changed, 284 insertions(+), 328 deletions(-) create mode 100644 third_party/cacheinvalidation/overrides/google/cacheinvalidation/v2/callback.h create mode 100644 third_party/cacheinvalidation/overrides/google/cacheinvalidation/v2/gmock.h create mode 100644 third_party/cacheinvalidation/overrides/google/cacheinvalidation/v2/googletest.h create mode 100644 third_party/cacheinvalidation/overrides/google/cacheinvalidation/v2/random.h create mode 100644 third_party/cacheinvalidation/overrides/google/cacheinvalidation/v2/stl-namespace.h (limited to 'third_party/cacheinvalidation') diff --git a/third_party/cacheinvalidation/cacheinvalidation.gyp b/third_party/cacheinvalidation/cacheinvalidation.gyp index 4e0ae02..5c5a2a7 100644 --- a/third_party/cacheinvalidation/cacheinvalidation.gyp +++ b/third_party/cacheinvalidation/cacheinvalidation.gyp @@ -28,6 +28,7 @@ 'type': 'none', 'sources': [ '<(proto_dir_root)/<(proto_dir_relpath)/client.proto', + '<(proto_dir_root)/<(proto_dir_relpath)/client_gateway.proto', '<(proto_dir_root)/<(proto_dir_relpath)/client_protocol.proto', '<(proto_dir_root)/<(proto_dir_relpath)/client_test_internal.proto', '<(proto_dir_root)/<(proto_dir_relpath)/types.proto', @@ -67,6 +68,8 @@ 'sources': [ '<(protoc_out_dir)/<(proto_dir_relpath)/client.pb.h', '<(protoc_out_dir)/<(proto_dir_relpath)/client.pb.cc', + '<(protoc_out_dir)/<(proto_dir_relpath)/client_gateway.pb.h', + '<(protoc_out_dir)/<(proto_dir_relpath)/client_gateway.pb.cc', '<(protoc_out_dir)/<(proto_dir_relpath)/client_protocol.pb.h', '<(protoc_out_dir)/<(proto_dir_relpath)/client_protocol.pb.cc', '<(protoc_out_dir)/<(proto_dir_relpath)/client_test_internal.pb.h', @@ -99,27 +102,29 @@ 'target_name': 'cacheinvalidation', 'type': 'static_library', 'sources': [ - 'overrides/google/cacheinvalidation/callback.h', - 'overrides/google/cacheinvalidation/compiler-specific.h', - 'overrides/google/cacheinvalidation/gmock.h', - 'overrides/google/cacheinvalidation/googletest.h', + 'overrides/google/cacheinvalidation/v2/callback.h', + 'overrides/google/cacheinvalidation/v2/gmock.h', + 'overrides/google/cacheinvalidation/v2/googletest.h', 'overrides/google/cacheinvalidation/v2/logging.h', - 'overrides/google/cacheinvalidation/md5.h', 'overrides/google/cacheinvalidation/v2/mutex.h', - 'overrides/google/cacheinvalidation/random.h', + 'overrides/google/cacheinvalidation/v2/random.h', 'overrides/google/cacheinvalidation/v2/scoped_ptr.h', - 'overrides/google/cacheinvalidation/stl-namespace.h', + 'overrides/google/cacheinvalidation/v2/stl-namespace.h', 'overrides/google/cacheinvalidation/v2/string_util.h', 'overrides/google/cacheinvalidation/v2/time.h', + 'files/src/google/cacheinvalidation/v2/basic-system-resources.cc', + 'files/src/google/cacheinvalidation/v2/basic-system-resources.h', 'files/src/google/cacheinvalidation/v2/checking-invalidation-listener.cc', 'files/src/google/cacheinvalidation/v2/checking-invalidation-listener.h', 'files/src/google/cacheinvalidation/v2/client-protocol-namespace-fix.h', - 'files/src/google/cacheinvalidation/v2/constants.h', 'files/src/google/cacheinvalidation/v2/constants.cc', + 'files/src/google/cacheinvalidation/v2/constants.h', 'files/src/google/cacheinvalidation/v2/digest-function.h', 'files/src/google/cacheinvalidation/v2/digest-store.h', - 'files/src/google/cacheinvalidation/v2/exponential-backoff-delay-generator.h', 'files/src/google/cacheinvalidation/v2/exponential-backoff-delay-generator.cc', + 'files/src/google/cacheinvalidation/v2/exponential-backoff-delay-generator.h', + 'files/src/google/cacheinvalidation/v2/invalidation-client-factory.cc', + 'files/src/google/cacheinvalidation/v2/invalidation-client-factory.h', 'files/src/google/cacheinvalidation/v2/invalidation-client-impl.cc', 'files/src/google/cacheinvalidation/v2/invalidation-client-impl.h', 'files/src/google/cacheinvalidation/v2/invalidation-client.h', @@ -153,8 +158,8 @@ 'files/src/google/cacheinvalidation/v2/system-resources.h', 'files/src/google/cacheinvalidation/v2/throttle.cc', 'files/src/google/cacheinvalidation/v2/throttle.h', - 'files/src/google/cacheinvalidation/v2/ticl-message-validator.h', 'files/src/google/cacheinvalidation/v2/ticl-message-validator.cc', + 'files/src/google/cacheinvalidation/v2/ticl-message-validator.h', 'files/src/google/cacheinvalidation/v2/time.h', 'files/src/google/cacheinvalidation/v2/types.h', ], @@ -188,8 +193,12 @@ 'type': 'executable', 'sources': [ '../../base/test/run_all_unittests.cc', + 'files/src/google/cacheinvalidation/v2/test/deterministic-scheduler.cc', 'files/src/google/cacheinvalidation/v2/test/deterministic-scheduler.h', - 'files/src/google/cacheinvalidation/v2/test/throttle_test.cc', + 'files/src/google/cacheinvalidation/v2/test/test-logger.cc', + 'files/src/google/cacheinvalidation/v2/test/test-logger.h', + 'files/src/google/cacheinvalidation/v2/protocol-handler_test.cc', + 'files/src/google/cacheinvalidation/v2/throttle_test.cc', ], 'dependencies': [ '../../base/base.gyp:base', diff --git a/third_party/cacheinvalidation/overrides/google/cacheinvalidation/callback.h b/third_party/cacheinvalidation/overrides/google/cacheinvalidation/callback.h index ae09809..e69de29 100644 --- a/third_party/cacheinvalidation/overrides/google/cacheinvalidation/callback.h +++ b/third_party/cacheinvalidation/overrides/google/cacheinvalidation/callback.h @@ -1,126 +0,0 @@ -// Copyright (c) 2011 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 GOOGLE_CACHEINVALIDATION_CALLBACK_H_ -#define GOOGLE_CACHEINVALIDATION_CALLBACK_H_ - -#include "base/bind.h" -#include "base/callback.h" - -#define INVALIDATION_CALLBACK1_TYPE(Arg1) ::base::Callback - -// Below are a collection of types and functions that adapt base::Callback's -// pass-by-value semantics to the pointer-based callback system that -// cacheinvalidation needs. - -namespace invalidation { - -typedef ::base::Closure Closure; - -static inline void DoNothing() {} - -template -bool IsCallbackRepeatable(const T* callback) { - // The default cacheinvalidation Callbacks may be self-deleting. We don't - // support this behave, so we already return true to indicate that the - // cacheinvalidation implementation should delete our Callbacks. - return true; -} - -namespace internal { - -// Identity::type is a typedef of T. Useful for preventing the -// compiler from inferring the type of an argument in templates. -template -struct Identity { - typedef T type; -}; - -} // namespace internal - -// The cacheinvalidation callback system expects to take the callback by -// pointer and handle the ownership semantics itself. Adapting the -// Chromium Callback system requires returning a dynamically allocated -// copy of the result of Bind(). - -inline Closure* NewPermanentCallback(void (*fn)()) { - return new ::base::Closure(::base::Bind(fn)); -} - -template -Closure* NewPermanentCallback( - T1* object, void (T2::*method)()) { - return new ::base::Closure(::base::Bind(method, base::Unretained(object))); -} - -template -::base::Callback* NewPermanentCallback( - T1* object, void (T2::*method)(Arg1)) { - return new ::base::Callback( - ::base::Bind(method, base::Unretained(object))); -} - -template -Closure* NewPermanentCallback( - T1* object, - void (T2::*method)(Arg1), - typename internal::Identity::type arg1) { - return new ::base::Closure(::base::Bind(method, base::Unretained(object), - arg1)); -} - -template -Closure* NewPermanentCallback( - void (*fn)(Arg1, Arg2), - typename internal::Identity::type arg1, - typename internal::Identity::type arg2) { - return new ::base::Closure(::base::Bind(fn, arg1, arg2)); -} - -template -Closure* NewPermanentCallback( - T1* object, - void (T2::*method)(Arg1, Arg2), - typename internal::Identity::type arg1, - typename internal::Identity::type arg2) { - return new ::base::Closure(::base::Bind(method, base::Unretained(object), - arg1, arg2)); -} - -template -::base::Callback* NewPermanentCallback( - T1* object, - void (T2::*method)(Arg1, Arg2), - typename internal::Identity::type arg1) { - return new ::base::Callback( - ::base::Bind(method, base::Unretained(object), arg1)); -} - -template -Closure* NewPermanentCallback( - T1* object, - void (T2::*method)(Arg1, Arg2, Arg3), - typename internal::Identity::type arg1, - typename internal::Identity::type arg2, - typename internal::Identity::type arg3) { - return new ::base::Closure(::base::Bind(method, base::Unretained(object), - arg1, arg2, arg3)); -} - -template -Closure* NewPermanentCallback( - T1* object, - void (T2::*method)(Arg1, Arg2, Arg3, Arg4), - typename internal::Identity::type arg1, - typename internal::Identity::type arg2, - typename internal::Identity::type arg3, - typename internal::Identity::type arg4) { - return new ::base::Closure(::base::Bind(method, base::Unretained(object), - arg1, arg2, arg3, arg4)); -} - -} // namespace invalidation - -#endif // GOOGLE_CACHEINVALIDATION_CALLBACK_H_ diff --git a/third_party/cacheinvalidation/overrides/google/cacheinvalidation/compiler-specific.h b/third_party/cacheinvalidation/overrides/google/cacheinvalidation/compiler-specific.h index 5ca6b57..e69de29 100644 --- a/third_party/cacheinvalidation/overrides/google/cacheinvalidation/compiler-specific.h +++ b/third_party/cacheinvalidation/overrides/google/cacheinvalidation/compiler-specific.h @@ -1,10 +0,0 @@ -// Copyright (c) 2010 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 GOOGLE_CACHEINVALIDATION_COMPILER_SPECIFIC_H_ -#define GOOGLE_CACHEINVALIDATION_COMPILER_SPECIFIC_H_ - -#include "base/compiler_specific.h" - -#endif // GOOGLE_CACHEINVALIDATION_COMPILER_SPECIFIC_H_ diff --git a/third_party/cacheinvalidation/overrides/google/cacheinvalidation/gmock.h b/third_party/cacheinvalidation/overrides/google/cacheinvalidation/gmock.h index 8afb9fb..e69de29 100644 --- a/third_party/cacheinvalidation/overrides/google/cacheinvalidation/gmock.h +++ b/third_party/cacheinvalidation/overrides/google/cacheinvalidation/gmock.h @@ -1,10 +0,0 @@ -// Copyright (c) 2010 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 GOOGLE_CACHEINVALIDATION_GMOCK_H_ -#define GOOGLE_CACHEINVALIDATION_GMOCK_H_ - -#include "testing/gmock/include/gmock/gmock.h" - -#endif // GOOGLE_CACHEINVALIDATION_GMOCK_H_ diff --git a/third_party/cacheinvalidation/overrides/google/cacheinvalidation/googletest.h b/third_party/cacheinvalidation/overrides/google/cacheinvalidation/googletest.h index f24bd56..e69de29 100644 --- a/third_party/cacheinvalidation/overrides/google/cacheinvalidation/googletest.h +++ b/third_party/cacheinvalidation/overrides/google/cacheinvalidation/googletest.h @@ -1,10 +0,0 @@ -// Copyright (c) 2010 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 GOOGLE_CACHEINVALIDATION_GOOGLETEST_H_ -#define GOOGLE_CACHEINVALIDATION_GOOGLETEST_H_ - -#include "testing/gtest/include/gtest/gtest.h" - -#endif // GOOGLE_CACHEINVALIDATION_GOOGLETEST_H_ diff --git a/third_party/cacheinvalidation/overrides/google/cacheinvalidation/hash_map.h b/third_party/cacheinvalidation/overrides/google/cacheinvalidation/hash_map.h index 3dbe724..e69de29 100644 --- a/third_party/cacheinvalidation/overrides/google/cacheinvalidation/hash_map.h +++ b/third_party/cacheinvalidation/overrides/google/cacheinvalidation/hash_map.h @@ -1,16 +0,0 @@ -// Copyright (c) 2010 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 GOOGLE_CACHEINVALIDATION_HASH_MAP_H_ -#define GOOGLE_CACHEINVALIDATION_HASH_MAP_H_ - -#include "base/hash_tables.h" - -namespace invalidation { - -using base::hash_map; - -} // namespace invalidation - -#endif // GOOGLE_CACHEINVALIDATION_HASH_MAP_H_ diff --git a/third_party/cacheinvalidation/overrides/google/cacheinvalidation/logging.h b/third_party/cacheinvalidation/overrides/google/cacheinvalidation/logging.h index b1c76cf..e69de29 100644 --- a/third_party/cacheinvalidation/overrides/google/cacheinvalidation/logging.h +++ b/third_party/cacheinvalidation/overrides/google/cacheinvalidation/logging.h @@ -1,16 +0,0 @@ -// Copyright (c) 2010 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 GOOGLE_CACHEINVALIDATION_LOGGING_H_ -#define GOOGLE_CACHEINVALIDATION_LOGGING_H_ - -#include "base/logging.h" - -namespace invalidation { - -using logging::LogMessage; - -} // namespace invalidation - -#endif // GOOGLE_CACHEINVALIDATION_LOGGING_H_ diff --git a/third_party/cacheinvalidation/overrides/google/cacheinvalidation/md5.h b/third_party/cacheinvalidation/overrides/google/cacheinvalidation/md5.h index 5627db1..e69de29 100644 --- a/third_party/cacheinvalidation/overrides/google/cacheinvalidation/md5.h +++ b/third_party/cacheinvalidation/overrides/google/cacheinvalidation/md5.h @@ -1,18 +0,0 @@ -// Copyright (c) 2010 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 GOOGLE_CACHEINVALIDATION_MD5_H_ -#define GOOGLE_CACHEINVALIDATION_MD5_H_ - -#include "base/md5.h" - -namespace invalidation { - -inline void ComputeMd5Digest(const string& data, string* digest) { - *digest = MD5String(data); -} - -} // namespace invalidation - -#endif // GOOGLE_CACHEINVALIDATION_MD5_H_ diff --git a/third_party/cacheinvalidation/overrides/google/cacheinvalidation/mutex.h b/third_party/cacheinvalidation/overrides/google/cacheinvalidation/mutex.h index 4d64f0f..e69de29 100644 --- a/third_party/cacheinvalidation/overrides/google/cacheinvalidation/mutex.h +++ b/third_party/cacheinvalidation/overrides/google/cacheinvalidation/mutex.h @@ -1,26 +0,0 @@ -// Copyright (c) 2010 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 GOOGLE_CACHEINVALIDATION_MUTEX_H_ -#define GOOGLE_CACHEINVALIDATION_MUTEX_H_ - -#include "base/logging.h" -#include "base/synchronization/lock.h" - -namespace invalidation { - -typedef base::Lock Mutex; - -class MutexLock { - public: - explicit MutexLock(Mutex* m) : auto_lock_(*m) {} - - private: - base::AutoLock auto_lock_; - DISALLOW_COPY_AND_ASSIGN(MutexLock); -}; - -} // namespace invalidation - -#endif // GOOGLE_CACHEINVALIDATION_MUTEX_H_ diff --git a/third_party/cacheinvalidation/overrides/google/cacheinvalidation/random.h b/third_party/cacheinvalidation/overrides/google/cacheinvalidation/random.h index 89455f6..e69de29 100644 --- a/third_party/cacheinvalidation/overrides/google/cacheinvalidation/random.h +++ b/third_party/cacheinvalidation/overrides/google/cacheinvalidation/random.h @@ -1,25 +0,0 @@ -// Copyright (c) 2010 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 GOOGLE_CACHEINVALIDATION_RANDOM_H_ -#define GOOGLE_CACHEINVALIDATION_RANDOM_H_ - -#include "base/rand_util.h" - -namespace invalidation { - -class Random { - public: - // We don't actually use the seed. - explicit Random(int64 seed) {} - - // Returns a pseudorandom value between(inclusive) and(exclusive). - double RandDouble() { - return base::RandDouble(); - } -}; - -} // namespace invalidation - -#endif // GOOGLE_CACHEINVALIDATION_RANDOM_H_ diff --git a/third_party/cacheinvalidation/overrides/google/cacheinvalidation/scoped_ptr.h b/third_party/cacheinvalidation/overrides/google/cacheinvalidation/scoped_ptr.h index c31eb43e..e69de29 100644 --- a/third_party/cacheinvalidation/overrides/google/cacheinvalidation/scoped_ptr.h +++ b/third_party/cacheinvalidation/overrides/google/cacheinvalidation/scoped_ptr.h @@ -1,16 +0,0 @@ -// Copyright (c) 2011 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 GOOGLE_CACHEINVALIDATION_SCOPED_PTR_H_ -#define GOOGLE_CACHEINVALIDATION_SCOPED_PTR_H_ - -#include "base/memory/scoped_ptr.h" - -namespace invalidation { - -using ::scoped_ptr; - -} // namespace invalidation - -#endif // GOOGLE_CACHEINVALIDATION_SCOPED_PTR_H_ diff --git a/third_party/cacheinvalidation/overrides/google/cacheinvalidation/stl-namespace.h b/third_party/cacheinvalidation/overrides/google/cacheinvalidation/stl-namespace.h index fa6f031..e69de29 100644 --- a/third_party/cacheinvalidation/overrides/google/cacheinvalidation/stl-namespace.h +++ b/third_party/cacheinvalidation/overrides/google/cacheinvalidation/stl-namespace.h @@ -1,10 +0,0 @@ -// Copyright (c) 2010 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 GOOGLE_CACHEINVALIDATION_STL_NAMESPACE_H_ -#define GOOGLE_CACHEINVALIDATION_STL_NAMESPACE_H_ - -#define INVALIDATION_STL_NAMESPACE std - -#endif // GOOGLE_CACHEINVALIDATION_STL_NAMESPACE_H_ diff --git a/third_party/cacheinvalidation/overrides/google/cacheinvalidation/string_util.h b/third_party/cacheinvalidation/overrides/google/cacheinvalidation/string_util.h index 36d3713..e69de29 100644 --- a/third_party/cacheinvalidation/overrides/google/cacheinvalidation/string_util.h +++ b/third_party/cacheinvalidation/overrides/google/cacheinvalidation/string_util.h @@ -1,16 +0,0 @@ -// Copyright (c) 2010 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 GOOGLE_CACHEINVALIDATION_STRING_UTIL_H_ -#define GOOGLE_CACHEINVALIDATION_STRING_UTIL_H_ - -#include "base/stringprintf.h" - -namespace invalidation { - -using base::StringAppendV; - -} // namespace invalidation - -#endif // GOOGLE_CACHEINVALIDATION_STRING_UTIL_H_ diff --git a/third_party/cacheinvalidation/overrides/google/cacheinvalidation/time.h b/third_party/cacheinvalidation/overrides/google/cacheinvalidation/time.h index 559b8b8..e69de29 100644 --- a/third_party/cacheinvalidation/overrides/google/cacheinvalidation/time.h +++ b/third_party/cacheinvalidation/overrides/google/cacheinvalidation/time.h @@ -1,16 +0,0 @@ -// Copyright (c) 2010 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 GOOGLE_CACHEINVALIDATION_TIME_H_ -#define GOOGLE_CACHEINVALIDATION_TIME_H_ - -#include "base/time.h" - -namespace invalidation { -typedef base::Time Time; -typedef base::TimeTicks TimeTicks; -typedef base::TimeDelta TimeDelta; -} // namespace invalidation - -#endif // GOOGLE_CACHEINVALIDATION_TIME_H_ diff --git a/third_party/cacheinvalidation/overrides/google/cacheinvalidation/v2/callback.h b/third_party/cacheinvalidation/overrides/google/cacheinvalidation/v2/callback.h new file mode 100644 index 0000000..d1e9274 --- /dev/null +++ b/third_party/cacheinvalidation/overrides/google/cacheinvalidation/v2/callback.h @@ -0,0 +1,126 @@ +// Copyright (c) 2012 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 GOOGLE_CACHEINVALIDATION_V2_CALLBACK_H_ +#define GOOGLE_CACHEINVALIDATION_V2_CALLBACK_H_ + +#include "base/bind.h" +#include "base/callback.h" + +#define INVALIDATION_CALLBACK1_TYPE(Arg1) ::base::Callback + +// Below are a collection of types and functions that adapt base::Callback's +// pass-by-value semantics to the pointer-based callback system that +// cacheinvalidation needs. + +namespace invalidation { + +typedef ::base::Closure Closure; + +static inline void DoNothing() {} + +template +bool IsCallbackRepeatable(const T* callback) { + // The default cacheinvalidation Callbacks may be self-deleting. We don't + // support this behave, so we already return true to indicate that the + // cacheinvalidation implementation should delete our Callbacks. + return true; +} + +namespace internal { + +// Identity::type is a typedef of T. Useful for preventing the +// compiler from inferring the type of an argument in templates. +template +struct Identity { + typedef T type; +}; + +} // namespace internal + +// The cacheinvalidation callback system expects to take the callback by +// pointer and handle the ownership semantics itself. Adapting the +// Chromium Callback system requires returning a dynamically allocated +// copy of the result of Bind(). + +inline Closure* NewPermanentCallback(void (*fn)()) { + return new ::base::Closure(::base::Bind(fn)); +} + +template +Closure* NewPermanentCallback( + T1* object, void (T2::*method)()) { + return new ::base::Closure(::base::Bind(method, base::Unretained(object))); +} + +template +::base::Callback* NewPermanentCallback( + T1* object, void (T2::*method)(Arg1)) { + return new ::base::Callback( + ::base::Bind(method, base::Unretained(object))); +} + +template +Closure* NewPermanentCallback( + T1* object, + void (T2::*method)(Arg1), + typename internal::Identity::type arg1) { + return new ::base::Closure(::base::Bind(method, base::Unretained(object), + arg1)); +} + +template +Closure* NewPermanentCallback( + void (*fn)(Arg1, Arg2), + typename internal::Identity::type arg1, + typename internal::Identity::type arg2) { + return new ::base::Closure(::base::Bind(fn, arg1, arg2)); +} + +template +Closure* NewPermanentCallback( + T1* object, + void (T2::*method)(Arg1, Arg2), + typename internal::Identity::type arg1, + typename internal::Identity::type arg2) { + return new ::base::Closure(::base::Bind(method, base::Unretained(object), + arg1, arg2)); +} + +template +::base::Callback* NewPermanentCallback( + T1* object, + void (T2::*method)(Arg1, Arg2), + typename internal::Identity::type arg1) { + return new ::base::Callback( + ::base::Bind(method, base::Unretained(object), arg1)); +} + +template +Closure* NewPermanentCallback( + T1* object, + void (T2::*method)(Arg1, Arg2, Arg3), + typename internal::Identity::type arg1, + typename internal::Identity::type arg2, + typename internal::Identity::type arg3) { + return new ::base::Closure(::base::Bind(method, base::Unretained(object), + arg1, arg2, arg3)); +} + +template +Closure* NewPermanentCallback( + T1* object, + void (T2::*method)(Arg1, Arg2, Arg3, Arg4), + typename internal::Identity::type arg1, + typename internal::Identity::type arg2, + typename internal::Identity::type arg3, + typename internal::Identity::type arg4) { + return new ::base::Closure(::base::Bind(method, base::Unretained(object), + arg1, arg2, arg3, arg4)); +} + +} // namespace invalidation + +#endif // GOOGLE_CACHEINVALIDATION_V2_CALLBACK_H_ diff --git a/third_party/cacheinvalidation/overrides/google/cacheinvalidation/v2/gmock.h b/third_party/cacheinvalidation/overrides/google/cacheinvalidation/v2/gmock.h new file mode 100644 index 0000000..e6a121e --- /dev/null +++ b/third_party/cacheinvalidation/overrides/google/cacheinvalidation/v2/gmock.h @@ -0,0 +1,91 @@ +// Copyright (c) 2012 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 GOOGLE_CACHEINVALIDATION_V2_GMOCK_H_ +#define GOOGLE_CACHEINVALIDATION_V2_GMOCK_H_ + +#include "testing/gmock/include/gmock/gmock.h" + +namespace testing { +namespace internal { + +// WhenDeserializedAs and EqualsProto are utilities that aren't part of gmock. + +// Implements WhenDeserializedAs(proto_matcher). +template +class WhenDeserializedAsMatcher { + public: + typedef Matcher InnerMatcher; + + explicit WhenDeserializedAsMatcher(const InnerMatcher& proto_matcher) + : proto_matcher_(proto_matcher) {} + + virtual ~WhenDeserializedAsMatcher() {} + + // Deserializes the string as a protobuf of the same type as the expected + // protobuf. + Proto* Deserialize(const string& str) const { + Proto* proto = new Proto; + if (proto->ParsePartialFromString(str)) { + return proto; + } else { + delete proto; + return NULL; + } + } + + void DescribeTo(::std::ostream* os) const { + *os << "can be deserialized as a protobuf that "; + proto_matcher_.DescribeTo(os); + } + + void DescribeNegationTo(::std::ostream* os) const { + *os << "cannot be deserialized as a protobuf that "; + proto_matcher_.DescribeTo(os); + } + + bool MatchAndExplain(const string& arg, MatchResultListener* listener) const { + // Deserializes the string arg as a protobuf of the same type as the + // expected protobuf. + scoped_ptr deserialized_arg(Deserialize(arg)); + // No need to explain the match result. + return (deserialized_arg.get() != NULL) && + proto_matcher_.Matches(*deserialized_arg); + } + + private: + const InnerMatcher proto_matcher_; +}; + +} // namespace internal + +namespace proto { + +// WhenDeserializedAs(m) is a matcher that matches a string +// that can be deserialized as a protobuf of type Proto that matches +// m, which can be any valid protobuf matcher. +template +inline PolymorphicMatcher > +WhenDeserializedAs(const InnerMatcher& inner_matcher) { + return MakePolymorphicMatcher( + internal::WhenDeserializedAsMatcher( + SafeMatcherCast(inner_matcher))); +} + +} // namespace proto + +MATCHER_P(EqualsProto, message, "") { + // TOOD(ghc): This implementation assume protobuf serialization is + // deterministic, which is true in practice but technically not something that + // code is supposed to rely on. However, it vastly simplifies the + // implementation... + std::string expected_serialized, actual_serialized; + message.SerializeToString(&expected_serialized); + arg.SerializeToString(&actual_serialized); + return expected_serialized == actual_serialized; +} + +} // namespace testing + +#endif // GOOGLE_CACHEINVALIDATION_V2_GMOCK_H_ diff --git a/third_party/cacheinvalidation/overrides/google/cacheinvalidation/v2/googletest.h b/third_party/cacheinvalidation/overrides/google/cacheinvalidation/v2/googletest.h new file mode 100644 index 0000000..46bd071 --- /dev/null +++ b/third_party/cacheinvalidation/overrides/google/cacheinvalidation/v2/googletest.h @@ -0,0 +1,10 @@ +// Copyright (c) 2012 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 GOOGLE_CACHEINVALIDATION_V2_GOOGLETEST_H_ +#define GOOGLE_CACHEINVALIDATION_V2_GOOGLETEST_H_ + +#include "testing/gtest/include/gtest/gtest.h" + +#endif // GOOGLE_CACHEINVALIDATION_V2_GOOGLETEST_H_ diff --git a/third_party/cacheinvalidation/overrides/google/cacheinvalidation/v2/random.h b/third_party/cacheinvalidation/overrides/google/cacheinvalidation/v2/random.h new file mode 100644 index 0000000..d8c586a --- /dev/null +++ b/third_party/cacheinvalidation/overrides/google/cacheinvalidation/v2/random.h @@ -0,0 +1,25 @@ +// Copyright (c) 2012 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 GOOGLE_CACHEINVALIDATION_V2_RANDOM_H_ +#define GOOGLE_CACHEINVALIDATION_V2_RANDOM_H_ + +#include "base/rand_util.h" + +namespace invalidation { + +class Random { + public: + // We don't actually use the seed. + explicit Random(int64 seed) {} + + // Returns a pseudorandom value between(inclusive) and(exclusive). + double RandDouble() { + return base::RandDouble(); + } +}; + +} // namespace invalidation + +#endif // GOOGLE_CACHEINVALIDATION_V2_RANDOM_H_ diff --git a/third_party/cacheinvalidation/overrides/google/cacheinvalidation/v2/sha1-digest-function.h b/third_party/cacheinvalidation/overrides/google/cacheinvalidation/v2/sha1-digest-function.h index 8e15595..a22e3f2 100644 --- a/third_party/cacheinvalidation/overrides/google/cacheinvalidation/v2/sha1-digest-function.h +++ b/third_party/cacheinvalidation/overrides/google/cacheinvalidation/v2/sha1-digest-function.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -10,8 +10,8 @@ #include #include "base/sha1.h" -#include "google/cacheinvalidation/stl-namespace.h" #include "google/cacheinvalidation/v2/digest-function.h" +#include "google/cacheinvalidation/v2/stl-namespace.h" namespace invalidation { diff --git a/third_party/cacheinvalidation/overrides/google/cacheinvalidation/v2/stl-namespace.h b/third_party/cacheinvalidation/overrides/google/cacheinvalidation/v2/stl-namespace.h new file mode 100644 index 0000000..c660cbd --- /dev/null +++ b/third_party/cacheinvalidation/overrides/google/cacheinvalidation/v2/stl-namespace.h @@ -0,0 +1,10 @@ +// Copyright (c) 2012 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 GOOGLE_CACHEINVALIDATION_V2_STL_NAMESPACE_H_ +#define GOOGLE_CACHEINVALIDATION_V2_STL_NAMESPACE_H_ + +#define INVALIDATION_STL_NAMESPACE std + +#endif // GOOGLE_CACHEINVALIDATION_V2_STL_NAMESPACE_H_ -- cgit v1.1