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/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 if (result != NO_ERROR) { |
| 21 return result; |
20 } | 22 } |
21 | 23 |
22 const std::set<ModelSafeGroup>& groups_to_change = | 24 const std::set<ModelSafeGroup>& groups_to_change = |
23 GetGroupsToChange(*work_session_); | 25 GetGroupsToChange(*work_session_); |
24 for (size_t i = 0; i < session->workers().size(); ++i) { | 26 for (size_t i = 0; i < session->workers().size(); ++i) { |
25 ModelSafeWorker* worker = work_session_->workers()[i]; | 27 ModelSafeWorker* worker = work_session_->workers()[i]; |
26 ModelSafeGroup group = worker->GetModelSafeGroup(); | 28 ModelSafeGroup group = worker->GetModelSafeGroup(); |
27 // Skip workers whose group isn't active. | 29 // Skip workers whose group isn't active. |
28 if (groups_to_change.count(group) == 0u) { | 30 if (groups_to_change.count(group) == 0u) { |
29 DVLOG(2) << "Skipping worker for group " | 31 DVLOG(2) << "Skipping worker for group " |
30 << ModelSafeGroupToString(group); | 32 << ModelSafeGroupToString(group); |
31 continue; | 33 continue; |
32 } | 34 } |
33 | 35 |
34 sessions::StatusController* status = | 36 sessions::StatusController* status = |
35 work_session_->mutable_status_controller(); | 37 work_session_->mutable_status_controller(); |
36 sessions::ScopedModelSafeGroupRestriction r(status, group); | 38 sessions::ScopedModelSafeGroupRestriction r(status, group); |
37 WorkCallback c = base::Bind( | 39 WorkCallback c = base::Bind( |
38 &ModelChangingSyncerCommand::StartChangingModel, | 40 &ModelChangingSyncerCommand::StartChangingModel, |
39 // We wait until the callback is executed. So it is safe to use | 41 // We wait until the callback is executed. So it is safe to use |
40 // unretained. | 42 // unretained. |
41 base::Unretained(this)); | 43 base::Unretained(this)); |
42 | 44 |
43 // TODO(lipalani): Check the return value for an unrecoverable error. | 45 SyncerError this_worker_result = worker->DoWorkAndWaitUntilDone(c); |
44 ignore_result(worker->DoWorkAndWaitUntilDone(c)); | 46 // TODO(rlarocque): Figure out a better way to deal with errors from |
| 47 // multiple models at once. |
| 48 if (this_worker_result != NO_ERROR) |
| 49 result = this_worker_result; |
| 50 } |
45 | 51 |
46 } | 52 return result; |
47 } | 53 } |
48 | 54 |
49 bool ModelChangingSyncerCommand::ModelNeutralExecuteImpl( | 55 SyncerError ModelChangingSyncerCommand::ModelNeutralExecuteImpl( |
50 sessions::SyncSession* session) { | 56 sessions::SyncSession* session) { |
51 return true; | 57 return NO_ERROR; |
52 } | 58 } |
53 | 59 |
54 } // namespace browser_sync | 60 } // namespace browser_sync |
OLD | NEW |