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

Side by Side Diff: chrome/browser/sync/internal_api/sync_manager.cc

Issue 8919021: [Sync] Rename ModelEnumSet to ModelTypeSet (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years 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 | Annotate | Revision Log
OLDNEW
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/internal_api/sync_manager.h" 5 #include "chrome/browser/sync/internal_api/sync_manager.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 using browser_sync::ServerConnectionEventListener; 71 using browser_sync::ServerConnectionEventListener;
72 using browser_sync::SyncEngineEvent; 72 using browser_sync::SyncEngineEvent;
73 using browser_sync::SyncEngineEventListener; 73 using browser_sync::SyncEngineEventListener;
74 using browser_sync::SyncScheduler; 74 using browser_sync::SyncScheduler;
75 using browser_sync::Syncer; 75 using browser_sync::Syncer;
76 using browser_sync::WeakHandle; 76 using browser_sync::WeakHandle;
77 using browser_sync::sessions::SyncSessionContext; 77 using browser_sync::sessions::SyncSessionContext;
78 using syncable::DirectoryManager; 78 using syncable::DirectoryManager;
79 using syncable::ImmutableWriteTransactionInfo; 79 using syncable::ImmutableWriteTransactionInfo;
80 using syncable::ModelType; 80 using syncable::ModelType;
81 using syncable::ModelEnumSet; 81 using syncable::ModelTypeSet;
82 using syncable::SPECIFICS; 82 using syncable::SPECIFICS;
83 using sync_pb::GetUpdatesCallerInfo; 83 using sync_pb::GetUpdatesCallerInfo;
84 84
85 typedef GoogleServiceAuthError AuthError; 85 typedef GoogleServiceAuthError AuthError;
86 86
87 namespace { 87 namespace {
88 88
89 static const int kSyncSchedulerDelayMsec = 250; 89 static const int kSyncSchedulerDelayMsec = 250;
90 90
91 #if defined(OS_CHROMEOS) 91 #if defined(OS_CHROMEOS)
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 bool SignIn(const SyncCredentials& credentials); 200 bool SignIn(const SyncCredentials& credentials);
201 201
202 // Update tokens that we're using in Sync. Email must stay the same. 202 // Update tokens that we're using in Sync. Email must stay the same.
203 void UpdateCredentials(const SyncCredentials& credentials); 203 void UpdateCredentials(const SyncCredentials& credentials);
204 204
205 // Called when the user disables or enables a sync type. 205 // Called when the user disables or enables a sync type.
206 void UpdateEnabledTypes(); 206 void UpdateEnabledTypes();
207 207
208 // Conditionally sets the flag in the Nigori node which instructs other 208 // Conditionally sets the flag in the Nigori node which instructs other
209 // clients to start syncing tabs. 209 // clients to start syncing tabs.
210 void MaybeSetSyncTabsInNigoriNode(ModelEnumSet enabled_types); 210 void MaybeSetSyncTabsInNigoriNode(ModelTypeSet enabled_types);
211 211
212 // Tell the sync engine to start the syncing process. 212 // Tell the sync engine to start the syncing process.
213 void StartSyncingNormally(); 213 void StartSyncingNormally();
214 214
215 // Whether or not the Nigori node is encrypted using an explicit passphrase. 215 // Whether or not the Nigori node is encrypted using an explicit passphrase.
216 bool IsUsingExplicitPassphrase(); 216 bool IsUsingExplicitPassphrase();
217 217
218 // Update the Cryptographer from the current nigori node and write back any 218 // Update the Cryptographer from the current nigori node and write back any
219 // necessary changes to the nigori node. We also detect missing encryption 219 // necessary changes to the nigori node. We also detect missing encryption
220 // keys and write them into the nigori node. 220 // keys and write them into the nigori node.
(...skipping 15 matching lines...) Expand all
236 236
237 // Call periodically from a database-safe thread to persist recent changes 237 // Call periodically from a database-safe thread to persist recent changes
238 // to the syncapi model. 238 // to the syncapi model.
239 void SaveChanges(); 239 void SaveChanges();
240 240
241 // DirectoryChangeDelegate implementation. 241 // DirectoryChangeDelegate implementation.
242 // This listener is called upon completion of a syncable transaction, and 242 // This listener is called upon completion of a syncable transaction, and
243 // builds the list of sync-engine initiated changes that will be forwarded to 243 // builds the list of sync-engine initiated changes that will be forwarded to
244 // the SyncManager's Observers. 244 // the SyncManager's Observers.
245 virtual void HandleTransactionCompleteChangeEvent( 245 virtual void HandleTransactionCompleteChangeEvent(
246 ModelEnumSet models_with_changes) OVERRIDE; 246 ModelTypeSet models_with_changes) OVERRIDE;
247 virtual ModelEnumSet HandleTransactionEndingChangeEvent( 247 virtual ModelTypeSet HandleTransactionEndingChangeEvent(
248 const ImmutableWriteTransactionInfo& write_transaction_info, 248 const ImmutableWriteTransactionInfo& write_transaction_info,
249 syncable::BaseTransaction* trans) OVERRIDE; 249 syncable::BaseTransaction* trans) OVERRIDE;
250 virtual void HandleCalculateChangesChangeEventFromSyncApi( 250 virtual void HandleCalculateChangesChangeEventFromSyncApi(
251 const ImmutableWriteTransactionInfo& write_transaction_info, 251 const ImmutableWriteTransactionInfo& write_transaction_info,
252 syncable::BaseTransaction* trans) OVERRIDE; 252 syncable::BaseTransaction* trans) OVERRIDE;
253 virtual void HandleCalculateChangesChangeEventFromSyncer( 253 virtual void HandleCalculateChangesChangeEventFromSyncer(
254 const ImmutableWriteTransactionInfo& write_transaction_info, 254 const ImmutableWriteTransactionInfo& write_transaction_info,
255 syncable::BaseTransaction* trans) OVERRIDE; 255 syncable::BaseTransaction* trans) OVERRIDE;
256 256
257 // Listens for notifications from the ServerConnectionManager 257 // Listens for notifications from the ServerConnectionManager
258 void HandleServerConnectionEvent(const ServerConnectionEvent& event); 258 void HandleServerConnectionEvent(const ServerConnectionEvent& event);
259 259
260 // Open the directory named with username_for_share 260 // Open the directory named with username_for_share
261 bool OpenDirectory(); 261 bool OpenDirectory();
262 262
263 // Cryptographer::Observer implementation. 263 // Cryptographer::Observer implementation.
264 virtual void OnEncryptedTypesChanged( 264 virtual void OnEncryptedTypesChanged(
265 syncable::ModelEnumSet encrypted_types, 265 syncable::ModelTypeSet encrypted_types,
266 bool encrypt_everything) OVERRIDE; 266 bool encrypt_everything) OVERRIDE;
267 267
268 // SyncNotifierObserver implementation. 268 // SyncNotifierObserver implementation.
269 virtual void OnNotificationStateChange( 269 virtual void OnNotificationStateChange(
270 bool notifications_enabled) OVERRIDE; 270 bool notifications_enabled) OVERRIDE;
271 271
272 virtual void OnIncomingNotification( 272 virtual void OnIncomingNotification(
273 const syncable::ModelTypePayloadMap& type_payloads) OVERRIDE; 273 const syncable::ModelTypePayloadMap& type_payloads) OVERRIDE;
274 274
275 virtual void StoreState(const std::string& cookie) OVERRIDE; 275 virtual void StoreState(const std::string& cookie) OVERRIDE;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 ChangeReorderBuffer* buffer, 314 ChangeReorderBuffer* buffer,
315 Cryptographer* cryptographer, 315 Cryptographer* cryptographer,
316 const syncable::EntryKernel& original, 316 const syncable::EntryKernel& original,
317 bool existed_before, 317 bool existed_before,
318 bool exists_now); 318 bool exists_now);
319 319
320 // Called only by our NetworkChangeNotifier. 320 // Called only by our NetworkChangeNotifier.
321 virtual void OnIPAddressChanged() OVERRIDE; 321 virtual void OnIPAddressChanged() OVERRIDE;
322 322
323 bool InitialSyncEndedForAllEnabledTypes() { 323 bool InitialSyncEndedForAllEnabledTypes() {
324 syncable::ModelEnumSet types; 324 syncable::ModelTypeSet types;
325 ModelSafeRoutingInfo enabled_types; 325 ModelSafeRoutingInfo enabled_types;
326 registrar_->GetModelSafeRoutingInfo(&enabled_types); 326 registrar_->GetModelSafeRoutingInfo(&enabled_types);
327 for (ModelSafeRoutingInfo::const_iterator i = enabled_types.begin(); 327 for (ModelSafeRoutingInfo::const_iterator i = enabled_types.begin();
328 i != enabled_types.end(); ++i) { 328 i != enabled_types.end(); ++i) {
329 types.Put(i->first); 329 types.Put(i->first);
330 } 330 }
331 331
332 return InitialSyncEndedForTypes(types, &share_); 332 return InitialSyncEndedForTypes(types, &share_);
333 } 333 }
334 334
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 DCHECK(thread_checker_.CalledOnValidThread()); 635 DCHECK(thread_checker_.CalledOnValidThread());
636 data_->UpdateCredentials(credentials); 636 data_->UpdateCredentials(credentials);
637 } 637 }
638 638
639 void SyncManager::UpdateEnabledTypes() { 639 void SyncManager::UpdateEnabledTypes() {
640 DCHECK(thread_checker_.CalledOnValidThread()); 640 DCHECK(thread_checker_.CalledOnValidThread());
641 data_->UpdateEnabledTypes(); 641 data_->UpdateEnabledTypes();
642 } 642 }
643 643
644 void SyncManager::MaybeSetSyncTabsInNigoriNode( 644 void SyncManager::MaybeSetSyncTabsInNigoriNode(
645 ModelEnumSet enabled_types) { 645 ModelTypeSet enabled_types) {
646 DCHECK(thread_checker_.CalledOnValidThread()); 646 DCHECK(thread_checker_.CalledOnValidThread());
647 data_->MaybeSetSyncTabsInNigoriNode(enabled_types); 647 data_->MaybeSetSyncTabsInNigoriNode(enabled_types);
648 } 648 }
649 649
650 bool SyncManager::InitialSyncEndedForAllEnabledTypes() { 650 bool SyncManager::InitialSyncEndedForAllEnabledTypes() {
651 return data_->InitialSyncEndedForAllEnabledTypes(); 651 return data_->InitialSyncEndedForAllEnabledTypes();
652 } 652 }
653 653
654 void SyncManager::StartSyncingNormally() { 654 void SyncManager::StartSyncingNormally() {
655 DCHECK(thread_checker_.CalledOnValidThread()); 655 DCHECK(thread_checker_.CalledOnValidThread());
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 data_->scheduler()->ScheduleCleanupDisabledTypes(); 695 data_->scheduler()->ScheduleCleanupDisabledTypes();
696 } 696 }
697 697
698 void SyncManager::RequestClearServerData() { 698 void SyncManager::RequestClearServerData() {
699 DCHECK(thread_checker_.CalledOnValidThread()); 699 DCHECK(thread_checker_.CalledOnValidThread());
700 if (data_->scheduler()) 700 if (data_->scheduler())
701 data_->scheduler()->ScheduleClearUserData(); 701 data_->scheduler()->ScheduleClearUserData();
702 } 702 }
703 703
704 void SyncManager::RequestConfig( 704 void SyncManager::RequestConfig(
705 ModelEnumSet types, ConfigureReason reason) { 705 ModelTypeSet types, ConfigureReason reason) {
706 DCHECK(thread_checker_.CalledOnValidThread()); 706 DCHECK(thread_checker_.CalledOnValidThread());
707 if (!data_->scheduler()) { 707 if (!data_->scheduler()) {
708 LOG(INFO) 708 LOG(INFO)
709 << "SyncManager::RequestConfig: bailing out because scheduler is " 709 << "SyncManager::RequestConfig: bailing out because scheduler is "
710 << "null"; 710 << "null";
711 return; 711 return;
712 } 712 }
713 StartConfigurationMode(base::Closure()); 713 StartConfigurationMode(base::Closure());
714 data_->scheduler()->ScheduleConfig(types, GetSourceFromReason(reason)); 714 data_->scheduler()->ScheduleConfig(types, GetSourceFromReason(reason));
715 } 715 }
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
958 FROM_HERE, base::Bind(&SyncInternal::CheckServerReachable, 958 FROM_HERE, base::Bind(&SyncInternal::CheckServerReachable,
959 weak_ptr_factory_.GetWeakPtr())); 959 weak_ptr_factory_.GetWeakPtr()));
960 } 960 }
961 } 961 }
962 } 962 }
963 963
964 void SyncManager::SyncInternal::UpdateEnabledTypes() { 964 void SyncManager::SyncInternal::UpdateEnabledTypes() {
965 DCHECK(thread_checker_.CalledOnValidThread()); 965 DCHECK(thread_checker_.CalledOnValidThread());
966 ModelSafeRoutingInfo routes; 966 ModelSafeRoutingInfo routes;
967 registrar_->GetModelSafeRoutingInfo(&routes); 967 registrar_->GetModelSafeRoutingInfo(&routes);
968 const ModelEnumSet enabled_types = GetRoutingInfoTypes(routes); 968 const ModelTypeSet enabled_types = GetRoutingInfoTypes(routes);
969 sync_notifier_->UpdateEnabledTypes(enabled_types); 969 sync_notifier_->UpdateEnabledTypes(enabled_types);
970 if (CommandLine::ForCurrentProcess()->HasSwitch( 970 if (CommandLine::ForCurrentProcess()->HasSwitch(
971 switches::kEnableSyncTabsForOtherClients)) { 971 switches::kEnableSyncTabsForOtherClients)) {
972 MaybeSetSyncTabsInNigoriNode(enabled_types); 972 MaybeSetSyncTabsInNigoriNode(enabled_types);
973 } 973 }
974 } 974 }
975 975
976 void SyncManager::SyncInternal::MaybeSetSyncTabsInNigoriNode( 976 void SyncManager::SyncInternal::MaybeSetSyncTabsInNigoriNode(
977 const ModelEnumSet enabled_types) { 977 const ModelTypeSet enabled_types) {
978 // The initialized_ check is to ensure that we don't CHECK in GetUserShare 978 // The initialized_ check is to ensure that we don't CHECK in GetUserShare
979 // when this is called on start-up. It's ok to ignore that case, since 979 // when this is called on start-up. It's ok to ignore that case, since
980 // presumably this would've run when the user originally enabled sessions. 980 // presumably this would've run when the user originally enabled sessions.
981 if (initialized_ && enabled_types.Has(syncable::SESSIONS)) { 981 if (initialized_ && enabled_types.Has(syncable::SESSIONS)) {
982 WriteTransaction trans(FROM_HERE, GetUserShare()); 982 WriteTransaction trans(FROM_HERE, GetUserShare());
983 WriteNode node(&trans); 983 WriteNode node(&trans);
984 if (!node.InitByTagLookup(kNigoriTag)) { 984 if (!node.InitByTagLookup(kNigoriTag)) {
985 NOTREACHED() << "Unable to set 'sync_tabs' bit because Nigori node not " 985 NOTREACHED() << "Unable to set 'sync_tabs' bit because Nigori node not "
986 << "found."; 986 << "found.";
987 return; 987 return;
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
1128 // types changed to ensure that any stray unencrypted entries are overwritten. 1128 // types changed to ensure that any stray unencrypted entries are overwritten.
1129 ReEncryptEverything(&trans); 1129 ReEncryptEverything(&trans);
1130 } 1130 }
1131 1131
1132 // TODO(zea): Add unit tests that ensure no sync changes are made when not 1132 // TODO(zea): Add unit tests that ensure no sync changes are made when not
1133 // needed. 1133 // needed.
1134 void SyncManager::SyncInternal::ReEncryptEverything(WriteTransaction* trans) { 1134 void SyncManager::SyncInternal::ReEncryptEverything(WriteTransaction* trans) {
1135 Cryptographer* cryptographer = trans->GetCryptographer(); 1135 Cryptographer* cryptographer = trans->GetCryptographer();
1136 if (!cryptographer || !cryptographer->is_ready()) 1136 if (!cryptographer || !cryptographer->is_ready())
1137 return; 1137 return;
1138 syncable::ModelEnumSet encrypted_types = GetEncryptedTypes(trans); 1138 syncable::ModelTypeSet encrypted_types = GetEncryptedTypes(trans);
1139 ModelSafeRoutingInfo routes; 1139 ModelSafeRoutingInfo routes;
1140 registrar_->GetModelSafeRoutingInfo(&routes); 1140 registrar_->GetModelSafeRoutingInfo(&routes);
1141 std::string tag; 1141 std::string tag;
1142 for (syncable::ModelEnumSet::Iterator iter = encrypted_types.First(); 1142 for (syncable::ModelTypeSet::Iterator iter = encrypted_types.First();
1143 iter.Good(); iter.Inc()) { 1143 iter.Good(); iter.Inc()) {
1144 if (iter.Get() == syncable::PASSWORDS || 1144 if (iter.Get() == syncable::PASSWORDS ||
1145 iter.Get() == syncable::NIGORI || 1145 iter.Get() == syncable::NIGORI ||
1146 routes.count(iter.Get()) == 0) 1146 routes.count(iter.Get()) == 0)
1147 continue; 1147 continue;
1148 ReadNode type_root(trans); 1148 ReadNode type_root(trans);
1149 tag = syncable::ModelTypeToRootTag(iter.Get()); 1149 tag = syncable::ModelTypeToRootTag(iter.Get());
1150 if (!type_root.InitByTagLookup(tag)) { 1150 if (!type_root.InitByTagLookup(tag)) {
1151 // This can happen when we enable a datatype for the first time on restart 1151 // This can happen when we enable a datatype for the first time on restart
1152 // (for example when we upgrade) and therefore haven't done the initial 1152 // (for example when we upgrade) and therefore haven't done the initial
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
1342 } 1342 }
1343 1343
1344 if (event.connection_code == 1344 if (event.connection_code ==
1345 browser_sync::HttpResponse::SYNC_SERVER_ERROR) { 1345 browser_sync::HttpResponse::SYNC_SERVER_ERROR) {
1346 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, 1346 FOR_EACH_OBSERVER(SyncManager::Observer, observers_,
1347 OnAuthError(AuthError(AuthError::CONNECTION_FAILED))); 1347 OnAuthError(AuthError(AuthError::CONNECTION_FAILED)));
1348 } 1348 }
1349 } 1349 }
1350 1350
1351 void SyncManager::SyncInternal::HandleTransactionCompleteChangeEvent( 1351 void SyncManager::SyncInternal::HandleTransactionCompleteChangeEvent(
1352 ModelEnumSet models_with_changes) { 1352 ModelTypeSet models_with_changes) {
1353 // This notification happens immediately after the transaction mutex is 1353 // This notification happens immediately after the transaction mutex is
1354 // released. This allows work to be performed without blocking other threads 1354 // released. This allows work to be performed without blocking other threads
1355 // from acquiring a transaction. 1355 // from acquiring a transaction.
1356 if (!change_delegate_) 1356 if (!change_delegate_)
1357 return; 1357 return;
1358 1358
1359 // Call commit. 1359 // Call commit.
1360 for (ModelEnumSet::Iterator it = models_with_changes.First(); 1360 for (ModelTypeSet::Iterator it = models_with_changes.First();
1361 it.Good(); it.Inc()) { 1361 it.Good(); it.Inc()) {
1362 change_delegate_->OnChangesComplete(it.Get()); 1362 change_delegate_->OnChangesComplete(it.Get());
1363 change_observer_.Call( 1363 change_observer_.Call(
1364 FROM_HERE, &SyncManager::ChangeObserver::OnChangesComplete, it.Get()); 1364 FROM_HERE, &SyncManager::ChangeObserver::OnChangesComplete, it.Get());
1365 } 1365 }
1366 } 1366 }
1367 1367
1368 ModelEnumSet 1368 ModelTypeSet
1369 SyncManager::SyncInternal::HandleTransactionEndingChangeEvent( 1369 SyncManager::SyncInternal::HandleTransactionEndingChangeEvent(
1370 const ImmutableWriteTransactionInfo& write_transaction_info, 1370 const ImmutableWriteTransactionInfo& write_transaction_info,
1371 syncable::BaseTransaction* trans) { 1371 syncable::BaseTransaction* trans) {
1372 // This notification happens immediately before a syncable WriteTransaction 1372 // This notification happens immediately before a syncable WriteTransaction
1373 // falls out of scope. It happens while the channel mutex is still held, 1373 // falls out of scope. It happens while the channel mutex is still held,
1374 // and while the transaction mutex is held, so it cannot be re-entrant. 1374 // and while the transaction mutex is held, so it cannot be re-entrant.
1375 if (!change_delegate_ || ChangeBuffersAreEmpty()) 1375 if (!change_delegate_ || ChangeBuffersAreEmpty())
1376 return ModelEnumSet(); 1376 return ModelTypeSet();
1377 1377
1378 // This will continue the WriteTransaction using a read only wrapper. 1378 // This will continue the WriteTransaction using a read only wrapper.
1379 // This is the last chance for read to occur in the WriteTransaction 1379 // This is the last chance for read to occur in the WriteTransaction
1380 // that's closing. This special ReadTransaction will not close the 1380 // that's closing. This special ReadTransaction will not close the
1381 // underlying transaction. 1381 // underlying transaction.
1382 ReadTransaction read_trans(GetUserShare(), trans); 1382 ReadTransaction read_trans(GetUserShare(), trans);
1383 1383
1384 ModelEnumSet models_with_changes; 1384 ModelTypeSet models_with_changes;
1385 for (int i = syncable::FIRST_REAL_MODEL_TYPE; 1385 for (int i = syncable::FIRST_REAL_MODEL_TYPE;
1386 i < syncable::MODEL_TYPE_COUNT; ++i) { 1386 i < syncable::MODEL_TYPE_COUNT; ++i) {
1387 const syncable::ModelType type = syncable::ModelTypeFromInt(i); 1387 const syncable::ModelType type = syncable::ModelTypeFromInt(i);
1388 if (change_buffers_[type].IsEmpty()) 1388 if (change_buffers_[type].IsEmpty())
1389 continue; 1389 continue;
1390 1390
1391 ImmutableChangeRecordList ordered_changes; 1391 ImmutableChangeRecordList ordered_changes;
1392 // TODO(akalin): Propagate up the error further (see 1392 // TODO(akalin): Propagate up the error further (see
1393 // http://crbug.com/100907). 1393 // http://crbug.com/100907).
1394 CHECK(change_buffers_[type].GetAllChangesInTreeOrder(&read_trans, 1394 CHECK(change_buffers_[type].GetAllChangesInTreeOrder(&read_trans,
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
1529 1529
1530 SyncManager::Status SyncManager::SyncInternal::GetStatus() { 1530 SyncManager::Status SyncManager::SyncInternal::GetStatus() {
1531 return allstatus_.status(); 1531 return allstatus_.status();
1532 } 1532 }
1533 1533
1534 void SyncManager::SyncInternal::RequestNudge( 1534 void SyncManager::SyncInternal::RequestNudge(
1535 const tracked_objects::Location& location) { 1535 const tracked_objects::Location& location) {
1536 if (scheduler()) 1536 if (scheduler())
1537 scheduler()->ScheduleNudge( 1537 scheduler()->ScheduleNudge(
1538 TimeDelta::FromMilliseconds(0), browser_sync::NUDGE_SOURCE_LOCAL, 1538 TimeDelta::FromMilliseconds(0), browser_sync::NUDGE_SOURCE_LOCAL,
1539 ModelEnumSet(), location); 1539 ModelTypeSet(), location);
1540 } 1540 }
1541 1541
1542 void SyncManager::SyncInternal::RequestNudgeForDataType( 1542 void SyncManager::SyncInternal::RequestNudgeForDataType(
1543 const tracked_objects::Location& nudge_location, 1543 const tracked_objects::Location& nudge_location,
1544 const ModelType& type) { 1544 const ModelType& type) {
1545 if (!scheduler()) { 1545 if (!scheduler()) {
1546 NOTREACHED(); 1546 NOTREACHED();
1547 return; 1547 return;
1548 } 1548 }
1549 base::TimeDelta nudge_delay; 1549 base::TimeDelta nudge_delay;
1550 switch (type) { 1550 switch (type) {
1551 case syncable::PREFERENCES: 1551 case syncable::PREFERENCES:
1552 nudge_delay = 1552 nudge_delay =
1553 TimeDelta::FromMilliseconds(kPreferencesNudgeDelayMilliseconds); 1553 TimeDelta::FromMilliseconds(kPreferencesNudgeDelayMilliseconds);
1554 break; 1554 break;
1555 case syncable::SESSIONS: 1555 case syncable::SESSIONS:
1556 nudge_delay = scheduler()->sessions_commit_delay(); 1556 nudge_delay = scheduler()->sessions_commit_delay();
1557 break; 1557 break;
1558 default: 1558 default:
1559 nudge_delay = 1559 nudge_delay =
1560 TimeDelta::FromMilliseconds(kDefaultNudgeDelayMilliseconds); 1560 TimeDelta::FromMilliseconds(kDefaultNudgeDelayMilliseconds);
1561 break; 1561 break;
1562 } 1562 }
1563 scheduler()->ScheduleNudge(nudge_delay, 1563 scheduler()->ScheduleNudge(nudge_delay,
1564 browser_sync::NUDGE_SOURCE_LOCAL, 1564 browser_sync::NUDGE_SOURCE_LOCAL,
1565 ModelEnumSet(type), 1565 ModelTypeSet(type),
1566 nudge_location); 1566 nudge_location);
1567 } 1567 }
1568 1568
1569 void SyncManager::SyncInternal::OnSyncEngineEvent( 1569 void SyncManager::SyncInternal::OnSyncEngineEvent(
1570 const SyncEngineEvent& event) { 1570 const SyncEngineEvent& event) {
1571 DCHECK(thread_checker_.CalledOnValidThread()); 1571 DCHECK(thread_checker_.CalledOnValidThread());
1572 // Only send an event if this is due to a cycle ending and this cycle 1572 // Only send an event if this is due to a cycle ending and this cycle
1573 // concludes a canonical "sync" process; that is, based on what is known 1573 // concludes a canonical "sync" process; that is, based on what is known
1574 // locally we are "all happy" and up-to-date. There may be new changes on 1574 // locally we are "all happy" and up-to-date. There may be new changes on
1575 // the server, but we'll get them on a subsequent sync. 1575 // the server, but we'll get them on a subsequent sync.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1617 1617
1618 // This is here for tests, which are still using p2p notifications. 1618 // This is here for tests, which are still using p2p notifications.
1619 // 1619 //
1620 // TODO(chron): Consider changing this back to track has_more_to_sync 1620 // TODO(chron): Consider changing this back to track has_more_to_sync
1621 // only notify peers if a successful commit has occurred. 1621 // only notify peers if a successful commit has occurred.
1622 bool is_notifiable_commit = 1622 bool is_notifiable_commit =
1623 (event.snapshot->syncer_status.num_successful_commits > 0); 1623 (event.snapshot->syncer_status.num_successful_commits > 0);
1624 if (is_notifiable_commit) { 1624 if (is_notifiable_commit) {
1625 allstatus_.IncrementNotifiableCommits(); 1625 allstatus_.IncrementNotifiableCommits();
1626 if (sync_notifier_.get()) { 1626 if (sync_notifier_.get()) {
1627 const ModelEnumSet changed_types = 1627 const ModelTypeSet changed_types =
1628 syncable::ModelTypePayloadMapToEnumSet( 1628 syncable::ModelTypePayloadMapToEnumSet(
1629 event.snapshot->source.types); 1629 event.snapshot->source.types);
1630 sync_notifier_->SendNotification(changed_types); 1630 sync_notifier_->SendNotification(changed_types);
1631 } else { 1631 } else {
1632 DVLOG(1) << "Not sending notification: sync_notifier_ is NULL"; 1632 DVLOG(1) << "Not sending notification: sync_notifier_ is NULL";
1633 } 1633 }
1634 } 1634 }
1635 } 1635 }
1636 1636
1637 if (event.what_happened == SyncEngineEvent::STOP_SYNCING_PERMANENTLY) { 1637 if (event.what_happened == SyncEngineEvent::STOP_SYNCING_PERMANENTLY) {
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
1845 if ((*it)->ContainsString(lowercase_query)) { 1845 if ((*it)->ContainsString(lowercase_query)) {
1846 result->Append(new StringValue(base::Int64ToString( 1846 result->Append(new StringValue(base::Int64ToString(
1847 (*it)->ref(syncable::META_HANDLE)))); 1847 (*it)->ref(syncable::META_HANDLE))));
1848 } 1848 }
1849 } 1849 }
1850 1850
1851 return JsArgList(&return_args); 1851 return JsArgList(&return_args);
1852 } 1852 }
1853 1853
1854 void SyncManager::SyncInternal::OnEncryptedTypesChanged( 1854 void SyncManager::SyncInternal::OnEncryptedTypesChanged(
1855 syncable::ModelEnumSet encrypted_types, 1855 syncable::ModelTypeSet encrypted_types,
1856 bool encrypt_everything) { 1856 bool encrypt_everything) {
1857 // NOTE: We're in a transaction. 1857 // NOTE: We're in a transaction.
1858 FOR_EACH_OBSERVER( 1858 FOR_EACH_OBSERVER(
1859 SyncManager::Observer, observers_, 1859 SyncManager::Observer, observers_,
1860 OnEncryptedTypesChanged(encrypted_types, encrypt_everything)); 1860 OnEncryptedTypesChanged(encrypted_types, encrypt_everything));
1861 } 1861 }
1862 1862
1863 void SyncManager::SyncInternal::OnNotificationStateChange( 1863 void SyncManager::SyncInternal::OnNotificationStateChange(
1864 bool notifications_enabled) { 1864 bool notifications_enabled) {
1865 DVLOG(1) << "P2P: Notifications enabled = " 1865 DVLOG(1) << "P2P: Notifications enabled = "
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
1974 UserShare* SyncManager::GetUserShare() const { 1974 UserShare* SyncManager::GetUserShare() const {
1975 return data_->GetUserShare(); 1975 return data_->GetUserShare();
1976 } 1976 }
1977 1977
1978 void SyncManager::RefreshEncryption() { 1978 void SyncManager::RefreshEncryption() {
1979 DCHECK(thread_checker_.CalledOnValidThread()); 1979 DCHECK(thread_checker_.CalledOnValidThread());
1980 if (data_->UpdateCryptographerAndNigori()) 1980 if (data_->UpdateCryptographerAndNigori())
1981 data_->RefreshEncryption(); 1981 data_->RefreshEncryption();
1982 } 1982 }
1983 1983
1984 syncable::ModelEnumSet SyncManager::GetEncryptedDataTypesForTest() const { 1984 syncable::ModelTypeSet SyncManager::GetEncryptedDataTypesForTest() const {
1985 ReadTransaction trans(FROM_HERE, GetUserShare()); 1985 ReadTransaction trans(FROM_HERE, GetUserShare());
1986 return GetEncryptedTypes(&trans); 1986 return GetEncryptedTypes(&trans);
1987 } 1987 }
1988 1988
1989 bool SyncManager::ReceivedExperimentalTypes(syncable::ModelEnumSet* to_add) 1989 bool SyncManager::ReceivedExperimentalTypes(syncable::ModelTypeSet* to_add)
1990 const { 1990 const {
1991 ReadTransaction trans(FROM_HERE, GetUserShare()); 1991 ReadTransaction trans(FROM_HERE, GetUserShare());
1992 ReadNode node(&trans); 1992 ReadNode node(&trans);
1993 if (!node.InitByTagLookup(kNigoriTag)) { 1993 if (!node.InitByTagLookup(kNigoriTag)) {
1994 DVLOG(1) << "Couldn't find Nigori node."; 1994 DVLOG(1) << "Couldn't find Nigori node.";
1995 return false; 1995 return false;
1996 } 1996 }
1997 if (node.GetNigoriSpecifics().sync_tabs()) { 1997 if (node.GetNigoriSpecifics().sync_tabs()) {
1998 to_add->Put(syncable::SESSIONS); 1998 to_add->Put(syncable::SESSIONS);
1999 return true; 1999 return true;
2000 } 2000 }
2001 return false; 2001 return false;
2002 } 2002 }
2003 2003
2004 bool SyncManager::HasUnsyncedItems() const { 2004 bool SyncManager::HasUnsyncedItems() const {
2005 sync_api::ReadTransaction trans(FROM_HERE, GetUserShare()); 2005 sync_api::ReadTransaction trans(FROM_HERE, GetUserShare());
2006 return (trans.GetWrappedTrans()->directory()->unsynced_entity_count() != 0); 2006 return (trans.GetWrappedTrans()->directory()->unsynced_entity_count() != 0);
2007 } 2007 }
2008 2008
2009 void SyncManager::TriggerOnNotificationStateChangeForTest( 2009 void SyncManager::TriggerOnNotificationStateChangeForTest(
2010 bool notifications_enabled) { 2010 bool notifications_enabled) {
2011 DCHECK(thread_checker_.CalledOnValidThread()); 2011 DCHECK(thread_checker_.CalledOnValidThread());
2012 data_->OnNotificationStateChange(notifications_enabled); 2012 data_->OnNotificationStateChange(notifications_enabled);
2013 } 2013 }
2014 2014
2015 void SyncManager::TriggerOnIncomingNotificationForTest( 2015 void SyncManager::TriggerOnIncomingNotificationForTest(
2016 ModelEnumSet model_types) { 2016 ModelTypeSet model_types) {
2017 DCHECK(thread_checker_.CalledOnValidThread()); 2017 DCHECK(thread_checker_.CalledOnValidThread());
2018 syncable::ModelTypePayloadMap model_types_with_payloads = 2018 syncable::ModelTypePayloadMap model_types_with_payloads =
2019 syncable::ModelTypePayloadMapFromEnumSet(model_types, 2019 syncable::ModelTypePayloadMapFromEnumSet(model_types,
2020 std::string()); 2020 std::string());
2021 2021
2022 data_->OnIncomingNotification(model_types_with_payloads); 2022 data_->OnIncomingNotification(model_types_with_payloads);
2023 } 2023 }
2024 2024
2025 // Helper function that converts a PassphraseRequiredReason value to a string. 2025 // Helper function that converts a PassphraseRequiredReason value to a string.
2026 std::string PassphraseRequiredReasonToString( 2026 std::string PassphraseRequiredReasonToString(
2027 PassphraseRequiredReason reason) { 2027 PassphraseRequiredReason reason) {
2028 switch (reason) { 2028 switch (reason) {
2029 case REASON_PASSPHRASE_NOT_REQUIRED: 2029 case REASON_PASSPHRASE_NOT_REQUIRED:
2030 return "REASON_PASSPHRASE_NOT_REQUIRED"; 2030 return "REASON_PASSPHRASE_NOT_REQUIRED";
2031 case REASON_ENCRYPTION: 2031 case REASON_ENCRYPTION:
2032 return "REASON_ENCRYPTION"; 2032 return "REASON_ENCRYPTION";
2033 case REASON_DECRYPTION: 2033 case REASON_DECRYPTION:
2034 return "REASON_DECRYPTION"; 2034 return "REASON_DECRYPTION";
2035 case REASON_SET_PASSPHRASE_FAILED: 2035 case REASON_SET_PASSPHRASE_FAILED:
2036 return "REASON_SET_PASSPHRASE_FAILED"; 2036 return "REASON_SET_PASSPHRASE_FAILED";
2037 default: 2037 default:
2038 NOTREACHED(); 2038 NOTREACHED();
2039 return "INVALID_REASON"; 2039 return "INVALID_REASON";
2040 } 2040 }
2041 } 2041 }
2042 2042
2043 // Helper function to determine if initial sync had ended for types. 2043 // Helper function to determine if initial sync had ended for types.
2044 bool InitialSyncEndedForTypes(syncable::ModelEnumSet types, 2044 bool InitialSyncEndedForTypes(syncable::ModelTypeSet types,
2045 sync_api::UserShare* share) { 2045 sync_api::UserShare* share) {
2046 syncable::ScopedDirLookup lookup(share->dir_manager.get(), 2046 syncable::ScopedDirLookup lookup(share->dir_manager.get(),
2047 share->name); 2047 share->name);
2048 if (!lookup.good()) { 2048 if (!lookup.good()) {
2049 DCHECK(false) << "ScopedDirLookup failed when checking initial sync"; 2049 DCHECK(false) << "ScopedDirLookup failed when checking initial sync";
2050 return false; 2050 return false;
2051 } 2051 }
2052 2052
2053 for (syncable::ModelEnumSet::Iterator i = types.First(); 2053 for (syncable::ModelTypeSet::Iterator i = types.First();
2054 i.Good(); i.Inc()) { 2054 i.Good(); i.Inc()) {
2055 if (!lookup->initial_sync_ended_for_type(i.Get())) 2055 if (!lookup->initial_sync_ended_for_type(i.Get()))
2056 return false; 2056 return false;
2057 } 2057 }
2058 return true; 2058 return true;
2059 } 2059 }
2060 2060
2061 syncable::ModelEnumSet GetTypesWithEmptyProgressMarkerToken( 2061 syncable::ModelTypeSet GetTypesWithEmptyProgressMarkerToken(
2062 syncable::ModelEnumSet types, 2062 syncable::ModelTypeSet types,
2063 sync_api::UserShare* share) { 2063 sync_api::UserShare* share) {
2064 syncable::ScopedDirLookup lookup(share->dir_manager.get(), 2064 syncable::ScopedDirLookup lookup(share->dir_manager.get(),
2065 share->name); 2065 share->name);
2066 if (!lookup.good()) { 2066 if (!lookup.good()) {
2067 NOTREACHED() << "ScopedDirLookup failed for " 2067 NOTREACHED() << "ScopedDirLookup failed for "
2068 << "GetTypesWithEmptyProgressMarkerToken"; 2068 << "GetTypesWithEmptyProgressMarkerToken";
2069 return syncable::ModelEnumSet(); 2069 return syncable::ModelTypeSet();
2070 } 2070 }
2071 2071
2072 syncable::ModelEnumSet result; 2072 syncable::ModelTypeSet result;
2073 for (syncable::ModelEnumSet::Iterator i = types.First(); 2073 for (syncable::ModelTypeSet::Iterator i = types.First();
2074 i.Good(); i.Inc()) { 2074 i.Good(); i.Inc()) {
2075 sync_pb::DataTypeProgressMarker marker; 2075 sync_pb::DataTypeProgressMarker marker;
2076 lookup->GetDownloadProgress(i.Get(), &marker); 2076 lookup->GetDownloadProgress(i.Get(), &marker);
2077 2077
2078 if (marker.token().empty()) 2078 if (marker.token().empty())
2079 result.Put(i.Get()); 2079 result.Put(i.Get());
2080 2080
2081 } 2081 }
2082 return result; 2082 return result;
2083 } 2083 }
2084 2084
2085 } // namespace sync_api 2085 } // namespace sync_api
OLDNEW
« no previous file with comments | « chrome/browser/sync/internal_api/sync_manager.h ('k') | chrome/browser/sync/internal_api/syncapi_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698