Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: sync/engine/model_type_entity.cc

Issue 351523003: sync: Mass rename of non-blocking sync classes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: const ref some smart pointers Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sync/engine/model_type_entity.h ('k') | sync/engine/model_type_entity_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "sync/engine/model_thread_sync_entity.h" 5 #include "sync/engine/model_type_entity.h"
6 #include "sync/syncable/syncable_util.h" 6 #include "sync/syncable/syncable_util.h"
7 7
8 namespace syncer { 8 namespace syncer {
9 9
10 scoped_ptr<ModelThreadSyncEntity> ModelThreadSyncEntity::NewLocalItem( 10 scoped_ptr<ModelTypeEntity> ModelTypeEntity::NewLocalItem(
11 const std::string& client_tag, 11 const std::string& client_tag,
12 const sync_pb::EntitySpecifics& specifics, 12 const sync_pb::EntitySpecifics& specifics,
13 base::Time now) { 13 base::Time now) {
14 return scoped_ptr<ModelThreadSyncEntity>(new ModelThreadSyncEntity( 14 return scoped_ptr<ModelTypeEntity>(new ModelTypeEntity(
15 1, 15 1,
16 0, 16 0,
17 0, 17 0,
18 kUncommittedVersion, 18 kUncommittedVersion,
19 true, 19 true,
20 std::string(), // Sync thread will assign the initial ID. 20 std::string(), // Sync thread will assign the initial ID.
21 syncable::GenerateSyncableHash(GetModelTypeFromSpecifics(specifics), 21 syncable::GenerateSyncableHash(GetModelTypeFromSpecifics(specifics),
22 client_tag), 22 client_tag),
23 client_tag, // As non-unique name. 23 client_tag, // As non-unique name.
24 specifics, 24 specifics,
25 false, 25 false,
26 now, 26 now,
27 now)); 27 now));
28 } 28 }
29 29
30 scoped_ptr<ModelThreadSyncEntity> ModelThreadSyncEntity::FromServerUpdate( 30 scoped_ptr<ModelTypeEntity> ModelTypeEntity::FromServerUpdate(
31 const std::string& id, 31 const std::string& id,
32 const std::string& client_tag_hash, 32 const std::string& client_tag_hash,
33 const std::string& non_unique_name, 33 const std::string& non_unique_name,
34 int64 version, 34 int64 version,
35 const sync_pb::EntitySpecifics& specifics, 35 const sync_pb::EntitySpecifics& specifics,
36 bool deleted, 36 bool deleted,
37 base::Time ctime, 37 base::Time ctime,
38 base::Time mtime) { 38 base::Time mtime) {
39 return scoped_ptr<ModelThreadSyncEntity>( 39 return scoped_ptr<ModelTypeEntity>(new ModelTypeEntity(0,
40 new ModelThreadSyncEntity(0, 40 0,
41 0, 41 0,
42 0, 42 version,
43 version, 43 true,
44 true, 44 id,
45 id, 45 client_tag_hash,
46 client_tag_hash, 46 non_unique_name,
47 non_unique_name, 47 specifics,
48 specifics, 48 deleted,
49 deleted, 49 ctime,
50 ctime, 50 mtime));
51 mtime));
52 } 51 }
53 52
54 ModelThreadSyncEntity::ModelThreadSyncEntity( 53 ModelTypeEntity::ModelTypeEntity(int64 sequence_number,
55 int64 sequence_number, 54 int64 commit_requested_sequence_number,
56 int64 commit_requested_sequence_number, 55 int64 acked_sequence_number,
57 int64 acked_sequence_number, 56 int64 base_version,
58 int64 base_version, 57 bool is_dirty,
59 bool is_dirty, 58 const std::string& id,
60 const std::string& id, 59 const std::string& client_tag_hash,
61 const std::string& client_tag_hash, 60 const std::string& non_unique_name,
62 const std::string& non_unique_name, 61 const sync_pb::EntitySpecifics& specifics,
63 const sync_pb::EntitySpecifics& specifics, 62 bool deleted,
64 bool deleted, 63 base::Time ctime,
65 base::Time ctime, 64 base::Time mtime)
66 base::Time mtime)
67 : sequence_number_(sequence_number), 65 : sequence_number_(sequence_number),
68 commit_requested_sequence_number_(commit_requested_sequence_number), 66 commit_requested_sequence_number_(commit_requested_sequence_number),
69 acked_sequence_number_(acked_sequence_number), 67 acked_sequence_number_(acked_sequence_number),
70 base_version_(base_version), 68 base_version_(base_version),
71 is_dirty_(is_dirty), 69 is_dirty_(is_dirty),
72 id_(id), 70 id_(id),
73 client_tag_hash_(client_tag_hash), 71 client_tag_hash_(client_tag_hash),
74 non_unique_name_(non_unique_name), 72 non_unique_name_(non_unique_name),
75 specifics_(specifics), 73 specifics_(specifics),
76 deleted_(deleted), 74 deleted_(deleted),
77 ctime_(ctime), 75 ctime_(ctime),
78 mtime_(mtime) { 76 mtime_(mtime) {
79 } 77 }
80 78
81 ModelThreadSyncEntity::~ModelThreadSyncEntity() { 79 ModelTypeEntity::~ModelTypeEntity() {
82 } 80 }
83 81
84 bool ModelThreadSyncEntity::IsWriteRequired() const { 82 bool ModelTypeEntity::IsWriteRequired() const {
85 return is_dirty_; 83 return is_dirty_;
86 } 84 }
87 85
88 bool ModelThreadSyncEntity::IsUnsynced() const { 86 bool ModelTypeEntity::IsUnsynced() const {
89 return sequence_number_ > acked_sequence_number_; 87 return sequence_number_ > acked_sequence_number_;
90 } 88 }
91 89
92 bool ModelThreadSyncEntity::RequiresCommitRequest() const { 90 bool ModelTypeEntity::RequiresCommitRequest() const {
93 return sequence_number_ > commit_requested_sequence_number_; 91 return sequence_number_ > commit_requested_sequence_number_;
94 } 92 }
95 93
96 bool ModelThreadSyncEntity::UpdateIsReflection(int64 update_version) const { 94 bool ModelTypeEntity::UpdateIsReflection(int64 update_version) const {
97 return base_version_ >= update_version; 95 return base_version_ >= update_version;
98 } 96 }
99 97
100 bool ModelThreadSyncEntity::UpdateIsInConflict(int64 update_version) const { 98 bool ModelTypeEntity::UpdateIsInConflict(int64 update_version) const {
101 return IsUnsynced() && !UpdateIsReflection(update_version); 99 return IsUnsynced() && !UpdateIsReflection(update_version);
102 } 100 }
103 101
104 void ModelThreadSyncEntity::ApplyUpdateFromServer( 102 void ModelTypeEntity::ApplyUpdateFromServer(
105 int64 update_version, 103 int64 update_version,
106 bool deleted, 104 bool deleted,
107 const sync_pb::EntitySpecifics& specifics, 105 const sync_pb::EntitySpecifics& specifics,
108 base::Time mtime) { 106 base::Time mtime) {
109 // There was a conflict and the server just won it. 107 // There was a conflict and the server just won it.
110 // This implicitly acks all outstanding commits because a received update 108 // This implicitly acks all outstanding commits because a received update
111 // will clobber any pending commits on the sync thread. 109 // will clobber any pending commits on the sync thread.
112 acked_sequence_number_ = sequence_number_; 110 acked_sequence_number_ = sequence_number_;
113 commit_requested_sequence_number_ = sequence_number_; 111 commit_requested_sequence_number_ = sequence_number_;
114 112
115 base_version_ = update_version; 113 base_version_ = update_version;
116 specifics_ = specifics; 114 specifics_ = specifics;
117 mtime_ = mtime; 115 mtime_ = mtime;
118 } 116 }
119 117
120 void ModelThreadSyncEntity::MakeLocalChange( 118 void ModelTypeEntity::MakeLocalChange(
121 const sync_pb::EntitySpecifics& specifics) { 119 const sync_pb::EntitySpecifics& specifics) {
122 sequence_number_++; 120 sequence_number_++;
123 specifics_ = specifics; 121 specifics_ = specifics;
124 } 122 }
125 123
126 void ModelThreadSyncEntity::Delete() { 124 void ModelTypeEntity::Delete() {
127 sequence_number_++; 125 sequence_number_++;
128 specifics_.Clear(); 126 specifics_.Clear();
129 deleted_ = true; 127 deleted_ = true;
130 } 128 }
131 129
132 void ModelThreadSyncEntity::InitializeCommitRequestData( 130 void ModelTypeEntity::InitializeCommitRequestData(
133 CommitRequestData* request) const { 131 CommitRequestData* request) const {
134 request->id = id_; 132 request->id = id_;
135 request->client_tag_hash = client_tag_hash_; 133 request->client_tag_hash = client_tag_hash_;
136 request->sequence_number = sequence_number_; 134 request->sequence_number = sequence_number_;
137 request->base_version = base_version_; 135 request->base_version = base_version_;
138 request->ctime = ctime_; 136 request->ctime = ctime_;
139 request->mtime = mtime_; 137 request->mtime = mtime_;
140 request->non_unique_name = non_unique_name_; 138 request->non_unique_name = non_unique_name_;
141 request->deleted = deleted_; 139 request->deleted = deleted_;
142 request->specifics.CopyFrom(specifics_); 140 request->specifics.CopyFrom(specifics_);
143 } 141 }
144 142
145 void ModelThreadSyncEntity::SetCommitRequestInProgress() { 143 void ModelTypeEntity::SetCommitRequestInProgress() {
146 commit_requested_sequence_number_ = sequence_number_; 144 commit_requested_sequence_number_ = sequence_number_;
147 } 145 }
148 146
149 void ModelThreadSyncEntity::ReceiveCommitResponse(const std::string& id, 147 void ModelTypeEntity::ReceiveCommitResponse(const std::string& id,
150 int64 sequence_number, 148 int64 sequence_number,
151 int64 response_version) { 149 int64 response_version) {
152 id_ = id; // The server can assign us a new ID in a commit response. 150 id_ = id; // The server can assign us a new ID in a commit response.
153 acked_sequence_number_ = sequence_number; 151 acked_sequence_number_ = sequence_number;
154 base_version_ = response_version; 152 base_version_ = response_version;
155 } 153 }
156 154
157 void ModelThreadSyncEntity::ClearTransientSyncState() { 155 void ModelTypeEntity::ClearTransientSyncState() {
158 // If we have any unacknowledged commit requests outstatnding, they've been 156 // If we have any unacknowledged commit requests outstatnding, they've been
159 // dropped and we should forget about them. 157 // dropped and we should forget about them.
160 commit_requested_sequence_number_ = acked_sequence_number_; 158 commit_requested_sequence_number_ = acked_sequence_number_;
161 } 159 }
162 160
163 void ModelThreadSyncEntity::ClearSyncState() { 161 void ModelTypeEntity::ClearSyncState() {
164 base_version_ = kUncommittedVersion; 162 base_version_ = kUncommittedVersion;
165 is_dirty_ = true; 163 is_dirty_ = true;
166 sequence_number_ = 1; 164 sequence_number_ = 1;
167 commit_requested_sequence_number_ = 0; 165 commit_requested_sequence_number_ = 0;
168 acked_sequence_number_ = 0; 166 acked_sequence_number_ = 0;
169 id_.clear(); 167 id_.clear();
170 } 168 }
171 169
172 } // namespace syncer 170 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/engine/model_type_entity.h ('k') | sync/engine/model_type_entity_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698