OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/sync/engine/model_changing_syncer_command.h" | |
6 | |
7 #include "base/basictypes.h" | |
8 #include "base/bind.h" | |
9 #include "base/bind_helpers.h" | |
10 #include "chrome/browser/sync/sessions/status_controller.h" | |
11 #include "chrome/browser/sync/sessions/sync_session.h" | |
12 | |
13 namespace browser_sync { | |
14 | |
15 SyncerError ModelChangingSyncerCommand::ExecuteImpl( | |
16 sessions::SyncSession* session) { | |
17 work_session_ = session; | |
18 SyncerError result = ModelNeutralExecuteImpl(work_session_); | |
19 | |
20 if (result != SYNCER_OK) | |
21 return result; | |
22 | |
23 const std::set<ModelSafeGroup>& groups_to_change = | |
24 GetGroupsToChange(*work_session_); | |
25 for (size_t i = 0; i < session->workers().size(); ++i) { | |
26 ModelSafeWorker* worker = work_session_->workers()[i]; | |
27 ModelSafeGroup group = worker->GetModelSafeGroup(); | |
28 // Skip workers whose group isn't active. | |
29 if (groups_to_change.count(group) == 0u) { | |
30 DVLOG(2) << "Skipping worker for group " | |
31 << ModelSafeGroupToString(group); | |
32 continue; | |
33 } | |
34 | |
35 sessions::StatusController* status = | |
36 work_session_->mutable_status_controller(); | |
37 sessions::ScopedModelSafeGroupRestriction r(status, group); | |
38 WorkCallback c = base::Bind( | |
39 &ModelChangingSyncerCommand::StartChangingModel, | |
40 // We wait until the callback is executed. So it is safe to use | |
41 // unretained. | |
42 base::Unretained(this)); | |
43 | |
44 SyncerError this_worker_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 } | |
50 | |
51 return result; | |
52 } | |
53 | |
54 SyncerError ModelChangingSyncerCommand::ModelNeutralExecuteImpl( | |
55 sessions::SyncSession* session) { | |
56 return SYNCER_OK; | |
57 } | |
58 | |
59 } // namespace browser_sync | |
OLD | NEW |