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

Side by Side Diff: chrome/browser/sync/engine/model_changing_syncer_command.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/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"
9 #include "chrome/browser/sync/sessions/status_controller.h" 10 #include "chrome/browser/sync/sessions/status_controller.h"
10 #include "chrome/browser/sync/sessions/sync_session.h" 11 #include "chrome/browser/sync/sessions/sync_session.h"
11 #include "chrome/browser/sync/util/unrecoverable_error_info.h" 12 #include "chrome/browser/sync/util/unrecoverable_error_info.h"
12 13
13 namespace browser_sync { 14 namespace browser_sync {
14 15
15 void ModelChangingSyncerCommand::ExecuteImpl(sessions::SyncSession* session) { 16 void ModelChangingSyncerCommand::ExecuteImpl(sessions::SyncSession* session) {
16 work_session_ = session; 17 work_session_ = session;
17 if (!ModelNeutralExecuteImpl(work_session_)) { 18 if (!ModelNeutralExecuteImpl(work_session_)) {
18 return; 19 return;
19 } 20 }
20 21
21 const std::set<ModelSafeGroup>& groups_to_change = 22 // Project the list of active types (i.e., types in the routing
22 GetGroupsToChange(*work_session_); 23 // info) to a list of groups.
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
23 for (size_t i = 0; i < session->workers().size(); ++i) { 38 for (size_t i = 0; i < session->workers().size(); ++i) {
24 ModelSafeWorker* worker = work_session_->workers()[i]; 39 ModelSafeWorker* worker = session->workers()[i];
25 ModelSafeGroup group = worker->GetModelSafeGroup(); 40 ModelSafeGroup group = worker->GetModelSafeGroup();
26 // Skip workers whose group isn't active. 41 // Skip workers whose group isn't active.
27 if (groups_to_change.count(group) == 0u) { 42 if (active_groups.find(group) == active_groups.end()) {
28 DVLOG(2) << "Skipping worker for group " 43 DVLOG(2) << "Skipping worker for group "
29 << ModelSafeGroupToString(group); 44 << ModelSafeGroupToString(group);
30 continue; 45 continue;
31 } 46 }
32 47
33 sessions::StatusController* status = 48 sessions::StatusController* status =
34 work_session_->mutable_status_controller(); 49 work_session_->mutable_status_controller();
35 sessions::ScopedModelSafeGroupRestriction r(status, group); 50 sessions::ScopedModelSafeGroupRestriction r(status, group);
36 WorkCallback c = base::Bind( 51 WorkCallback c = base::Bind(
37 &ModelChangingSyncerCommand::StartChangingModel, 52 &ModelChangingSyncerCommand::StartChangingModel,
38 // We wait until the callback is executed. So it is safe to use 53 // We wait until the callback is executed. So it is safe to use
39 // unretained. 54 // unretained.
40 base::Unretained(this)); 55 base::Unretained(this));
41 56
42 // TODO(lipalani): Check the return value for an unrecoverable error. 57 // TODO(lipalani): Check the return value for an unrecoverable error.
43 ignore_result(worker->DoWorkAndWaitUntilDone(c)); 58 ignore_result(worker->DoWorkAndWaitUntilDone(c));
44 59
45 } 60 }
46 } 61 }
47 62
48 bool ModelChangingSyncerCommand::ModelNeutralExecuteImpl( 63 bool ModelChangingSyncerCommand::ModelNeutralExecuteImpl(
49 sessions::SyncSession* session) { 64 sessions::SyncSession* session) {
50 return true; 65 return true;
51 } 66 }
52 67
53 } // namespace browser_sync 68 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698