| OLD | NEW |
| 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 |
| 63 bool ModelChangingSyncerCommand::ModelNeutralExecuteImpl( | 48 bool ModelChangingSyncerCommand::ModelNeutralExecuteImpl( |
| 64 sessions::SyncSession* session) { | 49 sessions::SyncSession* session) { |
| 65 return true; | 50 return true; |
| 66 } | 51 } |
| 67 | 52 |
| 68 } // namespace browser_sync | 53 } // namespace browser_sync |
| OLD | NEW |