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" |
8 #include "chrome/browser/sync/engine/apply_updates_command.h" | 10 #include "chrome/browser/sync/engine/apply_updates_command.h" |
9 #include "chrome/browser/sync/engine/build_and_process_conflict_sets_command.h" | 11 #include "chrome/browser/sync/engine/build_and_process_conflict_sets_command.h" |
10 #include "chrome/browser/sync/engine/build_commit_command.h" | 12 #include "chrome/browser/sync/engine/build_commit_command.h" |
11 #include "chrome/browser/sync/engine/conflict_resolver.h" | 13 #include "chrome/browser/sync/engine/conflict_resolver.h" |
12 #include "chrome/browser/sync/engine/download_updates_command.h" | 14 #include "chrome/browser/sync/engine/download_updates_command.h" |
13 #include "chrome/browser/sync/engine/get_commit_ids_command.h" | 15 #include "chrome/browser/sync/engine/get_commit_ids_command.h" |
14 #include "chrome/browser/sync/engine/net/server_connection_manager.h" | 16 #include "chrome/browser/sync/engine/net/server_connection_manager.h" |
15 #include "chrome/browser/sync/engine/post_commit_message_command.h" | 17 #include "chrome/browser/sync/engine/post_commit_message_command.h" |
16 #include "chrome/browser/sync/engine/process_commit_response_command.h" | 18 #include "chrome/browser/sync/engine/process_commit_response_command.h" |
17 #include "chrome/browser/sync/engine/process_updates_command.h" | 19 #include "chrome/browser/sync/engine/process_updates_command.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 dirman_(dirman), | 61 dirman_(dirman), |
60 command_channel_(NULL), | 62 command_channel_(NULL), |
61 model_safe_worker_(model_safe_worker), | 63 model_safe_worker_(model_safe_worker), |
62 updates_source_(sync_pb::GetUpdatesCallerInfo::UNKNOWN), | 64 updates_source_(sync_pb::GetUpdatesCallerInfo::UNKNOWN), |
63 notifications_enabled_(false), | 65 notifications_enabled_(false), |
64 pre_conflict_resolution_function_(NULL) { | 66 pre_conflict_resolution_function_(NULL) { |
65 SyncerEvent shutdown = { SyncerEvent::SHUTDOWN_USE_WITH_CARE }; | 67 SyncerEvent shutdown = { SyncerEvent::SHUTDOWN_USE_WITH_CARE }; |
66 syncer_event_channel_.reset(new SyncerEventChannel(shutdown)); | 68 syncer_event_channel_.reset(new SyncerEventChannel(shutdown)); |
67 shutdown_channel_.reset(new ShutdownChannel(this)); | 69 shutdown_channel_.reset(new ShutdownChannel(this)); |
68 | 70 |
| 71 extensions_monitor_ = new ExtensionsActivityMonitor( |
| 72 ChromeThread::GetMessageLoop(ChromeThread::UI)); |
| 73 |
69 ScopedDirLookup dir(dirman_, account_name_); | 74 ScopedDirLookup dir(dirman_, account_name_); |
70 // The directory must be good here. | 75 // The directory must be good here. |
71 CHECK(dir.good()); | 76 CHECK(dir.good()); |
72 } | 77 } |
73 | 78 |
74 Syncer::~Syncer() {} | 79 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 } |
75 | 89 |
76 void Syncer::RequestNudge(int milliseconds) { | 90 void Syncer::RequestNudge(int milliseconds) { |
77 SyncerEvent event; | 91 SyncerEvent event; |
78 event.what_happened = SyncerEvent::REQUEST_SYNC_NUDGE; | 92 event.what_happened = SyncerEvent::REQUEST_SYNC_NUDGE; |
79 event.nudge_delay_milliseconds = milliseconds; | 93 event.nudge_delay_milliseconds = milliseconds; |
80 channel()->NotifyListeners(event); | 94 channel()->NotifyListeners(event); |
81 } | 95 } |
82 | 96 |
83 bool Syncer::SyncShare() { | 97 bool Syncer::SyncShare() { |
84 SyncProcessState state(dirman_, account_name_, connection_manager_, | 98 SyncProcessState state(dirman_, account_name_, connection_manager_, |
85 &resolver_, syncer_event_channel_.get(), | 99 &resolver_, syncer_event_channel_.get(), |
86 model_safe_worker()); | 100 model_safe_worker()); |
87 return SyncShare(&state); | 101 return SyncShare(&state); |
88 } | 102 } |
89 | 103 |
90 bool Syncer::SyncShare(SyncProcessState* process_state) { | 104 bool Syncer::SyncShare(SyncProcessState* process_state) { |
91 SyncCycleState cycle_state; | 105 SyncCycleState cycle_state; |
92 SyncerSession session(&cycle_state, process_state); | 106 SyncerSession session(&cycle_state, process_state); |
93 session.set_source(TestAndSetUpdatesSource()); | 107 session.set_source(TestAndSetUpdatesSource()); |
94 session.set_notifications_enabled(notifications_enabled()); | 108 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()); |
95 SyncShare(&session, SYNCER_BEGIN, SYNCER_END); | 120 SyncShare(&session, SYNCER_BEGIN, SYNCER_END); |
96 return session.HasMoreToSync(); | 121 return session.HasMoreToSync(); |
97 } | 122 } |
98 | 123 |
99 bool Syncer::SyncShare(SyncerStep first_step, SyncerStep last_step) { | 124 bool Syncer::SyncShare(SyncerStep first_step, SyncerStep last_step) { |
100 SyncCycleState cycle_state; | 125 SyncCycleState cycle_state; |
101 SyncProcessState state(dirman_, account_name_, connection_manager_, | 126 SyncProcessState state(dirman_, account_name_, connection_manager_, |
102 &resolver_, syncer_event_channel_.get(), | 127 &resolver_, syncer_event_channel_.get(), |
103 model_safe_worker()); | 128 model_safe_worker()); |
104 SyncerSession session(&cycle_state, &state); | 129 SyncerSession session(&cycle_state, &state); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 } | 223 } |
199 case POST_COMMIT_MESSAGE: { | 224 case POST_COMMIT_MESSAGE: { |
200 LOG(INFO) << "Posting a commit request"; | 225 LOG(INFO) << "Posting a commit request"; |
201 PostCommitMessageCommand post_commit_command; | 226 PostCommitMessageCommand post_commit_command; |
202 post_commit_command.Execute(session); | 227 post_commit_command.Execute(session); |
203 next_step = PROCESS_COMMIT_RESPONSE; | 228 next_step = PROCESS_COMMIT_RESPONSE; |
204 break; | 229 break; |
205 } | 230 } |
206 case PROCESS_COMMIT_RESPONSE: { | 231 case PROCESS_COMMIT_RESPONSE: { |
207 LOG(INFO) << "Processing the commit response"; | 232 LOG(INFO) << "Processing the commit response"; |
208 ProcessCommitResponseCommand process_response_command; | 233 ProcessCommitResponseCommand process_response_command( |
| 234 extensions_monitor_); |
209 process_response_command.Execute(session); | 235 process_response_command.Execute(session); |
210 next_step = BUILD_AND_PROCESS_CONFLICT_SETS; | 236 next_step = BUILD_AND_PROCESS_CONFLICT_SETS; |
211 break; | 237 break; |
212 } | 238 } |
213 case BUILD_AND_PROCESS_CONFLICT_SETS: { | 239 case BUILD_AND_PROCESS_CONFLICT_SETS: { |
214 LOG(INFO) << "Building and Processing Conflict Sets"; | 240 LOG(INFO) << "Building and Processing Conflict Sets"; |
215 BuildAndProcessConflictSetsCommand build_process_conflict_sets; | 241 BuildAndProcessConflictSetsCommand build_process_conflict_sets; |
216 build_process_conflict_sets.Execute(session); | 242 build_process_conflict_sets.Execute(session); |
217 if (session->conflict_sets_built()) | 243 if (session->conflict_sets_built()) |
218 next_step = SYNCER_END; | 244 next_step = SYNCER_END; |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 entry.id_string().c_str(), | 357 entry.id_string().c_str(), |
332 entry.parent_id_string().c_str(), | 358 entry.parent_id_string().c_str(), |
333 entry.version(), | 359 entry.version(), |
334 entry.mtime(), ServerTimeToClientTime(entry.mtime()), | 360 entry.mtime(), ServerTimeToClientTime(entry.mtime()), |
335 entry.ctime(), ServerTimeToClientTime(entry.ctime()), | 361 entry.ctime(), ServerTimeToClientTime(entry.ctime()), |
336 entry.name().c_str(), entry.sync_timestamp(), | 362 entry.name().c_str(), entry.sync_timestamp(), |
337 entry.deleted() ? "deleted, ":""); | 363 entry.deleted() ? "deleted, ":""); |
338 } | 364 } |
339 | 365 |
340 } // namespace browser_sync | 366 } // namespace browser_sync |
OLD | NEW |