summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-07 21:45:02 +0000
committerakalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-07 21:45:02 +0000
commit6c852924d5dad5c800b025c1b37233a355270122 (patch)
tree861ec1c6c03474c40461934458ea03710faf27a6
parentd5f94a38d31a35e3327de49d9857a92f483c2a88 (diff)
downloadchromium_src-6c852924d5dad5c800b025c1b37233a355270122.zip
chromium_src-6c852924d5dad5c800b025c1b37233a355270122.tar.gz
chromium_src-6c852924d5dad5c800b025c1b37233a355270122.tar.bz2
[Sync] Rolled cache-invalidation-api to @39.
Updated sync notifier code to work with new cache-invalidation APIs. Added TODOs to support persistence for sync notifications. Use a chrome test runner for cacheinvalidation_unittests to get it to work again. fixed cache invalidation unit tests BUG=None TEST=cacheinvalidation_unittests Review URL: http://codereview.chromium.org/3532018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@61851 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--DEPS2
-rw-r--r--chrome/browser/sync/notifier/chrome_invalidation_client.cc6
-rw-r--r--chrome/browser/sync/notifier/chrome_system_resources.cc21
-rw-r--r--chrome/browser/sync/notifier/chrome_system_resources.h8
-rw-r--r--chrome/browser/sync/notifier/chrome_system_resources_unittest.cc28
-rw-r--r--chrome/browser/sync/notifier/registration_manager_unittest.cc14
-rw-r--r--third_party/cacheinvalidation/cacheinvalidation.gyp3
7 files changed, 71 insertions, 11 deletions
diff --git a/DEPS b/DEPS
index 2eeae40..5bf5278 100644
--- a/DEPS
+++ b/DEPS
@@ -52,7 +52,7 @@ deps = {
"http://google-safe-browsing.googlecode.com/svn/trunk/testing@101",
"src/third_party/cacheinvalidation/files":
- (Var("googlecode_url") % "google-cache-invalidation-api") + "/trunk@35",
+ (Var("googlecode_url") % "google-cache-invalidation-api") + "/trunk@39",
"src/tools/gyp":
(Var("googlecode_url") % "gyp") + "/trunk@840",
diff --git a/chrome/browser/sync/notifier/chrome_invalidation_client.cc b/chrome/browser/sync/notifier/chrome_invalidation_client.cc
index 8eb02f4..89f5bde 100644
--- a/chrome/browser/sync/notifier/chrome_invalidation_client.cc
+++ b/chrome/browser/sync/notifier/chrome_invalidation_client.cc
@@ -49,10 +49,12 @@ void ChromeInvalidationClient::Start(
// replies we get.
client_config.max_registrations_per_message = 20;
client_config.max_ops_per_message = 40;
+ // TODO(akalin): Grab |persisted_state| from persistent storage.
+ std::string persisted_state;
invalidation_client_.reset(
new invalidation::InvalidationClientImpl(
- &chrome_system_resources_, client_type, client_id, this,
- client_config));
+ &chrome_system_resources_, client_type, client_id,
+ persisted_state, client_config, this));
cache_invalidation_packet_handler_.reset(
new CacheInvalidationPacketHandler(base_task,
invalidation_client_.get()));
diff --git a/chrome/browser/sync/notifier/chrome_system_resources.cc b/chrome/browser/sync/notifier/chrome_system_resources.cc
index cc3c8d2..11ef0f0 100644
--- a/chrome/browser/sync/notifier/chrome_system_resources.cc
+++ b/chrome/browser/sync/notifier/chrome_system_resources.cc
@@ -64,6 +64,19 @@ void ChromeSystemResources::ScheduleImmediately(
MessageLoop::current()->PostTask(FROM_HERE, task_to_post);
}
+// The listener thread is just our current thread.
+void ChromeSystemResources::ScheduleOnListenerThread(
+ invalidation::Closure* task) {
+ DCHECK(non_thread_safe_.CalledOnValidThread());
+ ScheduleImmediately(task);
+}
+
+// We're already on a separate thread, so always return true.
+bool ChromeSystemResources::IsRunningOnInternalThread() {
+ DCHECK(non_thread_safe_.CalledOnValidThread());
+ return true;
+}
+
void ChromeSystemResources::Log(
LogLevel level, const char* file, int line,
const char* format, ...) {
@@ -93,6 +106,14 @@ void ChromeSystemResources::Log(
}
}
+void ChromeSystemResources::WriteState(
+ const invalidation::string& state,
+ invalidation::StorageCallback* callback) {
+ // TODO(akalin): Write the given state to persistent storage.
+ callback->Run(false);
+ delete callback;
+}
+
Task* ChromeSystemResources::MakeTaskToPost(
invalidation::Closure* task) {
DCHECK(non_thread_safe_.CalledOnValidThread());
diff --git a/chrome/browser/sync/notifier/chrome_system_resources.h b/chrome/browser/sync/notifier/chrome_system_resources.h
index 1305c7c..c9e79b7 100644
--- a/chrome/browser/sync/notifier/chrome_system_resources.h
+++ b/chrome/browser/sync/notifier/chrome_system_resources.h
@@ -11,6 +11,7 @@
#pragma once
#include <set>
+#include <string>
#include "base/non_thread_safe.h"
#include "base/scoped_ptr.h"
@@ -38,9 +39,16 @@ class ChromeSystemResources : public invalidation::SystemResources {
virtual void ScheduleImmediately(invalidation::Closure* task);
+ virtual void ScheduleOnListenerThread(invalidation::Closure* task);
+
+ virtual bool IsRunningOnInternalThread();
+
virtual void Log(LogLevel level, const char* file, int line,
const char* format, ...);
+ virtual void WriteState(const invalidation::string& state,
+ invalidation::StorageCallback* callback);
+
private:
NonThreadSafe non_thread_safe_;
scoped_ptr<ScopedRunnableMethodFactory<ChromeSystemResources> >
diff --git a/chrome/browser/sync/notifier/chrome_system_resources_unittest.cc b/chrome/browser/sync/notifier/chrome_system_resources_unittest.cc
index cb915f1..9e74fa1 100644
--- a/chrome/browser/sync/notifier/chrome_system_resources_unittest.cc
+++ b/chrome/browser/sync/notifier/chrome_system_resources_unittest.cc
@@ -17,10 +17,16 @@ void ShouldNotRun() {
class ChromeSystemResourcesTest : public testing::Test {
public:
+ // Used as a callback.
void IncrementCounter() {
++counter_;
}
+ // Used as a callback.
+ void ExpectFalse(bool result) {
+ EXPECT_FALSE(result);
+ }
+
protected:
ChromeSystemResourcesTest() : counter_(0) {}
@@ -89,6 +95,17 @@ TEST_F(ChromeSystemResourcesTest, ScheduleImmediately) {
EXPECT_EQ(1, counter_);
}
+TEST_F(ChromeSystemResourcesTest, ScheduleOnListenerThread) {
+ chrome_system_resources_.StartScheduler();
+ chrome_system_resources_.ScheduleOnListenerThread(
+ invalidation::NewPermanentCallback(
+ this, &ChromeSystemResourcesTest::IncrementCounter));
+ EXPECT_TRUE(chrome_system_resources_.IsRunningOnInternalThread());
+ EXPECT_EQ(0, counter_);
+ message_loop_.RunAllPending();
+ EXPECT_EQ(1, counter_);
+}
+
TEST_F(ChromeSystemResourcesTest, ScheduleWithZeroDelay) {
chrome_system_resources_.StartScheduler();
chrome_system_resources_.ScheduleWithDelay(
@@ -102,5 +119,16 @@ TEST_F(ChromeSystemResourcesTest, ScheduleWithZeroDelay) {
// TODO(akalin): Figure out how to test with a non-zero delay.
+TEST_F(ChromeSystemResourcesTest, WriteState) {
+ // Explicitness hack here to work around broken callback
+ // implementations.
+ ChromeSystemResourcesTest* run_object = this;
+ void (ChromeSystemResourcesTest::*run_function)(bool) =
+ &ChromeSystemResourcesTest::ExpectFalse;
+
+ chrome_system_resources_.WriteState(
+ "state", invalidation::NewPermanentCallback(run_object, run_function));
+}
+
} // namespace
} // namespace notifier
diff --git a/chrome/browser/sync/notifier/registration_manager_unittest.cc b/chrome/browser/sync/notifier/registration_manager_unittest.cc
index e8b9a85..de773f6 100644
--- a/chrome/browser/sync/notifier/registration_manager_unittest.cc
+++ b/chrome/browser/sync/notifier/registration_manager_unittest.cc
@@ -41,24 +41,24 @@ class FakeInvalidationClient : public invalidation::InvalidationClient {
}
}
- void Register(const invalidation::ObjectId& oid,
- invalidation::RegistrationCallback* callback) {
+ virtual void Register(const invalidation::ObjectId& oid,
+ invalidation::RegistrationCallback* callback) {
register_calls.push_back(Args(oid, callback));
}
- void Unregister(const invalidation::ObjectId& oid,
- invalidation::RegistrationCallback* callback) {
+ virtual void Unregister(const invalidation::ObjectId& oid,
+ invalidation::RegistrationCallback* callback) {
ADD_FAILURE();
delete callback;
}
- invalidation::NetworkEndpoint* network_endpoint() {
+ virtual void PermanentShutdown() {
ADD_FAILURE();
- return NULL;
}
- void GetClientUniquifier(invalidation::string* uniquifier) const {
+ virtual invalidation::NetworkEndpoint* network_endpoint() {
ADD_FAILURE();
+ return NULL;
}
std::deque<Args> register_calls;
diff --git a/third_party/cacheinvalidation/cacheinvalidation.gyp b/third_party/cacheinvalidation/cacheinvalidation.gyp
index 5e0b074..5cadd54 100644
--- a/third_party/cacheinvalidation/cacheinvalidation.gyp
+++ b/third_party/cacheinvalidation/cacheinvalidation.gyp
@@ -120,14 +120,15 @@
'target_name': 'cacheinvalidation_unittests',
'type': 'executable',
'sources': [
+ '../../base/test/run_all_unittests.cc',
'files/src/google/cacheinvalidation/system-resources-for-test.h',
'files/src/google/cacheinvalidation/invalidation-client-impl_test.cc',
'files/src/google/cacheinvalidation/throttle_test.cc',
],
'dependencies': [
'../../base/base.gyp:base',
+ '../../base/base.gyp:test_support_base',
'../../testing/gtest.gyp:gtest',
- '../../testing/gtest.gyp:gtestmain',
'cacheinvalidation',
],
},