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

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: Sync to head, fix windows compile 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/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 HasCustomGroupsToChange() ?
24 // 23 GetGroupsToChange(*work_session_) :
25 // TODO(akalin): Make this overrideable by subclasses (who might be 24 session->GetEnabledGroups();
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) { 25 for (size_t i = 0; i < session->workers().size(); ++i) {
39 ModelSafeWorker* worker = session->workers()[i]; 26 ModelSafeWorker* worker = work_session_->workers()[i];
40 ModelSafeGroup group = worker->GetModelSafeGroup(); 27 ModelSafeGroup group = worker->GetModelSafeGroup();
41 // Skip workers whose group isn't active. 28 // Skip workers whose group isn't active.
42 if (active_groups.find(group) == active_groups.end()) { 29 if (groups_to_change.count(group) == 0u) {
43 DVLOG(2) << "Skipping worker for group " 30 DVLOG(2) << "Skipping worker for group "
44 << ModelSafeGroupToString(group); 31 << ModelSafeGroupToString(group);
45 continue; 32 continue;
46 } 33 }
47 34
48 sessions::StatusController* status = 35 sessions::StatusController* status =
49 work_session_->mutable_status_controller(); 36 work_session_->mutable_status_controller();
50 sessions::ScopedModelSafeGroupRestriction r(status, group); 37 sessions::ScopedModelSafeGroupRestriction r(status, group);
51 WorkCallback c = base::Bind( 38 WorkCallback c = base::Bind(
52 &ModelChangingSyncerCommand::StartChangingModel, 39 &ModelChangingSyncerCommand::StartChangingModel,
53 // We wait until the callback is executed. So it is safe to use 40 // We wait until the callback is executed. So it is safe to use
54 // unretained. 41 // unretained.
55 base::Unretained(this)); 42 base::Unretained(this));
56 43
57 // TODO(lipalani): Check the return value for an unrecoverable error. 44 // TODO(lipalani): Check the return value for an unrecoverable error.
58 ignore_result(worker->DoWorkAndWaitUntilDone(c)); 45 ignore_result(worker->DoWorkAndWaitUntilDone(c));
59 46
60 } 47 }
61 } 48 }
62 49
63 bool ModelChangingSyncerCommand::ModelNeutralExecuteImpl( 50 bool ModelChangingSyncerCommand::ModelNeutralExecuteImpl(
64 sessions::SyncSession* session) { 51 sessions::SyncSession* session) {
65 return true; 52 return true;
66 } 53 }
67 54
68 } // namespace browser_sync 55 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698