| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/sync/engine/apply_updates_command.h" | 9 #include "chrome/browser/sync/engine/apply_updates_command.h" |
| 10 #include "chrome/browser/sync/engine/build_and_process_conflict_sets_command.h" | 10 #include "chrome/browser/sync/engine/build_and_process_conflict_sets_command.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 bool Syncer::ExitRequested() { | 63 bool Syncer::ExitRequested() { |
| 64 base::AutoLock lock(early_exit_requested_lock_); | 64 base::AutoLock lock(early_exit_requested_lock_); |
| 65 return early_exit_requested_; | 65 return early_exit_requested_; |
| 66 } | 66 } |
| 67 | 67 |
| 68 void Syncer::RequestEarlyExit() { | 68 void Syncer::RequestEarlyExit() { |
| 69 base::AutoLock lock(early_exit_requested_lock_); | 69 base::AutoLock lock(early_exit_requested_lock_); |
| 70 early_exit_requested_ = true; | 70 early_exit_requested_ = true; |
| 71 } | 71 } |
| 72 | 72 |
| 73 // TODO(tim): Deprecated. |
| 73 void Syncer::SyncShare(sessions::SyncSession* session) { | 74 void Syncer::SyncShare(sessions::SyncSession* session) { |
| 74 ScopedDirLookup dir(session->context()->directory_manager(), | 75 ScopedDirLookup dir(session->context()->directory_manager(), |
| 75 session->context()->account_name()); | 76 session->context()->account_name()); |
| 76 // The directory must be good here. | 77 // The directory must be good here. |
| 77 CHECK(dir.good()); | 78 CHECK(dir.good()); |
| 78 | 79 |
| 79 const sessions::SyncSourceInfo& source(session->source()); | 80 const sessions::SyncSourceInfo& source(session->source()); |
| 80 if (sync_pb::GetUpdatesCallerInfo::CLEAR_PRIVATE_DATA == | 81 if (sync_pb::GetUpdatesCallerInfo::CLEAR_PRIVATE_DATA == |
| 81 source.updates_source) { | 82 source.updates_source) { |
| 82 SyncShare(session, CLEAR_PRIVATE_DATA, SYNCER_END); | 83 SyncShare(session, CLEAR_PRIVATE_DATA, SYNCER_END); |
| 83 return; | 84 return; |
| 84 } else { | 85 } else { |
| 85 // This isn't perfect, as we can end up bundling extensions activity | |
| 86 // intended for the next session into the current one. We could do a | |
| 87 // test-and-reset as with the source, but note that also falls short if | |
| 88 // the commit request fails (e.g. due to lost connection), as we will | |
| 89 // fall all the way back to the syncer thread main loop in that case, and | |
| 90 // wind up creating a new session when a connection is established, losing | |
| 91 // the records set here on the original attempt. This should provide us | |
| 92 // with the right data "most of the time", and we're only using this for | |
| 93 // analysis purposes, so Law of Large Numbers FTW. | |
| 94 session->context()->extensions_monitor()->GetAndClearRecords( | |
| 95 session->mutable_extensions_activity()); | |
| 96 SyncShare(session, SYNCER_BEGIN, SYNCER_END); | 86 SyncShare(session, SYNCER_BEGIN, SYNCER_END); |
| 97 } | 87 } |
| 98 } | 88 } |
| 99 | 89 |
| 100 void Syncer::SyncShare(sessions::SyncSession* session, | 90 void Syncer::SyncShare(sessions::SyncSession* session, |
| 101 const SyncerStep first_step, | 91 const SyncerStep first_step, |
| 102 const SyncerStep last_step) { | 92 const SyncerStep last_step) { |
| 93 ScopedDirLookup dir(session->context()->directory_manager(), |
| 94 session->context()->account_name()); |
| 95 // The directory must be good here. |
| 96 CHECK(dir.good()); |
| 97 |
| 103 ScopedSessionContextConflictResolver scoped(session->context(), | 98 ScopedSessionContextConflictResolver scoped(session->context(), |
| 104 &resolver_); | 99 &resolver_); |
| 105 SyncerStep current_step = first_step; | 100 SyncerStep current_step = first_step; |
| 106 | 101 |
| 107 SyncerStep next_step = current_step; | 102 SyncerStep next_step = current_step; |
| 108 while (!ExitRequested()) { | 103 while (!ExitRequested()) { |
| 109 switch (current_step) { | 104 switch (current_step) { |
| 110 case SYNCER_BEGIN: | 105 case SYNCER_BEGIN: |
| 111 VLOG(1) << "Syncer Begin"; | 106 VLOG(1) << "Syncer Begin"; |
| 107 // This isn't perfect, as we can end up bundling extensions activity |
| 108 // intended for the next session into the current one. We could do a |
| 109 // test-and-reset as with the source, but note that also falls short if |
| 110 // the commit request fails (e.g. due to lost connection), as we will |
| 111 // fall all the way back to the syncer thread main loop in that case, |
| 112 // creating a new session when a connection is established, losing the |
| 113 // records set here on the original attempt. This should provide us |
| 114 // with the right data "most of the time", and we're only using this |
| 115 // for analysis purposes, so Law of Large Numbers FTW. |
| 116 session->context()->extensions_monitor()->GetAndClearRecords( |
| 117 session->mutable_extensions_activity()); |
| 112 next_step = CLEANUP_DISABLED_TYPES; | 118 next_step = CLEANUP_DISABLED_TYPES; |
| 113 break; | 119 break; |
| 114 case CLEANUP_DISABLED_TYPES: { | 120 case CLEANUP_DISABLED_TYPES: { |
| 115 VLOG(1) << "Cleaning up disabled types"; | 121 VLOG(1) << "Cleaning up disabled types"; |
| 116 CleanupDisabledTypesCommand cleanup; | 122 CleanupDisabledTypesCommand cleanup; |
| 117 cleanup.Execute(session); | 123 cleanup.Execute(session); |
| 118 next_step = DOWNLOAD_UPDATES; | 124 next_step = DOWNLOAD_UPDATES; |
| 119 break; | 125 break; |
| 120 } | 126 } |
| 121 case DOWNLOAD_UPDATES: { | 127 case DOWNLOAD_UPDATES: { |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 entry->Put(SERVER_CTIME, 0); | 329 entry->Put(SERVER_CTIME, 0); |
| 324 entry->Put(SERVER_VERSION, 0); | 330 entry->Put(SERVER_VERSION, 0); |
| 325 entry->Put(SERVER_IS_DIR, false); | 331 entry->Put(SERVER_IS_DIR, false); |
| 326 entry->Put(SERVER_IS_DEL, false); | 332 entry->Put(SERVER_IS_DEL, false); |
| 327 entry->Put(IS_UNAPPLIED_UPDATE, false); | 333 entry->Put(IS_UNAPPLIED_UPDATE, false); |
| 328 entry->Put(SERVER_SPECIFICS, sync_pb::EntitySpecifics::default_instance()); | 334 entry->Put(SERVER_SPECIFICS, sync_pb::EntitySpecifics::default_instance()); |
| 329 entry->Put(SERVER_POSITION_IN_PARENT, 0); | 335 entry->Put(SERVER_POSITION_IN_PARENT, 0); |
| 330 } | 336 } |
| 331 | 337 |
| 332 } // namespace browser_sync | 338 } // namespace browser_sync |
| OLD | NEW |