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

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

Issue 2258873003: [Sync] Move sessions/ to engine/cycle/ and rename things to match. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments. Created 4 years, 4 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_proto_util.h » ('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/location.h" 10 #include "base/location.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/time/time.h" 13 #include "base/time/time.h"
14 #include "base/trace_event/trace_event.h" 14 #include "base/trace_event/trace_event.h"
15 #include "build/build_config.h" 15 #include "build/build_config.h"
16 #include "components/sync/base/cancelation_signal.h" 16 #include "components/sync/base/cancelation_signal.h"
17 #include "components/sync/base/syncer_error.h" 17 #include "components/sync/base/syncer_error.h"
18 #include "components/sync/base/unique_position.h" 18 #include "components/sync/base/unique_position.h"
19 #include "components/sync/engine_impl/apply_control_data_updates.h" 19 #include "components/sync/engine_impl/apply_control_data_updates.h"
20 #include "components/sync/engine_impl/clear_server_data.h" 20 #include "components/sync/engine_impl/clear_server_data.h"
21 #include "components/sync/engine_impl/commit.h" 21 #include "components/sync/engine_impl/commit.h"
22 #include "components/sync/engine_impl/commit_processor.h" 22 #include "components/sync/engine_impl/commit_processor.h"
23 #include "components/sync/engine_impl/conflict_resolver.h" 23 #include "components/sync/engine_impl/conflict_resolver.h"
24 #include "components/sync/engine_impl/cycle/nudge_tracker.h"
24 #include "components/sync/engine_impl/get_updates_delegate.h" 25 #include "components/sync/engine_impl/get_updates_delegate.h"
25 #include "components/sync/engine_impl/get_updates_processor.h" 26 #include "components/sync/engine_impl/get_updates_processor.h"
26 #include "components/sync/engine_impl/net/server_connection_manager.h" 27 #include "components/sync/engine_impl/net/server_connection_manager.h"
27 #include "components/sync/engine_impl/syncer_types.h" 28 #include "components/sync/engine_impl/syncer_types.h"
28 #include "components/sync/sessions_impl/nudge_tracker.h"
29 #include "components/sync/syncable/directory.h" 29 #include "components/sync/syncable/directory.h"
30 #include "components/sync/syncable/mutable_entry.h" 30 #include "components/sync/syncable/mutable_entry.h"
31 #include "components/sync/syncable/syncable-inl.h" 31 #include "components/sync/syncable/syncable-inl.h"
32 32
33 using base::Time; 33 using base::Time;
34 using base::TimeDelta; 34 using base::TimeDelta;
35 using sync_pb::ClientCommand; 35 using sync_pb::ClientCommand;
36 36
37 namespace syncer { 37 namespace syncer {
38 38
39 // TODO(akalin): We may want to propagate this switch up 39 // TODO(akalin): We may want to propagate this switch up
40 // eventually. 40 // eventually.
41 #if defined(OS_ANDROID) || defined(OS_IOS) 41 #if defined(OS_ANDROID) || defined(OS_IOS)
42 static const bool kCreateMobileBookmarksFolder = true; 42 static const bool kCreateMobileBookmarksFolder = true;
43 #else 43 #else
44 static const bool kCreateMobileBookmarksFolder = false; 44 static const bool kCreateMobileBookmarksFolder = false;
45 #endif 45 #endif
46 46
47 using sessions::StatusController;
48 using sessions::SyncSession;
49 using sessions::NudgeTracker;
50
51 Syncer::Syncer(syncer::CancelationSignal* cancelation_signal) 47 Syncer::Syncer(syncer::CancelationSignal* cancelation_signal)
52 : cancelation_signal_(cancelation_signal), is_syncing_(false) {} 48 : cancelation_signal_(cancelation_signal), is_syncing_(false) {}
53 49
54 Syncer::~Syncer() {} 50 Syncer::~Syncer() {}
55 51
56 bool Syncer::ExitRequested() { 52 bool Syncer::ExitRequested() {
57 return cancelation_signal_->IsSignalled(); 53 return cancelation_signal_->IsSignalled();
58 } 54 }
59 55
60 bool Syncer::IsSyncing() const { 56 bool Syncer::IsSyncing() const {
61 return is_syncing_; 57 return is_syncing_;
62 } 58 }
63 59
64 bool Syncer::NormalSyncShare(ModelTypeSet request_types, 60 bool Syncer::NormalSyncShare(ModelTypeSet request_types,
65 NudgeTracker* nudge_tracker, 61 NudgeTracker* nudge_tracker,
66 SyncSession* session) { 62 SyncCycle* cycle) {
67 base::AutoReset<bool> is_syncing(&is_syncing_, true); 63 base::AutoReset<bool> is_syncing(&is_syncing_, true);
68 HandleCycleBegin(session); 64 HandleCycleBegin(cycle);
69 if (nudge_tracker->IsGetUpdatesRequired() || 65 if (nudge_tracker->IsGetUpdatesRequired() ||
70 session->context()->ShouldFetchUpdatesBeforeCommit()) { 66 cycle->context()->ShouldFetchUpdatesBeforeCommit()) {
71 VLOG(1) << "Downloading types " << ModelTypeSetToString(request_types); 67 VLOG(1) << "Downloading types " << ModelTypeSetToString(request_types);
72 NormalGetUpdatesDelegate normal_delegate(*nudge_tracker); 68 NormalGetUpdatesDelegate normal_delegate(*nudge_tracker);
73 GetUpdatesProcessor get_updates_processor( 69 GetUpdatesProcessor get_updates_processor(
74 session->context()->model_type_registry()->update_handler_map(), 70 cycle->context()->model_type_registry()->update_handler_map(),
75 normal_delegate); 71 normal_delegate);
76 if (!DownloadAndApplyUpdates(&request_types, session, 72 if (!DownloadAndApplyUpdates(&request_types, cycle, &get_updates_processor,
77 &get_updates_processor,
78 kCreateMobileBookmarksFolder)) { 73 kCreateMobileBookmarksFolder)) {
79 return HandleCycleEnd(session, nudge_tracker->GetLegacySource()); 74 return HandleCycleEnd(cycle, nudge_tracker->GetLegacySource());
80 } 75 }
81 } 76 }
82 77
83 VLOG(1) << "Committing from types " << ModelTypeSetToString(request_types); 78 VLOG(1) << "Committing from types " << ModelTypeSetToString(request_types);
84 CommitProcessor commit_processor( 79 CommitProcessor commit_processor(
85 session->context()->model_type_registry()->commit_contributor_map()); 80 cycle->context()->model_type_registry()->commit_contributor_map());
86 SyncerError commit_result = BuildAndPostCommits(request_types, nudge_tracker, 81 SyncerError commit_result = BuildAndPostCommits(request_types, nudge_tracker,
87 session, &commit_processor); 82 cycle, &commit_processor);
88 session->mutable_status_controller()->set_commit_result(commit_result); 83 cycle->mutable_status_controller()->set_commit_result(commit_result);
89 84
90 return HandleCycleEnd(session, nudge_tracker->GetLegacySource()); 85 return HandleCycleEnd(cycle, nudge_tracker->GetLegacySource());
91 } 86 }
92 87
93 bool Syncer::ConfigureSyncShare( 88 bool Syncer::ConfigureSyncShare(
94 ModelTypeSet request_types, 89 ModelTypeSet request_types,
95 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source, 90 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source,
96 SyncSession* session) { 91 SyncCycle* cycle) {
97 base::AutoReset<bool> is_syncing(&is_syncing_, true); 92 base::AutoReset<bool> is_syncing(&is_syncing_, true);
98 VLOG(1) << "Configuring types " << ModelTypeSetToString(request_types); 93 VLOG(1) << "Configuring types " << ModelTypeSetToString(request_types);
99 HandleCycleBegin(session); 94 HandleCycleBegin(cycle);
100 ConfigureGetUpdatesDelegate configure_delegate(source); 95 ConfigureGetUpdatesDelegate configure_delegate(source);
101 GetUpdatesProcessor get_updates_processor( 96 GetUpdatesProcessor get_updates_processor(
102 session->context()->model_type_registry()->update_handler_map(), 97 cycle->context()->model_type_registry()->update_handler_map(),
103 configure_delegate); 98 configure_delegate);
104 DownloadAndApplyUpdates(&request_types, session, &get_updates_processor, 99 DownloadAndApplyUpdates(&request_types, cycle, &get_updates_processor,
105 kCreateMobileBookmarksFolder); 100 kCreateMobileBookmarksFolder);
106 return HandleCycleEnd(session, source); 101 return HandleCycleEnd(cycle, source);
107 } 102 }
108 103
109 bool Syncer::PollSyncShare(ModelTypeSet request_types, SyncSession* session) { 104 bool Syncer::PollSyncShare(ModelTypeSet request_types, SyncCycle* cycle) {
110 base::AutoReset<bool> is_syncing(&is_syncing_, true); 105 base::AutoReset<bool> is_syncing(&is_syncing_, true);
111 VLOG(1) << "Polling types " << ModelTypeSetToString(request_types); 106 VLOG(1) << "Polling types " << ModelTypeSetToString(request_types);
112 HandleCycleBegin(session); 107 HandleCycleBegin(cycle);
113 PollGetUpdatesDelegate poll_delegate; 108 PollGetUpdatesDelegate poll_delegate;
114 GetUpdatesProcessor get_updates_processor( 109 GetUpdatesProcessor get_updates_processor(
115 session->context()->model_type_registry()->update_handler_map(), 110 cycle->context()->model_type_registry()->update_handler_map(),
116 poll_delegate); 111 poll_delegate);
117 DownloadAndApplyUpdates(&request_types, session, &get_updates_processor, 112 DownloadAndApplyUpdates(&request_types, cycle, &get_updates_processor,
118 kCreateMobileBookmarksFolder); 113 kCreateMobileBookmarksFolder);
119 return HandleCycleEnd(session, sync_pb::GetUpdatesCallerInfo::PERIODIC); 114 return HandleCycleEnd(cycle, sync_pb::GetUpdatesCallerInfo::PERIODIC);
120 } 115 }
121 116
122 bool Syncer::DownloadAndApplyUpdates(ModelTypeSet* request_types, 117 bool Syncer::DownloadAndApplyUpdates(ModelTypeSet* request_types,
123 SyncSession* session, 118 SyncCycle* cycle,
124 GetUpdatesProcessor* get_updates_processor, 119 GetUpdatesProcessor* get_updates_processor,
125 bool create_mobile_bookmarks_folder) { 120 bool create_mobile_bookmarks_folder) {
126 SyncerError download_result = UNSET; 121 SyncerError download_result = UNSET;
127 do { 122 do {
128 download_result = get_updates_processor->DownloadUpdates( 123 download_result = get_updates_processor->DownloadUpdates(
129 request_types, session, create_mobile_bookmarks_folder); 124 request_types, cycle, create_mobile_bookmarks_folder);
130 } while (download_result == SERVER_MORE_TO_DOWNLOAD); 125 } while (download_result == SERVER_MORE_TO_DOWNLOAD);
131 126
132 // Exit without applying if we're shutting down or an error was detected. 127 // Exit without applying if we're shutting down or an error was detected.
133 if (download_result != SYNCER_OK) 128 if (download_result != SYNCER_OK)
134 return false; 129 return false;
135 if (ExitRequested()) 130 if (ExitRequested())
136 return false; 131 return false;
137 132
138 { 133 {
139 TRACE_EVENT0("sync", "ApplyUpdates"); 134 TRACE_EVENT0("sync", "ApplyUpdates");
140 135
141 // Control type updates always get applied first. 136 // Control type updates always get applied first.
142 ApplyControlDataUpdates(session->context()->directory()); 137 ApplyControlDataUpdates(cycle->context()->directory());
143 138
144 // Apply upates to the other types. May or may not involve cross-thread 139 // Apply upates to the other types. May or may not involve cross-thread
145 // traffic, depending on the underlying update handlers and the GU type's 140 // traffic, depending on the underlying update handlers and the GU type's
146 // delegate. 141 // delegate.
147 get_updates_processor->ApplyUpdates(*request_types, 142 get_updates_processor->ApplyUpdates(*request_types,
148 session->mutable_status_controller()); 143 cycle->mutable_status_controller());
149 144
150 session->context()->set_hierarchy_conflict_detected( 145 cycle->context()->set_hierarchy_conflict_detected(
151 session->status_controller().num_hierarchy_conflicts() > 0); 146 cycle->status_controller().num_hierarchy_conflicts() > 0);
152 session->SendEventNotification(SyncCycleEvent::STATUS_CHANGED); 147 cycle->SendEventNotification(SyncCycleEvent::STATUS_CHANGED);
153 } 148 }
154 149
155 if (ExitRequested()) 150 if (ExitRequested())
156 return false; 151 return false;
157 return true; 152 return true;
158 } 153 }
159 154
160 SyncerError Syncer::BuildAndPostCommits(ModelTypeSet requested_types, 155 SyncerError Syncer::BuildAndPostCommits(ModelTypeSet requested_types,
161 sessions::NudgeTracker* nudge_tracker, 156 NudgeTracker* nudge_tracker,
162 sessions::SyncSession* session, 157 SyncCycle* cycle,
163 CommitProcessor* commit_processor) { 158 CommitProcessor* commit_processor) {
164 // The ExitRequested() check is unnecessary, since we should start getting 159 // The ExitRequested() check is unnecessary, since we should start getting
165 // errors from the ServerConnectionManager if an exist has been requested. 160 // errors from the ServerConnectionManager if an exist has been requested.
166 // However, it doesn't hurt to check it anyway. 161 // However, it doesn't hurt to check it anyway.
167 while (!ExitRequested()) { 162 while (!ExitRequested()) {
168 std::unique_ptr<Commit> commit( 163 std::unique_ptr<Commit> commit(
169 Commit::Init(requested_types, session->context()->GetEnabledTypes(), 164 Commit::Init(requested_types, cycle->context()->GetEnabledTypes(),
170 session->context()->max_commit_batch_size(), 165 cycle->context()->max_commit_batch_size(),
171 session->context()->account_name(), 166 cycle->context()->account_name(),
172 session->context()->directory()->cache_guid(), 167 cycle->context()->directory()->cache_guid(),
173 session->context()->cookie_jar_mismatch(), 168 cycle->context()->cookie_jar_mismatch(),
174 session->context()->cookie_jar_empty(), commit_processor, 169 cycle->context()->cookie_jar_empty(), commit_processor,
175 session->context()->extensions_activity())); 170 cycle->context()->extensions_activity()));
176 if (!commit) { 171 if (!commit) {
177 break; 172 break;
178 } 173 }
179 174
180 SyncerError error = commit->PostAndProcessResponse( 175 SyncerError error = commit->PostAndProcessResponse(
181 nudge_tracker, session, session->mutable_status_controller(), 176 nudge_tracker, cycle, cycle->mutable_status_controller(),
182 session->context()->extensions_activity()); 177 cycle->context()->extensions_activity());
183 commit->CleanUp(); 178 commit->CleanUp();
184 if (error != SYNCER_OK) { 179 if (error != SYNCER_OK) {
185 return error; 180 return error;
186 } 181 }
187 } 182 }
188 183
189 return SYNCER_OK; 184 return SYNCER_OK;
190 } 185 }
191 186
192 void Syncer::HandleCycleBegin(SyncSession* session) { 187 void Syncer::HandleCycleBegin(SyncCycle* cycle) {
193 session->mutable_status_controller()->UpdateStartTime(); 188 cycle->mutable_status_controller()->UpdateStartTime();
194 session->SendEventNotification(SyncCycleEvent::SYNC_CYCLE_BEGIN); 189 cycle->SendEventNotification(SyncCycleEvent::SYNC_CYCLE_BEGIN);
195 } 190 }
196 191
197 bool Syncer::HandleCycleEnd( 192 bool Syncer::HandleCycleEnd(
198 SyncSession* session, 193 SyncCycle* cycle,
199 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source) { 194 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source) {
200 if (!ExitRequested()) { 195 if (!ExitRequested()) {
201 session->SendSyncCycleEndEventNotification(source); 196 cycle->SendSyncCycleEndEventNotification(source);
202 197
203 bool success = !sessions::HasSyncerError( 198 bool success =
204 session->status_controller().model_neutral_state()); 199 !HasSyncerError(cycle->status_controller().model_neutral_state());
205 if (success && source == sync_pb::GetUpdatesCallerInfo::PERIODIC) 200 if (success && source == sync_pb::GetUpdatesCallerInfo::PERIODIC)
206 session->mutable_status_controller()->UpdatePollTime(); 201 cycle->mutable_status_controller()->UpdatePollTime();
207 return success; 202 return success;
208 } else { 203 } else {
209 return false; 204 return false;
210 } 205 }
211 } 206 }
212 207
213 bool Syncer::PostClearServerData(SyncSession* session) { 208 bool Syncer::PostClearServerData(SyncCycle* cycle) {
214 DCHECK(session); 209 DCHECK(cycle);
215 ClearServerData clear_server_data(session->context()->account_name()); 210 ClearServerData clear_server_data(cycle->context()->account_name());
216 const SyncerError post_result = clear_server_data.SendRequest(session); 211 const SyncerError post_result = clear_server_data.SendRequest(cycle);
217 return post_result == SYNCER_OK; 212 return post_result == SYNCER_OK;
218 } 213 }
219 214
220 } // namespace syncer 215 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/engine_impl/syncer.h ('k') | components/sync/engine_impl/syncer_proto_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698