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

Side by Side Diff: components/sync/engine_impl/syncer.cc

Issue 2850213002: [Sync] Minor refactor around SyncCycle and ModelTypeSet usage. (Closed)
Patch Set: Fix comment grammar. Created 3 years, 7 months 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
« no previous file with comments | « components/sync/engine_impl/syncer.h ('k') | components/sync/engine_impl/syncer_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 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 "components/sync/engine_impl/syncer.h" 5 #include "components/sync/engine_impl/syncer.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 if (nudge_tracker->IsGetUpdatesRequired() || 57 if (nudge_tracker->IsGetUpdatesRequired() ||
58 cycle->context()->ShouldFetchUpdatesBeforeCommit()) { 58 cycle->context()->ShouldFetchUpdatesBeforeCommit()) {
59 VLOG(1) << "Downloading types " << ModelTypeSetToString(request_types); 59 VLOG(1) << "Downloading types " << ModelTypeSetToString(request_types);
60 if (!DownloadAndApplyUpdates(&request_types, cycle, 60 if (!DownloadAndApplyUpdates(&request_types, cycle,
61 NormalGetUpdatesDelegate(*nudge_tracker), 61 NormalGetUpdatesDelegate(*nudge_tracker),
62 kCreateMobileBookmarksFolder)) { 62 kCreateMobileBookmarksFolder)) {
63 return HandleCycleEnd(cycle, nudge_tracker->GetLegacySource()); 63 return HandleCycleEnd(cycle, nudge_tracker->GetLegacySource());
64 } 64 }
65 } 65 }
66 66
67 VLOG(1) << "Committing from types " << ModelTypeSetToString(request_types);
68 CommitProcessor commit_processor( 67 CommitProcessor commit_processor(
69 cycle->context()->model_type_registry()->commit_contributor_map()); 68 cycle->context()->model_type_registry()->commit_contributor_map());
70 SyncerError commit_result = BuildAndPostCommits(request_types, nudge_tracker, 69 SyncerError commit_result = BuildAndPostCommits(request_types, nudge_tracker,
71 cycle, &commit_processor); 70 cycle, &commit_processor);
72 cycle->mutable_status_controller()->set_commit_result(commit_result); 71 cycle->mutable_status_controller()->set_commit_result(commit_result);
73 72
74 return HandleCycleEnd(cycle, nudge_tracker->GetLegacySource()); 73 return HandleCycleEnd(cycle, nudge_tracker->GetLegacySource());
75 } 74 }
76 75
77 bool Syncer::ConfigureSyncShare( 76 bool Syncer::ConfigureSyncShare(
78 ModelTypeSet request_types, 77 const ModelTypeSet& request_types,
79 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source, 78 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source,
80 SyncCycle* cycle) { 79 SyncCycle* cycle) {
81 base::AutoReset<bool> is_syncing(&is_syncing_, true); 80 base::AutoReset<bool> is_syncing(&is_syncing_, true);
82 81
83 // It is possible during configuration that datatypes get unregistered from 82 // It is possible during configuration that datatypes get unregistered from
84 // ModelTypeRegistry before scheduled configure sync cycle gets executed. 83 // ModelTypeRegistry before scheduled configure sync cycle gets executed.
85 // This happens either because DataTypeController::LoadModels fail and type 84 // This happens either because DataTypeController::LoadModels fail and type
86 // need to be stopped or during shutdown when all datatypes are stopped. When 85 // need to be stopped or during shutdown when all datatypes are stopped. When
87 // it happens we should adjust set of types to download to only include 86 // it happens we should adjust set of types to download to only include
88 // registered types. 87 // registered types.
89 request_types.RetainAll(cycle->context()->GetEnabledTypes()); 88 ModelTypeSet still_enabled_types =
90 VLOG(1) << "Configuring types " << ModelTypeSetToString(request_types); 89 Intersection(request_types, cycle->context()->GetEnabledTypes());
90 VLOG(1) << "Configuring types " << ModelTypeSetToString(still_enabled_types);
91 HandleCycleBegin(cycle); 91 HandleCycleBegin(cycle);
92 DownloadAndApplyUpdates(&request_types, cycle, 92 DownloadAndApplyUpdates(&still_enabled_types, cycle,
93 ConfigureGetUpdatesDelegate(source), 93 ConfigureGetUpdatesDelegate(source),
94 kCreateMobileBookmarksFolder); 94 kCreateMobileBookmarksFolder);
95 return HandleCycleEnd(cycle, source); 95 return HandleCycleEnd(cycle, source);
96 } 96 }
97 97
98 bool Syncer::PollSyncShare(ModelTypeSet request_types, SyncCycle* cycle) { 98 bool Syncer::PollSyncShare(ModelTypeSet request_types, SyncCycle* cycle) {
99 base::AutoReset<bool> is_syncing(&is_syncing_, true); 99 base::AutoReset<bool> is_syncing(&is_syncing_, true);
100 VLOG(1) << "Polling types " << ModelTypeSetToString(request_types); 100 VLOG(1) << "Polling types " << ModelTypeSetToString(request_types);
101 HandleCycleBegin(cycle); 101 HandleCycleBegin(cycle);
102 DownloadAndApplyUpdates(&request_types, cycle, PollGetUpdatesDelegate(), 102 DownloadAndApplyUpdates(&request_types, cycle, PollGetUpdatesDelegate(),
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 cycle->mutable_status_controller()); 139 cycle->mutable_status_controller());
140 140
141 cycle->context()->set_hierarchy_conflict_detected( 141 cycle->context()->set_hierarchy_conflict_detected(
142 cycle->status_controller().num_hierarchy_conflicts() > 0); 142 cycle->status_controller().num_hierarchy_conflicts() > 0);
143 cycle->SendEventNotification(SyncCycleEvent::STATUS_CHANGED); 143 cycle->SendEventNotification(SyncCycleEvent::STATUS_CHANGED);
144 } 144 }
145 145
146 return !ExitRequested(); 146 return !ExitRequested();
147 } 147 }
148 148
149 SyncerError Syncer::BuildAndPostCommits(ModelTypeSet request_types, 149 SyncerError Syncer::BuildAndPostCommits(const ModelTypeSet& request_types,
150 NudgeTracker* nudge_tracker, 150 NudgeTracker* nudge_tracker,
151 SyncCycle* cycle, 151 SyncCycle* cycle,
152 CommitProcessor* commit_processor) { 152 CommitProcessor* commit_processor) {
153 VLOG(1) << "Committing from types " << ModelTypeSetToString(request_types);
154
153 // The ExitRequested() check is unnecessary, since we should start getting 155 // The ExitRequested() check is unnecessary, since we should start getting
154 // errors from the ServerConnectionManager if an exist has been requested. 156 // errors from the ServerConnectionManager if an exist has been requested.
155 // However, it doesn't hurt to check it anyway. 157 // However, it doesn't hurt to check it anyway.
156 while (!ExitRequested()) { 158 while (!ExitRequested()) {
157 std::unique_ptr<Commit> commit( 159 std::unique_ptr<Commit> commit(
158 Commit::Init(request_types, cycle->context()->GetEnabledTypes(), 160 Commit::Init(request_types, cycle->context()->GetEnabledTypes(),
159 cycle->context()->max_commit_batch_size(), 161 cycle->context()->max_commit_batch_size(),
160 cycle->context()->account_name(), 162 cycle->context()->account_name(),
161 cycle->context()->directory()->cache_guid(), 163 cycle->context()->directory()->cache_guid(),
162 cycle->context()->cookie_jar_mismatch(), 164 cycle->context()->cookie_jar_mismatch(),
(...skipping 29 matching lines...) Expand all
192 bool success = 194 bool success =
193 !HasSyncerError(cycle->status_controller().model_neutral_state()); 195 !HasSyncerError(cycle->status_controller().model_neutral_state());
194 if (success && source == sync_pb::GetUpdatesCallerInfo::PERIODIC) { 196 if (success && source == sync_pb::GetUpdatesCallerInfo::PERIODIC) {
195 cycle->mutable_status_controller()->UpdatePollTime(); 197 cycle->mutable_status_controller()->UpdatePollTime();
196 } 198 }
197 199
198 return success; 200 return success;
199 } 201 }
200 202
201 } // namespace syncer 203 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/engine_impl/syncer.h ('k') | components/sync/engine_impl/syncer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698