summaryrefslogtreecommitdiffstats
path: root/chrome/browser/sync/sessions
diff options
context:
space:
mode:
authortim@chromium.org <tim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-26 19:21:59 +0000
committertim@chromium.org <tim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-26 19:21:59 +0000
commita55fde6d976fc328946c02270fa6c517b0faa9a7 (patch)
treeac780f2e5aed836459d1a9edc7fd9e8ad40568f6 /chrome/browser/sync/sessions
parentac522c7e26be18b614d514a5131199658d5c57cb (diff)
downloadchromium_src-a55fde6d976fc328946c02270fa6c517b0faa9a7.zip
chromium_src-a55fde6d976fc328946c02270fa6c517b0faa9a7.tar.gz
chromium_src-a55fde6d976fc328946c02270fa6c517b0faa9a7.tar.bz2
sync: beginnings of MessageLoop based SyncerThread
This is just a checkpoint. It's not wired up to anything yet, and not fully implemented (note several NOTIMPLEMENTED() checks). For design and overview, see https://docs.google.com/document/d/1bFqqtpA7TZuwtyEqlSxgkCCRrHvYRnnH6HlHou2LwVo/edit BUG=26339 TEST=sync_unit_tests Review URL: http://codereview.chromium.org/5939006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@72663 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/sync/sessions')
-rw-r--r--chrome/browser/sync/sessions/session_state.cc6
-rw-r--r--chrome/browser/sync/sessions/session_state.h7
-rw-r--r--chrome/browser/sync/sessions/sync_session.cc29
-rw-r--r--chrome/browser/sync/sessions/sync_session.h22
-rw-r--r--chrome/browser/sync/sessions/sync_session_context.h1
-rw-r--r--chrome/browser/sync/sessions/sync_session_unittest.cc45
-rw-r--r--chrome/browser/sync/sessions/test_util.cc53
-rw-r--r--chrome/browser/sync/sessions/test_util.h39
8 files changed, 191 insertions, 11 deletions
diff --git a/chrome/browser/sync/sessions/session_state.cc b/chrome/browser/sync/sessions/session_state.cc
index 1fe714f..fda99b8 100644
--- a/chrome/browser/sync/sessions/session_state.cc
+++ b/chrome/browser/sync/sessions/session_state.cc
@@ -40,7 +40,8 @@ SyncSessionSnapshot::SyncSessionSnapshot(
bool is_silenced,
int64 unsynced_count,
int num_conflicting_updates,
- bool did_commit_items)
+ bool did_commit_items,
+ const SyncSourceInfo& source)
: syncer_status(syncer_status),
errors(errors),
num_server_changes_remaining(num_server_changes_remaining),
@@ -51,7 +52,8 @@ SyncSessionSnapshot::SyncSessionSnapshot(
is_silenced(is_silenced),
unsynced_count(unsynced_count),
num_conflicting_updates(num_conflicting_updates),
- did_commit_items(did_commit_items) {
+ did_commit_items(did_commit_items),
+ source(source) {
for (int i = 0; i < syncable::MODEL_TYPE_COUNT; ++i) {
const_cast<std::string&>(this->download_progress_markers[i]).assign(
download_progress_markers[i]);
diff --git a/chrome/browser/sync/sessions/session_state.h b/chrome/browser/sync/sessions/session_state.h
index fc42994..2d8381e3 100644
--- a/chrome/browser/sync/sessions/session_state.h
+++ b/chrome/browser/sync/sessions/session_state.h
@@ -32,6 +32,9 @@ namespace sessions {
class UpdateProgress;
+typedef std::pair<sync_pb::GetUpdatesCallerInfo::GetUpdatesSource,
+ syncable::ModelTypeBitSet> SyncSourceInfo;
+
// Data pertaining to the status of an active Syncer object.
struct SyncerStatus {
SyncerStatus();
@@ -79,7 +82,8 @@ struct SyncSessionSnapshot {
bool is_silenced,
int64 unsynced_count,
int num_conflicting_updates,
- bool did_commit_items);
+ bool did_commit_items,
+ const SyncSourceInfo& source);
~SyncSessionSnapshot();
const SyncerStatus syncer_status;
@@ -93,6 +97,7 @@ struct SyncSessionSnapshot {
const int64 unsynced_count;
const int num_conflicting_updates;
const bool did_commit_items;
+ const SyncSourceInfo source;
};
// Tracks progress of conflicts and their resolution using conflict sets.
diff --git a/chrome/browser/sync/sessions/sync_session.cc b/chrome/browser/sync/sessions/sync_session.cc
index da6412f..077b629 100644
--- a/chrome/browser/sync/sessions/sync_session.cc
+++ b/chrome/browser/sync/sessions/sync_session.cc
@@ -24,6 +24,32 @@ SyncSession::SyncSession(SyncSessionContext* context, Delegate* delegate,
SyncSession::~SyncSession() {}
+void SyncSession::Coalesce(const SyncSession& session) {
+ if (context_ != session.context() || delegate_ != session.delegate_) {
+ NOTREACHED();
+ return;
+ }
+
+ source_ = SyncSourceInfo(session.source_.first,
+ source_.second | session.source_.second);
+
+ std::vector<ModelSafeWorker*> temp;
+ std::set_union(workers_.begin(), workers_.end(),
+ session.workers_.begin(), session.workers_.end(),
+ std::back_inserter(temp));
+ workers_.swap(temp);
+
+ ModelSafeRoutingInfo temp_r;
+ std::set_union(routing_info_.begin(), routing_info_.end(),
+ session.routing_info_.begin(), session.routing_info_.end(),
+ std::insert_iterator<ModelSafeRoutingInfo>(temp_r, temp_r.begin()));
+ routing_info_.swap(temp_r);
+}
+
+void SyncSession::ResetTransientState() {
+ status_controller_.reset(new StatusController(routing_info_));
+}
+
SyncSessionSnapshot SyncSession::TakeSnapshot() const {
syncable::ScopedDirLookup dir(context_->directory_manager(),
context_->account_name());
@@ -55,7 +81,8 @@ SyncSessionSnapshot SyncSession::TakeSnapshot() const {
delegate_->IsSyncingCurrentlySilenced(),
status_controller_->unsynced_handles().size(),
status_controller_->TotalNumConflictingItems(),
- status_controller_->did_commit_items());
+ status_controller_->did_commit_items(),
+ source_);
}
SyncSourceInfo SyncSession::TestAndSetSource() {
diff --git a/chrome/browser/sync/sessions/sync_session.h b/chrome/browser/sync/sessions/sync_session.h
index ce7c9e5..3626d11 100644
--- a/chrome/browser/sync/sessions/sync_session.h
+++ b/chrome/browser/sync/sessions/sync_session.h
@@ -35,8 +35,6 @@ namespace browser_sync {
class ModelSafeWorker;
namespace sessions {
-typedef std::pair<sync_pb::GetUpdatesCallerInfo::GetUpdatesSource,
- syncable::ModelTypeBitSet> SyncSourceInfo;
class SyncSession {
public:
@@ -92,8 +90,19 @@ class SyncSession {
// engine again.
bool HasMoreToSync() const;
- SyncSessionContext* context() { return context_; }
- Delegate* delegate() { return delegate_; }
+ // Collects all state pertaining to how and why |s| originated and unions it
+ // with corresponding state in |this|, leaving |s| unchanged. Allows |this|
+ // to take on the responsibilities |s| had (e.g. certain data types) in the
+ // next SyncShare operation using |this|, rather than needed two separate
+ // sessions.
+ void Coalesce(const SyncSession& session);
+
+ // Should be called any time |this| is being re-used in a new call to
+ // SyncShare (e.g., HasMoreToSync returned true).
+ void ResetTransientState();
+
+ SyncSessionContext* context() const { return context_; }
+ Delegate* delegate() const { return delegate_; }
syncable::WriteTransaction* write_transaction() { return write_transaction_; }
StatusController* status_controller() { return status_controller_.get(); }
@@ -138,12 +147,13 @@ class SyncSession {
scoped_ptr<StatusController> status_controller_;
// The set of active ModelSafeWorkers for the duration of this session.
- const std::vector<ModelSafeWorker*> workers_;
+ // This can change if this session is Coalesce()'d with another.
+ std::vector<ModelSafeWorker*> workers_;
// The routing info for the duration of this session, dictating which
// datatypes should be synced and which workers should be used when working
// on those datatypes.
- const ModelSafeRoutingInfo routing_info_;
+ ModelSafeRoutingInfo routing_info_;
DISALLOW_COPY_AND_ASSIGN(SyncSession);
};
diff --git a/chrome/browser/sync/sessions/sync_session_context.h b/chrome/browser/sync/sessions/sync_session_context.h
index c6d87a1..2fe8832 100644
--- a/chrome/browser/sync/sessions/sync_session_context.h
+++ b/chrome/browser/sync/sessions/sync_session_context.h
@@ -84,6 +84,7 @@ class SyncSessionContext {
previous_session_routing_info_ = info;
}
+ // TODO(tim): Deprecated. Bug 26339.
sessions::SyncSessionSnapshot* previous_session_snapshot() {
return previous_session_snapshot_.get();
}
diff --git a/chrome/browser/sync/sessions/sync_session_unittest.cc b/chrome/browser/sync/sessions/sync_session_unittest.cc
index 9bb1e3b..681c0ad 100644
--- a/chrome/browser/sync/sessions/sync_session_unittest.cc
+++ b/chrome/browser/sync/sessions/sync_session_unittest.cc
@@ -4,7 +4,9 @@
#include "chrome/browser/sync/sessions/sync_session.h"
+#include "base/ref_counted.h"
#include "chrome/browser/sync/engine/conflict_resolver.h"
+#include "chrome/browser/sync/engine/mock_model_safe_workers.h"
#include "chrome/browser/sync/engine/syncer_types.h"
#include "chrome/browser/sync/engine/syncer_util.h"
#include "chrome/browser/sync/syncable/directory_manager.h"
@@ -108,7 +110,7 @@ TEST_F(SyncSessionTest, ScopedContextHelpers) {
TEST_F(SyncSessionTest, SetWriteTransaction) {
TestDirectorySetterUpper db;
db.SetUp();
- session_.reset(NULL);
+ session_.reset();
context_.reset(new SyncSessionContext(NULL, db.manager(), this,
std::vector<SyncEngineEventListener*>()));
session_.reset(MakeSession());
@@ -250,6 +252,47 @@ TEST_F(SyncSessionTest, MoreToSyncIfConflictsResolved) {
EXPECT_TRUE(session_->HasMoreToSync());
}
+TEST_F(SyncSessionTest, ResetTransientState) {
+ status()->update_conflicts_resolved(true);
+ status()->increment_num_successful_commits();
+ EXPECT_TRUE(session_->HasMoreToSync());
+ session_->ResetTransientState();
+ EXPECT_FALSE(status()->conflicts_resolved());
+ EXPECT_FALSE(session_->HasMoreToSync());
+ EXPECT_FALSE(status()->TestAndClearIsDirty());
+}
+
+TEST_F(SyncSessionTest, Coalesce) {
+ std::vector<ModelSafeWorker*> workers_one, workers_two;
+ ModelSafeRoutingInfo routes_one, routes_two;
+ SyncSourceInfo source_one(sync_pb::GetUpdatesCallerInfo::PERIODIC,
+ ParamsMeaningJustOneEnabledType());
+ SyncSourceInfo source_two(sync_pb::GetUpdatesCallerInfo::LOCAL,
+ ParamsMeaningAllEnabledTypes());
+ scoped_refptr<MockDBModelWorker> db_worker(new MockDBModelWorker());
+ scoped_refptr<MockUIModelWorker> ui_worker(new MockUIModelWorker());
+ workers_one.push_back(db_worker);
+ workers_two.push_back(db_worker);
+ workers_two.push_back(ui_worker);
+ routes_one[syncable::AUTOFILL] = GROUP_DB;
+ routes_two[syncable::AUTOFILL] = GROUP_DB;
+ routes_two[syncable::BOOKMARKS] = GROUP_UI;
+ SyncSession one(context_.get(), this, source_one, routes_one, workers_one);
+ SyncSession two(context_.get(), this, source_two, routes_two, workers_two);
+
+ one.Coalesce(two);
+
+ EXPECT_EQ(two.source().first, one.source().first);
+ EXPECT_EQ(ParamsMeaningAllEnabledTypes(), one.source().second);
+ std::vector<ModelSafeWorker*>::const_iterator it_db =
+ std::find(one.workers().begin(), one.workers().end(), db_worker);
+ std::vector<ModelSafeWorker*>::const_iterator it_ui =
+ std::find(one.workers().begin(), one.workers().end(), ui_worker);
+ EXPECT_NE(it_db, one.workers().end());
+ EXPECT_NE(it_ui, one.workers().end());
+ EXPECT_EQ(routes_two, one.routing_info());
+}
+
} // namespace
} // namespace sessions
} // namespace browser_sync
diff --git a/chrome/browser/sync/sessions/test_util.cc b/chrome/browser/sync/sessions/test_util.cc
new file mode 100644
index 0000000..d6fdef5
--- /dev/null
+++ b/chrome/browser/sync/sessions/test_util.cc
@@ -0,0 +1,53 @@
+// 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.
+
+#include "chrome/browser/sync/sessions/test_util.h"
+
+namespace browser_sync {
+namespace sessions {
+namespace test_util {
+
+void SimulateHasMoreToSync(sessions::SyncSession* session) {
+ session->status_controller()->update_conflicts_resolved(true);
+ ASSERT_TRUE(session->HasMoreToSync());
+}
+
+void SimulateDownloadUpdatesFailed(sessions::SyncSession* session) {
+ // Note that a non-zero value of changes_remaining once a session has
+ // completed implies that the Syncer was unable to exhaust this count during
+ // the GetUpdates cycle. This is an indication that an error occurred.
+ session->status_controller()->set_num_server_changes_remaining(1);
+}
+
+void SimulateCommitFailed(sessions::SyncSession* session) {
+ // Note that a non-zero number of unsynced handles once a session has
+ // completed implies that the Syncer was unable to make forward progress
+ // during a commit, indicating an error occurred.
+ // See implementation of SyncSession::HasMoreToSync.
+ std::vector<int64> handles;
+ handles.push_back(1);
+ session->status_controller()->set_unsynced_handles(handles);
+}
+
+void SimulateSuccess(sessions::SyncSession* session) {
+ if (session->HasMoreToSync()) {
+ ADD_FAILURE() << "Shouldn't have more to sync";
+ }
+ ASSERT_EQ(0U, session->status_controller()->num_server_changes_remaining());
+ ASSERT_EQ(0U, session->status_controller()->unsynced_handles().size());
+}
+
+void SimulateThrottledImpl(sessions::SyncSession* session,
+ const base::TimeDelta& delta) {
+ session->delegate()->OnSilencedUntil(base::TimeTicks::Now() + delta);
+}
+
+void SimulatePollIntervalUpdateImpl(sessions::SyncSession* session,
+ const base::TimeDelta& new_poll) {
+ session->delegate()->OnReceivedLongPollIntervalUpdate(new_poll);
+}
+
+} // namespace test_util
+} // namespace sessions
+} // namespace browser_sync
diff --git a/chrome/browser/sync/sessions/test_util.h b/chrome/browser/sync/sessions/test_util.h
new file mode 100644
index 0000000..420cf3f
--- /dev/null
+++ b/chrome/browser/sync/sessions/test_util.h
@@ -0,0 +1,39 @@
+// 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.
+//
+// Utils to simulate various outcomes of a sync session.
+#ifndef CHROME_BROWSER_SYNC_SESSIONS_TEST_UTIL_H_
+#define CHROME_BROWSER_SYNC_SESSIONS_TEST_UTIL_H_
+#pragma once
+
+#include "chrome/browser/sync/sessions/sync_session.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "testing/gmock/include/gmock/gmock.h"
+
+namespace browser_sync {
+namespace sessions {
+namespace test_util {
+
+void SimulateHasMoreToSync(sessions::SyncSession* session);
+void SimulateDownloadUpdatesFailed(sessions::SyncSession* session);
+void SimulateCommitFailed(sessions::SyncSession* session);
+void SimulateSuccess(sessions::SyncSession* session);
+void SimulateThrottledImpl(sessions::SyncSession* session,
+ const base::TimeDelta& delta);
+void SimulatePollIntervalUpdateImpl(sessions::SyncSession* session,
+ const base::TimeDelta& new_poll);
+
+ACTION_P(SimulateThrottled, throttle) {
+ SimulateThrottledImpl(arg0, throttle);
+}
+
+ACTION_P(SimulatePollIntervalUpdate, poll) {
+ SimulatePollIntervalUpdateImpl(arg0, poll);
+}
+
+} // namespace test_util
+} // namespace sessions
+} // namespace browser_sync
+
+#endif // CHROME_BROWSER_SYNC_SESSIONS_TEST_UTIL_H_