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

Side by Side Diff: chrome/browser/sync/engine/apply_updates_command.cc

Issue 8785015: Revert 112815 - [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/apply_updates_command.h" 5 #include "chrome/browser/sync/engine/apply_updates_command.h"
6 6
7 #include "base/location.h" 7 #include "base/location.h"
8 #include "chrome/browser/sync/engine/update_applicator.h" 8 #include "chrome/browser/sync/engine/update_applicator.h"
9 #include "chrome/browser/sync/sessions/sync_session.h" 9 #include "chrome/browser/sync/sessions/sync_session.h"
10 #include "chrome/browser/sync/syncable/directory_manager.h" 10 #include "chrome/browser/sync/syncable/directory_manager.h"
11 #include "chrome/browser/sync/syncable/syncable.h" 11 #include "chrome/browser/sync/syncable/syncable.h"
12 12
13 namespace browser_sync { 13 namespace browser_sync {
14 14
15 using sessions::SyncSession; 15 using sessions::SyncSession;
16 16
17 ApplyUpdatesCommand::ApplyUpdatesCommand() {} 17 ApplyUpdatesCommand::ApplyUpdatesCommand() {}
18 ApplyUpdatesCommand::~ApplyUpdatesCommand() {} 18 ApplyUpdatesCommand::~ApplyUpdatesCommand() {}
19 19
20 std::set<ModelSafeGroup> ApplyUpdatesCommand::GetGroupsToChange(
21 const sessions::SyncSession& session) const {
22 std::set<ModelSafeGroup> groups_with_unapplied_updates;
23
24 syncable::ModelTypeBitSet server_types_with_unapplied_updates;
25 {
26 syncable::ScopedDirLookup dir(session.context()->directory_manager(),
27 session.context()->account_name());
28 if (!dir.good()) {
29 LOG(ERROR) << "Scoped dir lookup failed!";
30 return groups_with_unapplied_updates;
31 }
32
33 syncable::ReadTransaction trans(FROM_HERE, dir);
34 server_types_with_unapplied_updates =
35 dir->GetServerTypesWithUnappliedUpdates(&trans);
36 }
37
38 for (int i = 0; i < syncable::MODEL_TYPE_COUNT; ++i) {
39 const syncable::ModelType type = syncable::ModelTypeFromInt(i);
40 if (server_types_with_unapplied_updates.test(type)) {
41 groups_with_unapplied_updates.insert(
42 GetGroupForModelType(type, session.routing_info()));
43 }
44 }
45
46 return groups_with_unapplied_updates;
47 }
48
49 void ApplyUpdatesCommand::ModelChangingExecuteImpl(SyncSession* session) { 20 void ApplyUpdatesCommand::ModelChangingExecuteImpl(SyncSession* session) {
50 syncable::ScopedDirLookup dir(session->context()->directory_manager(), 21 syncable::ScopedDirLookup dir(session->context()->directory_manager(),
51 session->context()->account_name()); 22 session->context()->account_name());
52 if (!dir.good()) { 23 if (!dir.good()) {
53 LOG(ERROR) << "Scoped dir lookup failed!"; 24 LOG(ERROR) << "Scoped dir lookup failed!";
54 return; 25 return;
55 } 26 }
56
57 syncable::WriteTransaction trans(FROM_HERE, syncable::SYNCER, dir); 27 syncable::WriteTransaction trans(FROM_HERE, syncable::SYNCER, dir);
58
59 // Compute server types with unapplied updates that fall under our
60 // group restriction.
61 const syncable::ModelTypeBitSet server_types_with_unapplied_updates =
62 dir->GetServerTypesWithUnappliedUpdates(&trans);
63 syncable::ModelTypeBitSet server_type_restriction;
64 for (int i = 0; i < syncable::MODEL_TYPE_COUNT; ++i) {
65 const syncable::ModelType server_type = syncable::ModelTypeFromInt(i);
66 if (server_types_with_unapplied_updates.test(server_type)) {
67 if (GetGroupForModelType(server_type, session->routing_info()) ==
68 session->status_controller().group_restriction()) {
69 server_type_restriction.set(server_type);
70 }
71 }
72 }
73
74 syncable::Directory::UnappliedUpdateMetaHandles handles; 28 syncable::Directory::UnappliedUpdateMetaHandles handles;
75 dir->GetUnappliedUpdateMetaHandles( 29 dir->GetUnappliedUpdateMetaHandles(&trans, &handles);
76 &trans, server_type_restriction, &handles);
77 30
78 UpdateApplicator applicator( 31 UpdateApplicator applicator(
79 session->context()->resolver(), 32 session->context()->resolver(),
80 session->context()->directory_manager()->GetCryptographer(&trans), 33 session->context()->directory_manager()->GetCryptographer(&trans),
81 handles.begin(), handles.end(), session->routing_info(), 34 handles.begin(), handles.end(), session->routing_info(),
82 session->status_controller().group_restriction()); 35 session->status_controller().group_restriction());
83 while (applicator.AttemptOneApplication(&trans)) {} 36 while (applicator.AttemptOneApplication(&trans)) {}
84 applicator.SaveProgressIntoSessionState( 37 applicator.SaveProgressIntoSessionState(
85 session->mutable_status_controller()->mutable_conflict_progress(), 38 session->mutable_status_controller()->mutable_conflict_progress(),
86 session->mutable_status_controller()->mutable_update_progress()); 39 session->mutable_status_controller()->mutable_update_progress());
87 40
88 // This might be the first time we've fully completed a sync cycle, for 41 // This might be the first time we've fully completed a sync cycle, for
89 // some subset of the currently synced datatypes. 42 // some subset of the currently synced datatypes.
90 const sessions::StatusController& status(session->status_controller()); 43 const sessions::StatusController& status(session->status_controller());
91 if (status.ServerSaysNothingMoreToDownload()) { 44 if (status.ServerSaysNothingMoreToDownload()) {
45 syncable::ScopedDirLookup dir(session->context()->directory_manager(),
46 session->context()->account_name());
47 if (!dir.good()) {
48 LOG(ERROR) << "Scoped dir lookup failed!";
49 return;
50 }
51
92 for (int i = syncable::FIRST_REAL_MODEL_TYPE; 52 for (int i = syncable::FIRST_REAL_MODEL_TYPE;
93 i < syncable::MODEL_TYPE_COUNT; ++i) { 53 i < syncable::MODEL_TYPE_COUNT; ++i) {
94 syncable::ModelType model_type = syncable::ModelTypeFromInt(i); 54 syncable::ModelType model_type = syncable::ModelTypeFromInt(i);
95 if (status.updates_request_types()[i]) { 55 if (status.updates_request_types()[i]) {
96 // This gets persisted to the directory's backing store. 56 // This gets persisted to the directory's backing store.
97 dir->set_initial_sync_ended_for_type(model_type, true); 57 dir->set_initial_sync_ended_for_type(model_type, true);
98 } 58 }
99 } 59 }
100 } 60 }
101 } 61 }
102 62
103 } // namespace browser_sync 63 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/engine/apply_updates_command.h ('k') | chrome/browser/sync/engine/apply_updates_command_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698