diff options
author | zea@chromium.org <zea@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-14 00:38:04 +0000 |
---|---|---|
committer | zea@chromium.org <zea@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-14 00:38:04 +0000 |
commit | 6ce93eac08ab2a2630b6cceeb4608f9f3f20ebde (patch) | |
tree | 770cb6d2035f7885733d576febf06e0d5ed279e8 /sync | |
parent | 4588b3d14c1b2b91729ea4807d13c92e9e48b427 (diff) | |
download | chromium_src-6ce93eac08ab2a2630b6cceeb4608f9f3f20ebde.zip chromium_src-6ce93eac08ab2a2630b6cceeb4608f9f3f20ebde.tar.gz chromium_src-6ce93eac08ab2a2630b6cceeb4608f9f3f20ebde.tar.bz2 |
[Sync] Add datatype controller support for tracking association stats
SyncMergeResult is a new class that allows datatypes and sync itself to record
association information for later use by the debug info listener. We introduce
the class and add some plumbing at the DTC level to pass these on to the
model association manager (and from there to the debug listener).
Similarly, to track syncer changes, we pass a SyncMergeResult weak pointer
to the SharedChangeProcessor, which while it's valid will increment the deltas
as changes arrive (in a future patch). The weak pointer is invalidated at the end
of association by the DTC.
To simplify the DTC plumbing of merge results, StartFailed has been merged
into StartDone. Additionally, removed some old logging code attempting to
identify which datatype was being Stopped that isn't necessary anymore.
BUG=158576
Review URL: https://chromiumcodereview.appspot.com/11401002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@167528 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync')
-rw-r--r-- | sync/api/sync_merge_result.cc | 77 | ||||
-rw-r--r-- | sync/api/sync_merge_result.h | 73 | ||||
-rw-r--r-- | sync/api/sync_merge_result_unittest.cc | 77 | ||||
-rw-r--r-- | sync/sync.gyp | 5 |
4 files changed, 231 insertions, 1 deletions
diff --git a/sync/api/sync_merge_result.cc b/sync/api/sync_merge_result.cc new file mode 100644 index 0000000..c2253b3 --- /dev/null +++ b/sync/api/sync_merge_result.cc @@ -0,0 +1,77 @@ +// 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. + +#include "sync/api/sync_merge_result.h" + +namespace syncer { + +SyncMergeResult::SyncMergeResult(ModelType type) + : model_type_(type), + num_items_before_association_(0), + num_items_after_association_(0), + num_items_added_(0), + num_items_deleted_(0), + num_items_modified_(0) { +} + +SyncMergeResult::~SyncMergeResult() { +} + +// Setters. +void SyncMergeResult::set_error(SyncError error) { + DCHECK_EQ(model_type_, error.type()); + error_ = error; +} + +void SyncMergeResult::set_num_items_before_association( + int num_items_before_association) { + num_items_before_association_ = num_items_before_association; +} + +void SyncMergeResult::set_num_items_after_association( + int num_items_after_association) { + num_items_after_association_ = num_items_after_association; +} + +void SyncMergeResult::set_num_items_added(int num_items_added) { + num_items_added_ = num_items_added; +} + +void SyncMergeResult::set_num_items_deleted(int num_items_deleted) { + num_items_deleted_ = num_items_deleted; +} + +void SyncMergeResult::set_num_items_modified(int num_items_modified) { + num_items_modified_ = num_items_modified; +} + +ModelType SyncMergeResult::model_type() const { + return model_type_; +} + +SyncError SyncMergeResult::error() const { + return error_; +} + +int SyncMergeResult::num_items_before_association() const { + return num_items_before_association_; +} + +int SyncMergeResult::num_items_after_association() const { + return num_items_after_association_; +} + +int SyncMergeResult::num_items_added() const { + return num_items_added_; +} + +int SyncMergeResult::num_items_deleted() const { + return num_items_deleted_; +} + +int SyncMergeResult::num_items_modified() const { + return num_items_modified_; +} + +} // namespace syncer diff --git a/sync/api/sync_merge_result.h b/sync/api/sync_merge_result.h new file mode 100644 index 0000000..41accfd --- /dev/null +++ b/sync/api/sync_merge_result.h @@ -0,0 +1,73 @@ +// 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 SYNC_API_SYNC_MERGE_RESULT_H_ +#define SYNC_API_SYNC_MERGE_RESULT_H_ + +#include "sync/api/sync_error.h" +#include "sync/internal_api/public/base/model_type.h" + +namespace syncer { + +// A model-type-specific view of a sync merge. This class encapsulates the +// state before and after the merge as well as the deltas and any error that +// occurred. +// Note: This class only tracks one side of the merge. In other words, if built +// by the local SyncableService, all values correspond to the local state before +// and after merging, and the delta's applied to that state. Sync's change +// processor will create a separate merge result. +class SyncMergeResult { + public: + // Initialize an empty merge result for model type |type|. + explicit SyncMergeResult(ModelType type); + ~SyncMergeResult(); + + // Default copy and assign welcome. + + // Setters. + // Note: |error.IsSet()| must be true, and |error.type()| must match + // model_type_ + void set_error(SyncError error); + void set_num_items_before_association(int num_items_before_association); + void set_num_items_after_association(int num_items_after_association); + void set_num_items_added(int num_items_added); + void set_num_items_deleted(int num_items_deleted); + void set_num_items_modified(int num_items_modified); + + // Getters. + ModelType model_type() const; + SyncError error() const; + int num_items_before_association() const; + int num_items_after_association() const; + int num_items_added() const; + int num_items_deleted() const; + int num_items_modified() const; + + private: + // Make |this| into a copy of |other|. + void CopyFrom(const SyncMergeResult& other); + + // The datatype that was associated. + ModelType model_type_; + + // The error encountered during association. Unset if no error was + // encountered. + SyncError error_; + + // The state of the world before association. + int num_items_before_association_; + + // The state of the world after association. + int num_items_after_association_; + + // The changes that took place during association. In a correctly working + // system these should be the deltas between before and after. + int num_items_added_; + int num_items_deleted_; + int num_items_modified_; +}; + +} // namespace syncer + +#endif // SYNC_API_SYNC_MERGE_RESULT_H_ diff --git a/sync/api/sync_merge_result_unittest.cc b/sync/api/sync_merge_result_unittest.cc new file mode 100644 index 0000000..dddfa4c --- /dev/null +++ b/sync/api/sync_merge_result_unittest.cc @@ -0,0 +1,77 @@ +// 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. + +#include "sync/api/sync_merge_result.h" + +#include "base/location.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace syncer { + +namespace { + +typedef testing::Test SyncMergeResultTest; + +TEST_F(SyncMergeResultTest, Unset) { + SyncMergeResult merge_result(BOOKMARKS); + EXPECT_FALSE(merge_result.error().IsSet()); + EXPECT_EQ(0, merge_result.num_items_before_association()); + EXPECT_EQ(0, merge_result.num_items_after_association()); + EXPECT_EQ(0, merge_result.num_items_added()); + EXPECT_EQ(0, merge_result.num_items_deleted()); + EXPECT_EQ(0, merge_result.num_items_modified()); +} + +TEST_F(SyncMergeResultTest, SetError) { + SyncError error(FROM_HERE, "message", BOOKMARKS); + SyncMergeResult merge_result(BOOKMARKS); + + merge_result.set_error(error); + EXPECT_TRUE(merge_result.error().IsSet()); + EXPECT_EQ(BOOKMARKS, merge_result.model_type()); +} + +TEST_F(SyncMergeResultTest, SetNumItemsBeforeAssociation) { + SyncMergeResult merge_result(BOOKMARKS); + EXPECT_EQ(0, merge_result.num_items_before_association()); + + merge_result.set_num_items_before_association(10); + EXPECT_EQ(10, merge_result.num_items_before_association()); +} + +TEST_F(SyncMergeResultTest, SetNumItemsAfterAssociation) { + SyncMergeResult merge_result(BOOKMARKS); + EXPECT_EQ(0, merge_result.num_items_after_association()); + + merge_result.set_num_items_after_association(10); + EXPECT_EQ(10, merge_result.num_items_after_association()); +} + +TEST_F(SyncMergeResultTest, SetNumItemsAdded) { + SyncMergeResult merge_result(BOOKMARKS); + EXPECT_EQ(0, merge_result.num_items_added()); + + merge_result.set_num_items_added(10); + EXPECT_EQ(10, merge_result.num_items_added()); +} + +TEST_F(SyncMergeResultTest, SetNumItemsDeleted) { + SyncMergeResult merge_result(BOOKMARKS); + EXPECT_EQ(0, merge_result.num_items_deleted()); + + merge_result.set_num_items_deleted(10); + EXPECT_EQ(10, merge_result.num_items_deleted()); +} + +TEST_F(SyncMergeResultTest, SetNumItemsModified) { + SyncMergeResult merge_result(BOOKMARKS); + EXPECT_EQ(0, merge_result.num_items_modified()); + + merge_result.set_num_items_modified(10); + EXPECT_EQ(10, merge_result.num_items_modified()); +} + +} // namespace + +} // namespace syncer diff --git a/sync/sync.gyp b/sync/sync.gyp index 6172b84..758ef4c 100644 --- a/sync/sync.gyp +++ b/sync/sync.gyp @@ -415,6 +415,8 @@ 'api/sync_error.cc', 'api/sync_error_factory.h', 'api/sync_error_factory.cc', + 'api/sync_merge_result.h', + 'api/sync_merge_result.cc', 'api/time.h', ], }, @@ -612,6 +614,7 @@ 'internal_api/public/base/ordinal_unittest.cc', 'internal_api/public/engine/model_safe_worker_unittest.cc', 'internal_api/public/util/immutable_unittest.cc', + 'internal_api/public/util/weak_handle_unittest.cc', 'engine/apply_control_data_updates_unittest.cc', 'engine/apply_updates_and_resolve_conflicts_command_unittest.cc', 'engine/backoff_delay_provider_unittest.cc', @@ -647,7 +650,6 @@ 'util/get_session_name_unittest.cc', 'util/nigori_unittest.cc', 'util/protobuf_unittest.cc', - 'internal_api/public/util/weak_handle_unittest.cc', ], 'conditions': [ ['OS == "ios" and coverage != 0', { @@ -832,6 +834,7 @@ 'sources': [ 'api/sync_change_unittest.cc', 'api/sync_error_unittest.cc', + 'api/sync_merge_result_unittest.cc', ], }, }, |