Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "sync/internal_api/sync_manager_impl.h" | 5 #include "sync/internal_api/sync_manager_impl.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 58 #include "sync/syncable/in_memory_directory_backing_store.h" | 58 #include "sync/syncable/in_memory_directory_backing_store.h" |
| 59 #include "sync/syncable/nigori_util.h" | 59 #include "sync/syncable/nigori_util.h" |
| 60 #include "sync/syncable/on_disk_directory_backing_store.h" | 60 #include "sync/syncable/on_disk_directory_backing_store.h" |
| 61 #include "sync/util/cryptographer.h" | 61 #include "sync/util/cryptographer.h" |
| 62 #include "sync/util/get_session_name.h" | 62 #include "sync/util/get_session_name.h" |
| 63 #include "sync/util/time.h" | 63 #include "sync/util/time.h" |
| 64 | 64 |
| 65 using base::TimeDelta; | 65 using base::TimeDelta; |
| 66 using sync_pb::GetUpdatesCallerInfo; | 66 using sync_pb::GetUpdatesCallerInfo; |
| 67 | 67 |
| 68 namespace syncer { | |
| 69 | |
| 70 using sessions::SyncSessionContext; | |
| 71 using syncable::ImmutableWriteTransactionInfo; | |
| 72 using syncable::SPECIFICS; | |
| 73 | |
| 68 namespace { | 74 namespace { |
| 69 | 75 |
| 70 // Delays for syncer nudges. | 76 // Delays for syncer nudges. |
| 71 static const int kDefaultNudgeDelayMilliseconds = 200; | 77 static const int kDefaultNudgeDelayMilliseconds = 200; |
| 72 static const int kPreferencesNudgeDelayMilliseconds = 2000; | 78 static const int kPreferencesNudgeDelayMilliseconds = 2000; |
| 73 static const int kSyncRefreshDelayMsec = 500; | 79 static const int kSyncRefreshDelayMsec = 500; |
| 74 static const int kSyncSchedulerDelayMsec = 250; | 80 static const int kSyncSchedulerDelayMsec = 250; |
| 75 | 81 |
| 82 // The maximum number of times we will automatically overwrite the nigori node | |
| 83 // because the encryption keys don't match (per chrome instantiation). | |
| 84 static const int kNigoriOverwriteLimit = 10; | |
| 85 | |
| 86 // Maximum count and size for traffic recorder. | |
| 87 static const unsigned int kMaxMessagesToRecord = 10; | |
| 88 static const unsigned int kMaxMessageSizeToRecord = 5 * 1024; | |
| 89 | |
| 76 GetUpdatesCallerInfo::GetUpdatesSource GetSourceFromReason( | 90 GetUpdatesCallerInfo::GetUpdatesSource GetSourceFromReason( |
| 77 syncer::ConfigureReason reason) { | 91 ConfigureReason reason) { |
| 78 switch (reason) { | 92 switch (reason) { |
| 79 case syncer::CONFIGURE_REASON_RECONFIGURATION: | 93 case CONFIGURE_REASON_RECONFIGURATION: |
| 80 return GetUpdatesCallerInfo::RECONFIGURATION; | 94 return GetUpdatesCallerInfo::RECONFIGURATION; |
| 81 case syncer::CONFIGURE_REASON_MIGRATION: | 95 case CONFIGURE_REASON_MIGRATION: |
| 82 return GetUpdatesCallerInfo::MIGRATION; | 96 return GetUpdatesCallerInfo::MIGRATION; |
| 83 case syncer::CONFIGURE_REASON_NEW_CLIENT: | 97 case CONFIGURE_REASON_NEW_CLIENT: |
| 84 return GetUpdatesCallerInfo::NEW_CLIENT; | 98 return GetUpdatesCallerInfo::NEW_CLIENT; |
| 85 case syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE: | 99 case CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE: |
| 86 return GetUpdatesCallerInfo::NEWLY_SUPPORTED_DATATYPE; | 100 return GetUpdatesCallerInfo::NEWLY_SUPPORTED_DATATYPE; |
| 87 default: | 101 default: |
| 88 NOTREACHED(); | 102 NOTREACHED(); |
| 89 } | 103 } |
| 90 | 104 |
| 91 return GetUpdatesCallerInfo::UNKNOWN; | 105 return GetUpdatesCallerInfo::UNKNOWN; |
| 92 } | 106 } |
| 93 | 107 |
| 94 // The maximum number of times we will automatically overwrite the nigori node | 108 } // namespace |
| 95 // because the encryption keys don't match (per chrome instantiation). | |
| 96 static const int kNigoriOverwriteLimit = 10; | |
| 97 | |
| 98 } // namespace | |
| 99 | |
| 100 namespace syncer { | |
| 101 | |
| 102 using sessions::SyncSessionContext; | |
| 103 using syncable::ImmutableWriteTransactionInfo; | |
| 104 using syncable::SPECIFICS; | |
| 105 | |
| 106 // Maximum count and size for traffic recorder. | |
| 107 const unsigned int kMaxMessagesToRecord = 10; | |
| 108 const unsigned int kMaxMessageSizeToRecord = 5 * 1024; | |
| 109 | 109 |
| 110 ////////////////////////////////////////////////////////////////////////// | 110 ////////////////////////////////////////////////////////////////////////// |
| 111 // SyncManagerImpl's implementation: SyncManagerImpl::SyncInternal | 111 // SyncManagerImpl's implementation: SyncManagerImpl::SyncInternal |
| 112 class SyncManagerImpl::SyncInternal | 112 class SyncManagerImpl::SyncInternal |
| 113 : public net::NetworkChangeNotifier::IPAddressObserver, | 113 : public net::NetworkChangeNotifier::IPAddressObserver, |
| 114 public syncer::Cryptographer::Observer, | 114 public Cryptographer::Observer, |
| 115 public syncer::SyncNotifierObserver, | 115 public SyncNotifierObserver, |
| 116 public JsBackend, | 116 public JsBackend, |
| 117 public SyncEngineEventListener, | 117 public SyncEngineEventListener, |
| 118 public ServerConnectionEventListener, | 118 public ServerConnectionEventListener, |
| 119 public syncable::DirectoryChangeDelegate { | 119 public syncable::DirectoryChangeDelegate { |
| 120 public: | 120 public: |
| 121 explicit SyncInternal(const std::string& name) | 121 explicit SyncInternal(const std::string& name) |
| 122 : name_(name), | 122 : name_(name), |
| 123 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 123 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 124 change_delegate_(NULL), | 124 change_delegate_(NULL), |
| 125 initialized_(false), | 125 initialized_(false), |
| 126 testing_mode_(NON_TEST), | 126 testing_mode_(NON_TEST), |
| 127 observing_ip_address_changes_(false), | 127 observing_ip_address_changes_(false), |
| 128 throttled_data_type_tracker_(&allstatus_), | 128 throttled_data_type_tracker_(&allstatus_), |
| 129 traffic_recorder_(kMaxMessagesToRecord, kMaxMessageSizeToRecord), | 129 traffic_recorder_(kMaxMessagesToRecord, kMaxMessageSizeToRecord), |
| 130 encryptor_(NULL), | 130 encryptor_(NULL), |
| 131 unrecoverable_error_handler_(NULL), | 131 unrecoverable_error_handler_(NULL), |
| 132 report_unrecoverable_error_function_(NULL), | 132 report_unrecoverable_error_function_(NULL), |
| 133 created_on_loop_(MessageLoop::current()), | 133 created_on_loop_(MessageLoop::current()), |
| 134 nigori_overwrite_count_(0) { | 134 nigori_overwrite_count_(0) { |
| 135 // Pre-fill |notification_info_map_|. | 135 // Pre-fill |notification_info_map_|. |
| 136 for (int i = syncer::FIRST_REAL_MODEL_TYPE; | 136 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { |
| 137 i < syncer::MODEL_TYPE_COUNT; ++i) { | |
| 138 notification_info_map_.insert( | 137 notification_info_map_.insert( |
| 139 std::make_pair(syncer::ModelTypeFromInt(i), NotificationInfo())); | 138 std::make_pair(ModelTypeFromInt(i), NotificationInfo())); |
| 140 } | 139 } |
| 141 | 140 |
| 142 // Bind message handlers. | 141 // Bind message handlers. |
| 143 BindJsMessageHandler( | 142 BindJsMessageHandler( |
| 144 "getNotificationState", | 143 "getNotificationState", |
| 145 &SyncManagerImpl::SyncInternal::GetNotificationState); | 144 &SyncManagerImpl::SyncInternal::GetNotificationState); |
| 146 BindJsMessageHandler( | 145 BindJsMessageHandler( |
| 147 "getNotificationInfo", | 146 "getNotificationInfo", |
| 148 &SyncManagerImpl::SyncInternal::GetNotificationInfo); | 147 &SyncManagerImpl::SyncInternal::GetNotificationInfo); |
| 149 BindJsMessageHandler( | 148 BindJsMessageHandler( |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 170 CHECK(!initialized_); | 169 CHECK(!initialized_); |
| 171 } | 170 } |
| 172 | 171 |
| 173 bool Init(const FilePath& database_location, | 172 bool Init(const FilePath& database_location, |
| 174 const WeakHandle<JsEventHandler>& event_handler, | 173 const WeakHandle<JsEventHandler>& event_handler, |
| 175 const std::string& sync_server_and_path, | 174 const std::string& sync_server_and_path, |
| 176 int port, | 175 int port, |
| 177 bool use_ssl, | 176 bool use_ssl, |
| 178 const scoped_refptr<base::TaskRunner>& blocking_task_runner, | 177 const scoped_refptr<base::TaskRunner>& blocking_task_runner, |
| 179 scoped_ptr<HttpPostProviderFactory> post_factory, | 178 scoped_ptr<HttpPostProviderFactory> post_factory, |
| 180 const syncer::ModelSafeRoutingInfo& model_safe_routing_info, | 179 const ModelSafeRoutingInfo& model_safe_routing_info, |
| 181 const std::vector<syncer::ModelSafeWorker*>& workers, | 180 const std::vector<ModelSafeWorker*>& workers, |
| 182 syncer::ExtensionsActivityMonitor* | 181 ExtensionsActivityMonitor* |
| 183 extensions_activity_monitor, | 182 extensions_activity_monitor, |
| 184 SyncManager::ChangeDelegate* change_delegate, | 183 SyncManager::ChangeDelegate* change_delegate, |
| 185 const SyncCredentials& credentials, | 184 const SyncCredentials& credentials, |
| 186 scoped_ptr<syncer::SyncNotifier> sync_notifier, | 185 scoped_ptr<SyncNotifier> sync_notifier, |
| 187 const std::string& restored_key_for_bootstrapping, | 186 const std::string& restored_key_for_bootstrapping, |
| 188 SyncManager::TestingMode testing_mode, | 187 SyncManager::TestingMode testing_mode, |
| 189 Encryptor* encryptor, | 188 Encryptor* encryptor, |
| 190 UnrecoverableErrorHandler* unrecoverable_error_handler, | 189 UnrecoverableErrorHandler* unrecoverable_error_handler, |
| 191 ReportUnrecoverableErrorFunction | 190 ReportUnrecoverableErrorFunction |
| 192 report_unrecoverable_error_function); | 191 report_unrecoverable_error_function); |
| 193 | 192 |
| 194 // Sign into sync with given credentials. | 193 // Sign into sync with given credentials. |
| 195 // We do not verify the tokens given. After this call, the tokens are set | 194 // We do not verify the tokens given. After this call, the tokens are set |
| 196 // and the sync DB is open. True if successful, false if something | 195 // and the sync DB is open. True if successful, false if something |
| 197 // went wrong. | 196 // went wrong. |
| 198 bool SignIn(const SyncCredentials& credentials); | 197 bool SignIn(const SyncCredentials& credentials); |
| 199 | 198 |
| 200 // Purge from the directory those types with non-empty progress markers | 199 // Purge from the directory those types with non-empty progress markers |
| 201 // but without initial synced ended set. | 200 // but without initial synced ended set. |
| 202 // Returns false if an error occurred, true otherwise. | 201 // Returns false if an error occurred, true otherwise. |
| 203 bool PurgePartiallySyncedTypes(); | 202 bool PurgePartiallySyncedTypes(); |
| 204 | 203 |
| 205 // Update tokens that we're using in Sync. Email must stay the same. | 204 // Update tokens that we're using in Sync. Email must stay the same. |
| 206 void UpdateCredentials(const SyncCredentials& credentials); | 205 void UpdateCredentials(const SyncCredentials& credentials); |
| 207 | 206 |
| 208 // Called when the user disables or enables a sync type. | 207 // Called when the user disables or enables a sync type. |
| 209 void UpdateEnabledTypes(const ModelTypeSet& enabled_types); | 208 void UpdateEnabledTypes(const ModelTypeSet& enabled_types); |
| 210 | 209 |
| 211 // Tell the sync engine to start the syncing process. | 210 // Tell the sync engine to start the syncing process. |
| 212 void StartSyncingNormally( | 211 void StartSyncingNormally( |
| 213 const syncer::ModelSafeRoutingInfo& routing_info); | 212 const ModelSafeRoutingInfo& routing_info); |
| 214 | 213 |
| 215 // Whether or not the Nigori node is encrypted using an explicit passphrase. | 214 // Whether or not the Nigori node is encrypted using an explicit passphrase. |
| 216 bool IsUsingExplicitPassphrase(); | 215 bool IsUsingExplicitPassphrase(); |
| 217 | 216 |
| 218 // Update the Cryptographer from the current nigori node and write back any | 217 // Update the Cryptographer from the current nigori node and write back any |
| 219 // necessary changes to the nigori node. We also detect missing encryption | 218 // necessary changes to the nigori node. We also detect missing encryption |
| 220 // keys and write them into the nigori node. | 219 // keys and write them into the nigori node. |
| 221 // Also updates or adds the device information into the nigori node. | 220 // Also updates or adds the device information into the nigori node. |
| 222 // Note: opens a transaction and can trigger an ON_PASSPHRASE_REQUIRED, so | 221 // Note: opens a transaction and can trigger an ON_PASSPHRASE_REQUIRED, so |
| 223 // should only be called after syncapi is fully initialized. | 222 // should only be called after syncapi is fully initialized. |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 293 syncable::BaseTransaction* trans) OVERRIDE; | 292 syncable::BaseTransaction* trans) OVERRIDE; |
| 294 virtual void HandleCalculateChangesChangeEventFromSyncer( | 293 virtual void HandleCalculateChangesChangeEventFromSyncer( |
| 295 const ImmutableWriteTransactionInfo& write_transaction_info, | 294 const ImmutableWriteTransactionInfo& write_transaction_info, |
| 296 syncable::BaseTransaction* trans) OVERRIDE; | 295 syncable::BaseTransaction* trans) OVERRIDE; |
| 297 | 296 |
| 298 // Open the directory named with username_for_share | 297 // Open the directory named with username_for_share |
| 299 bool OpenDirectory(); | 298 bool OpenDirectory(); |
| 300 | 299 |
| 301 // Cryptographer::Observer implementation. | 300 // Cryptographer::Observer implementation. |
| 302 virtual void OnEncryptedTypesChanged( | 301 virtual void OnEncryptedTypesChanged( |
| 303 syncer::ModelTypeSet encrypted_types, | 302 ModelTypeSet encrypted_types, |
| 304 bool encrypt_everything) OVERRIDE; | 303 bool encrypt_everything) OVERRIDE; |
| 305 | 304 |
| 306 // SyncNotifierObserver implementation. | 305 // SyncNotifierObserver implementation. |
| 307 virtual void OnNotificationsEnabled() OVERRIDE; | 306 virtual void OnNotificationsEnabled() OVERRIDE; |
| 308 virtual void OnNotificationsDisabled( | 307 virtual void OnNotificationsDisabled( |
| 309 syncer::NotificationsDisabledReason reason) OVERRIDE; | 308 NotificationsDisabledReason reason) OVERRIDE; |
| 310 virtual void OnIncomingNotification( | 309 virtual void OnIncomingNotification( |
| 311 const syncer::ModelTypePayloadMap& type_payloads, | 310 const ModelTypePayloadMap& type_payloads, |
| 312 syncer::IncomingNotificationSource source) OVERRIDE; | 311 IncomingNotificationSource source) OVERRIDE; |
| 313 | 312 |
| 314 void AddObserver(SyncManager::Observer* observer); | 313 void AddObserver(SyncManager::Observer* observer); |
| 315 void RemoveObserver(SyncManager::Observer* observer); | 314 void RemoveObserver(SyncManager::Observer* observer); |
| 316 | 315 |
| 317 // Accessors for the private members. | 316 // Accessors for the private members. |
| 318 syncable::Directory* directory() { return share_.directory.get(); } | 317 syncable::Directory* directory() { return share_.directory.get(); } |
| 319 SyncAPIServerConnectionManager* connection_manager() { | 318 SyncAPIServerConnectionManager* connection_manager() { |
| 320 return connection_manager_.get(); | 319 return connection_manager_.get(); |
| 321 } | 320 } |
| 322 SyncSessionContext* session_context() { return session_context_.get(); } | 321 SyncSessionContext* session_context() { return session_context_.get(); } |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 345 void NotifyCryptographerState(Cryptographer* cryptographer); | 344 void NotifyCryptographerState(Cryptographer* cryptographer); |
| 346 | 345 |
| 347 // See SyncManager::Shutdown* for information. | 346 // See SyncManager::Shutdown* for information. |
| 348 void StopSyncingForShutdown(const base::Closure& callback); | 347 void StopSyncingForShutdown(const base::Closure& callback); |
| 349 void ShutdownOnSyncThread(); | 348 void ShutdownOnSyncThread(); |
| 350 | 349 |
| 351 // If this is a deletion for a password, sets the legacy | 350 // If this is a deletion for a password, sets the legacy |
| 352 // ExtraPasswordChangeRecordData field of |buffer|. Otherwise sets | 351 // ExtraPasswordChangeRecordData field of |buffer|. Otherwise sets |
| 353 // |buffer|'s specifics field to contain the unencrypted data. | 352 // |buffer|'s specifics field to contain the unencrypted data. |
| 354 void SetExtraChangeRecordData(int64 id, | 353 void SetExtraChangeRecordData(int64 id, |
| 355 syncer::ModelType type, | 354 ModelType type, |
| 356 ChangeReorderBuffer* buffer, | 355 ChangeReorderBuffer* buffer, |
| 357 Cryptographer* cryptographer, | 356 Cryptographer* cryptographer, |
| 358 const syncable::EntryKernel& original, | 357 const syncable::EntryKernel& original, |
| 359 bool existed_before, | 358 bool existed_before, |
| 360 bool exists_now); | 359 bool exists_now); |
| 361 | 360 |
| 362 // Called only by our NetworkChangeNotifier. | 361 // Called only by our NetworkChangeNotifier. |
| 363 virtual void OnIPAddressChanged() OVERRIDE; | 362 virtual void OnIPAddressChanged() OVERRIDE; |
| 364 | 363 |
| 365 ModelTypeSet GetTypesWithEmptyProgressMarkerToken(ModelTypeSet types) { | 364 ModelTypeSet GetTypesWithEmptyProgressMarkerToken(ModelTypeSet types) { |
| 366 DCHECK(initialized_); | 365 DCHECK(initialized_); |
| 367 syncer::ModelTypeSet result; | 366 ModelTypeSet result; |
| 368 for (syncer::ModelTypeSet::Iterator i = types.First(); | 367 for (ModelTypeSet::Iterator i = types.First(); |
| 369 i.Good(); i.Inc()) { | 368 i.Good(); i.Inc()) { |
| 370 sync_pb::DataTypeProgressMarker marker; | 369 sync_pb::DataTypeProgressMarker marker; |
| 371 directory()->GetDownloadProgress(i.Get(), &marker); | 370 directory()->GetDownloadProgress(i.Get(), &marker); |
| 372 | 371 |
| 373 if (marker.token().empty()) | 372 if (marker.token().empty()) |
| 374 result.Put(i.Get()); | 373 result.Put(i.Get()); |
| 375 | 374 |
| 376 } | 375 } |
| 377 return result; | 376 return result; |
| 378 } | 377 } |
| 379 | 378 |
| 380 syncer::ModelTypeSet InitialSyncEndedTypes() { | 379 ModelTypeSet InitialSyncEndedTypes() { |
| 381 DCHECK(initialized_); | 380 DCHECK(initialized_); |
| 382 return directory()->initial_sync_ended_types(); | 381 return directory()->initial_sync_ended_types(); |
| 383 } | 382 } |
| 384 | 383 |
| 385 // SyncEngineEventListener implementation. | 384 // SyncEngineEventListener implementation. |
| 386 virtual void OnSyncEngineEvent(const SyncEngineEvent& event) OVERRIDE; | 385 virtual void OnSyncEngineEvent(const SyncEngineEvent& event) OVERRIDE; |
| 387 | 386 |
| 388 // ServerConnectionEventListener implementation. | 387 // ServerConnectionEventListener implementation. |
| 389 virtual void OnServerConnectionEvent( | 388 virtual void OnServerConnectionEvent( |
| 390 const ServerConnectionEvent& event) OVERRIDE; | 389 const ServerConnectionEvent& event) OVERRIDE; |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 409 | 408 |
| 410 // Returned pointer owned by the caller. | 409 // Returned pointer owned by the caller. |
| 411 DictionaryValue* ToValue() const { | 410 DictionaryValue* ToValue() const { |
| 412 DictionaryValue* value = new DictionaryValue(); | 411 DictionaryValue* value = new DictionaryValue(); |
| 413 value->SetInteger("totalCount", total_count); | 412 value->SetInteger("totalCount", total_count); |
| 414 value->SetString("payload", payload); | 413 value->SetString("payload", payload); |
| 415 return value; | 414 return value; |
| 416 } | 415 } |
| 417 }; | 416 }; |
| 418 | 417 |
| 419 typedef std::map<syncer::ModelType, NotificationInfo> NotificationInfoMap; | 418 typedef std::map<ModelType, NotificationInfo> NotificationInfoMap; |
| 420 typedef JsArgList | 419 typedef JsArgList |
| 421 (SyncManagerImpl::SyncInternal::*UnboundJsMessageHandler)( | 420 (SyncManagerImpl::SyncInternal::*UnboundJsMessageHandler)( |
| 422 const JsArgList&); | 421 const JsArgList&); |
| 423 typedef base::Callback<JsArgList(const JsArgList&)> JsMessageHandler; | 422 typedef base::Callback<JsArgList(const JsArgList&)> JsMessageHandler; |
| 424 typedef std::map<std::string, JsMessageHandler> JsMessageHandlerMap; | 423 typedef std::map<std::string, JsMessageHandler> JsMessageHandlerMap; |
| 425 | 424 |
| 426 // Internal callback of UpdateCryptographerAndNigoriCallback. | 425 // Internal callback of UpdateCryptographerAndNigoriCallback. |
| 427 void UpdateCryptographerAndNigoriCallback( | 426 void UpdateCryptographerAndNigoriCallback( |
| 428 const std::string& chrome_version, | 427 const std::string& chrome_version, |
| 429 const base::Closure& done_callback, | 428 const base::Closure& done_callback, |
| 430 const std::string& session_name); | 429 const std::string& session_name); |
| 431 | 430 |
| 432 // Determine if the parents or predecessors differ between the old and new | 431 // Determine if the parents or predecessors differ between the old and new |
| 433 // versions of an entry stored in |a| and |b|. Note that a node's index may | 432 // versions of an entry stored in |a| and |b|. Note that a node's index may |
| 434 // change without its NEXT_ID changing if the node at NEXT_ID also moved (but | 433 // change without its NEXT_ID changing if the node at NEXT_ID also moved (but |
| 435 // the relative order is unchanged). To handle such cases, we rely on the | 434 // the relative order is unchanged). To handle such cases, we rely on the |
| 436 // caller to treat a position update on any sibling as updating the positions | 435 // caller to treat a position update on any sibling as updating the positions |
| 437 // of all siblings. | 436 // of all siblings. |
| 438 static bool VisiblePositionsDiffer( | 437 static bool VisiblePositionsDiffer( |
| 439 const syncable::EntryKernelMutation& mutation) { | 438 const syncable::EntryKernelMutation& mutation) { |
| 440 const syncable::EntryKernel& a = mutation.original; | 439 const syncable::EntryKernel& a = mutation.original; |
| 441 const syncable::EntryKernel& b = mutation.mutated; | 440 const syncable::EntryKernel& b = mutation.mutated; |
| 442 // If the datatype isn't one where the browser model cares about position, | 441 // If the datatype isn't one where the browser model cares about position, |
| 443 // don't bother notifying that data model of position-only changes. | 442 // don't bother notifying that data model of position-only changes. |
| 444 if (!ShouldMaintainPosition( | 443 if (!ShouldMaintainPosition( |
| 445 syncer::GetModelTypeFromSpecifics(b.ref(SPECIFICS)))) | 444 GetModelTypeFromSpecifics(b.ref(SPECIFICS)))) |
| 446 return false; | 445 return false; |
| 447 if (a.ref(syncable::NEXT_ID) != b.ref(syncable::NEXT_ID)) | 446 if (a.ref(syncable::NEXT_ID) != b.ref(syncable::NEXT_ID)) |
| 448 return true; | 447 return true; |
| 449 if (a.ref(syncable::PARENT_ID) != b.ref(syncable::PARENT_ID)) | 448 if (a.ref(syncable::PARENT_ID) != b.ref(syncable::PARENT_ID)) |
| 450 return true; | 449 return true; |
| 451 return false; | 450 return false; |
| 452 } | 451 } |
| 453 | 452 |
| 454 // Determine if any of the fields made visible to clients of the Sync API | 453 // Determine if any of the fields made visible to clients of the Sync API |
| 455 // differ between the versions of an entry stored in |a| and |b|. A return | 454 // differ between the versions of an entry stored in |a| and |b|. A return |
| 456 // value of false means that it should be OK to ignore this change. | 455 // value of false means that it should be OK to ignore this change. |
| 457 static bool VisiblePropertiesDiffer( | 456 static bool VisiblePropertiesDiffer( |
| 458 const syncable::EntryKernelMutation& mutation, | 457 const syncable::EntryKernelMutation& mutation, |
| 459 Cryptographer* cryptographer) { | 458 Cryptographer* cryptographer) { |
| 460 const syncable::EntryKernel& a = mutation.original; | 459 const syncable::EntryKernel& a = mutation.original; |
| 461 const syncable::EntryKernel& b = mutation.mutated; | 460 const syncable::EntryKernel& b = mutation.mutated; |
| 462 const sync_pb::EntitySpecifics& a_specifics = a.ref(SPECIFICS); | 461 const sync_pb::EntitySpecifics& a_specifics = a.ref(SPECIFICS); |
| 463 const sync_pb::EntitySpecifics& b_specifics = b.ref(SPECIFICS); | 462 const sync_pb::EntitySpecifics& b_specifics = b.ref(SPECIFICS); |
| 464 DCHECK_EQ(syncer::GetModelTypeFromSpecifics(a_specifics), | 463 DCHECK_EQ(GetModelTypeFromSpecifics(a_specifics), |
| 465 syncer::GetModelTypeFromSpecifics(b_specifics)); | 464 GetModelTypeFromSpecifics(b_specifics)); |
| 466 syncer::ModelType model_type = | 465 ModelType model_type = GetModelTypeFromSpecifics(b_specifics); |
| 467 syncer::GetModelTypeFromSpecifics(b_specifics); | |
| 468 // Suppress updates to items that aren't tracked by any browser model. | 466 // Suppress updates to items that aren't tracked by any browser model. |
| 469 if (model_type < syncer::FIRST_REAL_MODEL_TYPE || | 467 if (model_type < FIRST_REAL_MODEL_TYPE || |
| 470 !a.ref(syncable::UNIQUE_SERVER_TAG).empty()) { | 468 !a.ref(syncable::UNIQUE_SERVER_TAG).empty()) { |
| 471 return false; | 469 return false; |
| 472 } | 470 } |
| 473 if (a.ref(syncable::IS_DIR) != b.ref(syncable::IS_DIR)) | 471 if (a.ref(syncable::IS_DIR) != b.ref(syncable::IS_DIR)) |
| 474 return true; | 472 return true; |
| 475 if (!AreSpecificsEqual(cryptographer, | 473 if (!AreSpecificsEqual(cryptographer, |
| 476 a.ref(syncable::SPECIFICS), | 474 a.ref(syncable::SPECIFICS), |
| 477 b.ref(syncable::SPECIFICS))) { | 475 b.ref(syncable::SPECIFICS))) { |
| 478 return true; | 476 return true; |
| 479 } | 477 } |
| 480 // We only care if the name has changed if neither specifics is encrypted | 478 // We only care if the name has changed if neither specifics is encrypted |
| 481 // (encrypted nodes blow away the NON_UNIQUE_NAME). | 479 // (encrypted nodes blow away the NON_UNIQUE_NAME). |
| 482 if (!a_specifics.has_encrypted() && !b_specifics.has_encrypted() && | 480 if (!a_specifics.has_encrypted() && !b_specifics.has_encrypted() && |
| 483 a.ref(syncable::NON_UNIQUE_NAME) != b.ref(syncable::NON_UNIQUE_NAME)) | 481 a.ref(syncable::NON_UNIQUE_NAME) != b.ref(syncable::NON_UNIQUE_NAME)) |
| 484 return true; | 482 return true; |
| 485 if (VisiblePositionsDiffer(mutation)) | 483 if (VisiblePositionsDiffer(mutation)) |
| 486 return true; | 484 return true; |
| 487 return false; | 485 return false; |
| 488 } | 486 } |
| 489 | 487 |
| 490 bool ChangeBuffersAreEmpty() { | 488 bool ChangeBuffersAreEmpty() { |
| 491 for (int i = 0; i < syncer::MODEL_TYPE_COUNT; ++i) { | 489 for (int i = 0; i < MODEL_TYPE_COUNT; ++i) { |
| 492 if (!change_buffers_[i].IsEmpty()) | 490 if (!change_buffers_[i].IsEmpty()) |
| 493 return false; | 491 return false; |
| 494 } | 492 } |
| 495 return true; | 493 return true; |
| 496 } | 494 } |
| 497 | 495 |
| 498 void ReEncryptEverything(WriteTransaction* trans); | 496 void ReEncryptEverything(WriteTransaction* trans); |
| 499 | 497 |
| 500 // Called for every notification. This updates the notification statistics | 498 // Called for every notification. This updates the notification statistics |
| 501 // to be displayed in about:sync. | 499 // to be displayed in about:sync. |
| 502 void UpdateNotificationInfo( | 500 void UpdateNotificationInfo(const ModelTypePayloadMap& type_payloads); |
| 503 const syncer::ModelTypePayloadMap& type_payloads); | |
| 504 | 501 |
| 505 // Checks for server reachabilty and requests a nudge. | 502 // Checks for server reachabilty and requests a nudge. |
| 506 void OnIPAddressChangedImpl(); | 503 void OnIPAddressChangedImpl(); |
| 507 | 504 |
| 508 // Helper function used only by the constructor. | 505 // Helper function used only by the constructor. |
| 509 void BindJsMessageHandler( | 506 void BindJsMessageHandler( |
| 510 const std::string& name, UnboundJsMessageHandler unbound_message_handler); | 507 const std::string& name, UnboundJsMessageHandler unbound_message_handler); |
| 511 | 508 |
| 512 // Returned pointer is owned by the caller. | 509 // Returned pointer is owned by the caller. |
| 513 static DictionaryValue* NotificationInfoToValue( | 510 static DictionaryValue* NotificationInfoToValue( |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 545 // |blocking_task_runner| is a TaskRunner to be used for tasks that | 542 // |blocking_task_runner| is a TaskRunner to be used for tasks that |
| 546 // may block on disk I/O. | 543 // may block on disk I/O. |
| 547 scoped_refptr<base::TaskRunner> blocking_task_runner_; | 544 scoped_refptr<base::TaskRunner> blocking_task_runner_; |
| 548 | 545 |
| 549 // We give a handle to share_ to clients of the API for use when constructing | 546 // We give a handle to share_ to clients of the API for use when constructing |
| 550 // any transaction type. | 547 // any transaction type. |
| 551 UserShare share_; | 548 UserShare share_; |
| 552 | 549 |
| 553 // This can be called from any thread, but only between calls to | 550 // This can be called from any thread, but only between calls to |
| 554 // OpenDirectory() and ShutdownOnSyncThread(). | 551 // OpenDirectory() and ShutdownOnSyncThread(). |
| 555 syncer::WeakHandle<SyncManager::ChangeObserver> change_observer_; | 552 WeakHandle<SyncManager::ChangeObserver> change_observer_; |
| 556 | 553 |
| 557 ObserverList<SyncManager::Observer> observers_; | 554 ObserverList<SyncManager::Observer> observers_; |
| 558 | 555 |
| 559 // The ServerConnectionManager used to abstract communication between the | 556 // The ServerConnectionManager used to abstract communication between the |
| 560 // client (the Syncer) and the sync server. | 557 // client (the Syncer) and the sync server. |
| 561 scoped_ptr<SyncAPIServerConnectionManager> connection_manager_; | 558 scoped_ptr<SyncAPIServerConnectionManager> connection_manager_; |
| 562 | 559 |
| 563 // A container of various bits of information used by the SyncScheduler to | 560 // A container of various bits of information used by the SyncScheduler to |
| 564 // create SyncSessions. Must outlive the SyncScheduler. | 561 // create SyncSessions. Must outlive the SyncScheduler. |
| 565 scoped_ptr<SyncSessionContext> session_context_; | 562 scoped_ptr<SyncSessionContext> session_context_; |
| 566 | 563 |
| 567 // The scheduler that runs the Syncer. Needs to be explicitly | 564 // The scheduler that runs the Syncer. Needs to be explicitly |
| 568 // Start()ed. | 565 // Start()ed. |
| 569 scoped_ptr<SyncScheduler> scheduler_; | 566 scoped_ptr<SyncScheduler> scheduler_; |
| 570 | 567 |
| 571 // The SyncNotifier which notifies us when updates need to be downloaded. | 568 // The SyncNotifier which notifies us when updates need to be downloaded. |
| 572 scoped_ptr<syncer::SyncNotifier> sync_notifier_; | 569 scoped_ptr<SyncNotifier> sync_notifier_; |
| 573 | 570 |
| 574 // A multi-purpose status watch object that aggregates stats from various | 571 // A multi-purpose status watch object that aggregates stats from various |
| 575 // sync components. | 572 // sync components. |
| 576 AllStatus allstatus_; | 573 AllStatus allstatus_; |
| 577 | 574 |
| 578 // Each element of this array is a store of change records produced by | 575 // Each element of this array is a store of change records produced by |
| 579 // HandleChangeEvent during the CALCULATE_CHANGES step. The changes are | 576 // HandleChangeEvent during the CALCULATE_CHANGES step. The changes are |
| 580 // segregated by model type, and are stored here to be processed and | 577 // segregated by model type, and are stored here to be processed and |
| 581 // forwarded to the observer slightly later, at the TRANSACTION_ENDING | 578 // forwarded to the observer slightly later, at the TRANSACTION_ENDING |
| 582 // step by HandleTransactionEndingChangeEvent. The list is cleared in the | 579 // step by HandleTransactionEndingChangeEvent. The list is cleared in the |
| 583 // TRANSACTION_COMPLETE step by HandleTransactionCompleteChangeEvent. | 580 // TRANSACTION_COMPLETE step by HandleTransactionCompleteChangeEvent. |
| 584 ChangeReorderBuffer change_buffers_[syncer::MODEL_TYPE_COUNT]; | 581 ChangeReorderBuffer change_buffers_[MODEL_TYPE_COUNT]; |
| 585 | 582 |
| 586 SyncManager::ChangeDelegate* change_delegate_; | 583 SyncManager::ChangeDelegate* change_delegate_; |
| 587 | 584 |
| 588 // Set to true once Init has been called. | 585 // Set to true once Init has been called. |
| 589 bool initialized_; | 586 bool initialized_; |
| 590 | 587 |
| 591 // Controls the disabling of certain SyncManager features. | 588 // Controls the disabling of certain SyncManager features. |
| 592 // Can be used to disable communication with the server and the use of an | 589 // Can be used to disable communication with the server and the use of an |
| 593 // on-disk file for maintaining syncer state. | 590 // on-disk file for maintaining syncer state. |
| 594 // TODO(117836): Clean up implementation of SyncManager unit tests. | 591 // TODO(117836): Clean up implementation of SyncManager unit tests. |
| 595 SyncManager::TestingMode testing_mode_; | 592 SyncManager::TestingMode testing_mode_; |
| 596 | 593 |
| 597 bool observing_ip_address_changes_; | 594 bool observing_ip_address_changes_; |
| 598 | 595 |
| 599 // Map used to store the notification info to be displayed in | 596 // Map used to store the notification info to be displayed in |
| 600 // about:sync page. | 597 // about:sync page. |
| 601 NotificationInfoMap notification_info_map_; | 598 NotificationInfoMap notification_info_map_; |
| 602 | 599 |
| 603 // These are for interacting with chrome://sync-internals. | 600 // These are for interacting with chrome://sync-internals. |
| 604 JsMessageHandlerMap js_message_handlers_; | 601 JsMessageHandlerMap js_message_handlers_; |
| 605 WeakHandle<JsEventHandler> js_event_handler_; | 602 WeakHandle<JsEventHandler> js_event_handler_; |
| 606 JsSyncManagerObserver js_sync_manager_observer_; | 603 JsSyncManagerObserver js_sync_manager_observer_; |
| 607 JsMutationEventObserver js_mutation_event_observer_; | 604 JsMutationEventObserver js_mutation_event_observer_; |
| 608 | 605 |
| 609 syncer::ThrottledDataTypeTracker throttled_data_type_tracker_; | 606 ThrottledDataTypeTracker throttled_data_type_tracker_; |
| 610 | 607 |
| 611 // This is for keeping track of client events to send to the server. | 608 // This is for keeping track of client events to send to the server. |
| 612 DebugInfoEventListener debug_info_event_listener_; | 609 DebugInfoEventListener debug_info_event_listener_; |
| 613 | 610 |
| 614 syncer::TrafficRecorder traffic_recorder_; | 611 TrafficRecorder traffic_recorder_; |
| 615 | 612 |
| 616 Encryptor* encryptor_; | 613 Encryptor* encryptor_; |
| 617 UnrecoverableErrorHandler* unrecoverable_error_handler_; | 614 UnrecoverableErrorHandler* unrecoverable_error_handler_; |
| 618 ReportUnrecoverableErrorFunction report_unrecoverable_error_function_; | 615 ReportUnrecoverableErrorFunction report_unrecoverable_error_function_; |
| 619 | 616 |
| 620 MessageLoop* const created_on_loop_; | 617 MessageLoop* const created_on_loop_; |
| 621 | 618 |
| 622 // The number of times we've automatically (i.e. not via SetPassphrase or | 619 // The number of times we've automatically (i.e. not via SetPassphrase or |
| 623 // conflict resolver) updated the nigori's encryption keys in this chrome | 620 // conflict resolver) updated the nigori's encryption keys in this chrome |
| 624 // instantiation. | 621 // instantiation. |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 647 // Sync this change while syncing another change. | 644 // Sync this change while syncing another change. |
| 648 ACCOMPANY_ONLY, | 645 ACCOMPANY_ONLY, |
| 649 | 646 |
| 650 // The datatype does not use one of the predefined wait times but defines | 647 // The datatype does not use one of the predefined wait times but defines |
| 651 // its own wait time logic for nudge. | 648 // its own wait time logic for nudge. |
| 652 CUSTOM, | 649 CUSTOM, |
| 653 }; | 650 }; |
| 654 | 651 |
| 655 static NudgeDelayStrategy GetNudgeDelayStrategy(const ModelType& type) { | 652 static NudgeDelayStrategy GetNudgeDelayStrategy(const ModelType& type) { |
| 656 switch (type) { | 653 switch (type) { |
| 657 case syncer::AUTOFILL: | 654 case AUTOFILL: |
| 658 return ACCOMPANY_ONLY; | 655 return ACCOMPANY_ONLY; |
| 659 case syncer::PREFERENCES: | 656 case PREFERENCES: |
| 660 case syncer::SESSIONS: | 657 case SESSIONS: |
| 661 return CUSTOM; | 658 return CUSTOM; |
| 662 default: | 659 default: |
| 663 return IMMEDIATE; | 660 return IMMEDIATE; |
| 664 } | 661 } |
| 665 } | 662 } |
| 666 | 663 |
| 667 static TimeDelta GetNudgeDelayTimeDeltaFromType( | 664 static TimeDelta GetNudgeDelayTimeDeltaFromType( |
| 668 const NudgeDelayStrategy& delay_type, const ModelType& model_type, | 665 const NudgeDelayStrategy& delay_type, const ModelType& model_type, |
| 669 const SyncManagerImpl::SyncInternal* core) { | 666 const SyncManagerImpl::SyncInternal* core) { |
| 670 CHECK(core); | 667 CHECK(core); |
| 671 TimeDelta delay = TimeDelta::FromMilliseconds( | 668 TimeDelta delay = TimeDelta::FromMilliseconds( |
| 672 kDefaultNudgeDelayMilliseconds); | 669 kDefaultNudgeDelayMilliseconds); |
| 673 switch (delay_type) { | 670 switch (delay_type) { |
| 674 case IMMEDIATE: | 671 case IMMEDIATE: |
| 675 delay = TimeDelta::FromMilliseconds( | 672 delay = TimeDelta::FromMilliseconds( |
| 676 kDefaultNudgeDelayMilliseconds); | 673 kDefaultNudgeDelayMilliseconds); |
| 677 break; | 674 break; |
| 678 case ACCOMPANY_ONLY: | 675 case ACCOMPANY_ONLY: |
| 679 delay = TimeDelta::FromSeconds( | 676 delay = TimeDelta::FromSeconds(kDefaultShortPollIntervalSeconds); |
| 680 syncer::kDefaultShortPollIntervalSeconds); | |
| 681 break; | 677 break; |
| 682 case CUSTOM: | 678 case CUSTOM: |
| 683 switch (model_type) { | 679 switch (model_type) { |
| 684 case syncer::PREFERENCES: | 680 case PREFERENCES: |
| 685 delay = TimeDelta::FromMilliseconds( | 681 delay = TimeDelta::FromMilliseconds( |
| 686 kPreferencesNudgeDelayMilliseconds); | 682 kPreferencesNudgeDelayMilliseconds); |
| 687 break; | 683 break; |
| 688 case syncer::SESSIONS: | 684 case SESSIONS: |
| 689 delay = core->scheduler()->sessions_commit_delay(); | 685 delay = core->scheduler()->sessions_commit_delay(); |
| 690 break; | 686 break; |
| 691 default: | 687 default: |
| 692 NOTREACHED(); | 688 NOTREACHED(); |
| 693 } | 689 } |
| 694 break; | 690 break; |
| 695 default: | 691 default: |
| 696 NOTREACHED(); | 692 NOTREACHED(); |
| 697 } | 693 } |
| 698 return delay; | 694 return delay; |
| 699 } | 695 } |
| 700 }; | 696 }; |
| 701 | 697 |
| 702 SyncManagerImpl::SyncManagerImpl(const std::string& name) | 698 SyncManagerImpl::SyncManagerImpl(const std::string& name) |
| 703 : data_(new SyncInternal(name)) {} | 699 : data_(new SyncInternal(name)) {} |
| 704 | 700 |
| 705 bool SyncManagerImpl::Init( | 701 bool SyncManagerImpl::Init( |
| 706 const FilePath& database_location, | 702 const FilePath& database_location, |
| 707 const WeakHandle<JsEventHandler>& event_handler, | 703 const WeakHandle<JsEventHandler>& event_handler, |
| 708 const std::string& sync_server_and_path, | 704 const std::string& sync_server_and_path, |
| 709 int sync_server_port, | 705 int sync_server_port, |
| 710 bool use_ssl, | 706 bool use_ssl, |
| 711 const scoped_refptr<base::TaskRunner>& blocking_task_runner, | 707 const scoped_refptr<base::TaskRunner>& blocking_task_runner, |
| 712 scoped_ptr<HttpPostProviderFactory> post_factory, | 708 scoped_ptr<HttpPostProviderFactory> post_factory, |
| 713 const syncer::ModelSafeRoutingInfo& model_safe_routing_info, | 709 const ModelSafeRoutingInfo& model_safe_routing_info, |
| 714 const std::vector<syncer::ModelSafeWorker*>& workers, | 710 const std::vector<ModelSafeWorker*>& workers, |
| 715 syncer::ExtensionsActivityMonitor* extensions_activity_monitor, | 711 ExtensionsActivityMonitor* extensions_activity_monitor, |
| 716 SyncManager::ChangeDelegate* change_delegate, | 712 SyncManager::ChangeDelegate* change_delegate, |
| 717 const SyncCredentials& credentials, | 713 const SyncCredentials& credentials, |
| 718 scoped_ptr<syncer::SyncNotifier> sync_notifier, | 714 scoped_ptr<SyncNotifier> sync_notifier, |
| 719 const std::string& restored_key_for_bootstrapping, | 715 const std::string& restored_key_for_bootstrapping, |
| 720 SyncManager::TestingMode testing_mode, | 716 SyncManager::TestingMode testing_mode, |
| 721 Encryptor* encryptor, | 717 Encryptor* encryptor, |
| 722 UnrecoverableErrorHandler* unrecoverable_error_handler, | 718 UnrecoverableErrorHandler* unrecoverable_error_handler, |
| 723 ReportUnrecoverableErrorFunction report_unrecoverable_error_function) { | 719 ReportUnrecoverableErrorFunction report_unrecoverable_error_function) { |
| 724 DCHECK(thread_checker_.CalledOnValidThread()); | 720 DCHECK(thread_checker_.CalledOnValidThread()); |
| 725 DCHECK(post_factory.get()); | 721 DCHECK(post_factory.get()); |
| 726 DVLOG(1) << "SyncManager starting Init..."; | 722 DVLOG(1) << "SyncManager starting Init..."; |
| 727 std::string server_string(sync_server_and_path); | 723 std::string server_string(sync_server_and_path); |
| 728 return data_->Init(database_location, | 724 return data_->Init(database_location, |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 755 data_->UpdateEnabledTypes(enabled_types); | 751 data_->UpdateEnabledTypes(enabled_types); |
| 756 } | 752 } |
| 757 | 753 |
| 758 void SyncManagerImpl::ThrowUnrecoverableError() { | 754 void SyncManagerImpl::ThrowUnrecoverableError() { |
| 759 DCHECK(thread_checker_.CalledOnValidThread()); | 755 DCHECK(thread_checker_.CalledOnValidThread()); |
| 760 ReadTransaction trans(FROM_HERE, GetUserShare()); | 756 ReadTransaction trans(FROM_HERE, GetUserShare()); |
| 761 trans.GetWrappedTrans()->OnUnrecoverableError( | 757 trans.GetWrappedTrans()->OnUnrecoverableError( |
| 762 FROM_HERE, "Simulating unrecoverable error for testing purposes."); | 758 FROM_HERE, "Simulating unrecoverable error for testing purposes."); |
| 763 } | 759 } |
| 764 | 760 |
| 765 syncer::ModelTypeSet SyncManagerImpl::InitialSyncEndedTypes() { | 761 ModelTypeSet SyncManagerImpl::InitialSyncEndedTypes() { |
| 766 return data_->InitialSyncEndedTypes(); | 762 return data_->InitialSyncEndedTypes(); |
| 767 } | 763 } |
| 768 | 764 |
| 769 syncer::ModelTypeSet SyncManagerImpl::GetTypesWithEmptyProgressMarkerToken( | 765 ModelTypeSet SyncManagerImpl::GetTypesWithEmptyProgressMarkerToken( |
| 770 syncer::ModelTypeSet types) { | 766 ModelTypeSet types) { |
| 771 return data_->GetTypesWithEmptyProgressMarkerToken(types); | 767 return data_->GetTypesWithEmptyProgressMarkerToken(types); |
| 772 } | 768 } |
| 773 | 769 |
| 774 bool SyncManagerImpl::PurgePartiallySyncedTypes() { | 770 bool SyncManagerImpl::PurgePartiallySyncedTypes() { |
| 775 return data_->PurgePartiallySyncedTypes(); | 771 return data_->PurgePartiallySyncedTypes(); |
| 776 } | 772 } |
| 777 | 773 |
| 778 void SyncManagerImpl::StartSyncingNormally( | 774 void SyncManagerImpl::StartSyncingNormally( |
| 779 const syncer::ModelSafeRoutingInfo& routing_info) { | 775 const ModelSafeRoutingInfo& routing_info) { |
| 780 DCHECK(thread_checker_.CalledOnValidThread()); | 776 DCHECK(thread_checker_.CalledOnValidThread()); |
| 781 data_->StartSyncingNormally(routing_info); | 777 data_->StartSyncingNormally(routing_info); |
| 782 } | 778 } |
| 783 | 779 |
| 784 void SyncManagerImpl::SetEncryptionPassphrase(const std::string& passphrase, | 780 void SyncManagerImpl::SetEncryptionPassphrase(const std::string& passphrase, |
| 785 bool is_explicit) { | 781 bool is_explicit) { |
| 786 DCHECK(thread_checker_.CalledOnValidThread()); | 782 DCHECK(thread_checker_.CalledOnValidThread()); |
| 787 data_->SetEncryptionPassphrase(passphrase, is_explicit); | 783 data_->SetEncryptionPassphrase(passphrase, is_explicit); |
| 788 } | 784 } |
| 789 | 785 |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 814 ReadTransaction trans(FROM_HERE, GetUserShare()); | 810 ReadTransaction trans(FROM_HERE, GetUserShare()); |
| 815 return trans.GetCryptographer()->encrypt_everything(); | 811 return trans.GetCryptographer()->encrypt_everything(); |
| 816 } | 812 } |
| 817 | 813 |
| 818 bool SyncManagerImpl::IsUsingExplicitPassphrase() { | 814 bool SyncManagerImpl::IsUsingExplicitPassphrase() { |
| 819 return data_ && data_->IsUsingExplicitPassphrase(); | 815 return data_ && data_->IsUsingExplicitPassphrase(); |
| 820 } | 816 } |
| 821 | 817 |
| 822 void SyncManagerImpl::ConfigureSyncer( | 818 void SyncManagerImpl::ConfigureSyncer( |
| 823 ConfigureReason reason, | 819 ConfigureReason reason, |
| 824 const syncer::ModelTypeSet& types_to_config, | 820 const ModelTypeSet& types_to_config, |
| 825 const syncer::ModelSafeRoutingInfo& new_routing_info, | 821 const ModelSafeRoutingInfo& new_routing_info, |
| 826 const base::Closure& ready_task, | 822 const base::Closure& ready_task, |
| 827 const base::Closure& retry_task) { | 823 const base::Closure& retry_task) { |
| 828 DCHECK(thread_checker_.CalledOnValidThread()); | 824 DCHECK(thread_checker_.CalledOnValidThread()); |
| 829 DCHECK(!ready_task.is_null()); | 825 DCHECK(!ready_task.is_null()); |
| 830 DCHECK(!retry_task.is_null()); | 826 DCHECK(!retry_task.is_null()); |
| 831 | 827 |
| 832 // TODO(zea): set this based on whether cryptographer has keystore | 828 // TODO(zea): set this based on whether cryptographer has keystore |
| 833 // encryption key or not (requires opening a transaction). crbug.com/129665. | 829 // encryption key or not (requires opening a transaction). crbug.com/129665. |
| 834 ConfigurationParams::KeystoreKeyStatus keystore_key_status = | 830 ConfigurationParams::KeystoreKeyStatus keystore_key_status = |
| 835 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY; | 831 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY; |
| 836 | 832 |
| 837 ConfigurationParams params(GetSourceFromReason(reason), | 833 ConfigurationParams params(GetSourceFromReason(reason), |
| 838 types_to_config, | 834 types_to_config, |
| 839 new_routing_info, | 835 new_routing_info, |
| 840 keystore_key_status, | 836 keystore_key_status, |
| 841 ready_task); | 837 ready_task); |
| 842 | 838 |
| 843 if (!data_->scheduler()) { | 839 if (!data_->scheduler()) { |
| 844 LOG(INFO) | 840 LOG(INFO) |
| 845 << "SyncManagerImpl::ConfigureSyncer: could not configure because " | 841 << "SyncManagerImpl::ConfigureSyncer: could not configure because " |
| 846 << "scheduler is null"; | 842 << "scheduler is null"; |
| 847 params.ready_task.Run(); | 843 params.ready_task.Run(); |
| 848 return; | 844 return; |
| 849 } | 845 } |
| 850 | 846 |
| 851 data_->scheduler()->Start(syncer::SyncScheduler::CONFIGURATION_MODE); | 847 data_->scheduler()->Start(SyncScheduler::CONFIGURATION_MODE); |
| 852 if (!data_->scheduler()->ScheduleConfiguration(params)) | 848 if (!data_->scheduler()->ScheduleConfiguration(params)) |
| 853 retry_task.Run(); | 849 retry_task.Run(); |
| 854 | 850 |
| 855 } | 851 } |
| 856 | 852 |
| 857 bool SyncManagerImpl::SyncInternal::Init( | 853 bool SyncManagerImpl::SyncInternal::Init( |
| 858 const FilePath& database_location, | 854 const FilePath& database_location, |
| 859 const WeakHandle<JsEventHandler>& event_handler, | 855 const WeakHandle<JsEventHandler>& event_handler, |
| 860 const std::string& sync_server_and_path, | 856 const std::string& sync_server_and_path, |
| 861 int port, | 857 int port, |
| 862 bool use_ssl, | 858 bool use_ssl, |
| 863 const scoped_refptr<base::TaskRunner>& blocking_task_runner, | 859 const scoped_refptr<base::TaskRunner>& blocking_task_runner, |
| 864 scoped_ptr<HttpPostProviderFactory> post_factory, | 860 scoped_ptr<HttpPostProviderFactory> post_factory, |
| 865 const syncer::ModelSafeRoutingInfo& model_safe_routing_info, | 861 const ModelSafeRoutingInfo& model_safe_routing_info, |
| 866 const std::vector<syncer::ModelSafeWorker*>& workers, | 862 const std::vector<ModelSafeWorker*>& workers, |
| 867 syncer::ExtensionsActivityMonitor* extensions_activity_monitor, | 863 ExtensionsActivityMonitor* extensions_activity_monitor, |
| 868 SyncManager::ChangeDelegate* change_delegate, | 864 SyncManager::ChangeDelegate* change_delegate, |
| 869 const SyncCredentials& credentials, | 865 const SyncCredentials& credentials, |
| 870 scoped_ptr<syncer::SyncNotifier> sync_notifier, | 866 scoped_ptr<SyncNotifier> sync_notifier, |
| 871 const std::string& restored_key_for_bootstrapping, | 867 const std::string& restored_key_for_bootstrapping, |
| 872 SyncManager::TestingMode testing_mode, | 868 SyncManager::TestingMode testing_mode, |
| 873 Encryptor* encryptor, | 869 Encryptor* encryptor, |
| 874 UnrecoverableErrorHandler* unrecoverable_error_handler, | 870 UnrecoverableErrorHandler* unrecoverable_error_handler, |
| 875 ReportUnrecoverableErrorFunction report_unrecoverable_error_function) { | 871 ReportUnrecoverableErrorFunction report_unrecoverable_error_function) { |
| 876 CHECK(!initialized_); | 872 CHECK(!initialized_); |
| 877 | 873 |
| 878 DCHECK(thread_checker_.CalledOnValidThread()); | 874 DCHECK(thread_checker_.CalledOnValidThread()); |
| 879 | 875 |
| 880 DVLOG(1) << "Starting SyncInternal initialization."; | 876 DVLOG(1) << "Starting SyncInternal initialization."; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 945 &debug_info_event_listener_, | 941 &debug_info_event_listener_, |
| 946 &traffic_recorder_)); | 942 &traffic_recorder_)); |
| 947 session_context()->set_account_name(credentials.email); | 943 session_context()->set_account_name(credentials.email); |
| 948 scheduler_.reset(new SyncScheduler(name_, session_context(), new Syncer())); | 944 scheduler_.reset(new SyncScheduler(name_, session_context(), new Syncer())); |
| 949 } | 945 } |
| 950 | 946 |
| 951 bool success = SignIn(credentials); | 947 bool success = SignIn(credentials); |
| 952 | 948 |
| 953 if (success) { | 949 if (success) { |
| 954 if (scheduler()) { | 950 if (scheduler()) { |
| 955 scheduler()->Start(syncer::SyncScheduler::CONFIGURATION_MODE); | 951 scheduler()->Start(SyncScheduler::CONFIGURATION_MODE); |
| 956 } | 952 } |
| 957 | 953 |
| 958 initialized_ = true; | 954 initialized_ = true; |
| 959 | 955 |
| 960 // Unapplied datatypes (those that do not have initial sync ended set) get | 956 // Unapplied datatypes (those that do not have initial sync ended set) get |
| 961 // re-downloaded during any configuration. But, it's possible for a datatype | 957 // re-downloaded during any configuration. But, it's possible for a datatype |
| 962 // to have a progress marker but not have initial sync ended yet, making | 958 // to have a progress marker but not have initial sync ended yet, making |
| 963 // it a candidate for migration. This is a problem, as the DataTypeManager | 959 // it a candidate for migration. This is a problem, as the DataTypeManager |
| 964 // does not support a migration while it's already in the middle of a | 960 // does not support a migration while it's already in the middle of a |
| 965 // configuration. As a result, any partially synced datatype can stall the | 961 // configuration. As a result, any partially synced datatype can stall the |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 995 | 991 |
| 996 sync_notifier_->AddObserver(this); | 992 sync_notifier_->AddObserver(this); |
| 997 | 993 |
| 998 return success; | 994 return success; |
| 999 } | 995 } |
| 1000 | 996 |
| 1001 void SyncManagerImpl::SyncInternal::UpdateCryptographerAndNigori( | 997 void SyncManagerImpl::SyncInternal::UpdateCryptographerAndNigori( |
| 1002 const std::string& chrome_version, | 998 const std::string& chrome_version, |
| 1003 const base::Closure& done_callback) { | 999 const base::Closure& done_callback) { |
| 1004 DCHECK(initialized_); | 1000 DCHECK(initialized_); |
| 1005 syncer::GetSessionName( | 1001 GetSessionName( |
| 1006 blocking_task_runner_, | 1002 blocking_task_runner_, |
| 1007 base::Bind( | 1003 base::Bind( |
| 1008 &SyncManagerImpl::SyncInternal::UpdateCryptographerAndNigoriCallback, | 1004 &SyncManagerImpl::SyncInternal::UpdateCryptographerAndNigoriCallback, |
| 1009 weak_ptr_factory_.GetWeakPtr(), | 1005 weak_ptr_factory_.GetWeakPtr(), |
| 1010 chrome_version, | 1006 chrome_version, |
| 1011 done_callback)); | 1007 done_callback)); |
| 1012 } | 1008 } |
| 1013 | 1009 |
| 1014 void SyncManagerImpl::SyncInternal::UpdateNigoriEncryptionState( | 1010 void SyncManagerImpl::SyncInternal::UpdateNigoriEncryptionState( |
| 1015 Cryptographer* cryptographer, | 1011 Cryptographer* cryptographer, |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 1042 cryptographer->UpdateNigoriFromEncryptedTypes(&nigori); | 1038 cryptographer->UpdateNigoriFromEncryptedTypes(&nigori); |
| 1043 | 1039 |
| 1044 // If nothing has changed, this is a no-op. | 1040 // If nothing has changed, this is a no-op. |
| 1045 nigori_node->SetNigoriSpecifics(nigori); | 1041 nigori_node->SetNigoriSpecifics(nigori); |
| 1046 } | 1042 } |
| 1047 | 1043 |
| 1048 void SyncManagerImpl::SyncInternal::UpdateCryptographerAndNigoriCallback( | 1044 void SyncManagerImpl::SyncInternal::UpdateCryptographerAndNigoriCallback( |
| 1049 const std::string& chrome_version, | 1045 const std::string& chrome_version, |
| 1050 const base::Closure& done_callback, | 1046 const base::Closure& done_callback, |
| 1051 const std::string& session_name) { | 1047 const std::string& session_name) { |
| 1052 if (!directory()->initial_sync_ended_for_type(syncer::NIGORI)) { | 1048 if (!directory()->initial_sync_ended_for_type(NIGORI)) { |
| 1053 done_callback.Run(); // Should only happen during first time sync. | 1049 done_callback.Run(); // Should only happen during first time sync. |
| 1054 return; | 1050 return; |
| 1055 } | 1051 } |
| 1056 | 1052 |
| 1057 bool success = false; | 1053 bool success = false; |
| 1058 { | 1054 { |
| 1059 WriteTransaction trans(FROM_HERE, GetUserShare()); | 1055 WriteTransaction trans(FROM_HERE, GetUserShare()); |
| 1060 Cryptographer* cryptographer = trans.GetCryptographer(); | 1056 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 1061 WriteNode node(&trans); | 1057 WriteNode node(&trans); |
| 1062 | 1058 |
| 1063 if (node.InitByTagLookup(kNigoriTag) == syncer::BaseNode::INIT_OK) { | 1059 if (node.InitByTagLookup(kNigoriTag) == BaseNode::INIT_OK) { |
| 1064 sync_pb::NigoriSpecifics nigori(node.GetNigoriSpecifics()); | 1060 sync_pb::NigoriSpecifics nigori(node.GetNigoriSpecifics()); |
| 1065 Cryptographer::UpdateResult result = cryptographer->Update(nigori); | 1061 Cryptographer::UpdateResult result = cryptographer->Update(nigori); |
| 1066 if (result == Cryptographer::NEEDS_PASSPHRASE) { | 1062 if (result == Cryptographer::NEEDS_PASSPHRASE) { |
| 1067 sync_pb::EncryptedData pending_keys; | 1063 sync_pb::EncryptedData pending_keys; |
| 1068 if (cryptographer->has_pending_keys()) | 1064 if (cryptographer->has_pending_keys()) |
| 1069 pending_keys = cryptographer->GetPendingKeys(); | 1065 pending_keys = cryptographer->GetPendingKeys(); |
| 1070 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 1066 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| 1071 OnPassphraseRequired(syncer::REASON_DECRYPTION, | 1067 OnPassphraseRequired(REASON_DECRYPTION, |
| 1072 pending_keys)); | 1068 pending_keys)); |
| 1073 } | 1069 } |
| 1074 | 1070 |
| 1075 | 1071 |
| 1076 // Add or update device information. | 1072 // Add or update device information. |
| 1077 bool contains_this_device = false; | 1073 bool contains_this_device = false; |
| 1078 for (int i = 0; i < nigori.device_information_size(); ++i) { | 1074 for (int i = 0; i < nigori.device_information_size(); ++i) { |
| 1079 const sync_pb::DeviceInformation& device_information = | 1075 const sync_pb::DeviceInformation& device_information = |
| 1080 nigori.device_information(i); | 1076 nigori.device_information(i); |
| 1081 if (device_information.cache_guid() == directory()->cache_guid()) { | 1077 if (device_information.cache_guid() == directory()->cache_guid()) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1131 // TODO(lipalani): Explore the possibility of hooking this up to | 1127 // TODO(lipalani): Explore the possibility of hooking this up to |
| 1132 // SyncManager::Observer and making |AllStatus| a listener for that. | 1128 // SyncManager::Observer and making |AllStatus| a listener for that. |
| 1133 allstatus_.SetCryptographerReady(cryptographer->is_ready()); | 1129 allstatus_.SetCryptographerReady(cryptographer->is_ready()); |
| 1134 allstatus_.SetCryptoHasPendingKeys(cryptographer->has_pending_keys()); | 1130 allstatus_.SetCryptoHasPendingKeys(cryptographer->has_pending_keys()); |
| 1135 debug_info_event_listener_.SetCryptographerReady(cryptographer->is_ready()); | 1131 debug_info_event_listener_.SetCryptographerReady(cryptographer->is_ready()); |
| 1136 debug_info_event_listener_.SetCrytographerHasPendingKeys( | 1132 debug_info_event_listener_.SetCrytographerHasPendingKeys( |
| 1137 cryptographer->has_pending_keys()); | 1133 cryptographer->has_pending_keys()); |
| 1138 } | 1134 } |
| 1139 | 1135 |
| 1140 void SyncManagerImpl::SyncInternal::StartSyncingNormally( | 1136 void SyncManagerImpl::SyncInternal::StartSyncingNormally( |
| 1141 const syncer::ModelSafeRoutingInfo& routing_info) { | 1137 const ModelSafeRoutingInfo& routing_info) { |
| 1142 // Start the sync scheduler. | 1138 // Start the sync scheduler. |
| 1143 if (scheduler()) { // NULL during certain unittests. | 1139 if (scheduler()) { // NULL during certain unittests. |
| 1144 // TODO(sync): We always want the newest set of routes when we switch back | 1140 // TODO(sync): We always want the newest set of routes when we switch back |
| 1145 // to normal mode. Figure out how to enforce set_routing_info is always | 1141 // to normal mode. Figure out how to enforce set_routing_info is always |
| 1146 // appropriately set and that it's only modified when switching to normal | 1142 // appropriately set and that it's only modified when switching to normal |
| 1147 // mode. | 1143 // mode. |
| 1148 session_context()->set_routing_info(routing_info); | 1144 session_context()->set_routing_info(routing_info); |
| 1149 scheduler()->Start(SyncScheduler::NORMAL_MODE); | 1145 scheduler()->Start(SyncScheduler::NORMAL_MODE); |
| 1150 } | 1146 } |
| 1151 } | 1147 } |
| 1152 | 1148 |
| 1153 bool SyncManagerImpl::SyncInternal::OpenDirectory() { | 1149 bool SyncManagerImpl::SyncInternal::OpenDirectory() { |
| 1154 DCHECK(!initialized_) << "Should only happen once"; | 1150 DCHECK(!initialized_) << "Should only happen once"; |
| 1155 | 1151 |
| 1156 // Set before Open(). | 1152 // Set before Open(). |
| 1157 change_observer_ = | 1153 change_observer_ = |
| 1158 syncer::MakeWeakHandle(js_mutation_event_observer_.AsWeakPtr()); | 1154 MakeWeakHandle(js_mutation_event_observer_.AsWeakPtr()); |
| 1159 WeakHandle<syncable::TransactionObserver> transaction_observer( | 1155 WeakHandle<syncable::TransactionObserver> transaction_observer( |
| 1160 syncer::MakeWeakHandle(js_mutation_event_observer_.AsWeakPtr())); | 1156 MakeWeakHandle(js_mutation_event_observer_.AsWeakPtr())); |
| 1161 | 1157 |
| 1162 syncable::DirOpenResult open_result = syncable::NOT_INITIALIZED; | 1158 syncable::DirOpenResult open_result = syncable::NOT_INITIALIZED; |
| 1163 open_result = directory()->Open(username_for_share(), this, | 1159 open_result = directory()->Open(username_for_share(), this, |
| 1164 transaction_observer); | 1160 transaction_observer); |
| 1165 if (open_result != syncable::OPENED) { | 1161 if (open_result != syncable::OPENED) { |
| 1166 LOG(ERROR) << "Could not open share for:" << username_for_share(); | 1162 LOG(ERROR) << "Could not open share for:" << username_for_share(); |
| 1167 return false; | 1163 return false; |
| 1168 } | 1164 } |
| 1169 | 1165 |
| 1170 connection_manager()->set_client_id(directory()->cache_guid()); | 1166 connection_manager()->set_client_id(directory()->cache_guid()); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 1194 sync_notifier_->SetUniqueId(unique_id); | 1190 sync_notifier_->SetUniqueId(unique_id); |
| 1195 // TODO(tim): Remove once invalidation state has been migrated to new | 1191 // TODO(tim): Remove once invalidation state has been migrated to new |
| 1196 // InvalidationStateTracker store. Bug 124140. | 1192 // InvalidationStateTracker store. Bug 124140. |
| 1197 sync_notifier_->SetStateDeprecated(state); | 1193 sync_notifier_->SetStateDeprecated(state); |
| 1198 | 1194 |
| 1199 UpdateCredentials(credentials); | 1195 UpdateCredentials(credentials); |
| 1200 return true; | 1196 return true; |
| 1201 } | 1197 } |
| 1202 | 1198 |
| 1203 bool SyncManagerImpl::SyncInternal::PurgePartiallySyncedTypes() { | 1199 bool SyncManagerImpl::SyncInternal::PurgePartiallySyncedTypes() { |
| 1204 syncer::ModelTypeSet partially_synced_types = | 1200 ModelTypeSet partially_synced_types = ModelTypeSet::All(); |
| 1205 syncer::ModelTypeSet::All(); | |
| 1206 partially_synced_types.RemoveAll(InitialSyncEndedTypes()); | 1201 partially_synced_types.RemoveAll(InitialSyncEndedTypes()); |
| 1207 partially_synced_types.RemoveAll(GetTypesWithEmptyProgressMarkerToken( | 1202 partially_synced_types.RemoveAll(GetTypesWithEmptyProgressMarkerToken( |
| 1208 syncer::ModelTypeSet::All())); | 1203 ModelTypeSet::All())); |
| 1209 | 1204 |
| 1210 UMA_HISTOGRAM_COUNTS("Sync.PartiallySyncedTypes", | 1205 UMA_HISTOGRAM_COUNTS("Sync.PartiallySyncedTypes", |
| 1211 partially_synced_types.Size()); | 1206 partially_synced_types.Size()); |
| 1212 if (partially_synced_types.Empty()) | 1207 if (partially_synced_types.Empty()) |
| 1213 return true; | 1208 return true; |
| 1214 return directory()->PurgeEntriesWithTypeIn(partially_synced_types); | 1209 return directory()->PurgeEntriesWithTypeIn(partially_synced_types); |
| 1215 } | 1210 } |
| 1216 | 1211 |
| 1217 void SyncManagerImpl::SyncInternal::UpdateCredentials( | 1212 void SyncManagerImpl::SyncInternal::UpdateCredentials( |
| 1218 const SyncCredentials& credentials) { | 1213 const SyncCredentials& credentials) { |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 1244 if (passphrase.empty()) { | 1239 if (passphrase.empty()) { |
| 1245 NOTREACHED() << "Cannot encrypt with an empty passphrase."; | 1240 NOTREACHED() << "Cannot encrypt with an empty passphrase."; |
| 1246 return; | 1241 return; |
| 1247 } | 1242 } |
| 1248 | 1243 |
| 1249 // All accesses to the cryptographer are protected by a transaction. | 1244 // All accesses to the cryptographer are protected by a transaction. |
| 1250 WriteTransaction trans(FROM_HERE, GetUserShare()); | 1245 WriteTransaction trans(FROM_HERE, GetUserShare()); |
| 1251 Cryptographer* cryptographer = trans.GetCryptographer(); | 1246 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 1252 KeyParams key_params = {"localhost", "dummy", passphrase}; | 1247 KeyParams key_params = {"localhost", "dummy", passphrase}; |
| 1253 WriteNode node(&trans); | 1248 WriteNode node(&trans); |
| 1254 if (node.InitByTagLookup(kNigoriTag) != syncer::BaseNode::INIT_OK) { | 1249 if (node.InitByTagLookup(kNigoriTag) != BaseNode::INIT_OK) { |
| 1255 // TODO(albertb): Plumb an UnrecoverableError all the way back to the PSS. | 1250 // TODO(albertb): Plumb an UnrecoverableError all the way back to the PSS. |
| 1256 NOTREACHED(); | 1251 NOTREACHED(); |
| 1257 return; | 1252 return; |
| 1258 } | 1253 } |
| 1259 | 1254 |
| 1260 bool nigori_has_explicit_passphrase = | 1255 bool nigori_has_explicit_passphrase = |
| 1261 node.GetNigoriSpecifics().using_explicit_passphrase(); | 1256 node.GetNigoriSpecifics().using_explicit_passphrase(); |
| 1262 std::string bootstrap_token; | 1257 std::string bootstrap_token; |
| 1263 sync_pb::EncryptedData pending_keys; | 1258 sync_pb::EncryptedData pending_keys; |
| 1264 if (cryptographer->has_pending_keys()) | 1259 if (cryptographer->has_pending_keys()) |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1358 if (passphrase.empty()) { | 1353 if (passphrase.empty()) { |
| 1359 NOTREACHED() << "Cannot decrypt with an empty passphrase."; | 1354 NOTREACHED() << "Cannot decrypt with an empty passphrase."; |
| 1360 return; | 1355 return; |
| 1361 } | 1356 } |
| 1362 | 1357 |
| 1363 // All accesses to the cryptographer are protected by a transaction. | 1358 // All accesses to the cryptographer are protected by a transaction. |
| 1364 WriteTransaction trans(FROM_HERE, GetUserShare()); | 1359 WriteTransaction trans(FROM_HERE, GetUserShare()); |
| 1365 Cryptographer* cryptographer = trans.GetCryptographer(); | 1360 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 1366 KeyParams key_params = {"localhost", "dummy", passphrase}; | 1361 KeyParams key_params = {"localhost", "dummy", passphrase}; |
| 1367 WriteNode node(&trans); | 1362 WriteNode node(&trans); |
| 1368 if (node.InitByTagLookup(kNigoriTag) != syncer::BaseNode::INIT_OK) { | 1363 if (node.InitByTagLookup(kNigoriTag) != BaseNode::INIT_OK) { |
| 1369 // TODO(albertb): Plumb an UnrecoverableError all the way back to the PSS. | 1364 // TODO(albertb): Plumb an UnrecoverableError all the way back to the PSS. |
| 1370 NOTREACHED(); | 1365 NOTREACHED(); |
| 1371 return; | 1366 return; |
| 1372 } | 1367 } |
| 1373 | 1368 |
| 1374 if (!cryptographer->has_pending_keys()) { | 1369 if (!cryptographer->has_pending_keys()) { |
| 1375 // Note that this *can* happen in a rare situation where data is | 1370 // Note that this *can* happen in a rare situation where data is |
| 1376 // re-encrypted on another client while a SetDecryptionPassphrase() call is | 1371 // re-encrypted on another client while a SetDecryptionPassphrase() call is |
| 1377 // in-flight on this client. It is rare enough that we choose to do nothing. | 1372 // in-flight on this client. It is rare enough that we choose to do nothing. |
| 1378 NOTREACHED() << "Attempt to set decryption passphrase failed because there " | 1373 NOTREACHED() << "Attempt to set decryption passphrase failed because there " |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1511 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 1506 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| 1512 OnBootstrapTokenUpdated(bootstrap_token)); | 1507 OnBootstrapTokenUpdated(bootstrap_token)); |
| 1513 } | 1508 } |
| 1514 | 1509 |
| 1515 if (!success) { | 1510 if (!success) { |
| 1516 if (cryptographer->is_ready()) { | 1511 if (cryptographer->is_ready()) { |
| 1517 LOG(ERROR) << "Attempt to change passphrase failed while cryptographer " | 1512 LOG(ERROR) << "Attempt to change passphrase failed while cryptographer " |
| 1518 << "was ready."; | 1513 << "was ready."; |
| 1519 } else if (cryptographer->has_pending_keys()) { | 1514 } else if (cryptographer->has_pending_keys()) { |
| 1520 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 1515 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| 1521 OnPassphraseRequired(syncer::REASON_DECRYPTION, | 1516 OnPassphraseRequired(REASON_DECRYPTION, |
| 1522 cryptographer->GetPendingKeys())); | 1517 cryptographer->GetPendingKeys())); |
| 1523 } else { | 1518 } else { |
| 1524 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 1519 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| 1525 OnPassphraseRequired(syncer::REASON_ENCRYPTION, | 1520 OnPassphraseRequired(REASON_ENCRYPTION, |
| 1526 sync_pb::EncryptedData())); | 1521 sync_pb::EncryptedData())); |
| 1527 } | 1522 } |
| 1528 return; | 1523 return; |
| 1529 } | 1524 } |
| 1530 | 1525 |
| 1531 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 1526 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| 1532 OnPassphraseAccepted()); | 1527 OnPassphraseAccepted()); |
| 1533 DCHECK(cryptographer->is_ready()); | 1528 DCHECK(cryptographer->is_ready()); |
| 1534 | 1529 |
| 1535 // TODO(tim): Bug 58231. It would be nice if setting a passphrase didn't | 1530 // TODO(tim): Bug 58231. It would be nice if setting a passphrase didn't |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1547 nigori_node->SetNigoriSpecifics(specifics); | 1542 nigori_node->SetNigoriSpecifics(specifics); |
| 1548 | 1543 |
| 1549 // Does nothing if everything is already encrypted or the cryptographer has | 1544 // Does nothing if everything is already encrypted or the cryptographer has |
| 1550 // pending keys. | 1545 // pending keys. |
| 1551 ReEncryptEverything(trans); | 1546 ReEncryptEverything(trans); |
| 1552 } | 1547 } |
| 1553 | 1548 |
| 1554 bool SyncManagerImpl::SyncInternal::IsUsingExplicitPassphrase() { | 1549 bool SyncManagerImpl::SyncInternal::IsUsingExplicitPassphrase() { |
| 1555 ReadTransaction trans(FROM_HERE, &share_); | 1550 ReadTransaction trans(FROM_HERE, &share_); |
| 1556 ReadNode node(&trans); | 1551 ReadNode node(&trans); |
| 1557 if (node.InitByTagLookup(kNigoriTag) != syncer::BaseNode::INIT_OK) { | 1552 if (node.InitByTagLookup(kNigoriTag) != BaseNode::INIT_OK) { |
| 1558 // TODO(albertb): Plumb an UnrecoverableError all the way back to the PSS. | 1553 // TODO(albertb): Plumb an UnrecoverableError all the way back to the PSS. |
| 1559 NOTREACHED(); | 1554 NOTREACHED(); |
| 1560 return false; | 1555 return false; |
| 1561 } | 1556 } |
| 1562 | 1557 |
| 1563 return node.GetNigoriSpecifics().using_explicit_passphrase(); | 1558 return node.GetNigoriSpecifics().using_explicit_passphrase(); |
| 1564 } | 1559 } |
| 1565 | 1560 |
| 1566 void SyncManagerImpl::SyncInternal::RefreshEncryption() { | 1561 void SyncManagerImpl::SyncInternal::RefreshEncryption() { |
| 1567 DCHECK(initialized_); | 1562 DCHECK(initialized_); |
| 1568 | 1563 |
| 1569 WriteTransaction trans(FROM_HERE, GetUserShare()); | 1564 WriteTransaction trans(FROM_HERE, GetUserShare()); |
| 1570 WriteNode node(&trans); | 1565 WriteNode node(&trans); |
| 1571 if (node.InitByTagLookup(kNigoriTag) != syncer::BaseNode::INIT_OK) { | 1566 if (node.InitByTagLookup(kNigoriTag) != BaseNode::INIT_OK) { |
| 1572 NOTREACHED() << "Unable to set encrypted datatypes because Nigori node not " | 1567 NOTREACHED() << "Unable to set encrypted datatypes because Nigori node not " |
| 1573 << "found."; | 1568 << "found."; |
| 1574 return; | 1569 return; |
| 1575 } | 1570 } |
| 1576 | 1571 |
| 1577 Cryptographer* cryptographer = trans.GetCryptographer(); | 1572 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 1578 | 1573 |
| 1579 if (!cryptographer->is_ready()) { | 1574 if (!cryptographer->is_ready()) { |
| 1580 DVLOG(1) << "Attempting to encrypt datatypes when cryptographer not " | 1575 DVLOG(1) << "Attempting to encrypt datatypes when cryptographer not " |
| 1581 << "initialized, prompting for passphrase."; | 1576 << "initialized, prompting for passphrase."; |
| 1582 // TODO(zea): this isn't really decryption, but that's the only way we have | 1577 // TODO(zea): this isn't really decryption, but that's the only way we have |
| 1583 // to prompt the user for a passsphrase. See http://crbug.com/91379. | 1578 // to prompt the user for a passsphrase. See http://crbug.com/91379. |
| 1584 sync_pb::EncryptedData pending_keys; | 1579 sync_pb::EncryptedData pending_keys; |
| 1585 if (cryptographer->has_pending_keys()) | 1580 if (cryptographer->has_pending_keys()) |
| 1586 pending_keys = cryptographer->GetPendingKeys(); | 1581 pending_keys = cryptographer->GetPendingKeys(); |
| 1587 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 1582 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| 1588 OnPassphraseRequired(syncer::REASON_DECRYPTION, | 1583 OnPassphraseRequired(REASON_DECRYPTION, |
| 1589 pending_keys)); | 1584 pending_keys)); |
| 1590 return; | 1585 return; |
| 1591 } | 1586 } |
| 1592 | 1587 |
| 1593 UpdateNigoriEncryptionState(cryptographer, &node); | 1588 UpdateNigoriEncryptionState(cryptographer, &node); |
| 1594 | 1589 |
| 1595 allstatus_.SetEncryptedTypes(cryptographer->GetEncryptedTypes()); | 1590 allstatus_.SetEncryptedTypes(cryptographer->GetEncryptedTypes()); |
| 1596 | 1591 |
| 1597 // We reencrypt everything regardless of whether the set of encrypted | 1592 // We reencrypt everything regardless of whether the set of encrypted |
| 1598 // types changed to ensure that any stray unencrypted entries are overwritten. | 1593 // types changed to ensure that any stray unencrypted entries are overwritten. |
| 1599 ReEncryptEverything(&trans); | 1594 ReEncryptEverything(&trans); |
| 1600 } | 1595 } |
| 1601 | 1596 |
| 1602 // This function iterates over all encrypted types. There are many scenarios in | 1597 // This function iterates over all encrypted types. There are many scenarios in |
| 1603 // which data for some or all types is not currently available. In that case, | 1598 // which data for some or all types is not currently available. In that case, |
| 1604 // the lookup of the root node will fail and we will skip encryption for that | 1599 // the lookup of the root node will fail and we will skip encryption for that |
| 1605 // type. | 1600 // type. |
| 1606 void SyncManagerImpl::SyncInternal::ReEncryptEverything( | 1601 void SyncManagerImpl::SyncInternal::ReEncryptEverything( |
| 1607 WriteTransaction* trans) { | 1602 WriteTransaction* trans) { |
| 1608 Cryptographer* cryptographer = trans->GetCryptographer(); | 1603 Cryptographer* cryptographer = trans->GetCryptographer(); |
| 1609 if (!cryptographer || !cryptographer->is_ready()) | 1604 if (!cryptographer || !cryptographer->is_ready()) |
| 1610 return; | 1605 return; |
| 1611 syncer::ModelTypeSet encrypted_types = GetEncryptedTypes(trans); | 1606 ModelTypeSet encrypted_types = GetEncryptedTypes(trans); |
| 1612 for (syncer::ModelTypeSet::Iterator iter = encrypted_types.First(); | 1607 for (ModelTypeSet::Iterator iter = encrypted_types.First(); |
| 1613 iter.Good(); iter.Inc()) { | 1608 iter.Good(); iter.Inc()) { |
| 1614 if (iter.Get() == syncer::PASSWORDS || iter.Get() == syncer::NIGORI) | 1609 if (iter.Get() == PASSWORDS || iter.Get() == NIGORI) |
| 1615 continue; // These types handle encryption differently. | 1610 continue; // These types handle encryption differently. |
| 1616 | 1611 |
| 1617 ReadNode type_root(trans); | 1612 ReadNode type_root(trans); |
| 1618 std::string tag = syncer::ModelTypeToRootTag(iter.Get()); | 1613 std::string tag = ModelTypeToRootTag(iter.Get()); |
| 1619 if (type_root.InitByTagLookup(tag) != syncer::BaseNode::INIT_OK) | 1614 if (type_root.InitByTagLookup(tag) != BaseNode::INIT_OK) |
| 1620 continue; // Don't try to reencrypt if the type's data is unavailable. | 1615 continue; // Don't try to reencrypt if the type's data is unavailable. |
| 1621 | 1616 |
| 1622 // Iterate through all children of this datatype. | 1617 // Iterate through all children of this datatype. |
| 1623 std::queue<int64> to_visit; | 1618 std::queue<int64> to_visit; |
| 1624 int64 child_id = type_root.GetFirstChildId(); | 1619 int64 child_id = type_root.GetFirstChildId(); |
| 1625 to_visit.push(child_id); | 1620 to_visit.push(child_id); |
| 1626 while (!to_visit.empty()) { | 1621 while (!to_visit.empty()) { |
| 1627 child_id = to_visit.front(); | 1622 child_id = to_visit.front(); |
| 1628 to_visit.pop(); | 1623 to_visit.pop(); |
| 1629 if (child_id == kInvalidId) | 1624 if (child_id == kInvalidId) |
| 1630 continue; | 1625 continue; |
| 1631 | 1626 |
| 1632 WriteNode child(trans); | 1627 WriteNode child(trans); |
| 1633 if (child.InitByIdLookup(child_id) != syncer::BaseNode::INIT_OK) { | 1628 if (child.InitByIdLookup(child_id) != BaseNode::INIT_OK) { |
| 1634 NOTREACHED(); | 1629 NOTREACHED(); |
| 1635 continue; | 1630 continue; |
| 1636 } | 1631 } |
| 1637 if (child.GetIsFolder()) { | 1632 if (child.GetIsFolder()) { |
| 1638 to_visit.push(child.GetFirstChildId()); | 1633 to_visit.push(child.GetFirstChildId()); |
| 1639 } | 1634 } |
| 1640 if (child.GetEntry()->Get(syncable::UNIQUE_SERVER_TAG).empty()) { | 1635 if (child.GetEntry()->Get(syncable::UNIQUE_SERVER_TAG).empty()) { |
| 1641 // Rewrite the specifics of the node with encrypted data if necessary | 1636 // Rewrite the specifics of the node with encrypted data if necessary |
| 1642 // (only rewrite the non-unique folders). | 1637 // (only rewrite the non-unique folders). |
| 1643 child.ResetFromSpecifics(); | 1638 child.ResetFromSpecifics(); |
| 1644 } | 1639 } |
| 1645 to_visit.push(child.GetSuccessorId()); | 1640 to_visit.push(child.GetSuccessorId()); |
| 1646 } | 1641 } |
| 1647 } | 1642 } |
| 1648 | 1643 |
| 1649 // Passwords are encrypted with their own legacy scheme. Passwords are always | 1644 // Passwords are encrypted with their own legacy scheme. Passwords are always |
| 1650 // encrypted so we don't need to check GetEncryptedTypes() here. | 1645 // encrypted so we don't need to check GetEncryptedTypes() here. |
| 1651 ReadNode passwords_root(trans); | 1646 ReadNode passwords_root(trans); |
| 1652 std::string passwords_tag = syncer::ModelTypeToRootTag(syncer::PASSWORDS); | 1647 std::string passwords_tag = ModelTypeToRootTag(PASSWORDS); |
| 1653 if (passwords_root.InitByTagLookup(passwords_tag) == | 1648 if (passwords_root.InitByTagLookup(passwords_tag) == BaseNode::INIT_OK) { |
| 1654 syncer::BaseNode::INIT_OK) { | |
| 1655 int64 child_id = passwords_root.GetFirstChildId(); | 1649 int64 child_id = passwords_root.GetFirstChildId(); |
| 1656 while (child_id != kInvalidId) { | 1650 while (child_id != kInvalidId) { |
| 1657 WriteNode child(trans); | 1651 WriteNode child(trans); |
| 1658 if (child.InitByIdLookup(child_id) != syncer::BaseNode::INIT_OK) { | 1652 if (child.InitByIdLookup(child_id) != BaseNode::INIT_OK) { |
| 1659 NOTREACHED(); | 1653 NOTREACHED(); |
| 1660 return; | 1654 return; |
| 1661 } | 1655 } |
| 1662 child.SetPasswordSpecifics(child.GetPasswordSpecifics()); | 1656 child.SetPasswordSpecifics(child.GetPasswordSpecifics()); |
| 1663 child_id = child.GetSuccessorId(); | 1657 child_id = child.GetSuccessorId(); |
| 1664 } | 1658 } |
| 1665 } | 1659 } |
| 1666 | 1660 |
| 1667 // NOTE: We notify from within a transaction. | 1661 // NOTE: We notify from within a transaction. |
| 1668 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 1662 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1769 void SyncManagerImpl::SyncInternal::OnIPAddressChangedImpl() { | 1763 void SyncManagerImpl::SyncInternal::OnIPAddressChangedImpl() { |
| 1770 DCHECK(thread_checker_.CalledOnValidThread()); | 1764 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1771 if (scheduler()) | 1765 if (scheduler()) |
| 1772 scheduler()->OnConnectionStatusChange(); | 1766 scheduler()->OnConnectionStatusChange(); |
| 1773 } | 1767 } |
| 1774 | 1768 |
| 1775 void SyncManagerImpl::SyncInternal::OnServerConnectionEvent( | 1769 void SyncManagerImpl::SyncInternal::OnServerConnectionEvent( |
| 1776 const ServerConnectionEvent& event) { | 1770 const ServerConnectionEvent& event) { |
| 1777 DCHECK(thread_checker_.CalledOnValidThread()); | 1771 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1778 if (event.connection_code == | 1772 if (event.connection_code == |
| 1779 syncer::HttpResponse::SERVER_CONNECTION_OK) { | 1773 HttpResponse::SERVER_CONNECTION_OK) { |
| 1780 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 1774 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| 1781 OnConnectionStatusChange(CONNECTION_OK)); | 1775 OnConnectionStatusChange(CONNECTION_OK)); |
| 1782 } | 1776 } |
| 1783 | 1777 |
| 1784 if (event.connection_code == syncer::HttpResponse::SYNC_AUTH_ERROR) { | 1778 if (event.connection_code == HttpResponse::SYNC_AUTH_ERROR) { |
| 1785 observing_ip_address_changes_ = false; | 1779 observing_ip_address_changes_ = false; |
| 1786 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 1780 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| 1787 OnConnectionStatusChange(CONNECTION_AUTH_ERROR)); | 1781 OnConnectionStatusChange(CONNECTION_AUTH_ERROR)); |
| 1788 } | 1782 } |
| 1789 | 1783 |
| 1790 if (event.connection_code == | 1784 if (event.connection_code == |
| 1791 syncer::HttpResponse::SYNC_SERVER_ERROR) { | 1785 HttpResponse::SYNC_SERVER_ERROR) { |
| 1792 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 1786 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| 1793 OnConnectionStatusChange(CONNECTION_SERVER_ERROR)); | 1787 OnConnectionStatusChange(CONNECTION_SERVER_ERROR)); |
| 1794 } | 1788 } |
| 1795 } | 1789 } |
| 1796 | 1790 |
| 1797 void SyncManagerImpl::SyncInternal::HandleTransactionCompleteChangeEvent( | 1791 void SyncManagerImpl::SyncInternal::HandleTransactionCompleteChangeEvent( |
| 1798 ModelTypeSet models_with_changes) { | 1792 ModelTypeSet models_with_changes) { |
| 1799 // This notification happens immediately after the transaction mutex is | 1793 // This notification happens immediately after the transaction mutex is |
| 1800 // released. This allows work to be performed without blocking other threads | 1794 // released. This allows work to be performed without blocking other threads |
| 1801 // from acquiring a transaction. | 1795 // from acquiring a transaction. |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 1823 if (!change_delegate_ || ChangeBuffersAreEmpty()) | 1817 if (!change_delegate_ || ChangeBuffersAreEmpty()) |
| 1824 return ModelTypeSet(); | 1818 return ModelTypeSet(); |
| 1825 | 1819 |
| 1826 // This will continue the WriteTransaction using a read only wrapper. | 1820 // This will continue the WriteTransaction using a read only wrapper. |
| 1827 // This is the last chance for read to occur in the WriteTransaction | 1821 // This is the last chance for read to occur in the WriteTransaction |
| 1828 // that's closing. This special ReadTransaction will not close the | 1822 // that's closing. This special ReadTransaction will not close the |
| 1829 // underlying transaction. | 1823 // underlying transaction. |
| 1830 ReadTransaction read_trans(GetUserShare(), trans); | 1824 ReadTransaction read_trans(GetUserShare(), trans); |
| 1831 | 1825 |
| 1832 ModelTypeSet models_with_changes; | 1826 ModelTypeSet models_with_changes; |
| 1833 for (int i = syncer::FIRST_REAL_MODEL_TYPE; | 1827 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { |
| 1834 i < syncer::MODEL_TYPE_COUNT; ++i) { | 1828 const ModelType type = ModelTypeFromInt(i); |
| 1835 const syncer::ModelType type = syncer::ModelTypeFromInt(i); | |
| 1836 if (change_buffers_[type].IsEmpty()) | 1829 if (change_buffers_[type].IsEmpty()) |
| 1837 continue; | 1830 continue; |
| 1838 | 1831 |
| 1839 ImmutableChangeRecordList ordered_changes; | 1832 ImmutableChangeRecordList ordered_changes; |
| 1840 // TODO(akalin): Propagate up the error further (see | 1833 // TODO(akalin): Propagate up the error further (see |
| 1841 // http://crbug.com/100907). | 1834 // http://crbug.com/100907). |
| 1842 CHECK(change_buffers_[type].GetAllChangesInTreeOrder(&read_trans, | 1835 CHECK(change_buffers_[type].GetAllChangesInTreeOrder(&read_trans, |
| 1843 &ordered_changes)); | 1836 &ordered_changes)); |
| 1844 if (!ordered_changes.Get().empty()) { | 1837 if (!ordered_changes.Get().empty()) { |
| 1845 change_delegate_-> | 1838 change_delegate_-> |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 1860 syncable::BaseTransaction* trans) { | 1853 syncable::BaseTransaction* trans) { |
| 1861 if (!scheduler()) { | 1854 if (!scheduler()) { |
| 1862 return; | 1855 return; |
| 1863 } | 1856 } |
| 1864 | 1857 |
| 1865 // We have been notified about a user action changing a sync model. | 1858 // We have been notified about a user action changing a sync model. |
| 1866 LOG_IF(WARNING, !ChangeBuffersAreEmpty()) << | 1859 LOG_IF(WARNING, !ChangeBuffersAreEmpty()) << |
| 1867 "CALCULATE_CHANGES called with unapplied old changes."; | 1860 "CALCULATE_CHANGES called with unapplied old changes."; |
| 1868 | 1861 |
| 1869 // The mutated model type, or UNSPECIFIED if nothing was mutated. | 1862 // The mutated model type, or UNSPECIFIED if nothing was mutated. |
| 1870 syncer::ModelTypeSet mutated_model_types; | 1863 ModelTypeSet mutated_model_types; |
| 1871 | 1864 |
| 1872 const syncable::ImmutableEntryKernelMutationMap& mutations = | 1865 const syncable::ImmutableEntryKernelMutationMap& mutations = |
| 1873 write_transaction_info.Get().mutations; | 1866 write_transaction_info.Get().mutations; |
| 1874 for (syncable::EntryKernelMutationMap::const_iterator it = | 1867 for (syncable::EntryKernelMutationMap::const_iterator it = |
| 1875 mutations.Get().begin(); it != mutations.Get().end(); ++it) { | 1868 mutations.Get().begin(); it != mutations.Get().end(); ++it) { |
| 1876 if (!it->second.mutated.ref(syncable::IS_UNSYNCED)) { | 1869 if (!it->second.mutated.ref(syncable::IS_UNSYNCED)) { |
| 1877 continue; | 1870 continue; |
| 1878 } | 1871 } |
| 1879 | 1872 |
| 1880 syncer::ModelType model_type = | 1873 ModelType model_type = |
| 1881 syncer::GetModelTypeFromSpecifics( | 1874 GetModelTypeFromSpecifics( |
|
Nicolas Zea
2012/07/19 19:37:56
move onto previous line?
akalin
2012/07/19 20:56:02
Done.
| |
| 1882 it->second.mutated.ref(SPECIFICS)); | 1875 it->second.mutated.ref(SPECIFICS)); |
| 1883 if (model_type < syncer::FIRST_REAL_MODEL_TYPE) { | 1876 if (model_type < FIRST_REAL_MODEL_TYPE) { |
| 1884 NOTREACHED() << "Permanent or underspecified item changed via syncapi."; | 1877 NOTREACHED() << "Permanent or underspecified item changed via syncapi."; |
| 1885 continue; | 1878 continue; |
| 1886 } | 1879 } |
| 1887 | 1880 |
| 1888 // Found real mutation. | 1881 // Found real mutation. |
| 1889 if (model_type != syncer::UNSPECIFIED) { | 1882 if (model_type != UNSPECIFIED) { |
| 1890 mutated_model_types.Put(model_type); | 1883 mutated_model_types.Put(model_type); |
| 1891 } | 1884 } |
| 1892 } | 1885 } |
| 1893 | 1886 |
| 1894 // Nudge if necessary. | 1887 // Nudge if necessary. |
| 1895 if (!mutated_model_types.Empty()) { | 1888 if (!mutated_model_types.Empty()) { |
| 1896 if (weak_handle_this_.IsInitialized()) { | 1889 if (weak_handle_this_.IsInitialized()) { |
| 1897 weak_handle_this_.Call(FROM_HERE, | 1890 weak_handle_this_.Call(FROM_HERE, |
| 1898 &SyncInternal::RequestNudgeForDataTypes, | 1891 &SyncInternal::RequestNudgeForDataTypes, |
| 1899 FROM_HERE, | 1892 FROM_HERE, |
| 1900 mutated_model_types); | 1893 mutated_model_types); |
| 1901 } else { | 1894 } else { |
| 1902 NOTREACHED(); | 1895 NOTREACHED(); |
| 1903 } | 1896 } |
| 1904 } | 1897 } |
| 1905 } | 1898 } |
| 1906 | 1899 |
| 1907 void SyncManagerImpl::SyncInternal::SetExtraChangeRecordData(int64 id, | 1900 void SyncManagerImpl::SyncInternal::SetExtraChangeRecordData(int64 id, |
| 1908 syncer::ModelType type, ChangeReorderBuffer* buffer, | 1901 ModelType type, ChangeReorderBuffer* buffer, |
| 1909 Cryptographer* cryptographer, const syncable::EntryKernel& original, | 1902 Cryptographer* cryptographer, const syncable::EntryKernel& original, |
| 1910 bool existed_before, bool exists_now) { | 1903 bool existed_before, bool exists_now) { |
| 1911 // If this is a deletion and the datatype was encrypted, we need to decrypt it | 1904 // If this is a deletion and the datatype was encrypted, we need to decrypt it |
| 1912 // and attach it to the buffer. | 1905 // and attach it to the buffer. |
| 1913 if (!exists_now && existed_before) { | 1906 if (!exists_now && existed_before) { |
| 1914 sync_pb::EntitySpecifics original_specifics(original.ref(SPECIFICS)); | 1907 sync_pb::EntitySpecifics original_specifics(original.ref(SPECIFICS)); |
| 1915 if (type == syncer::PASSWORDS) { | 1908 if (type == PASSWORDS) { |
| 1916 // Passwords must use their own legacy ExtraPasswordChangeRecordData. | 1909 // Passwords must use their own legacy ExtraPasswordChangeRecordData. |
| 1917 scoped_ptr<sync_pb::PasswordSpecificsData> data( | 1910 scoped_ptr<sync_pb::PasswordSpecificsData> data( |
| 1918 DecryptPasswordSpecifics(original_specifics, cryptographer)); | 1911 DecryptPasswordSpecifics(original_specifics, cryptographer)); |
| 1919 if (!data.get()) { | 1912 if (!data.get()) { |
| 1920 NOTREACHED(); | 1913 NOTREACHED(); |
| 1921 return; | 1914 return; |
| 1922 } | 1915 } |
| 1923 buffer->SetExtraDataForId(id, new ExtraPasswordChangeRecordData(*data)); | 1916 buffer->SetExtraDataForId(id, new ExtraPasswordChangeRecordData(*data)); |
| 1924 } else if (original_specifics.has_encrypted()) { | 1917 } else if (original_specifics.has_encrypted()) { |
| 1925 // All other datatypes can just create a new unencrypted specifics and | 1918 // All other datatypes can just create a new unencrypted specifics and |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 1944 | 1937 |
| 1945 Cryptographer* crypto = directory()->GetCryptographer(trans); | 1938 Cryptographer* crypto = directory()->GetCryptographer(trans); |
| 1946 const syncable::ImmutableEntryKernelMutationMap& mutations = | 1939 const syncable::ImmutableEntryKernelMutationMap& mutations = |
| 1947 write_transaction_info.Get().mutations; | 1940 write_transaction_info.Get().mutations; |
| 1948 for (syncable::EntryKernelMutationMap::const_iterator it = | 1941 for (syncable::EntryKernelMutationMap::const_iterator it = |
| 1949 mutations.Get().begin(); it != mutations.Get().end(); ++it) { | 1942 mutations.Get().begin(); it != mutations.Get().end(); ++it) { |
| 1950 bool existed_before = !it->second.original.ref(syncable::IS_DEL); | 1943 bool existed_before = !it->second.original.ref(syncable::IS_DEL); |
| 1951 bool exists_now = !it->second.mutated.ref(syncable::IS_DEL); | 1944 bool exists_now = !it->second.mutated.ref(syncable::IS_DEL); |
| 1952 | 1945 |
| 1953 // Omit items that aren't associated with a model. | 1946 // Omit items that aren't associated with a model. |
| 1954 syncer::ModelType type = | 1947 ModelType type = |
| 1955 syncer::GetModelTypeFromSpecifics( | 1948 GetModelTypeFromSpecifics( |
|
Nicolas Zea
2012/07/19 19:37:56
here too
akalin
2012/07/19 20:56:02
Done.
| |
| 1956 it->second.mutated.ref(SPECIFICS)); | 1949 it->second.mutated.ref(SPECIFICS)); |
| 1957 if (type < syncer::FIRST_REAL_MODEL_TYPE) | 1950 if (type < FIRST_REAL_MODEL_TYPE) |
| 1958 continue; | 1951 continue; |
| 1959 | 1952 |
| 1960 int64 handle = it->first; | 1953 int64 handle = it->first; |
| 1961 if (exists_now && !existed_before) | 1954 if (exists_now && !existed_before) |
| 1962 change_buffers_[type].PushAddedItem(handle); | 1955 change_buffers_[type].PushAddedItem(handle); |
| 1963 else if (!exists_now && existed_before) | 1956 else if (!exists_now && existed_before) |
| 1964 change_buffers_[type].PushDeletedItem(handle); | 1957 change_buffers_[type].PushDeletedItem(handle); |
| 1965 else if (exists_now && existed_before && | 1958 else if (exists_now && existed_before && |
| 1966 VisiblePropertiesDiffer(it->second, crypto)) { | 1959 VisiblePropertiesDiffer(it->second, crypto)) { |
| 1967 change_buffers_[type].PushUpdatedItem( | 1960 change_buffers_[type].PushUpdatedItem( |
| 1968 handle, VisiblePositionsDiffer(it->second)); | 1961 handle, VisiblePositionsDiffer(it->second)); |
| 1969 } | 1962 } |
| 1970 | 1963 |
| 1971 SetExtraChangeRecordData(handle, type, &change_buffers_[type], crypto, | 1964 SetExtraChangeRecordData(handle, type, &change_buffers_[type], crypto, |
| 1972 it->second.original, existed_before, exists_now); | 1965 it->second.original, existed_before, exists_now); |
| 1973 } | 1966 } |
| 1974 } | 1967 } |
| 1975 | 1968 |
| 1976 SyncStatus SyncManagerImpl::SyncInternal::GetStatus() { | 1969 SyncStatus SyncManagerImpl::SyncInternal::GetStatus() { |
| 1977 return allstatus_.status(); | 1970 return allstatus_.status(); |
| 1978 } | 1971 } |
| 1979 | 1972 |
| 1980 void SyncManagerImpl::SyncInternal::RequestNudge( | 1973 void SyncManagerImpl::SyncInternal::RequestNudge( |
| 1981 const tracked_objects::Location& location) { | 1974 const tracked_objects::Location& location) { |
| 1982 if (scheduler()) { | 1975 if (scheduler()) { |
| 1983 scheduler()->ScheduleNudgeAsync( | 1976 scheduler()->ScheduleNudgeAsync( |
| 1984 TimeDelta::FromMilliseconds(0), syncer::NUDGE_SOURCE_LOCAL, | 1977 TimeDelta::FromMilliseconds(0), NUDGE_SOURCE_LOCAL, |
| 1985 ModelTypeSet(), location); | 1978 ModelTypeSet(), location); |
| 1986 } | 1979 } |
| 1987 } | 1980 } |
| 1988 | 1981 |
| 1989 TimeDelta SyncManagerImpl::SyncInternal::GetNudgeDelayTimeDelta( | 1982 TimeDelta SyncManagerImpl::SyncInternal::GetNudgeDelayTimeDelta( |
| 1990 const ModelType& model_type) { | 1983 const ModelType& model_type) { |
| 1991 return NudgeStrategy::GetNudgeDelayTimeDelta(model_type, this); | 1984 return NudgeStrategy::GetNudgeDelayTimeDelta(model_type, this); |
| 1992 } | 1985 } |
| 1993 | 1986 |
| 1994 void SyncManagerImpl::SyncInternal::RequestNudgeForDataTypes( | 1987 void SyncManagerImpl::SyncInternal::RequestNudgeForDataTypes( |
| 1995 const tracked_objects::Location& nudge_location, | 1988 const tracked_objects::Location& nudge_location, |
| 1996 ModelTypeSet types) { | 1989 ModelTypeSet types) { |
| 1997 if (!scheduler()) { | 1990 if (!scheduler()) { |
| 1998 NOTREACHED(); | 1991 NOTREACHED(); |
| 1999 return; | 1992 return; |
| 2000 } | 1993 } |
| 2001 | 1994 |
| 2002 debug_info_event_listener_.OnNudgeFromDatatype(types.First().Get()); | 1995 debug_info_event_listener_.OnNudgeFromDatatype(types.First().Get()); |
| 2003 | 1996 |
| 2004 // TODO(lipalani) : Calculate the nudge delay based on all types. | 1997 // TODO(lipalani) : Calculate the nudge delay based on all types. |
| 2005 base::TimeDelta nudge_delay = NudgeStrategy::GetNudgeDelayTimeDelta( | 1998 base::TimeDelta nudge_delay = NudgeStrategy::GetNudgeDelayTimeDelta( |
| 2006 types.First().Get(), | 1999 types.First().Get(), |
| 2007 this); | 2000 this); |
| 2008 scheduler()->ScheduleNudgeAsync(nudge_delay, | 2001 scheduler()->ScheduleNudgeAsync(nudge_delay, |
| 2009 syncer::NUDGE_SOURCE_LOCAL, | 2002 NUDGE_SOURCE_LOCAL, |
| 2010 types, | 2003 types, |
| 2011 nudge_location); | 2004 nudge_location); |
| 2012 } | 2005 } |
| 2013 | 2006 |
| 2014 void SyncManagerImpl::SyncInternal::OnSyncEngineEvent( | 2007 void SyncManagerImpl::SyncInternal::OnSyncEngineEvent( |
| 2015 const SyncEngineEvent& event) { | 2008 const SyncEngineEvent& event) { |
| 2016 DCHECK(thread_checker_.CalledOnValidThread()); | 2009 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2017 // Only send an event if this is due to a cycle ending and this cycle | 2010 // Only send an event if this is due to a cycle ending and this cycle |
| 2018 // concludes a canonical "sync" process; that is, based on what is known | 2011 // concludes a canonical "sync" process; that is, based on what is known |
| 2019 // locally we are "all happy" and up-to-date. There may be new changes on | 2012 // locally we are "all happy" and up-to-date. There may be new changes on |
| 2020 // the server, but we'll get them on a subsequent sync. | 2013 // the server, but we'll get them on a subsequent sync. |
| 2021 // | 2014 // |
| 2022 // Notifications are sent at the end of every sync cycle, regardless of | 2015 // Notifications are sent at the end of every sync cycle, regardless of |
| 2023 // whether we should sync again. | 2016 // whether we should sync again. |
| 2024 if (event.what_happened == SyncEngineEvent::SYNC_CYCLE_ENDED) { | 2017 if (event.what_happened == SyncEngineEvent::SYNC_CYCLE_ENDED) { |
| 2025 { | 2018 { |
| 2026 // Check to see if we need to notify the frontend that we have newly | 2019 // Check to see if we need to notify the frontend that we have newly |
| 2027 // encrypted types or that we require a passphrase. | 2020 // encrypted types or that we require a passphrase. |
| 2028 ReadTransaction trans(FROM_HERE, GetUserShare()); | 2021 ReadTransaction trans(FROM_HERE, GetUserShare()); |
| 2029 Cryptographer* cryptographer = trans.GetCryptographer(); | 2022 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 2030 // If we've completed a sync cycle and the cryptographer isn't ready | 2023 // If we've completed a sync cycle and the cryptographer isn't ready |
| 2031 // yet, prompt the user for a passphrase. | 2024 // yet, prompt the user for a passphrase. |
| 2032 if (cryptographer->has_pending_keys()) { | 2025 if (cryptographer->has_pending_keys()) { |
| 2033 DVLOG(1) << "OnPassPhraseRequired Sent"; | 2026 DVLOG(1) << "OnPassPhraseRequired Sent"; |
| 2034 sync_pb::EncryptedData pending_keys = cryptographer->GetPendingKeys(); | 2027 sync_pb::EncryptedData pending_keys = cryptographer->GetPendingKeys(); |
| 2035 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 2028 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| 2036 OnPassphraseRequired(syncer::REASON_DECRYPTION, | 2029 OnPassphraseRequired(REASON_DECRYPTION, |
| 2037 pending_keys)); | 2030 pending_keys)); |
| 2038 } else if (!cryptographer->is_ready() && | 2031 } else if (!cryptographer->is_ready() && |
| 2039 event.snapshot.initial_sync_ended().Has(syncer::NIGORI)) { | 2032 event.snapshot.initial_sync_ended().Has(NIGORI)) { |
| 2040 DVLOG(1) << "OnPassphraseRequired sent because cryptographer is not " | 2033 DVLOG(1) << "OnPassphraseRequired sent because cryptographer is not " |
| 2041 << "ready"; | 2034 << "ready"; |
| 2042 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 2035 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| 2043 OnPassphraseRequired(syncer::REASON_ENCRYPTION, | 2036 OnPassphraseRequired(REASON_ENCRYPTION, |
| 2044 sync_pb::EncryptedData())); | 2037 sync_pb::EncryptedData())); |
| 2045 } | 2038 } |
| 2046 | 2039 |
| 2047 NotifyCryptographerState(cryptographer); | 2040 NotifyCryptographerState(cryptographer); |
| 2048 allstatus_.SetEncryptedTypes(cryptographer->GetEncryptedTypes()); | 2041 allstatus_.SetEncryptedTypes(cryptographer->GetEncryptedTypes()); |
| 2049 } | 2042 } |
| 2050 | 2043 |
| 2051 if (!initialized_) { | 2044 if (!initialized_) { |
| 2052 LOG(INFO) << "OnSyncCycleCompleted not sent because sync api is not " | 2045 LOG(INFO) << "OnSyncCycleCompleted not sent because sync api is not " |
| 2053 << "initialized"; | 2046 << "initialized"; |
| 2054 return; | 2047 return; |
| 2055 } | 2048 } |
| 2056 | 2049 |
| 2057 if (!event.snapshot.has_more_to_sync()) { | 2050 if (!event.snapshot.has_more_to_sync()) { |
| 2058 // To account for a nigori node arriving with stale/bad data, we ensure | 2051 // To account for a nigori node arriving with stale/bad data, we ensure |
| 2059 // that the nigori node is up to date at the end of each cycle. | 2052 // that the nigori node is up to date at the end of each cycle. |
| 2060 WriteTransaction trans(FROM_HERE, GetUserShare()); | 2053 WriteTransaction trans(FROM_HERE, GetUserShare()); |
| 2061 WriteNode nigori_node(&trans); | 2054 WriteNode nigori_node(&trans); |
| 2062 if (nigori_node.InitByTagLookup(kNigoriTag) == | 2055 if (nigori_node.InitByTagLookup(kNigoriTag) == |
| 2063 syncer::BaseNode::INIT_OK) { | 2056 BaseNode::INIT_OK) { |
| 2064 Cryptographer* cryptographer = trans.GetCryptographer(); | 2057 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 2065 UpdateNigoriEncryptionState(cryptographer, &nigori_node); | 2058 UpdateNigoriEncryptionState(cryptographer, &nigori_node); |
| 2066 } | 2059 } |
| 2067 | 2060 |
| 2068 DVLOG(1) << "Sending OnSyncCycleCompleted"; | 2061 DVLOG(1) << "Sending OnSyncCycleCompleted"; |
| 2069 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 2062 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| 2070 OnSyncCycleCompleted(event.snapshot)); | 2063 OnSyncCycleCompleted(event.snapshot)); |
| 2071 } | 2064 } |
| 2072 | 2065 |
| 2073 // This is here for tests, which are still using p2p notifications. | 2066 // This is here for tests, which are still using p2p notifications. |
| 2074 // | 2067 // |
| 2075 // TODO(chron): Consider changing this back to track has_more_to_sync | 2068 // TODO(chron): Consider changing this back to track has_more_to_sync |
| 2076 // only notify peers if a successful commit has occurred. | 2069 // only notify peers if a successful commit has occurred. |
| 2077 bool is_notifiable_commit = | 2070 bool is_notifiable_commit = |
| 2078 (event.snapshot.model_neutral_state().num_successful_commits > 0); | 2071 (event.snapshot.model_neutral_state().num_successful_commits > 0); |
| 2079 if (is_notifiable_commit) { | 2072 if (is_notifiable_commit) { |
| 2080 if (sync_notifier_.get()) { | 2073 if (sync_notifier_.get()) { |
| 2081 const ModelTypeSet changed_types = | 2074 const ModelTypeSet changed_types = |
| 2082 syncer::ModelTypePayloadMapToEnumSet( | 2075 ModelTypePayloadMapToEnumSet(event.snapshot.source().types); |
| 2083 event.snapshot.source().types); | |
| 2084 sync_notifier_->SendNotification(changed_types); | 2076 sync_notifier_->SendNotification(changed_types); |
| 2085 } else { | 2077 } else { |
| 2086 DVLOG(1) << "Not sending notification: sync_notifier_ is NULL"; | 2078 DVLOG(1) << "Not sending notification: sync_notifier_ is NULL"; |
| 2087 } | 2079 } |
| 2088 } | 2080 } |
| 2089 } | 2081 } |
| 2090 | 2082 |
| 2091 if (event.what_happened == SyncEngineEvent::STOP_SYNCING_PERMANENTLY) { | 2083 if (event.what_happened == SyncEngineEvent::STOP_SYNCING_PERMANENTLY) { |
| 2092 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 2084 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| 2093 OnStopSyncingPermanently()); | 2085 OnStopSyncingPermanently()); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2150 base::Bind(unbound_message_handler, base::Unretained(this)); | 2142 base::Bind(unbound_message_handler, base::Unretained(this)); |
| 2151 } | 2143 } |
| 2152 | 2144 |
| 2153 DictionaryValue* SyncManagerImpl::SyncInternal::NotificationInfoToValue( | 2145 DictionaryValue* SyncManagerImpl::SyncInternal::NotificationInfoToValue( |
| 2154 const NotificationInfoMap& notification_info) { | 2146 const NotificationInfoMap& notification_info) { |
| 2155 DictionaryValue* value = new DictionaryValue(); | 2147 DictionaryValue* value = new DictionaryValue(); |
| 2156 | 2148 |
| 2157 for (NotificationInfoMap::const_iterator it = notification_info.begin(); | 2149 for (NotificationInfoMap::const_iterator it = notification_info.begin(); |
| 2158 it != notification_info.end(); ++it) { | 2150 it != notification_info.end(); ++it) { |
| 2159 const std::string& model_type_str = | 2151 const std::string& model_type_str = |
| 2160 syncer::ModelTypeToString(it->first); | 2152 ModelTypeToString(it->first); |
| 2161 value->Set(model_type_str, it->second.ToValue()); | 2153 value->Set(model_type_str, it->second.ToValue()); |
| 2162 } | 2154 } |
| 2163 | 2155 |
| 2164 return value; | 2156 return value; |
| 2165 } | 2157 } |
| 2166 | 2158 |
| 2167 JsArgList SyncManagerImpl::SyncInternal::GetNotificationState( | 2159 JsArgList SyncManagerImpl::SyncInternal::GetNotificationState( |
| 2168 const JsArgList& args) { | 2160 const JsArgList& args) { |
| 2169 bool notifications_enabled = allstatus_.status().notifications_enabled; | 2161 bool notifications_enabled = allstatus_.status().notifications_enabled; |
| 2170 ListValue return_args; | 2162 ListValue return_args; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2222 ListValue* id_list = NULL; | 2214 ListValue* id_list = NULL; |
| 2223 ReadTransaction trans(FROM_HERE, user_share); | 2215 ReadTransaction trans(FROM_HERE, user_share); |
| 2224 if (args.Get().GetList(0, &id_list)) { | 2216 if (args.Get().GetList(0, &id_list)) { |
| 2225 CHECK(id_list); | 2217 CHECK(id_list); |
| 2226 for (size_t i = 0; i < id_list->GetSize(); ++i) { | 2218 for (size_t i = 0; i < id_list->GetSize(); ++i) { |
| 2227 int64 id = GetId(*id_list, i); | 2219 int64 id = GetId(*id_list, i); |
| 2228 if (id == kInvalidId) { | 2220 if (id == kInvalidId) { |
| 2229 continue; | 2221 continue; |
| 2230 } | 2222 } |
| 2231 ReadNode node(&trans); | 2223 ReadNode node(&trans); |
| 2232 if (node.InitByIdLookup(id) != syncer::BaseNode::INIT_OK) { | 2224 if (node.InitByIdLookup(id) != BaseNode::INIT_OK) { |
| 2233 continue; | 2225 continue; |
| 2234 } | 2226 } |
| 2235 node_summaries->Append((node.*info_getter)()); | 2227 node_summaries->Append((node.*info_getter)()); |
| 2236 } | 2228 } |
| 2237 } | 2229 } |
| 2238 return JsArgList(&return_args); | 2230 return JsArgList(&return_args); |
| 2239 } | 2231 } |
| 2240 | 2232 |
| 2241 } // namespace | 2233 } // namespace |
| 2242 | 2234 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2283 for (syncable::Directory::ChildHandles::const_iterator it = | 2275 for (syncable::Directory::ChildHandles::const_iterator it = |
| 2284 child_handles.begin(); it != child_handles.end(); ++it) { | 2276 child_handles.begin(); it != child_handles.end(); ++it) { |
| 2285 child_ids->Append(Value::CreateStringValue( | 2277 child_ids->Append(Value::CreateStringValue( |
| 2286 base::Int64ToString(*it))); | 2278 base::Int64ToString(*it))); |
| 2287 } | 2279 } |
| 2288 } | 2280 } |
| 2289 return JsArgList(&return_args); | 2281 return JsArgList(&return_args); |
| 2290 } | 2282 } |
| 2291 | 2283 |
| 2292 void SyncManagerImpl::SyncInternal::OnEncryptedTypesChanged( | 2284 void SyncManagerImpl::SyncInternal::OnEncryptedTypesChanged( |
| 2293 syncer::ModelTypeSet encrypted_types, | 2285 ModelTypeSet encrypted_types, |
| 2294 bool encrypt_everything) { | 2286 bool encrypt_everything) { |
| 2295 // NOTE: We're in a transaction. | 2287 // NOTE: We're in a transaction. |
| 2296 FOR_EACH_OBSERVER( | 2288 FOR_EACH_OBSERVER( |
| 2297 SyncManager::Observer, observers_, | 2289 SyncManager::Observer, observers_, |
| 2298 OnEncryptedTypesChanged(encrypted_types, encrypt_everything)); | 2290 OnEncryptedTypesChanged(encrypted_types, encrypt_everything)); |
| 2299 } | 2291 } |
| 2300 | 2292 |
| 2301 void SyncManagerImpl::SyncInternal::UpdateNotificationInfo( | 2293 void SyncManagerImpl::SyncInternal::UpdateNotificationInfo( |
| 2302 const syncer::ModelTypePayloadMap& type_payloads) { | 2294 const ModelTypePayloadMap& type_payloads) { |
| 2303 for (syncer::ModelTypePayloadMap::const_iterator it = type_payloads.begin(); | 2295 for (ModelTypePayloadMap::const_iterator it = type_payloads.begin(); |
| 2304 it != type_payloads.end(); ++it) { | 2296 it != type_payloads.end(); ++it) { |
| 2305 NotificationInfo* info = ¬ification_info_map_[it->first]; | 2297 NotificationInfo* info = ¬ification_info_map_[it->first]; |
| 2306 info->total_count++; | 2298 info->total_count++; |
| 2307 info->payload = it->second; | 2299 info->payload = it->second; |
| 2308 } | 2300 } |
| 2309 } | 2301 } |
| 2310 | 2302 |
| 2311 void SyncManagerImpl::SyncInternal::OnNotificationsEnabled() { | 2303 void SyncManagerImpl::SyncInternal::OnNotificationsEnabled() { |
| 2312 DVLOG(1) << "Notifications enabled"; | 2304 DVLOG(1) << "Notifications enabled"; |
| 2313 allstatus_.SetNotificationsEnabled(true); | 2305 allstatus_.SetNotificationsEnabled(true); |
| 2314 if (scheduler()) { | 2306 if (scheduler()) { |
| 2315 scheduler()->set_notifications_enabled(true); | 2307 scheduler()->set_notifications_enabled(true); |
| 2316 } | 2308 } |
| 2317 // TODO(akalin): Separate onNotificationStateChange into | 2309 // TODO(akalin): Separate onNotificationStateChange into |
| 2318 // enabled/disabled events. | 2310 // enabled/disabled events. |
| 2319 if (js_event_handler_.IsInitialized()) { | 2311 if (js_event_handler_.IsInitialized()) { |
| 2320 DictionaryValue details; | 2312 DictionaryValue details; |
| 2321 details.Set("enabled", Value::CreateBooleanValue(true)); | 2313 details.Set("enabled", Value::CreateBooleanValue(true)); |
| 2322 js_event_handler_.Call(FROM_HERE, | 2314 js_event_handler_.Call(FROM_HERE, |
| 2323 &JsEventHandler::HandleJsEvent, | 2315 &JsEventHandler::HandleJsEvent, |
| 2324 "onNotificationStateChange", | 2316 "onNotificationStateChange", |
| 2325 JsEventDetails(&details)); | 2317 JsEventDetails(&details)); |
| 2326 } | 2318 } |
| 2327 } | 2319 } |
| 2328 | 2320 |
| 2329 void SyncManagerImpl::SyncInternal::OnNotificationsDisabled( | 2321 void SyncManagerImpl::SyncInternal::OnNotificationsDisabled( |
| 2330 syncer::NotificationsDisabledReason reason) { | 2322 NotificationsDisabledReason reason) { |
| 2331 DVLOG(1) << "Notifications disabled with reason " | 2323 DVLOG(1) << "Notifications disabled with reason " |
| 2332 << syncer::NotificationsDisabledReasonToString(reason); | 2324 << NotificationsDisabledReasonToString(reason); |
| 2333 allstatus_.SetNotificationsEnabled(false); | 2325 allstatus_.SetNotificationsEnabled(false); |
| 2334 if (scheduler()) { | 2326 if (scheduler()) { |
| 2335 scheduler()->set_notifications_enabled(false); | 2327 scheduler()->set_notifications_enabled(false); |
| 2336 } | 2328 } |
| 2337 if (js_event_handler_.IsInitialized()) { | 2329 if (js_event_handler_.IsInitialized()) { |
| 2338 DictionaryValue details; | 2330 DictionaryValue details; |
| 2339 details.Set("enabled", Value::CreateBooleanValue(false)); | 2331 details.Set("enabled", Value::CreateBooleanValue(false)); |
| 2340 js_event_handler_.Call(FROM_HERE, | 2332 js_event_handler_.Call(FROM_HERE, |
| 2341 &JsEventHandler::HandleJsEvent, | 2333 &JsEventHandler::HandleJsEvent, |
| 2342 "onNotificationStateChange", | 2334 "onNotificationStateChange", |
| 2343 JsEventDetails(&details)); | 2335 JsEventDetails(&details)); |
| 2344 } | 2336 } |
| 2345 // TODO(akalin): Treat a CREDENTIALS_REJECTED state as an auth | 2337 // TODO(akalin): Treat a CREDENTIALS_REJECTED state as an auth |
| 2346 // error. | 2338 // error. |
| 2347 } | 2339 } |
| 2348 | 2340 |
| 2349 void SyncManagerImpl::SyncInternal::OnIncomingNotification( | 2341 void SyncManagerImpl::SyncInternal::OnIncomingNotification( |
| 2350 const syncer::ModelTypePayloadMap& type_payloads, | 2342 const ModelTypePayloadMap& type_payloads, |
| 2351 syncer::IncomingNotificationSource source) { | 2343 IncomingNotificationSource source) { |
| 2352 DCHECK(thread_checker_.CalledOnValidThread()); | 2344 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2353 if (source == syncer::LOCAL_NOTIFICATION) { | 2345 if (source == LOCAL_NOTIFICATION) { |
| 2354 if (scheduler()) { | 2346 if (scheduler()) { |
| 2355 scheduler()->ScheduleNudgeWithPayloadsAsync( | 2347 scheduler()->ScheduleNudgeWithPayloadsAsync( |
| 2356 TimeDelta::FromMilliseconds(kSyncRefreshDelayMsec), | 2348 TimeDelta::FromMilliseconds(kSyncRefreshDelayMsec), |
| 2357 syncer::NUDGE_SOURCE_LOCAL_REFRESH, | 2349 NUDGE_SOURCE_LOCAL_REFRESH, |
| 2358 type_payloads, FROM_HERE); | 2350 type_payloads, FROM_HERE); |
| 2359 } | 2351 } |
| 2360 } else if (!type_payloads.empty()) { | 2352 } else if (!type_payloads.empty()) { |
| 2361 if (scheduler()) { | 2353 if (scheduler()) { |
| 2362 scheduler()->ScheduleNudgeWithPayloadsAsync( | 2354 scheduler()->ScheduleNudgeWithPayloadsAsync( |
| 2363 TimeDelta::FromMilliseconds(kSyncSchedulerDelayMsec), | 2355 TimeDelta::FromMilliseconds(kSyncSchedulerDelayMsec), |
| 2364 syncer::NUDGE_SOURCE_NOTIFICATION, | 2356 NUDGE_SOURCE_NOTIFICATION, |
| 2365 type_payloads, FROM_HERE); | 2357 type_payloads, FROM_HERE); |
| 2366 } | 2358 } |
| 2367 allstatus_.IncrementNotificationsReceived(); | 2359 allstatus_.IncrementNotificationsReceived(); |
| 2368 UpdateNotificationInfo(type_payloads); | 2360 UpdateNotificationInfo(type_payloads); |
| 2369 debug_info_event_listener_.OnIncomingNotification(type_payloads); | 2361 debug_info_event_listener_.OnIncomingNotification(type_payloads); |
| 2370 } else { | 2362 } else { |
| 2371 LOG(WARNING) << "Sync received notification without any type information."; | 2363 LOG(WARNING) << "Sync received notification without any type information."; |
| 2372 } | 2364 } |
| 2373 | 2365 |
| 2374 if (js_event_handler_.IsInitialized()) { | 2366 if (js_event_handler_.IsInitialized()) { |
| 2375 DictionaryValue details; | 2367 DictionaryValue details; |
| 2376 ListValue* changed_types = new ListValue(); | 2368 ListValue* changed_types = new ListValue(); |
| 2377 details.Set("changedTypes", changed_types); | 2369 details.Set("changedTypes", changed_types); |
| 2378 for (syncer::ModelTypePayloadMap::const_iterator | 2370 for (ModelTypePayloadMap::const_iterator it = type_payloads.begin(); |
| 2379 it = type_payloads.begin(); | |
| 2380 it != type_payloads.end(); ++it) { | 2371 it != type_payloads.end(); ++it) { |
| 2381 const std::string& model_type_str = | 2372 const std::string& model_type_str = |
| 2382 syncer::ModelTypeToString(it->first); | 2373 ModelTypeToString(it->first); |
| 2383 changed_types->Append(Value::CreateStringValue(model_type_str)); | 2374 changed_types->Append(Value::CreateStringValue(model_type_str)); |
| 2384 } | 2375 } |
| 2385 details.SetString("source", (source == syncer::LOCAL_NOTIFICATION) ? | 2376 details.SetString("source", (source == LOCAL_NOTIFICATION) ? |
| 2386 "LOCAL_NOTIFICATION" : "REMOTE_NOTIFICATION"); | 2377 "LOCAL_NOTIFICATION" : "REMOTE_NOTIFICATION"); |
| 2387 js_event_handler_.Call(FROM_HERE, | 2378 js_event_handler_.Call(FROM_HERE, |
| 2388 &JsEventHandler::HandleJsEvent, | 2379 &JsEventHandler::HandleJsEvent, |
| 2389 "onIncomingNotification", | 2380 "onIncomingNotification", |
| 2390 JsEventDetails(&details)); | 2381 JsEventDetails(&details)); |
| 2391 } | 2382 } |
| 2392 } | 2383 } |
| 2393 | 2384 |
| 2394 void SyncManagerImpl::SyncInternal::AddObserver( | 2385 void SyncManagerImpl::SyncInternal::AddObserver( |
| 2395 SyncManager::Observer* observer) { | 2386 SyncManager::Observer* observer) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2434 TimeDelta SyncManagerImpl::GetNudgeDelayTimeDelta( | 2425 TimeDelta SyncManagerImpl::GetNudgeDelayTimeDelta( |
| 2435 const ModelType& model_type) { | 2426 const ModelType& model_type) { |
| 2436 return data_->GetNudgeDelayTimeDelta(model_type); | 2427 return data_->GetNudgeDelayTimeDelta(model_type); |
| 2437 } | 2428 } |
| 2438 | 2429 |
| 2439 void SyncManagerImpl::SetSyncSchedulerForTest( | 2430 void SyncManagerImpl::SetSyncSchedulerForTest( |
| 2440 scoped_ptr<SyncScheduler> scheduler) { | 2431 scoped_ptr<SyncScheduler> scheduler) { |
| 2441 data_->SetSyncSchedulerForTest(scheduler.Pass()); | 2432 data_->SetSyncSchedulerForTest(scheduler.Pass()); |
| 2442 } | 2433 } |
| 2443 | 2434 |
| 2444 syncer::ModelTypeSet SyncManagerImpl::GetEncryptedDataTypesForTest() const { | 2435 ModelTypeSet SyncManagerImpl::GetEncryptedDataTypesForTest() const { |
| 2445 ReadTransaction trans(FROM_HERE, GetUserShare()); | 2436 ReadTransaction trans(FROM_HERE, GetUserShare()); |
| 2446 return GetEncryptedTypes(&trans); | 2437 return GetEncryptedTypes(&trans); |
| 2447 } | 2438 } |
| 2448 | 2439 |
| 2449 bool SyncManagerImpl::ReceivedExperiment( | 2440 bool SyncManagerImpl::ReceivedExperiment(Experiments* experiments) const { |
| 2450 syncer::Experiments* experiments) const { | |
| 2451 ReadTransaction trans(FROM_HERE, GetUserShare()); | 2441 ReadTransaction trans(FROM_HERE, GetUserShare()); |
| 2452 ReadNode node(&trans); | 2442 ReadNode node(&trans); |
| 2453 if (node.InitByTagLookup(kNigoriTag) != syncer::BaseNode::INIT_OK) { | 2443 if (node.InitByTagLookup(kNigoriTag) != BaseNode::INIT_OK) { |
| 2454 DVLOG(1) << "Couldn't find Nigori node."; | 2444 DVLOG(1) << "Couldn't find Nigori node."; |
| 2455 return false; | 2445 return false; |
| 2456 } | 2446 } |
| 2457 bool found_experiment = false; | 2447 bool found_experiment = false; |
| 2458 if (node.GetNigoriSpecifics().sync_tab_favicons()) { | 2448 if (node.GetNigoriSpecifics().sync_tab_favicons()) { |
| 2459 experiments->sync_tab_favicons = true; | 2449 experiments->sync_tab_favicons = true; |
| 2460 found_experiment = true; | 2450 found_experiment = true; |
| 2461 } | 2451 } |
| 2462 return found_experiment; | 2452 return found_experiment; |
| 2463 } | 2453 } |
| 2464 | 2454 |
| 2465 bool SyncManagerImpl::HasUnsyncedItems() const { | 2455 bool SyncManagerImpl::HasUnsyncedItems() const { |
| 2466 syncer::ReadTransaction trans(FROM_HERE, GetUserShare()); | 2456 ReadTransaction trans(FROM_HERE, GetUserShare()); |
| 2467 return (trans.GetWrappedTrans()->directory()->unsynced_entity_count() != 0); | 2457 return (trans.GetWrappedTrans()->directory()->unsynced_entity_count() != 0); |
| 2468 } | 2458 } |
| 2469 | 2459 |
| 2470 void SyncManagerImpl::SimulateEnableNotificationsForTest() { | 2460 void SyncManagerImpl::SimulateEnableNotificationsForTest() { |
| 2471 DCHECK(thread_checker_.CalledOnValidThread()); | 2461 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2472 data_->OnNotificationsEnabled(); | 2462 data_->OnNotificationsEnabled(); |
| 2473 } | 2463 } |
| 2474 | 2464 |
| 2475 void SyncManagerImpl::SimulateDisableNotificationsForTest(int reason) { | 2465 void SyncManagerImpl::SimulateDisableNotificationsForTest(int reason) { |
| 2476 DCHECK(thread_checker_.CalledOnValidThread()); | 2466 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2477 data_->OnNotificationsDisabled( | 2467 data_->OnNotificationsDisabled( |
| 2478 static_cast<syncer::NotificationsDisabledReason>(reason)); | 2468 static_cast<NotificationsDisabledReason>(reason)); |
| 2479 } | 2469 } |
| 2480 | 2470 |
| 2481 void SyncManagerImpl::TriggerOnIncomingNotificationForTest( | 2471 void SyncManagerImpl::TriggerOnIncomingNotificationForTest( |
| 2482 ModelTypeSet model_types) { | 2472 ModelTypeSet model_types) { |
| 2483 DCHECK(thread_checker_.CalledOnValidThread()); | 2473 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2484 syncer::ModelTypePayloadMap model_types_with_payloads = | 2474 ModelTypePayloadMap model_types_with_payloads = |
| 2485 syncer::ModelTypePayloadMapFromEnumSet(model_types, | 2475 ModelTypePayloadMapFromEnumSet(model_types, |
| 2486 std::string()); | 2476 std::string()); |
| 2487 | 2477 |
| 2488 data_->OnIncomingNotification(model_types_with_payloads, | 2478 data_->OnIncomingNotification(model_types_with_payloads, |
| 2489 syncer::REMOTE_NOTIFICATION); | 2479 REMOTE_NOTIFICATION); |
| 2490 } | 2480 } |
| 2491 | 2481 |
| 2492 // static. | 2482 // static. |
| 2493 int SyncManagerImpl::GetDefaultNudgeDelay() { | 2483 int SyncManagerImpl::GetDefaultNudgeDelay() { |
| 2494 return kDefaultNudgeDelayMilliseconds; | 2484 return kDefaultNudgeDelayMilliseconds; |
| 2495 } | 2485 } |
| 2496 | 2486 |
| 2497 // static. | 2487 // static. |
| 2498 int SyncManagerImpl::GetPreferencesNudgeDelay() { | 2488 int SyncManagerImpl::GetPreferencesNudgeDelay() { |
| 2499 return kPreferencesNudgeDelayMilliseconds; | 2489 return kPreferencesNudgeDelayMilliseconds; |
| 2500 } | 2490 } |
| 2501 | 2491 |
| 2502 } // namespace syncer | 2492 } // namespace syncer |
| OLD | NEW |