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

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

Issue 8771044: Revert 112743 - [Sync] Make syncer commands avoid posting tasks on threads with no work to do (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/sync/sessions/sync_session.h" 5 #include "chrome/browser/sync/sessions/sync_session.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h"
10 #include "chrome/browser/sync/syncable/directory_manager.h" 9 #include "chrome/browser/sync/syncable/directory_manager.h"
11 #include "chrome/browser/sync/syncable/model_type.h" 10 #include "chrome/browser/sync/syncable/model_type.h"
12 11
13 namespace browser_sync { 12 namespace browser_sync {
14 namespace sessions { 13 namespace sessions {
15 14
16 namespace {
17
18 std::set<ModelSafeGroup> ComputeEnabledGroups(
19 const ModelSafeRoutingInfo& routing_info,
20 const std::vector<ModelSafeWorker*>& workers) {
21 std::set<ModelSafeGroup> enabled_groups;
22 // Project the list of enabled types (i.e., types in the routing
23 // info) to a list of enabled groups.
24 for (ModelSafeRoutingInfo::const_iterator it = routing_info.begin();
25 it != routing_info.end(); ++it) {
26 enabled_groups.insert(it->second);
27 }
28 // GROUP_PASSIVE is always enabled, since that's the group that
29 // top-level folders map to.
30 enabled_groups.insert(GROUP_PASSIVE);
31 if (DCHECK_IS_ON()) {
32 // We sometimes create dummy SyncSession objects (see
33 // SyncScheduler::InitialSnapshot) so don't check in that case.
34 if (!routing_info.empty() || !workers.empty()) {
35 std::set<ModelSafeGroup> groups_with_workers;
36 for (std::vector<ModelSafeWorker*>::const_iterator it = workers.begin();
37 it != workers.end(); ++it) {
38 groups_with_workers.insert((*it)->GetModelSafeGroup());
39 }
40 // All enabled groups should have a corresponding worker.
41 DCHECK(std::includes(
42 groups_with_workers.begin(), groups_with_workers.end(),
43 enabled_groups.begin(), enabled_groups.end()));
44 }
45 }
46 return enabled_groups;
47 }
48
49 } // namesepace
50
51 SyncSession::SyncSession(SyncSessionContext* context, Delegate* delegate, 15 SyncSession::SyncSession(SyncSessionContext* context, Delegate* delegate,
52 const SyncSourceInfo& source, 16 const SyncSourceInfo& source,
53 const ModelSafeRoutingInfo& routing_info, 17 const ModelSafeRoutingInfo& routing_info,
54 const std::vector<ModelSafeWorker*>& workers) 18 const std::vector<ModelSafeWorker*>& workers)
55 : context_(context), 19 : context_(context),
56 source_(source), 20 source_(source),
57 write_transaction_(NULL), 21 write_transaction_(NULL),
58 delegate_(delegate), 22 delegate_(delegate),
59 workers_(workers), 23 workers_(workers),
60 routing_info_(routing_info), 24 routing_info_(routing_info) {
61 enabled_groups_(ComputeEnabledGroups(routing_info_, workers_)) {
62 status_controller_.reset(new StatusController(routing_info_)); 25 status_controller_.reset(new StatusController(routing_info_));
63 std::sort(workers_.begin(), workers_.end()); 26 std::sort(workers_.begin(), workers_.end());
64 } 27 }
65 28
66 SyncSession::~SyncSession() {} 29 SyncSession::~SyncSession() {}
67 30
68 void SyncSession::Coalesce(const SyncSession& session) { 31 void SyncSession::Coalesce(const SyncSession& session) {
69 if (context_ != session.context() || delegate_ != session.delegate_) { 32 if (context_ != session.context() || delegate_ != session.delegate_) {
70 NOTREACHED(); 33 NOTREACHED();
71 return; 34 return;
(...skipping 11 matching lines...) Expand all
83 workers_.swap(temp); 46 workers_.swap(temp);
84 47
85 // We have to update the model safe routing info to the union. In case the 48 // We have to update the model safe routing info to the union. In case the
86 // same key is present in both pick the one from session. 49 // same key is present in both pick the one from session.
87 for (ModelSafeRoutingInfo::const_iterator it = 50 for (ModelSafeRoutingInfo::const_iterator it =
88 session.routing_info_.begin(); 51 session.routing_info_.begin();
89 it != session.routing_info_.end(); 52 it != session.routing_info_.end();
90 ++it) { 53 ++it) {
91 routing_info_[it->first] = it->second; 54 routing_info_[it->first] = it->second;
92 } 55 }
93
94 // Now update enabled groups.
95 enabled_groups_ = ComputeEnabledGroups(routing_info_, workers_);
96 } 56 }
97 57
98 void SyncSession::RebaseRoutingInfoWithLatest(const SyncSession& session) { 58 void SyncSession::RebaseRoutingInfoWithLatest(SyncSession* session) {
99 ModelSafeRoutingInfo temp_routing_info; 59 ModelSafeRoutingInfo temp_routing_info;
100 60
101 // Take the intersecion and also set the routing info(it->second) from the 61 // Take the intersecion and also set the routing info(it->second) from the
102 // passed in session. 62 // passed in session.
103 for (ModelSafeRoutingInfo::const_iterator it = 63 for (ModelSafeRoutingInfo::const_iterator it =
104 session.routing_info_.begin(); it != session.routing_info_.end(); 64 session->routing_info_.begin(); it != session->routing_info_.end();
105 ++it) { 65 ++it) {
106 if (routing_info_.find(it->first) != routing_info_.end()) { 66 if (routing_info_.find(it->first) != routing_info_.end()) {
107 temp_routing_info[it->first] = it->second; 67 temp_routing_info[it->first] = it->second;
108 } 68 }
109 } 69 }
110 70
111 // Now swap it. 71 // Now swap it.
112 routing_info_.swap(temp_routing_info); 72 routing_info_.swap(temp_routing_info);
113 73
114 // Now update the payload map. 74 // Now update the payload map.
115 PurgeStalePayload(&source_.types, session.routing_info_); 75 PurgeStalePayload(&source_.types, session->routing_info_);
116 76
117 // Now update the workers. 77 // Now update the workers.
118 std::vector<ModelSafeWorker*> temp; 78 std::vector<ModelSafeWorker*> temp;
119 std::set_intersection(workers_.begin(), workers_.end(), 79 std::set_intersection(workers_.begin(), workers_.end(),
120 session.workers_.begin(), session.workers_.end(), 80 session->workers_.begin(), session->workers_.end(),
121 std::back_inserter(temp)); 81 std::back_inserter(temp));
122 workers_.swap(temp); 82 workers_.swap(temp);
123
124 // Now update enabled groups.
125 enabled_groups_ = ComputeEnabledGroups(routing_info_, workers_);
126 } 83 }
127 84
128 void SyncSession::ResetTransientState() { 85 void SyncSession::ResetTransientState() {
129 status_controller_.reset(new StatusController(routing_info_)); 86 status_controller_.reset(new StatusController(routing_info_));
130 } 87 }
131 88
132 SyncSessionSnapshot SyncSession::TakeSnapshot() const { 89 SyncSessionSnapshot SyncSession::TakeSnapshot() const {
133 syncable::ScopedDirLookup dir(context_->directory_manager(), 90 syncable::ScopedDirLookup dir(context_->directory_manager(),
134 context_->account_name()); 91 context_->account_name());
135 if (!dir.good()) 92 if (!dir.good())
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 } 134 }
178 135
179 bool SyncSession::HasMoreToSync() const { 136 bool SyncSession::HasMoreToSync() const {
180 const StatusController* status = status_controller_.get(); 137 const StatusController* status = status_controller_.get();
181 return ((status->commit_ids().size() < status->unsynced_handles().size()) && 138 return ((status->commit_ids().size() < status->unsynced_handles().size()) &&
182 status->syncer_status().num_successful_commits > 0) || 139 status->syncer_status().num_successful_commits > 0) ||
183 status->conflict_sets_built() || 140 status->conflict_sets_built() ||
184 status->conflicts_resolved(); 141 status->conflicts_resolved();
185 // Or, we have conflicting updates, but we're making progress on 142 // Or, we have conflicting updates, but we're making progress on
186 // resolving them... 143 // resolving them...
187 }
188
189 const std::set<ModelSafeGroup>& SyncSession::GetEnabledGroups() const {
190 return enabled_groups_;
191 }
192
193 std::set<ModelSafeGroup> SyncSession::GetEnabledGroupsWithConflicts() const {
194 const std::set<ModelSafeGroup>& enabled_groups = GetEnabledGroups();
195 std::set<ModelSafeGroup> enabled_groups_with_conflicts;
196 for (std::set<ModelSafeGroup>::const_iterator it =
197 enabled_groups.begin(); it != enabled_groups.end(); ++it) {
198 const sessions::ConflictProgress* conflict_progress =
199 status_controller_->GetUnrestrictedConflictProgress(*it);
200 if (conflict_progress &&
201 (conflict_progress->ConflictingItemsBegin() !=
202 conflict_progress->ConflictingItemsEnd())) {
203 enabled_groups_with_conflicts.insert(*it);
204 }
205 } 144 }
206 return enabled_groups_with_conflicts;
207 }
208
209 std::set<ModelSafeGroup>
210 SyncSession::GetEnabledGroupsWithVerifiedUpdates() const {
211 const std::set<ModelSafeGroup>& enabled_groups = GetEnabledGroups();
212 std::set<ModelSafeGroup> enabled_groups_with_verified_updates;
213 for (std::set<ModelSafeGroup>::const_iterator it =
214 enabled_groups.begin(); it != enabled_groups.end(); ++it) {
215 const UpdateProgress* update_progress =
216 status_controller_->GetUnrestrictedUpdateProgress(*it);
217 if (update_progress &&
218 (update_progress->VerifiedUpdatesBegin() !=
219 update_progress->VerifiedUpdatesEnd())) {
220 enabled_groups_with_verified_updates.insert(*it);
221 }
222 }
223
224 return enabled_groups_with_verified_updates;
225 }
226
227 145
228 } // namespace sessions 146 } // namespace sessions
229 } // namespace browser_sync 147 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/sessions/sync_session.h ('k') | chrome/browser/sync/sessions/sync_session_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698