Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/sync/engine/syncer.h" | 5 #include "chrome/browser/sync/engine/syncer.h" |
| 6 | 6 |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/time.h" | 8 #include "base/time.h" |
| 9 #include "base/tracked.h" | 9 #include "base/tracked.h" |
| 10 #include "chrome/browser/sync/engine/apply_updates_command.h" | 10 #include "chrome/browser/sync/engine/apply_updates_command.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 47 using syncable::ScopedDirLookup; | 47 using syncable::ScopedDirLookup; |
| 48 using syncable::WriteTransaction; | 48 using syncable::WriteTransaction; |
| 49 | 49 |
| 50 namespace browser_sync { | 50 namespace browser_sync { |
| 51 | 51 |
| 52 using sessions::ScopedSessionContextConflictResolver; | 52 using sessions::ScopedSessionContextConflictResolver; |
| 53 using sessions::StatusController; | 53 using sessions::StatusController; |
| 54 using sessions::SyncSession; | 54 using sessions::SyncSession; |
| 55 using sessions::ConflictProgress; | 55 using sessions::ConflictProgress; |
| 56 | 56 |
| 57 Syncer::ScopedSyncStartStopTracker::ScopedSyncStartStopTracker( | |
| 58 sessions::SyncSession* session) : session_(session) { | |
| 59 session_->status_controller()->SetSyncInProgressAndUpdateStartTime(true); | |
| 60 } | |
| 61 | |
| 62 Syncer::ScopedSyncStartStopTracker::~ScopedSyncStartStopTracker() { | |
| 63 session_->status_controller()->SetSyncInProgressAndUpdateStartTime(false); | |
| 64 } | |
| 65 | |
| 57 Syncer::Syncer() | 66 Syncer::Syncer() |
| 58 : early_exit_requested_(false), | 67 : early_exit_requested_(false), |
| 59 pre_conflict_resolution_closure_(NULL) { | 68 pre_conflict_resolution_closure_(NULL) { |
| 60 } | 69 } |
| 61 | 70 |
| 62 Syncer::~Syncer() {} | 71 Syncer::~Syncer() {} |
| 63 | 72 |
| 64 bool Syncer::ExitRequested() { | 73 bool Syncer::ExitRequested() { |
| 65 base::AutoLock lock(early_exit_requested_lock_); | 74 base::AutoLock lock(early_exit_requested_lock_); |
| 66 return early_exit_requested_; | 75 return early_exit_requested_; |
| 67 } | 76 } |
| 68 | 77 |
| 69 void Syncer::RequestEarlyExit() { | 78 void Syncer::RequestEarlyExit() { |
| 70 base::AutoLock lock(early_exit_requested_lock_); | 79 base::AutoLock lock(early_exit_requested_lock_); |
| 71 early_exit_requested_ = true; | 80 early_exit_requested_ = true; |
| 72 } | 81 } |
| 73 | 82 |
| 74 void Syncer::SyncShare(sessions::SyncSession* session, | 83 void Syncer::SyncShare(sessions::SyncSession* session, |
| 75 SyncerStep first_step, | 84 SyncerStep first_step, |
| 76 SyncerStep last_step) { | 85 SyncerStep last_step) { |
| 77 { | 86 { |
| 78 ScopedDirLookup dir(session->context()->directory_manager(), | 87 ScopedDirLookup dir(session->context()->directory_manager(), |
| 79 session->context()->account_name()); | 88 session->context()->account_name()); |
| 80 // The directory must be good here. | 89 // The directory must be good here. |
| 81 CHECK(dir.good()); | 90 CHECK(dir.good()); |
| 82 } | 91 } |
| 83 | 92 |
| 84 ScopedSessionContextConflictResolver scoped(session->context(), | 93 ScopedSessionContextConflictResolver scoped(session->context(), |
| 85 &resolver_); | 94 &resolver_); |
| 95 | |
| 96 ScopedSyncStartStopTracker start_stop_tracker(session); | |
| 86 SyncerStep current_step = first_step; | 97 SyncerStep current_step = first_step; |
| 87 | 98 |
| 88 SyncerStep next_step = current_step; | 99 SyncerStep next_step = current_step; |
| 89 while (!ExitRequested()) { | 100 while (!ExitRequested()) { |
| 90 switch (current_step) { | 101 switch (current_step) { |
| 91 case SYNCER_BEGIN: | 102 case SYNCER_BEGIN: |
| 92 VLOG(1) << "Syncer Begin"; | 103 VLOG(1) << "Syncer Begin"; |
| 93 // This isn't perfect, as we can end up bundling extensions activity | 104 // This isn't perfect, as we can end up bundling extensions activity |
| 94 // intended for the next session into the current one. We could do a | 105 // intended for the next session into the current one. We could do a |
| 95 // test-and-reset as with the source, but note that also falls short if | 106 // test-and-reset as with the source, but note that also falls short if |
| 96 // the commit request fails (e.g. due to lost connection), as we will | 107 // the commit request fails (e.g. due to lost connection), as we will |
| 97 // fall all the way back to the syncer thread main loop in that case, | 108 // fall all the way back to the syncer thread main loop in that case, |
| 98 // creating a new session when a connection is established, losing the | 109 // creating a new session when a connection is established, losing the |
| 99 // records set here on the original attempt. This should provide us | 110 // records set here on the original attempt. This should provide us |
| 100 // with the right data "most of the time", and we're only using this | 111 // with the right data "most of the time", and we're only using this |
| 101 // for analysis purposes, so Law of Large Numbers FTW. | 112 // for analysis purposes, so Law of Large Numbers FTW. |
| 102 session->context()->extensions_monitor()->GetAndClearRecords( | 113 session->context()->extensions_monitor()->GetAndClearRecords( |
| 103 session->mutable_extensions_activity()); | 114 session->mutable_extensions_activity()); |
| 104 next_step = CLEANUP_DISABLED_TYPES; | 115 next_step = CLEANUP_DISABLED_TYPES; |
| 105 break; | 116 break; |
| 106 case CLEANUP_DISABLED_TYPES: { | 117 case CLEANUP_DISABLED_TYPES: { |
| 107 VLOG(1) << "Cleaning up disabled types"; | 118 VLOG(1) << "Cleaning up disabled types"; |
| 108 CleanupDisabledTypesCommand cleanup; | 119 CleanupDisabledTypesCommand cleanup; |
| 109 cleanup.Execute(session); | 120 cleanup.Execute(session); |
| 110 next_step = DOWNLOAD_UPDATES; | 121 next_step = DOWNLOAD_UPDATES; |
| 111 break; | 122 break; |
| 112 } | 123 } |
| 113 case DOWNLOAD_UPDATES: { | 124 case DOWNLOAD_UPDATES: { |
| 114 VLOG(1) << "Downloading Updates"; | 125 VLOG(1) << "Downloading Updates"; |
| 126 | |
| 127 // We would call set_syncing(false) at the SYNCER_END step. Note if | |
| 128 // we are on DOWNLOAD_UPDATES state we would not exit without | |
| 129 // going to SYNCER_END because of various cleanup steps. | |
|
tim (not reviewing)
2011/08/10 00:08:29
remove comment
| |
| 115 DownloadUpdatesCommand download_updates; | 130 DownloadUpdatesCommand download_updates; |
| 116 download_updates.Execute(session); | 131 download_updates.Execute(session); |
| 117 next_step = PROCESS_CLIENT_COMMAND; | 132 next_step = PROCESS_CLIENT_COMMAND; |
| 118 break; | 133 break; |
| 119 } | 134 } |
| 120 case PROCESS_CLIENT_COMMAND: { | 135 case PROCESS_CLIENT_COMMAND: { |
| 121 VLOG(1) << "Processing Client Command"; | 136 VLOG(1) << "Processing Client Command"; |
| 122 ProcessClientCommand(session); | 137 ProcessClientCommand(session); |
| 123 next_step = VERIFY_UPDATES; | 138 next_step = VERIFY_UPDATES; |
| 124 break; | 139 break; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 161 last_step = SYNCER_END; | 176 last_step = SYNCER_END; |
| 162 next_step = SYNCER_END; | 177 next_step = SYNCER_END; |
| 163 } else { | 178 } else { |
| 164 next_step = BUILD_COMMIT_REQUEST; | 179 next_step = BUILD_COMMIT_REQUEST; |
| 165 } | 180 } |
| 166 break; | 181 break; |
| 167 } | 182 } |
| 168 // These two steps are combined since they are executed within the same | 183 // These two steps are combined since they are executed within the same |
| 169 // write transaction. | 184 // write transaction. |
| 170 case BUILD_COMMIT_REQUEST: { | 185 case BUILD_COMMIT_REQUEST: { |
| 171 session->status_controller()->set_syncing(true); | |
| 172 | |
| 173 VLOG(1) << "Processing Commit Request"; | 186 VLOG(1) << "Processing Commit Request"; |
| 174 ScopedDirLookup dir(session->context()->directory_manager(), | 187 ScopedDirLookup dir(session->context()->directory_manager(), |
| 175 session->context()->account_name()); | 188 session->context()->account_name()); |
| 176 if (!dir.good()) { | 189 if (!dir.good()) { |
| 177 LOG(ERROR) << "Scoped dir lookup failed!"; | 190 LOG(ERROR) << "Scoped dir lookup failed!"; |
| 178 return; | 191 return; |
| 179 } | 192 } |
| 180 WriteTransaction trans(FROM_HERE, SYNCER, dir); | 193 WriteTransaction trans(FROM_HERE, SYNCER, dir); |
| 181 sessions::ScopedSetSessionWriteTransaction set_trans(session, &trans); | 194 sessions::ScopedSetSessionWriteTransaction set_trans(session, &trans); |
| 182 | 195 |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 334 entry->Put(SERVER_CTIME, 0); | 347 entry->Put(SERVER_CTIME, 0); |
| 335 entry->Put(SERVER_VERSION, 0); | 348 entry->Put(SERVER_VERSION, 0); |
| 336 entry->Put(SERVER_IS_DIR, false); | 349 entry->Put(SERVER_IS_DIR, false); |
| 337 entry->Put(SERVER_IS_DEL, false); | 350 entry->Put(SERVER_IS_DEL, false); |
| 338 entry->Put(IS_UNAPPLIED_UPDATE, false); | 351 entry->Put(IS_UNAPPLIED_UPDATE, false); |
| 339 entry->Put(SERVER_SPECIFICS, sync_pb::EntitySpecifics::default_instance()); | 352 entry->Put(SERVER_SPECIFICS, sync_pb::EntitySpecifics::default_instance()); |
| 340 entry->Put(SERVER_POSITION_IN_PARENT, 0); | 353 entry->Put(SERVER_POSITION_IN_PARENT, 0); |
| 341 } | 354 } |
| 342 | 355 |
| 343 } // namespace browser_sync | 356 } // namespace browser_sync |
| OLD | NEW |