diff options
author | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-23 03:03:26 +0000 |
---|---|---|
committer | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-23 03:03:26 +0000 |
commit | 2cbb95c83e82662fbedf54e945d2e2e8b9d955d7 (patch) | |
tree | b18c9a82a0ad538a82905bb09b3f2b7e05261ae7 /third_party/cacheinvalidation | |
parent | 6c2cedb6057d33487d6cfe04af2e6821d1859aa0 (diff) | |
download | chromium_src-2cbb95c83e82662fbedf54e945d2e2e8b9d955d7.zip chromium_src-2cbb95c83e82662fbedf54e945d2e2e8b9d955d7.tar.gz chromium_src-2cbb95c83e82662fbedf54e945d2e2e8b9d955d7.tar.bz2 |
Added Google Cache Invalidation library to DEPS and got it to compile
with the Chromium libraries.
Added some override files to make it work, the biggest of which defines
NewPermanentCallback() overrides that base/callback.h doesn't handle.
BUG=34646
TEST=added unittests
Review URL: http://codereview.chromium.org/1720001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@45412 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'third_party/cacheinvalidation')
9 files changed, 425 insertions, 0 deletions
diff --git a/third_party/cacheinvalidation/README.chromium b/third_party/cacheinvalidation/README.chromium new file mode 100644 index 0000000..5db4b17 --- /dev/null +++ b/third_party/cacheinvalidation/README.chromium @@ -0,0 +1,6 @@ +Name: Google Cache Invalidation API +URL: http://code.google.com/p/google-cache-invalidation-api/ +License: Apache 2.0 + +Description: +This is the API to talk to the Google Cache Invalidation service. diff --git a/third_party/cacheinvalidation/cacheinvalidation.gyp b/third_party/cacheinvalidation/cacheinvalidation.gyp new file mode 100644 index 0000000..e400bcf --- /dev/null +++ b/third_party/cacheinvalidation/cacheinvalidation.gyp @@ -0,0 +1,143 @@ +# 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. + +{ + 'variables': { + # The root directory for the proto files. + 'proto_dir_root': 'files/src', + # The relative path of the cacheinvalidation proto files from + # proto_dir_root. + # TODO(akalin): Add a RULE_INPUT_DIR predefined variable to gyp so + # we don't need this variable. + 'proto_dir_relpath': 'google/cacheinvalidation', + # Where files generated from proto files are put. + 'protoc_out_dir': '<(SHARED_INTERMEDIATE_DIR)/protoc_out', + }, + 'targets': [ + # The rule/action to generate files from the cacheinvalidation proto + # files. + { + 'target_name': 'cacheinvalidation_proto', + 'type': 'none', + 'sources': [ + '<(proto_dir_root)/google/cacheinvalidation/types.proto', + ], + # TODO(akalin): This block was copied from the sync_proto target + # from chrome.gyp. Decomp the shared blocks out somehow. + 'rules': [ + { + 'rule_name': 'genproto', + 'extension': 'proto', + 'inputs': [ + '<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)protoc<(EXECUTABLE_SUFFIX)', + ], + 'outputs': [ + '<(protoc_out_dir)/<(proto_dir_relpath)/<(RULE_INPUT_ROOT).pb.h', + '<(protoc_out_dir)/<(proto_dir_relpath)/<(RULE_INPUT_ROOT).pb.cc', + ], + 'action': [ + '<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)protoc<(EXECUTABLE_SUFFIX)', + '--proto_path=<(proto_dir_root)', + '<(RULE_INPUT_PATH)', + '--cpp_out=<(protoc_out_dir)', + ], + 'message': 'Generating C++ code from <(RULE_INPUT_PATH)', + }, + ], + 'dependencies': [ + '../../third_party/protobuf2/protobuf.gyp:protoc#host', + ], + }, + # The library created from the generated c++ cacheinvalidation proto + # files. + { + 'target_name': 'cacheinvalidation_proto_cc', + 'type': '<(library)', + 'sources': [ + '<(protoc_out_dir)/<(proto_dir_relpath)/types.pb.h', + '<(protoc_out_dir)/<(proto_dir_relpath)/types.pb.cc', + ], + 'include_dirs': [ + '<(protoc_out_dir)', + ], + 'dependencies': [ + '../../third_party/protobuf2/protobuf.gyp:protobuf_lite', + 'cacheinvalidation_proto', + ], + 'direct_dependent_settings': { + 'include_dirs': [ + '<(protoc_out_dir)', + ], + }, + 'export_dependent_settings': [ + '../../third_party/protobuf2/protobuf.gyp:protobuf_lite', + ], + }, + # The main cache invalidation library. External clients should depend + # only on this. + { + 'target_name': 'cacheinvalidation', + 'type': '<(library)', + 'sources': [ + 'overrides/google/cacheinvalidation/callback.h', + 'overrides/google/cacheinvalidation/googletest.h', + 'overrides/google/cacheinvalidation/logging.h', + 'overrides/google/cacheinvalidation/mutex.h', + 'overrides/google/cacheinvalidation/stl-namespace.h' + 'overrides/google/cacheinvalidation/string_util.h' + 'overrides/google/cacheinvalidation/time.h', + 'files/src/google/cacheinvalidation/invalidation-client-impl.cc', + 'files/src/google/cacheinvalidation/invalidation-client-impl.h', + 'files/src/google/cacheinvalidation/invalidation-client.cc', + 'files/src/google/cacheinvalidation/invalidation-client.h', + 'files/src/google/cacheinvalidation/log-macro.h', + 'files/src/google/cacheinvalidation/network-manager.cc', + 'files/src/google/cacheinvalidation/network-manager.h', + 'files/src/google/cacheinvalidation/registration-update-manager.cc', + 'files/src/google/cacheinvalidation/registration-update-manager.h', + 'files/src/google/cacheinvalidation/session-manager.cc', + 'files/src/google/cacheinvalidation/session-manager.h', + ], + 'include_dirs': [ + './overrides', + './files/src', + ], + 'dependencies': [ + '../../base/base.gyp:base', + 'cacheinvalidation_proto_cc', + ], + 'direct_dependent_settings': { + 'include_dirs': [ + './overrides', + './files/src', + ], + }, + 'export_dependent_settings': [ + 'cacheinvalidation_proto_cc', + ], + }, + # Unittests for the cache invalidation library. + # TODO(akalin): Add these to build/all.gyp. + { + 'target_name': 'cacheinvalidation_unittests', + 'type': 'executable', + 'sources': [ + 'files/src/google/cacheinvalidation/system-resources-for-test.h', + 'files/src/google/cacheinvalidation/invalidation-client-impl_test.cc', + ], + 'dependencies': [ + '../../base/base.gyp:base', + '../../testing/gtest.gyp:gtest', + '../../testing/gtest.gyp:gtestmain', + 'cacheinvalidation', + ], + }, + ], +} + +# Local Variables: +# tab-width:2 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=2 shiftwidth=2: diff --git a/third_party/cacheinvalidation/overrides/google/cacheinvalidation/callback.h b/third_party/cacheinvalidation/overrides/google/cacheinvalidation/callback.h new file mode 100644 index 0000000..d0ec702 --- /dev/null +++ b/third_party/cacheinvalidation/overrides/google/cacheinvalidation/callback.h @@ -0,0 +1,182 @@ +// 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_CALLBACK_H_ +#define GOOGLE_CACHEINVALIDATION_CALLBACK_H_ + +#include "base/callback.h" + +#define INVALIDATION_CALLBACK1_TYPE(Arg1) ::Callback1<Arg1>::Type + +// Below are a collection of types and functions to make up for the +// limited capabilities of Chrome's callback.h. + +namespace invalidation { + +typedef ::Callback0::Type Closure; + +static inline void DoNothing() {} + +template <class T> +bool IsCallbackRepeatable(const T* callback) { + return true; +} + +namespace internal { + +// Identity<T>::type is a typedef of T. Useful for preventing the +// compiler from inferring the type of an argument in templates. +template <typename T> +struct Identity { + typedef T type; +}; + +// Specified by TR1 [4.7.2] +template <typename T> struct remove_reference { + typedef T type; +}; + +template <typename T> struct remove_reference<T&> { + typedef T type; +}; + +} // namespace internal + +// base/callback.h already handles partially applying member functions +// to an object, so just route to that. (We only need the one-arg +// case.) + +template <class T, typename Arg1> +typename Callback1<Arg1>::Type* NewPermanentCallback( + T* object, void (T::*method)(Arg1)) { + return new CallbackImpl<T, void (T::*)(Arg1), Tuple1<Arg1> >(object, method); +} + +// Define function runners for the partial application combinations +// that we need. + +class ZeroArgFunctionRunner : public CallbackRunner<Tuple0> { + public: + ZeroArgFunctionRunner(void (*fn)()) : fn_(fn) {} + + virtual ~ZeroArgFunctionRunner() {} + + virtual void RunWithParams(const Tuple0& params) { fn_(); } + + private: + void (*fn_)(); +}; + +template <class T> +class ZeroArgMethodRunner : public CallbackRunner<Tuple0> { + public: + ZeroArgMethodRunner(T* obj, void (T::*meth)()) : obj_(obj), meth_(meth) {} + + virtual ~ZeroArgMethodRunner() {} + + virtual void RunWithParams(const Tuple0& params) { + (obj_->*meth_)(); + } + + private: + T* obj_; + void (T::*meth_)(); +}; + +template <class T, typename Arg1> +class OneArgCallbackRunner : public CallbackRunner<Tuple0> { + public: + OneArgCallbackRunner(T* obj, void (T::*meth)(Arg1), + Arg1 arg1) + : obj_(obj), meth_(meth), arg1_(arg1) {} + + virtual ~OneArgCallbackRunner() {} + + virtual void RunWithParams(const Tuple0& params) { + (obj_->*meth_)(arg1_); + } + + private: + T* obj_; + void (T::*meth_)(Arg1); + typename internal::remove_reference<Arg1>::type arg1_; +}; + +template <typename Arg1, typename Arg2> +class TwoArgFunctionRunner : public CallbackRunner<Tuple0> { + public: + TwoArgFunctionRunner(void (*fn)(Arg1, Arg2), Arg1 arg1, Arg2 arg2) + : fn_(fn), arg1_(arg1), arg2_(arg2) {} + + virtual ~TwoArgFunctionRunner() {} + + virtual void RunWithParams(const Tuple0& params) { fn_(arg1_, arg2_); } + + private: + void (*fn_)(Arg1, Arg2); + typename internal::remove_reference<Arg1>::type arg1_; + typename internal::remove_reference<Arg2>::type arg2_; +}; + +template <class T, typename Arg1, typename Arg2> +class TwoArgCallbackRunner : public CallbackRunner<Tuple0> { + public: + TwoArgCallbackRunner(T* obj, void (T::*meth)(Arg1, Arg2), + Arg1 arg1, Arg2 arg2) + : obj_(obj), meth_(meth), arg1_(arg1), arg2_(arg2) {} + + virtual ~TwoArgCallbackRunner() {} + + virtual void RunWithParams(const Tuple0& params) { + (obj_->*meth_)(arg1_, arg2_); + } + + private: + T* obj_; + void (T::*meth_)(Arg1, Arg2); + typename internal::remove_reference<Arg1>::type arg1_; + typename internal::remove_reference<Arg2>::type arg2_; +}; + +// Then route the appropriate overloads of NewPermanentCallback() to +// use the above. + +inline Callback0::Type* NewPermanentCallback(void (*fn)()) { + return new ZeroArgFunctionRunner(fn); +} + +template <class T1, class T2> +typename Callback0::Type* NewPermanentCallback( + T1* object, void (T2::*method)()) { + return new ZeroArgMethodRunner<T1>(object, method); +} + +template <class T1, class T2, typename Arg1> +typename Callback0::Type* NewPermanentCallback( + T1* object, + void (T2::*method)(Arg1), + typename internal::Identity<Arg1>::type arg1) { + return new OneArgCallbackRunner<T1, Arg1>(object, method, arg1); +} + +template <typename Arg1, typename Arg2> +Callback0::Type* NewPermanentCallback( + void (*fn)(Arg1, Arg2), + typename internal::Identity<Arg1>::type arg1, + typename internal::Identity<Arg2>::type arg2) { + return new TwoArgFunctionRunner<Arg1, Arg2>(fn, arg1, arg2); +} + +template <class T1, class T2, typename Arg1, typename Arg2> +typename Callback0::Type* NewPermanentCallback( + T1* object, + void (T2::*method)(Arg1, Arg2), + typename internal::Identity<Arg1>::type arg1, + typename internal::Identity<Arg2>::type arg2) { + return new TwoArgCallbackRunner<T1, Arg1, Arg2>(object, method, arg1, arg2); +} + +} // namespace invalidation + +#endif // GOOGLE_CACHEINVALIDATION_CALLBACK_H_ diff --git a/third_party/cacheinvalidation/overrides/google/cacheinvalidation/googletest.h b/third_party/cacheinvalidation/overrides/google/cacheinvalidation/googletest.h new file mode 100644 index 0000000..f24bd56 --- /dev/null +++ b/third_party/cacheinvalidation/overrides/google/cacheinvalidation/googletest.h @@ -0,0 +1,10 @@ +// 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/logging.h b/third_party/cacheinvalidation/overrides/google/cacheinvalidation/logging.h new file mode 100644 index 0000000..b1c76cf --- /dev/null +++ b/third_party/cacheinvalidation/overrides/google/cacheinvalidation/logging.h @@ -0,0 +1,16 @@ +// 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/mutex.h b/third_party/cacheinvalidation/overrides/google/cacheinvalidation/mutex.h new file mode 100644 index 0000000..b99dcee --- /dev/null +++ b/third_party/cacheinvalidation/overrides/google/cacheinvalidation/mutex.h @@ -0,0 +1,26 @@ +// 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/lock.h" +#include "base/logging.h" + +namespace invalidation { + +typedef ::Lock Mutex; + +class MutexLock { + public: + explicit MutexLock(Mutex* m) : auto_lock_(*m) {} + + private: + AutoLock auto_lock_; + DISALLOW_COPY_AND_ASSIGN(MutexLock); +}; + +} // namespace invalidation + +#endif // GOOGLE_CACHEINVALIDATION_MUTEX_H_ diff --git a/third_party/cacheinvalidation/overrides/google/cacheinvalidation/stl-namespace.h b/third_party/cacheinvalidation/overrides/google/cacheinvalidation/stl-namespace.h new file mode 100644 index 0000000..fa6f031 --- /dev/null +++ b/third_party/cacheinvalidation/overrides/google/cacheinvalidation/stl-namespace.h @@ -0,0 +1,10 @@ +// 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 new file mode 100644 index 0000000..81e9d8b --- /dev/null +++ b/third_party/cacheinvalidation/overrides/google/cacheinvalidation/string_util.h @@ -0,0 +1,16 @@ +// 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/string_util.h" + +namespace invalidation { + +using ::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 new file mode 100644 index 0000000..559b8b8 --- /dev/null +++ b/third_party/cacheinvalidation/overrides/google/cacheinvalidation/time.h @@ -0,0 +1,16 @@ +// 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_ |