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

Side by Side Diff: sync/sessions/sync_session.cc

Issue 11314008: sync: Follow-up to conflict resolution refactor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix tests Created 8 years, 1 month 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/sessions/sync_session.h ('k') | sync/sessions/sync_session_context.h » ('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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/sessions/sync_session.h" 5 #include "sync/sessions/sync_session.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 std::sort(sorted_workers.begin(), sorted_workers.end()); 138 std::sort(sorted_workers.begin(), sorted_workers.end());
139 std::set_intersection(workers_.begin(), workers_.end(), 139 std::set_intersection(workers_.begin(), workers_.end(),
140 sorted_workers.begin(), sorted_workers.end(), 140 sorted_workers.begin(), sorted_workers.end(),
141 std::back_inserter(temp)); 141 std::back_inserter(temp));
142 workers_.swap(temp); 142 workers_.swap(temp);
143 143
144 // Now update enabled groups. 144 // Now update enabled groups.
145 enabled_groups_ = ComputeEnabledGroups(routing_info_, workers_); 145 enabled_groups_ = ComputeEnabledGroups(routing_info_, workers_);
146 } 146 }
147 147
148 void SyncSession::PrepareForAnotherSyncCycle() {
149 source_.updates_source =
150 sync_pb::GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION;
151 status_controller_.reset(new StatusController(routing_info_));
152 }
153
154 SyncSessionSnapshot SyncSession::TakeSnapshot() const { 148 SyncSessionSnapshot SyncSession::TakeSnapshot() const {
155 syncable::Directory* dir = context_->directory(); 149 syncable::Directory* dir = context_->directory();
156 150
157 bool is_share_useable = true; 151 bool is_share_useable = true;
158 ModelTypeSet initial_sync_ended; 152 ModelTypeSet initial_sync_ended;
159 ProgressMarkerMap download_progress_markers; 153 ProgressMarkerMap download_progress_markers;
160 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { 154 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) {
161 ModelType type(ModelTypeFromInt(i)); 155 ModelType type(ModelTypeFromInt(i));
162 if (routing_info_.count(type) != 0) { 156 if (routing_info_.count(type) != 0) {
163 if (dir->initial_sync_ended_for_type(type)) 157 if (dir->initial_sync_ended_for_type(type))
164 initial_sync_ended.Put(type); 158 initial_sync_ended.Put(type);
165 else 159 else
166 is_share_useable = false; 160 is_share_useable = false;
167 } 161 }
168 dir->GetDownloadProgressAsString(type, &download_progress_markers[type]); 162 dir->GetDownloadProgressAsString(type, &download_progress_markers[type]);
169 } 163 }
170 164
171 return SyncSessionSnapshot( 165 return SyncSessionSnapshot(
172 status_controller_->model_neutral_state(), 166 status_controller_->model_neutral_state(),
173 is_share_useable, 167 is_share_useable,
174 initial_sync_ended, 168 initial_sync_ended,
175 download_progress_markers, 169 download_progress_markers,
176 HasMoreToSync(),
177 delegate_->IsSyncingCurrentlySilenced(), 170 delegate_->IsSyncingCurrentlySilenced(),
178 status_controller_->num_encryption_conflicts(), 171 status_controller_->num_encryption_conflicts(),
179 status_controller_->num_hierarchy_conflicts(), 172 status_controller_->num_hierarchy_conflicts(),
180 status_controller_->num_simple_conflicts(),
181 status_controller_->num_server_conflicts(), 173 status_controller_->num_server_conflicts(),
182 source_, 174 source_,
183 context_->notifications_enabled(), 175 context_->notifications_enabled(),
184 dir->GetEntriesCount(), 176 dir->GetEntriesCount(),
185 status_controller_->sync_start_time()); 177 status_controller_->sync_start_time());
186 } 178 }
187 179
188 void SyncSession::SendEventNotification(SyncEngineEvent::EventCause cause) { 180 void SyncSession::SendEventNotification(SyncEngineEvent::EventCause cause) {
189 SyncEngineEvent event(cause); 181 SyncEngineEvent event(cause);
190 event.snapshot = TakeSnapshot(); 182 event.snapshot = TakeSnapshot();
191 183
192 DVLOG(1) << "Sending event with snapshot: " << event.snapshot.ToString(); 184 DVLOG(1) << "Sending event with snapshot: " << event.snapshot.ToString();
193 context()->NotifyListeners(event); 185 context()->NotifyListeners(event);
194 } 186 }
195 187
196 bool SyncSession::HasMoreToSync() const {
197 const StatusController* status = status_controller_.get();
198 return status->conflicts_resolved();
199 }
200
201 const std::set<ModelSafeGroup>& SyncSession::GetEnabledGroups() const { 188 const std::set<ModelSafeGroup>& SyncSession::GetEnabledGroups() const {
202 return enabled_groups_; 189 return enabled_groups_;
203 } 190 }
204 191
205 // TODO(rlarocque): Delete this function after refactoring conflict resolution.
206 std::set<ModelSafeGroup> SyncSession::GetEnabledGroupsWithConflicts() const {
207 const std::set<ModelSafeGroup>& enabled_groups = GetEnabledGroups();
208 std::set<ModelSafeGroup> enabled_groups_with_conflicts;
209 for (std::set<ModelSafeGroup>::const_iterator it =
210 enabled_groups.begin(); it != enabled_groups.end(); ++it) {
211 const std::set<syncable::Id>* ids =
212 status_controller_->GetUnrestrictedSimpleConflictIds(*it);
213 if (ids && ids->size() > 0) {
214 enabled_groups_with_conflicts.insert(*it);
215 }
216 }
217 return enabled_groups_with_conflicts;
218 }
219
220 bool SyncSession::DidReachServer() const { 192 bool SyncSession::DidReachServer() const {
221 const ModelNeutralState& state = status_controller_->model_neutral_state(); 193 const ModelNeutralState& state = status_controller_->model_neutral_state();
222 return state.last_get_key_result >= FIRST_SERVER_RETURN_VALUE || 194 return state.last_get_key_result >= FIRST_SERVER_RETURN_VALUE ||
223 state.last_download_updates_result >= FIRST_SERVER_RETURN_VALUE || 195 state.last_download_updates_result >= FIRST_SERVER_RETURN_VALUE ||
224 state.commit_result >= FIRST_SERVER_RETURN_VALUE; 196 state.commit_result >= FIRST_SERVER_RETURN_VALUE;
225 } 197 }
226 198
227 } // namespace sessions 199 } // namespace sessions
228 } // namespace syncer 200 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/sessions/sync_session.h ('k') | sync/sessions/sync_session_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698