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

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

Issue 8637006: [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: Sync to head, fix windows compile 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 bool ApplyUpdatesCommand::HasCustomGroupsToChange() const {
21 // TODO(akalin): Set to true.
22 return false;
23 }
24
25 std::set<ModelSafeGroup> ApplyUpdatesCommand::GetGroupsToChange(
26 const sessions::SyncSession& session) const {
27 std::set<ModelSafeGroup> groups_with_unapplied_updates;
28
29 syncable::ModelTypeBitSet server_types_with_unapplied_updates;
30 {
31 syncable::ScopedDirLookup dir(session.context()->directory_manager(),
32 session.context()->account_name());
33 if (!dir.good()) {
34 LOG(ERROR) << "Scoped dir lookup failed!";
35 return groups_with_unapplied_updates;
36 }
37
38 syncable::ReadTransaction trans(FROM_HERE, dir);
39 server_types_with_unapplied_updates =
40 dir->GetServerTypesWithUnappliedUpdates(&trans);
41 }
42
43 for (int i = 0; i < syncable::MODEL_TYPE_COUNT; ++i) {
44 const syncable::ModelType type = syncable::ModelTypeFromInt(i);
45 if (server_types_with_unapplied_updates.test(type)) {
46 groups_with_unapplied_updates.insert(
47 GetGroupForModelType(type, session.routing_info()));
48 }
49 }
50
51 return groups_with_unapplied_updates;
52 }
53
20 void ApplyUpdatesCommand::ModelChangingExecuteImpl(SyncSession* session) { 54 void ApplyUpdatesCommand::ModelChangingExecuteImpl(SyncSession* session) {
21 syncable::ScopedDirLookup dir(session->context()->directory_manager(), 55 syncable::ScopedDirLookup dir(session->context()->directory_manager(),
22 session->context()->account_name()); 56 session->context()->account_name());
23 if (!dir.good()) { 57 if (!dir.good()) {
24 LOG(ERROR) << "Scoped dir lookup failed!"; 58 LOG(ERROR) << "Scoped dir lookup failed!";
25 return; 59 return;
26 } 60 }
61
27 syncable::WriteTransaction trans(FROM_HERE, syncable::SYNCER, dir); 62 syncable::WriteTransaction trans(FROM_HERE, syncable::SYNCER, dir);
63
64 // Compute server types with unapplied updates that fall under our
65 // group restriction.
66 const syncable::ModelTypeBitSet server_types_with_unapplied_updates =
67 dir->GetServerTypesWithUnappliedUpdates(&trans);
68 syncable::ModelTypeBitSet server_type_restriction;
69 for (int i = 0; i < syncable::MODEL_TYPE_COUNT; ++i) {
70 const syncable::ModelType server_type = syncable::ModelTypeFromInt(i);
71 if (server_types_with_unapplied_updates.test(server_type)) {
72 if (GetGroupForModelType(server_type, session->routing_info()) ==
73 session->status_controller().group_restriction()) {
74 server_type_restriction.set(server_type);
75 }
76 }
77 }
78
28 syncable::Directory::UnappliedUpdateMetaHandles handles; 79 syncable::Directory::UnappliedUpdateMetaHandles handles;
29 dir->GetUnappliedUpdateMetaHandles(&trans, &handles); 80 dir->GetUnappliedUpdateMetaHandles(
81 &trans, server_type_restriction, &handles);
30 82
31 UpdateApplicator applicator( 83 UpdateApplicator applicator(
32 session->context()->resolver(), 84 session->context()->resolver(),
33 session->context()->directory_manager()->GetCryptographer(&trans), 85 session->context()->directory_manager()->GetCryptographer(&trans),
34 handles.begin(), handles.end(), session->routing_info(), 86 handles.begin(), handles.end(), session->routing_info(),
35 session->status_controller().group_restriction()); 87 session->status_controller().group_restriction());
36 while (applicator.AttemptOneApplication(&trans)) {} 88 while (applicator.AttemptOneApplication(&trans)) {}
37 applicator.SaveProgressIntoSessionState( 89 applicator.SaveProgressIntoSessionState(
38 session->mutable_status_controller()->mutable_conflict_progress(), 90 session->mutable_status_controller()->mutable_conflict_progress(),
39 session->mutable_status_controller()->mutable_update_progress()); 91 session->mutable_status_controller()->mutable_update_progress());
40 92
41 // This might be the first time we've fully completed a sync cycle, for 93 // This might be the first time we've fully completed a sync cycle, for
42 // some subset of the currently synced datatypes. 94 // some subset of the currently synced datatypes.
43 const sessions::StatusController& status(session->status_controller()); 95 const sessions::StatusController& status(session->status_controller());
44 if (status.ServerSaysNothingMoreToDownload()) { 96 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
52 for (int i = syncable::FIRST_REAL_MODEL_TYPE; 97 for (int i = syncable::FIRST_REAL_MODEL_TYPE;
53 i < syncable::MODEL_TYPE_COUNT; ++i) { 98 i < syncable::MODEL_TYPE_COUNT; ++i) {
54 syncable::ModelType model_type = syncable::ModelTypeFromInt(i); 99 syncable::ModelType model_type = syncable::ModelTypeFromInt(i);
55 if (status.updates_request_types()[i]) { 100 if (status.updates_request_types()[i]) {
56 // This gets persisted to the directory's backing store. 101 // This gets persisted to the directory's backing store.
57 dir->set_initial_sync_ended_for_type(model_type, true); 102 dir->set_initial_sync_ended_for_type(model_type, true);
58 } 103 }
59 } 104 }
60 } 105 }
61 } 106 }
62 107
63 } // namespace browser_sync 108 } // 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