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

Side by Side Diff: chrome/browser/sync/engine/model_changing_syncer_command.cc

Issue 8637006: [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: Refactor some test code Created 9 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
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/engine/model_changing_syncer_command.h" 5 #include "chrome/browser/sync/engine/model_changing_syncer_command.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/callback_old.h" 8 #include "base/callback_old.h"
9 #include "chrome/browser/sync/engine/model_safe_worker.h"
10 #include "chrome/browser/sync/sessions/status_controller.h" 9 #include "chrome/browser/sync/sessions/status_controller.h"
11 #include "chrome/browser/sync/sessions/sync_session.h" 10 #include "chrome/browser/sync/sessions/sync_session.h"
12 #include "chrome/browser/sync/util/unrecoverable_error_info.h" 11 #include "chrome/browser/sync/util/unrecoverable_error_info.h"
13 12
14 namespace browser_sync { 13 namespace browser_sync {
15 14
16 void ModelChangingSyncerCommand::ExecuteImpl(sessions::SyncSession* session) { 15 void ModelChangingSyncerCommand::ExecuteImpl(sessions::SyncSession* session) {
17 work_session_ = session; 16 work_session_ = session;
18 if (!ModelNeutralExecuteImpl(work_session_)) { 17 if (!ModelNeutralExecuteImpl(work_session_)) {
19 return; 18 return;
20 } 19 }
21 20
22 // Project the list of active types (i.e., types in the routing 21 const std::set<ModelSafeGroup>& groups_to_change =
23 // info) to a list of groups. 22 GetGroupsToChange(*work_session_);
24 //
25 // TODO(akalin): Make this overrideable by subclasses (who might be
26 // working on a subset of |active_groups|). (See
27 // http://crbug.com/97832.)
28 std::set<ModelSafeGroup> active_groups;
29 const ModelSafeRoutingInfo& routing_info = session->routing_info();
30 for (ModelSafeRoutingInfo::const_iterator it = routing_info.begin();
31 it != routing_info.end(); ++it) {
32 active_groups.insert(it->second);
33 }
34 // Always work on GROUP_PASSIVE, since that's the group that
35 // top-level folders map to.
36 active_groups.insert(GROUP_PASSIVE);
37
38 for (size_t i = 0; i < session->workers().size(); ++i) { 23 for (size_t i = 0; i < session->workers().size(); ++i) {
39 ModelSafeWorker* worker = session->workers()[i]; 24 ModelSafeWorker* worker = work_session_->workers()[i];
40 ModelSafeGroup group = worker->GetModelSafeGroup(); 25 ModelSafeGroup group = worker->GetModelSafeGroup();
41 // Skip workers whose group isn't active. 26 // Skip workers whose group isn't active.
42 if (active_groups.find(group) == active_groups.end()) { 27 if (groups_to_change.count(group) == 0u) {
43 VLOG(2) << "Skipping worker for group " 28 VLOG(2) << "Skipping worker for group "
44 << ModelSafeGroupToString(group); 29 << ModelSafeGroupToString(group);
45 continue; 30 continue;
46 } 31 }
47 32
48 sessions::StatusController* status = 33 sessions::StatusController* status =
49 work_session_->mutable_status_controller(); 34 work_session_->mutable_status_controller();
50 sessions::ScopedModelSafeGroupRestriction r(status, group); 35 sessions::ScopedModelSafeGroupRestriction r(status, group);
51 WorkCallback c = base::Bind( 36 WorkCallback c = base::Bind(
52 &ModelChangingSyncerCommand::StartChangingModel, 37 &ModelChangingSyncerCommand::StartChangingModel,
53 // We wait until the callback is executed. So it is safe to use 38 // We wait until the callback is executed. So it is safe to use
54 // unretained. 39 // unretained.
55 base::Unretained(this)); 40 base::Unretained(this));
56 41
57 // TODO(lipalani): Check the return value for an unrecoverable error. 42 // TODO(lipalani): Check the return value for an unrecoverable error.
58 ignore_result(worker->DoWorkAndWaitUntilDone(c)); 43 ignore_result(worker->DoWorkAndWaitUntilDone(c));
59 44
60 } 45 }
61 } 46 }
62 47
48 std::set<ModelSafeGroup> ModelChangingSyncerCommand::GetActiveGroups(
49 const sessions::SyncSession& session) {
50 // Project the list of active types (i.e., types in the routing
51 // info) to a list of active groups.
52 std::set<ModelSafeGroup> active_groups;
53 const ModelSafeRoutingInfo& routing_info = session.routing_info();
54 for (ModelSafeRoutingInfo::const_iterator it = routing_info.begin();
55 it != routing_info.end(); ++it) {
56 active_groups.insert(it->second);
tim (not reviewing) 2011/11/22 18:40:05 First, GetActiveGroups belongs on the SyncSession
akalin 2011/11/23 03:25:18 Done.
57 }
58 // GROUP_PASSIVE is always active, since that's the group that
59 // top-level folders map to.
60 active_groups.insert(GROUP_PASSIVE);
61 return active_groups;
62 }
63
64 std::set<ModelSafeGroup>
65 ModelChangingSyncerCommand::GetActiveGroupsWithConflicts(
66 const sessions::SyncSession& session) {
67 const std::set<ModelSafeGroup>& active_groups =
68 ModelChangingSyncerCommand::GetActiveGroups(session);
69 std::set<ModelSafeGroup> active_groups_with_conflicts;
70 for (std::set<ModelSafeGroup>::const_iterator it =
71 active_groups.begin(); it != active_groups.end(); ++it) {
72 const sessions::ConflictProgress* conflict_progress =
73 session.status_controller().GetUnrestrictedConflictProgress(*it);
74 if (conflict_progress &&
75 (conflict_progress->ConflictingItemsBegin() !=
76 conflict_progress->ConflictingItemsEnd())) {
77 active_groups_with_conflicts.insert(*it);
78 }
79 }
80 return active_groups_with_conflicts;
81 }
82
63 bool ModelChangingSyncerCommand::ModelNeutralExecuteImpl( 83 bool ModelChangingSyncerCommand::ModelNeutralExecuteImpl(
64 sessions::SyncSession* session) { 84 sessions::SyncSession* session) {
65 return true; 85 return true;
66 } 86 }
67 87
68 } // namespace browser_sync 88 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698