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

Side by Side Diff: components/sync/driver/backend_migrator.cc

Issue 2203673002: [Sync] Move //components/sync_driver to //components/sync/driver. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@sd-a
Patch Set: Full change rebased on static lib. 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
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 "components/sync_driver/backend_migrator.h" 5 #include "components/sync/driver/backend_migrator.h"
6 6
7 #include "base/location.h" 7 #include "base/location.h"
8 #include "base/single_thread_task_runner.h" 8 #include "base/single_thread_task_runner.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/threading/thread_task_runner_handle.h" 10 #include "base/threading/thread_task_runner_handle.h"
11 #include "base/tracked_objects.h" 11 #include "base/tracked_objects.h"
12 #include "components/sync/core/configure_reason.h" 12 #include "components/sync/core/configure_reason.h"
13 #include "components/sync/core/read_transaction.h" 13 #include "components/sync/core/read_transaction.h"
14 #include "components/sync/driver/sync_service.h"
14 #include "components/sync/protocol/sync.pb.h" 15 #include "components/sync/protocol/sync.pb.h"
15 #include "components/sync/syncable/directory.h" // TODO(tim): Bug 131130. 16 #include "components/sync/syncable/directory.h" // TODO(tim): Bug 131130.
16 #include "components/sync_driver/sync_service.h"
17 17
18 using syncer::ModelTypeSet; 18 using syncer::ModelTypeSet;
19 19
20 namespace browser_sync { 20 namespace browser_sync {
21 21
22 using syncer::ModelTypeToString; 22 using syncer::ModelTypeToString;
23 23
24 MigrationObserver::~MigrationObserver() {} 24 MigrationObserver::~MigrationObserver() {}
25 25
26 BackendMigrator::BackendMigrator(const std::string& name, 26 BackendMigrator::BackendMigrator(const std::string& name,
27 syncer::UserShare* user_share, 27 syncer::UserShare* user_share,
28 sync_driver::SyncService* service, 28 sync_driver::SyncService* service,
29 sync_driver::DataTypeManager* manager, 29 sync_driver::DataTypeManager* manager,
30 const base::Closure &migration_done_callback) 30 const base::Closure& migration_done_callback)
31 : name_(name), user_share_(user_share), service_(service), 31 : name_(name),
32 manager_(manager), state_(IDLE), 32 user_share_(user_share),
33 service_(service),
34 manager_(manager),
35 state_(IDLE),
33 migration_done_callback_(migration_done_callback), 36 migration_done_callback_(migration_done_callback),
34 weak_ptr_factory_(this) { 37 weak_ptr_factory_(this) {}
35 }
36 38
37 BackendMigrator::~BackendMigrator() { 39 BackendMigrator::~BackendMigrator() {}
38 }
39 40
40 // Helper macros to log with the syncer thread name; useful when there 41 // Helper macros to log with the syncer thread name; useful when there
41 // are multiple syncer threads involved. 42 // are multiple syncer threads involved.
42 43
43 #define SLOG(severity) LOG(severity) << name_ << ": " 44 #define SLOG(severity) LOG(severity) << name_ << ": "
44 45
45 #define SDVLOG(verbose_level) DVLOG(verbose_level) << name_ << ": " 46 #define SDVLOG(verbose_level) DVLOG(verbose_level) << name_ << ": "
46 47
47 void BackendMigrator::MigrateTypes(syncer::ModelTypeSet types) { 48 void BackendMigrator::MigrateTypes(syncer::ModelTypeSet types) {
48 const ModelTypeSet old_to_migrate = to_migrate_; 49 const ModelTypeSet old_to_migrate = to_migrate_;
49 to_migrate_.PutAll(types); 50 to_migrate_.PutAll(types);
50 SDVLOG(1) << "MigrateTypes called with " << ModelTypeSetToString(types) 51 SDVLOG(1) << "MigrateTypes called with " << ModelTypeSetToString(types)
51 << ", old_to_migrate = " << ModelTypeSetToString(old_to_migrate) 52 << ", old_to_migrate = " << ModelTypeSetToString(old_to_migrate)
52 << ", to_migrate_ = " << ModelTypeSetToString(to_migrate_); 53 << ", to_migrate_ = " << ModelTypeSetToString(to_migrate_);
53 if (old_to_migrate == to_migrate_) { 54 if (old_to_migrate == to_migrate_) {
54 SDVLOG(1) << "MigrateTypes called with no new types; ignoring"; 55 SDVLOG(1) << "MigrateTypes called with no new types; ignoring";
55 return; 56 return;
56 } 57 }
57 58
58 if (state_ == IDLE) 59 if (state_ == IDLE)
59 ChangeState(WAITING_TO_START); 60 ChangeState(WAITING_TO_START);
60 61
61 if (state_ == WAITING_TO_START) { 62 if (state_ == WAITING_TO_START) {
62 if (!TryStart()) 63 if (!TryStart())
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 base::ThreadTaskRunnerHandle::Get()->PostTask( 118 base::ThreadTaskRunnerHandle::Get()->PostTask(
118 FROM_HERE, base::Bind(&BackendMigrator::OnConfigureDoneImpl, 119 FROM_HERE, base::Bind(&BackendMigrator::OnConfigureDoneImpl,
119 weak_ptr_factory_.GetWeakPtr(), result)); 120 weak_ptr_factory_.GetWeakPtr(), result));
120 } 121 }
121 122
122 namespace { 123 namespace {
123 124
124 syncer::ModelTypeSet GetUnsyncedDataTypes(syncer::UserShare* user_share) { 125 syncer::ModelTypeSet GetUnsyncedDataTypes(syncer::UserShare* user_share) {
125 syncer::ReadTransaction trans(FROM_HERE, user_share); 126 syncer::ReadTransaction trans(FROM_HERE, user_share);
126 syncer::ModelTypeSet unsynced_data_types; 127 syncer::ModelTypeSet unsynced_data_types;
127 for (int i = syncer::FIRST_REAL_MODEL_TYPE; 128 for (int i = syncer::FIRST_REAL_MODEL_TYPE; i < syncer::MODEL_TYPE_COUNT;
128 i < syncer::MODEL_TYPE_COUNT; ++i) { 129 ++i) {
129 syncer::ModelType type = syncer::ModelTypeFromInt(i); 130 syncer::ModelType type = syncer::ModelTypeFromInt(i);
130 sync_pb::DataTypeProgressMarker progress_marker; 131 sync_pb::DataTypeProgressMarker progress_marker;
131 trans.GetDirectory()->GetDownloadProgress(type, &progress_marker); 132 trans.GetDirectory()->GetDownloadProgress(type, &progress_marker);
132 if (progress_marker.token().empty()) { 133 if (progress_marker.token().empty()) {
133 unsynced_data_types.Put(type); 134 unsynced_data_types.Put(type);
134 } 135 }
135 } 136 }
136 return unsynced_data_types; 137 return unsynced_data_types;
137 } 138 }
138 139
139 } // namespace 140 } // namespace
140 141
141 void BackendMigrator::OnConfigureDoneImpl( 142 void BackendMigrator::OnConfigureDoneImpl(
142 const sync_driver::DataTypeManager::ConfigureResult& result) { 143 const sync_driver::DataTypeManager::ConfigureResult& result) {
143 SDVLOG(1) << "OnConfigureDone with requested types " 144 SDVLOG(1) << "OnConfigureDone with requested types "
144 << ModelTypeSetToString(result.requested_types) 145 << ModelTypeSetToString(result.requested_types) << ", status "
145 << ", status " << result.status 146 << result.status
146 << ", and to_migrate_ = " << ModelTypeSetToString(to_migrate_); 147 << ", and to_migrate_ = " << ModelTypeSetToString(to_migrate_);
147 if (state_ == WAITING_TO_START) { 148 if (state_ == WAITING_TO_START) {
148 if (!TryStart()) 149 if (!TryStart())
149 SDVLOG(1) << "Manager still not configured; still waiting"; 150 SDVLOG(1) << "Manager still not configured; still waiting";
150 return; 151 return;
151 } 152 }
152 153
153 DCHECK_GT(state_, WAITING_TO_START); 154 DCHECK_GT(state_, WAITING_TO_START);
154 155
155 const ModelTypeSet intersection = 156 const ModelTypeSet intersection =
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 215
215 syncer::ModelTypeSet BackendMigrator::GetPendingMigrationTypesForTest() const { 216 syncer::ModelTypeSet BackendMigrator::GetPendingMigrationTypesForTest() const {
216 return to_migrate_; 217 return to_migrate_;
217 } 218 }
218 219
219 #undef SDVLOG 220 #undef SDVLOG
220 221
221 #undef SLOG 222 #undef SLOG
222 223
223 }; // namespace browser_sync 224 }; // namespace browser_sync
OLDNEW
« no previous file with comments | « components/sync/driver/backend_migrator.h ('k') | components/sync/driver/backend_migrator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698