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

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

Issue 10197004: [Sync] Convert SyncSessionSnapshot to a copy-able class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments. Created 8 years, 8 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/sessions/session_state_unittest.cc ('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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 source_.updates_source = 130 source_.updates_source =
131 sync_pb::GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION; 131 sync_pb::GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION;
132 status_controller_.reset(new StatusController(routing_info_)); 132 status_controller_.reset(new StatusController(routing_info_));
133 } 133 }
134 134
135 SyncSessionSnapshot SyncSession::TakeSnapshot() const { 135 SyncSessionSnapshot SyncSession::TakeSnapshot() const {
136 syncable::Directory* dir = context_->directory(); 136 syncable::Directory* dir = context_->directory();
137 137
138 bool is_share_useable = true; 138 bool is_share_useable = true;
139 syncable::ModelTypeSet initial_sync_ended; 139 syncable::ModelTypeSet initial_sync_ended;
140 std::string download_progress_markers[syncable::MODEL_TYPE_COUNT]; 140 syncable::ModelTypePayloadMap download_progress_markers;
141 for (int i = syncable::FIRST_REAL_MODEL_TYPE; 141 for (int i = syncable::FIRST_REAL_MODEL_TYPE;
142 i < syncable::MODEL_TYPE_COUNT; ++i) { 142 i < syncable::MODEL_TYPE_COUNT; ++i) {
143 syncable::ModelType type(syncable::ModelTypeFromInt(i)); 143 syncable::ModelType type(syncable::ModelTypeFromInt(i));
144 if (routing_info_.count(type) != 0) { 144 if (routing_info_.count(type) != 0) {
145 if (dir->initial_sync_ended_for_type(type)) 145 if (dir->initial_sync_ended_for_type(type))
146 initial_sync_ended.Put(type); 146 initial_sync_ended.Put(type);
147 else 147 else
148 is_share_useable = false; 148 is_share_useable = false;
149 } 149 }
150 dir->GetDownloadProgressAsString(type, &download_progress_markers[i]); 150 dir->GetDownloadProgressAsString(type, &download_progress_markers[type]);
151 } 151 }
152 152
153 return SyncSessionSnapshot( 153 return SyncSessionSnapshot(
154 status_controller_->syncer_status(), 154 status_controller_->syncer_status(),
155 status_controller_->error(), 155 status_controller_->error(),
156 status_controller_->num_server_changes_remaining(), 156 status_controller_->num_server_changes_remaining(),
157 is_share_useable, 157 is_share_useable,
158 initial_sync_ended, 158 initial_sync_ended,
159 download_progress_markers, 159 download_progress_markers,
160 HasMoreToSync(), 160 HasMoreToSync(),
161 delegate_->IsSyncingCurrentlySilenced(), 161 delegate_->IsSyncingCurrentlySilenced(),
162 status_controller_->unsynced_handles().size(), 162 status_controller_->unsynced_handles().size(),
163 status_controller_->TotalNumEncryptionConflictingItems(), 163 status_controller_->TotalNumEncryptionConflictingItems(),
164 status_controller_->TotalNumHierarchyConflictingItems(), 164 status_controller_->TotalNumHierarchyConflictingItems(),
165 status_controller_->TotalNumSimpleConflictingItems(), 165 status_controller_->TotalNumSimpleConflictingItems(),
166 status_controller_->TotalNumServerConflictingItems(), 166 status_controller_->TotalNumServerConflictingItems(),
167 status_controller_->did_commit_items(), 167 status_controller_->did_commit_items(),
168 source_, 168 source_,
169 context_->notifications_enabled(), 169 context_->notifications_enabled(),
170 dir->GetEntriesCount(), 170 dir->GetEntriesCount(),
171 status_controller_->sync_start_time(), 171 status_controller_->sync_start_time(),
172 !Succeeded()); 172 !Succeeded());
173 } 173 }
174 174
175 void SyncSession::SendEventNotification(SyncEngineEvent::EventCause cause) { 175 void SyncSession::SendEventNotification(SyncEngineEvent::EventCause cause) {
176 SyncEngineEvent event(cause); 176 SyncEngineEvent event(cause);
177 const SyncSessionSnapshot& snapshot = TakeSnapshot(); 177 event.snapshot = TakeSnapshot();
178 event.snapshot = &snapshot;
179 178
180 DVLOG(1) << "Sending event with snapshot: " << snapshot.ToString(); 179 DVLOG(1) << "Sending event with snapshot: " << event.snapshot.ToString();
181 context()->NotifyListeners(event); 180 context()->NotifyListeners(event);
182 } 181 }
183 182
184 bool SyncSession::HasMoreToSync() const { 183 bool SyncSession::HasMoreToSync() const {
185 const StatusController* status = status_controller_.get(); 184 const StatusController* status = status_controller_.get();
186 return ((status->commit_ids().size() < status->unsynced_handles().size()) && 185 return ((status->commit_ids().size() < status->unsynced_handles().size()) &&
187 status->syncer_status().num_successful_commits > 0) || 186 status->syncer_status().num_successful_commits > 0) ||
188 status->conflicts_resolved(); 187 status->conflicts_resolved();
189 // Or, we have conflicting updates, but we're making progress on 188 // Or, we have conflicting updates, but we're making progress on
190 // resolving them... 189 // resolving them...
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 IsError(status_controller_->error().last_post_commit_result); 244 IsError(status_controller_->error().last_post_commit_result);
246 const bool process_commit_response_error = 245 const bool process_commit_response_error =
247 IsError(status_controller_->error().last_process_commit_response_result); 246 IsError(status_controller_->error().last_process_commit_response_result);
248 return !download_updates_error 247 return !download_updates_error
249 && !post_commit_error 248 && !post_commit_error
250 && !process_commit_response_error; 249 && !process_commit_response_error;
251 } 250 }
252 251
253 } // namespace sessions 252 } // namespace sessions
254 } // namespace browser_sync 253 } // namespace browser_sync
OLDNEW
« no previous file with comments | « sync/sessions/session_state_unittest.cc ('k') | sync/sessions/sync_session_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698