| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
| 10 #include "chrome/browser/sync/sessions/status_controller.h" | 10 #include "chrome/browser/sync/sessions/status_controller.h" |
| 11 #include "chrome/browser/sync/sessions/sync_session.h" | 11 #include "chrome/browser/sync/sessions/sync_session.h" |
| 12 #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 SyncerError ModelChangingSyncerCommand::ExecuteImpl( |
| 16 sessions::SyncSession* session) { |
| 17 work_session_ = session; | 17 work_session_ = session; |
| 18 if (!ModelNeutralExecuteImpl(work_session_)) { | 18 SyncerError result = ModelNeutralExecuteImpl(work_session_); |
| 19 return; | 19 |
| 20 } | 20 if (result != SYNCER_OK) |
| 21 return result; |
| 21 | 22 |
| 22 const std::set<ModelSafeGroup>& groups_to_change = | 23 const std::set<ModelSafeGroup>& groups_to_change = |
| 23 GetGroupsToChange(*work_session_); | 24 GetGroupsToChange(*work_session_); |
| 24 for (size_t i = 0; i < session->workers().size(); ++i) { | 25 for (size_t i = 0; i < session->workers().size(); ++i) { |
| 25 ModelSafeWorker* worker = work_session_->workers()[i]; | 26 ModelSafeWorker* worker = work_session_->workers()[i]; |
| 26 ModelSafeGroup group = worker->GetModelSafeGroup(); | 27 ModelSafeGroup group = worker->GetModelSafeGroup(); |
| 27 // Skip workers whose group isn't active. | 28 // Skip workers whose group isn't active. |
| 28 if (groups_to_change.count(group) == 0u) { | 29 if (groups_to_change.count(group) == 0u) { |
| 29 DVLOG(2) << "Skipping worker for group " | 30 DVLOG(2) << "Skipping worker for group " |
| 30 << ModelSafeGroupToString(group); | 31 << ModelSafeGroupToString(group); |
| 31 continue; | 32 continue; |
| 32 } | 33 } |
| 33 | 34 |
| 34 sessions::StatusController* status = | 35 sessions::StatusController* status = |
| 35 work_session_->mutable_status_controller(); | 36 work_session_->mutable_status_controller(); |
| 36 sessions::ScopedModelSafeGroupRestriction r(status, group); | 37 sessions::ScopedModelSafeGroupRestriction r(status, group); |
| 37 WorkCallback c = base::Bind( | 38 WorkCallback c = base::Bind( |
| 38 &ModelChangingSyncerCommand::StartChangingModel, | 39 &ModelChangingSyncerCommand::StartChangingModel, |
| 39 // 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 |
| 40 // unretained. | 41 // unretained. |
| 41 base::Unretained(this)); | 42 base::Unretained(this)); |
| 42 | 43 |
| 43 // TODO(lipalani): Check the return value for an unrecoverable error. | 44 SyncerError this_worker_result = worker->DoWorkAndWaitUntilDone(c); |
| 44 ignore_result(worker->DoWorkAndWaitUntilDone(c)); | 45 // TODO(rlarocque): Figure out a better way to deal with errors from |
| 46 // multiple models at once. See also: crbug.com/109422. |
| 47 if (this_worker_result != SYNCER_OK) |
| 48 result = this_worker_result; |
| 49 } |
| 45 | 50 |
| 46 } | 51 return result; |
| 47 } | 52 } |
| 48 | 53 |
| 49 bool ModelChangingSyncerCommand::ModelNeutralExecuteImpl( | 54 SyncerError ModelChangingSyncerCommand::ModelNeutralExecuteImpl( |
| 50 sessions::SyncSession* session) { | 55 sessions::SyncSession* session) { |
| 51 return true; | 56 return SYNCER_OK; |
| 52 } | 57 } |
| 53 | 58 |
| 54 } // namespace browser_sync | 59 } // namespace browser_sync |
| OLD | NEW |