OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 entry. | 3 // found in the LICENSE entry. |
4 | 4 |
5 #include "chrome/browser/sync/engine/syncer.h" | 5 #include "chrome/browser/sync/engine/syncer.h" |
6 | 6 |
7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
8 #include "base/message_loop.h" | |
9 #include "chrome/browser/chrome_thread.h" | |
10 #include "chrome/browser/sync/engine/apply_updates_command.h" | 8 #include "chrome/browser/sync/engine/apply_updates_command.h" |
11 #include "chrome/browser/sync/engine/build_and_process_conflict_sets_command.h" | 9 #include "chrome/browser/sync/engine/build_and_process_conflict_sets_command.h" |
12 #include "chrome/browser/sync/engine/build_commit_command.h" | 10 #include "chrome/browser/sync/engine/build_commit_command.h" |
13 #include "chrome/browser/sync/engine/conflict_resolver.h" | 11 #include "chrome/browser/sync/engine/conflict_resolver.h" |
14 #include "chrome/browser/sync/engine/download_updates_command.h" | 12 #include "chrome/browser/sync/engine/download_updates_command.h" |
15 #include "chrome/browser/sync/engine/get_commit_ids_command.h" | 13 #include "chrome/browser/sync/engine/get_commit_ids_command.h" |
16 #include "chrome/browser/sync/engine/net/server_connection_manager.h" | 14 #include "chrome/browser/sync/engine/net/server_connection_manager.h" |
17 #include "chrome/browser/sync/engine/post_commit_message_command.h" | 15 #include "chrome/browser/sync/engine/post_commit_message_command.h" |
18 #include "chrome/browser/sync/engine/process_commit_response_command.h" | 16 #include "chrome/browser/sync/engine/process_commit_response_command.h" |
19 #include "chrome/browser/sync/engine/process_updates_command.h" | 17 #include "chrome/browser/sync/engine/process_updates_command.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 dirman_(dirman), | 59 dirman_(dirman), |
62 command_channel_(NULL), | 60 command_channel_(NULL), |
63 model_safe_worker_(model_safe_worker), | 61 model_safe_worker_(model_safe_worker), |
64 updates_source_(sync_pb::GetUpdatesCallerInfo::UNKNOWN), | 62 updates_source_(sync_pb::GetUpdatesCallerInfo::UNKNOWN), |
65 notifications_enabled_(false), | 63 notifications_enabled_(false), |
66 pre_conflict_resolution_function_(NULL) { | 64 pre_conflict_resolution_function_(NULL) { |
67 SyncerEvent shutdown = { SyncerEvent::SHUTDOWN_USE_WITH_CARE }; | 65 SyncerEvent shutdown = { SyncerEvent::SHUTDOWN_USE_WITH_CARE }; |
68 syncer_event_channel_.reset(new SyncerEventChannel(shutdown)); | 66 syncer_event_channel_.reset(new SyncerEventChannel(shutdown)); |
69 shutdown_channel_.reset(new ShutdownChannel(this)); | 67 shutdown_channel_.reset(new ShutdownChannel(this)); |
70 | 68 |
71 extensions_monitor_ = new ExtensionsActivityMonitor( | |
72 ChromeThread::GetMessageLoop(ChromeThread::UI)); | |
73 | |
74 ScopedDirLookup dir(dirman_, account_name_); | 69 ScopedDirLookup dir(dirman_, account_name_); |
75 // The directory must be good here. | 70 // The directory must be good here. |
76 CHECK(dir.good()); | 71 CHECK(dir.good()); |
77 } | 72 } |
78 | 73 |
79 Syncer::~Syncer() { | 74 Syncer::~Syncer() {} |
80 MessageLoop* ui_loop = ChromeThread::GetMessageLoop(ChromeThread::UI); | |
81 if (ui_loop) { | |
82 ui_loop->DeleteSoon(FROM_HERE, extensions_monitor_); | |
83 } else { | |
84 NOTREACHED(); | |
85 delete extensions_monitor_; | |
86 } | |
87 extensions_monitor_ = NULL; | |
88 } | |
89 | 75 |
90 void Syncer::RequestNudge(int milliseconds) { | 76 void Syncer::RequestNudge(int milliseconds) { |
91 SyncerEvent event; | 77 SyncerEvent event; |
92 event.what_happened = SyncerEvent::REQUEST_SYNC_NUDGE; | 78 event.what_happened = SyncerEvent::REQUEST_SYNC_NUDGE; |
93 event.nudge_delay_milliseconds = milliseconds; | 79 event.nudge_delay_milliseconds = milliseconds; |
94 channel()->NotifyListeners(event); | 80 channel()->NotifyListeners(event); |
95 } | 81 } |
96 | 82 |
97 bool Syncer::SyncShare() { | 83 bool Syncer::SyncShare() { |
98 SyncProcessState state(dirman_, account_name_, connection_manager_, | 84 SyncProcessState state(dirman_, account_name_, connection_manager_, |
99 &resolver_, syncer_event_channel_.get(), | 85 &resolver_, syncer_event_channel_.get(), |
100 model_safe_worker()); | 86 model_safe_worker()); |
101 return SyncShare(&state); | 87 return SyncShare(&state); |
102 } | 88 } |
103 | 89 |
104 bool Syncer::SyncShare(SyncProcessState* process_state) { | 90 bool Syncer::SyncShare(SyncProcessState* process_state) { |
105 SyncCycleState cycle_state; | 91 SyncCycleState cycle_state; |
106 SyncerSession session(&cycle_state, process_state); | 92 SyncerSession session(&cycle_state, process_state); |
107 session.set_source(TestAndSetUpdatesSource()); | 93 session.set_source(TestAndSetUpdatesSource()); |
108 session.set_notifications_enabled(notifications_enabled()); | 94 session.set_notifications_enabled(notifications_enabled()); |
109 // This isn't perfect, as we can end up bundling extensions activity | |
110 // intended for the next session into the current one. We could do a | |
111 // test-and-reset as with the source, but note that also falls short if | |
112 // the commit request fails (due to lost connection, for example), as we will | |
113 // fall all the way back to the syncer thread main loop in that case, and | |
114 // wind up creating a new session when a connection is established, losing | |
115 // the records set here on the original attempt. This should provide us | |
116 // with the right data "most of the time", and we're only using this for | |
117 // analysis purposes, so Law of Large Numbers FTW. | |
118 extensions_monitor_->GetAndClearRecords( | |
119 session.mutable_extensions_activity()); | |
120 SyncShare(&session, SYNCER_BEGIN, SYNCER_END); | 95 SyncShare(&session, SYNCER_BEGIN, SYNCER_END); |
121 return session.HasMoreToSync(); | 96 return session.HasMoreToSync(); |
122 } | 97 } |
123 | 98 |
124 bool Syncer::SyncShare(SyncerStep first_step, SyncerStep last_step) { | 99 bool Syncer::SyncShare(SyncerStep first_step, SyncerStep last_step) { |
125 SyncCycleState cycle_state; | 100 SyncCycleState cycle_state; |
126 SyncProcessState state(dirman_, account_name_, connection_manager_, | 101 SyncProcessState state(dirman_, account_name_, connection_manager_, |
127 &resolver_, syncer_event_channel_.get(), | 102 &resolver_, syncer_event_channel_.get(), |
128 model_safe_worker()); | 103 model_safe_worker()); |
129 SyncerSession session(&cycle_state, &state); | 104 SyncerSession session(&cycle_state, &state); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 } | 198 } |
224 case POST_COMMIT_MESSAGE: { | 199 case POST_COMMIT_MESSAGE: { |
225 LOG(INFO) << "Posting a commit request"; | 200 LOG(INFO) << "Posting a commit request"; |
226 PostCommitMessageCommand post_commit_command; | 201 PostCommitMessageCommand post_commit_command; |
227 post_commit_command.Execute(session); | 202 post_commit_command.Execute(session); |
228 next_step = PROCESS_COMMIT_RESPONSE; | 203 next_step = PROCESS_COMMIT_RESPONSE; |
229 break; | 204 break; |
230 } | 205 } |
231 case PROCESS_COMMIT_RESPONSE: { | 206 case PROCESS_COMMIT_RESPONSE: { |
232 LOG(INFO) << "Processing the commit response"; | 207 LOG(INFO) << "Processing the commit response"; |
233 ProcessCommitResponseCommand process_response_command( | 208 ProcessCommitResponseCommand process_response_command; |
234 extensions_monitor_); | |
235 process_response_command.Execute(session); | 209 process_response_command.Execute(session); |
236 next_step = BUILD_AND_PROCESS_CONFLICT_SETS; | 210 next_step = BUILD_AND_PROCESS_CONFLICT_SETS; |
237 break; | 211 break; |
238 } | 212 } |
239 case BUILD_AND_PROCESS_CONFLICT_SETS: { | 213 case BUILD_AND_PROCESS_CONFLICT_SETS: { |
240 LOG(INFO) << "Building and Processing Conflict Sets"; | 214 LOG(INFO) << "Building and Processing Conflict Sets"; |
241 BuildAndProcessConflictSetsCommand build_process_conflict_sets; | 215 BuildAndProcessConflictSetsCommand build_process_conflict_sets; |
242 build_process_conflict_sets.Execute(session); | 216 build_process_conflict_sets.Execute(session); |
243 if (session->conflict_sets_built()) | 217 if (session->conflict_sets_built()) |
244 next_step = SYNCER_END; | 218 next_step = SYNCER_END; |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 entry.id_string().c_str(), | 331 entry.id_string().c_str(), |
358 entry.parent_id_string().c_str(), | 332 entry.parent_id_string().c_str(), |
359 entry.version(), | 333 entry.version(), |
360 entry.mtime(), ServerTimeToClientTime(entry.mtime()), | 334 entry.mtime(), ServerTimeToClientTime(entry.mtime()), |
361 entry.ctime(), ServerTimeToClientTime(entry.ctime()), | 335 entry.ctime(), ServerTimeToClientTime(entry.ctime()), |
362 entry.name().c_str(), entry.sync_timestamp(), | 336 entry.name().c_str(), entry.sync_timestamp(), |
363 entry.deleted() ? "deleted, ":""); | 337 entry.deleted() ? "deleted, ":""); |
364 } | 338 } |
365 | 339 |
366 } // namespace browser_sync | 340 } // namespace browser_sync |
OLD | NEW |