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

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

Issue 2130453004: [Sync] Move //sync to //components/sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. 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 "sync/engine/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 "sync/engine/apply_control_data_updates.h" 16 #include "components/sync/base/cancelation_signal.h"
17 #include "sync/engine/clear_server_data.h" 17 #include "components/sync/base/syncer_error.h"
18 #include "sync/engine/commit.h" 18 #include "components/sync/base/unique_position.h"
19 #include "sync/engine/commit_processor.h" 19 #include "components/sync/engine_impl/apply_control_data_updates.h"
20 #include "sync/engine/conflict_resolver.h" 20 #include "components/sync/engine_impl/clear_server_data.h"
21 #include "sync/engine/get_updates_delegate.h" 21 #include "components/sync/engine_impl/commit.h"
22 #include "sync/engine/get_updates_processor.h" 22 #include "components/sync/engine_impl/commit_processor.h"
23 #include "sync/engine/net/server_connection_manager.h" 23 #include "components/sync/engine_impl/conflict_resolver.h"
24 #include "sync/engine/syncer_types.h" 24 #include "components/sync/engine_impl/get_updates_delegate.h"
25 #include "sync/internal_api/public/base/cancelation_signal.h" 25 #include "components/sync/engine_impl/get_updates_processor.h"
26 #include "sync/internal_api/public/base/unique_position.h" 26 #include "components/sync/engine_impl/net/server_connection_manager.h"
27 #include "sync/internal_api/public/util/syncer_error.h" 27 #include "components/sync/engine_impl/syncer_types.h"
28 #include "sync/sessions/nudge_tracker.h" 28 #include "components/sync/sessions_impl/nudge_tracker.h"
29 #include "sync/syncable/directory.h" 29 #include "components/sync/syncable/directory.h"
30 #include "sync/syncable/mutable_entry.h" 30 #include "components/sync/syncable/mutable_entry.h"
31 #include "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; 47 using sessions::StatusController;
48 using sessions::SyncSession; 48 using sessions::SyncSession;
49 using sessions::NudgeTracker; 49 using sessions::NudgeTracker;
50 50
51 Syncer::Syncer(syncer::CancelationSignal* cancelation_signal) 51 Syncer::Syncer(syncer::CancelationSignal* cancelation_signal)
52 : cancelation_signal_(cancelation_signal), 52 : cancelation_signal_(cancelation_signal), is_syncing_(false) {}
53 is_syncing_(false) {
54 }
55 53
56 Syncer::~Syncer() {} 54 Syncer::~Syncer() {}
57 55
58 bool Syncer::ExitRequested() { 56 bool Syncer::ExitRequested() {
59 return cancelation_signal_->IsSignalled(); 57 return cancelation_signal_->IsSignalled();
60 } 58 }
61 59
62 bool Syncer::IsSyncing() const { 60 bool Syncer::IsSyncing() const {
63 return is_syncing_; 61 return is_syncing_;
64 } 62 }
65 63
66 bool Syncer::NormalSyncShare(ModelTypeSet request_types, 64 bool Syncer::NormalSyncShare(ModelTypeSet request_types,
67 NudgeTracker* nudge_tracker, 65 NudgeTracker* nudge_tracker,
68 SyncSession* session) { 66 SyncSession* session) {
69 base::AutoReset<bool> is_syncing(&is_syncing_, true); 67 base::AutoReset<bool> is_syncing(&is_syncing_, true);
70 HandleCycleBegin(session); 68 HandleCycleBegin(session);
71 if (nudge_tracker->IsGetUpdatesRequired() || 69 if (nudge_tracker->IsGetUpdatesRequired() ||
72 session->context()->ShouldFetchUpdatesBeforeCommit()) { 70 session->context()->ShouldFetchUpdatesBeforeCommit()) {
73 VLOG(1) << "Downloading types " << ModelTypeSetToString(request_types); 71 VLOG(1) << "Downloading types " << ModelTypeSetToString(request_types);
74 NormalGetUpdatesDelegate normal_delegate(*nudge_tracker); 72 NormalGetUpdatesDelegate normal_delegate(*nudge_tracker);
75 GetUpdatesProcessor get_updates_processor( 73 GetUpdatesProcessor get_updates_processor(
76 session->context()->model_type_registry()->update_handler_map(), 74 session->context()->model_type_registry()->update_handler_map(),
77 normal_delegate); 75 normal_delegate);
78 if (!DownloadAndApplyUpdates( 76 if (!DownloadAndApplyUpdates(&request_types, session,
79 &request_types, 77 &get_updates_processor,
80 session, 78 kCreateMobileBookmarksFolder)) {
81 &get_updates_processor,
82 kCreateMobileBookmarksFolder)) {
83 return HandleCycleEnd(session, nudge_tracker->GetLegacySource()); 79 return HandleCycleEnd(session, nudge_tracker->GetLegacySource());
84 } 80 }
85 } 81 }
86 82
87 VLOG(1) << "Committing from types " << ModelTypeSetToString(request_types); 83 VLOG(1) << "Committing from types " << ModelTypeSetToString(request_types);
88 CommitProcessor commit_processor( 84 CommitProcessor commit_processor(
89 session->context()->model_type_registry()->commit_contributor_map()); 85 session->context()->model_type_registry()->commit_contributor_map());
90 SyncerError commit_result = BuildAndPostCommits(request_types, nudge_tracker, 86 SyncerError commit_result = BuildAndPostCommits(request_types, nudge_tracker,
91 session, &commit_processor); 87 session, &commit_processor);
92 session->mutable_status_controller()->set_commit_result(commit_result); 88 session->mutable_status_controller()->set_commit_result(commit_result);
93 89
94 return HandleCycleEnd(session, nudge_tracker->GetLegacySource()); 90 return HandleCycleEnd(session, nudge_tracker->GetLegacySource());
95 } 91 }
96 92
97 bool Syncer::ConfigureSyncShare( 93 bool Syncer::ConfigureSyncShare(
98 ModelTypeSet request_types, 94 ModelTypeSet request_types,
99 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source, 95 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source,
100 SyncSession* session) { 96 SyncSession* session) {
101 base::AutoReset<bool> is_syncing(&is_syncing_, true); 97 base::AutoReset<bool> is_syncing(&is_syncing_, true);
102 VLOG(1) << "Configuring types " << ModelTypeSetToString(request_types); 98 VLOG(1) << "Configuring types " << ModelTypeSetToString(request_types);
103 HandleCycleBegin(session); 99 HandleCycleBegin(session);
104 ConfigureGetUpdatesDelegate configure_delegate(source); 100 ConfigureGetUpdatesDelegate configure_delegate(source);
105 GetUpdatesProcessor get_updates_processor( 101 GetUpdatesProcessor get_updates_processor(
106 session->context()->model_type_registry()->update_handler_map(), 102 session->context()->model_type_registry()->update_handler_map(),
107 configure_delegate); 103 configure_delegate);
108 DownloadAndApplyUpdates( 104 DownloadAndApplyUpdates(&request_types, session, &get_updates_processor,
109 &request_types, 105 kCreateMobileBookmarksFolder);
110 session,
111 &get_updates_processor,
112 kCreateMobileBookmarksFolder);
113 return HandleCycleEnd(session, source); 106 return HandleCycleEnd(session, source);
114 } 107 }
115 108
116 bool Syncer::PollSyncShare(ModelTypeSet request_types, 109 bool Syncer::PollSyncShare(ModelTypeSet request_types, SyncSession* session) {
117 SyncSession* session) {
118 base::AutoReset<bool> is_syncing(&is_syncing_, true); 110 base::AutoReset<bool> is_syncing(&is_syncing_, true);
119 VLOG(1) << "Polling types " << ModelTypeSetToString(request_types); 111 VLOG(1) << "Polling types " << ModelTypeSetToString(request_types);
120 HandleCycleBegin(session); 112 HandleCycleBegin(session);
121 PollGetUpdatesDelegate poll_delegate; 113 PollGetUpdatesDelegate poll_delegate;
122 GetUpdatesProcessor get_updates_processor( 114 GetUpdatesProcessor get_updates_processor(
123 session->context()->model_type_registry()->update_handler_map(), 115 session->context()->model_type_registry()->update_handler_map(),
124 poll_delegate); 116 poll_delegate);
125 DownloadAndApplyUpdates( 117 DownloadAndApplyUpdates(&request_types, session, &get_updates_processor,
126 &request_types, 118 kCreateMobileBookmarksFolder);
127 session,
128 &get_updates_processor,
129 kCreateMobileBookmarksFolder);
130 return HandleCycleEnd(session, sync_pb::GetUpdatesCallerInfo::PERIODIC); 119 return HandleCycleEnd(session, sync_pb::GetUpdatesCallerInfo::PERIODIC);
131 } 120 }
132 121
133 bool Syncer::DownloadAndApplyUpdates( 122 bool Syncer::DownloadAndApplyUpdates(ModelTypeSet* request_types,
134 ModelTypeSet* request_types, 123 SyncSession* session,
135 SyncSession* session, 124 GetUpdatesProcessor* get_updates_processor,
136 GetUpdatesProcessor* get_updates_processor, 125 bool create_mobile_bookmarks_folder) {
137 bool create_mobile_bookmarks_folder) {
138 SyncerError download_result = UNSET; 126 SyncerError download_result = UNSET;
139 do { 127 do {
140 download_result = get_updates_processor->DownloadUpdates( 128 download_result = get_updates_processor->DownloadUpdates(
141 request_types, 129 request_types, session, create_mobile_bookmarks_folder);
142 session,
143 create_mobile_bookmarks_folder);
144 } while (download_result == SERVER_MORE_TO_DOWNLOAD); 130 } while (download_result == SERVER_MORE_TO_DOWNLOAD);
145 131
146 // Exit without applying if we're shutting down or an error was detected. 132 // Exit without applying if we're shutting down or an error was detected.
147 if (download_result != SYNCER_OK) 133 if (download_result != SYNCER_OK)
148 return false; 134 return false;
149 if (ExitRequested()) 135 if (ExitRequested())
150 return false; 136 return false;
151 137
152 { 138 {
153 TRACE_EVENT0("sync", "ApplyUpdates"); 139 TRACE_EVENT0("sync", "ApplyUpdates");
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 } 211 }
226 212
227 bool Syncer::PostClearServerData(SyncSession* session) { 213 bool Syncer::PostClearServerData(SyncSession* session) {
228 DCHECK(session); 214 DCHECK(session);
229 ClearServerData clear_server_data(session->context()->account_name()); 215 ClearServerData clear_server_data(session->context()->account_name());
230 const SyncerError post_result = clear_server_data.SendRequest(session); 216 const SyncerError post_result = clear_server_data.SendRequest(session);
231 return post_result == SYNCER_OK; 217 return post_result == SYNCER_OK;
232 } 218 }
233 219
234 } // namespace syncer 220 } // 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