| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 #include "sync/syncable/directory.h" | 47 #include "sync/syncable/directory.h" |
| 48 #include "sync/syncable/entry.h" | 48 #include "sync/syncable/entry.h" |
| 49 #include "sync/syncable/in_memory_directory_backing_store.h" | 49 #include "sync/syncable/in_memory_directory_backing_store.h" |
| 50 #include "sync/syncable/nigori_util.h" | 50 #include "sync/syncable/nigori_util.h" |
| 51 #include "sync/syncable/on_disk_directory_backing_store.h" | 51 #include "sync/syncable/on_disk_directory_backing_store.h" |
| 52 #include "sync/util/get_session_name.h" | 52 #include "sync/util/get_session_name.h" |
| 53 | 53 |
| 54 using base::TimeDelta; | 54 using base::TimeDelta; |
| 55 using sync_pb::GetUpdatesCallerInfo; | 55 using sync_pb::GetUpdatesCallerInfo; |
| 56 | 56 |
| 57 namespace syncer { |
| 58 |
| 59 using sessions::SyncSessionContext; |
| 60 using syncable::ImmutableWriteTransactionInfo; |
| 61 using syncable::SPECIFICS; |
| 62 |
| 57 namespace { | 63 namespace { |
| 58 | 64 |
| 59 // Delays for syncer nudges. | 65 // Delays for syncer nudges. |
| 60 static const int kDefaultNudgeDelayMilliseconds = 200; | 66 static const int kDefaultNudgeDelayMilliseconds = 200; |
| 61 static const int kPreferencesNudgeDelayMilliseconds = 2000; | 67 static const int kPreferencesNudgeDelayMilliseconds = 2000; |
| 62 static const int kSyncRefreshDelayMsec = 500; | 68 static const int kSyncRefreshDelayMsec = 500; |
| 63 static const int kSyncSchedulerDelayMsec = 250; | 69 static const int kSyncSchedulerDelayMsec = 250; |
| 64 | 70 |
| 71 // The maximum number of times we will automatically overwrite the nigori node |
| 72 // because the encryption keys don't match (per chrome instantiation). |
| 73 static const int kNigoriOverwriteLimit = 10; |
| 74 |
| 75 // Maximum count and size for traffic recorder. |
| 76 static const unsigned int kMaxMessagesToRecord = 10; |
| 77 static const unsigned int kMaxMessageSizeToRecord = 5 * 1024; |
| 78 |
| 65 GetUpdatesCallerInfo::GetUpdatesSource GetSourceFromReason( | 79 GetUpdatesCallerInfo::GetUpdatesSource GetSourceFromReason( |
| 66 syncer::ConfigureReason reason) { | 80 ConfigureReason reason) { |
| 67 switch (reason) { | 81 switch (reason) { |
| 68 case syncer::CONFIGURE_REASON_RECONFIGURATION: | 82 case CONFIGURE_REASON_RECONFIGURATION: |
| 69 return GetUpdatesCallerInfo::RECONFIGURATION; | 83 return GetUpdatesCallerInfo::RECONFIGURATION; |
| 70 case syncer::CONFIGURE_REASON_MIGRATION: | 84 case CONFIGURE_REASON_MIGRATION: |
| 71 return GetUpdatesCallerInfo::MIGRATION; | 85 return GetUpdatesCallerInfo::MIGRATION; |
| 72 case syncer::CONFIGURE_REASON_NEW_CLIENT: | 86 case CONFIGURE_REASON_NEW_CLIENT: |
| 73 return GetUpdatesCallerInfo::NEW_CLIENT; | 87 return GetUpdatesCallerInfo::NEW_CLIENT; |
| 74 case syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE: | 88 case CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE: |
| 75 return GetUpdatesCallerInfo::NEWLY_SUPPORTED_DATATYPE; | 89 return GetUpdatesCallerInfo::NEWLY_SUPPORTED_DATATYPE; |
| 76 default: | 90 default: |
| 77 NOTREACHED(); | 91 NOTREACHED(); |
| 78 } | 92 } |
| 79 return GetUpdatesCallerInfo::UNKNOWN; | 93 return GetUpdatesCallerInfo::UNKNOWN; |
| 80 } | 94 } |
| 81 | 95 |
| 82 // The maximum number of times we will automatically overwrite the nigori node | 96 } // namespace |
| 83 // because the encryption keys don't match (per chrome instantiation). | |
| 84 static const int kNigoriOverwriteLimit = 10; | |
| 85 | |
| 86 } // namespace | |
| 87 | |
| 88 namespace syncer { | |
| 89 | |
| 90 using sessions::SyncSessionContext; | |
| 91 using syncable::ImmutableWriteTransactionInfo; | |
| 92 using syncable::SPECIFICS; | |
| 93 | |
| 94 // Maximum count and size for traffic recorder. | |
| 95 const unsigned int kMaxMessagesToRecord = 10; | |
| 96 const unsigned int kMaxMessageSizeToRecord = 5 * 1024; | |
| 97 | 97 |
| 98 // A class to calculate nudge delays for types. | 98 // A class to calculate nudge delays for types. |
| 99 class NudgeStrategy { | 99 class NudgeStrategy { |
| 100 public: | 100 public: |
| 101 static TimeDelta GetNudgeDelayTimeDelta(const ModelType& model_type, | 101 static TimeDelta GetNudgeDelayTimeDelta(const ModelType& model_type, |
| 102 SyncManagerImpl* core) { | 102 SyncManagerImpl* core) { |
| 103 NudgeDelayStrategy delay_type = GetNudgeDelayStrategy(model_type); | 103 NudgeDelayStrategy delay_type = GetNudgeDelayStrategy(model_type); |
| 104 return GetNudgeDelayTimeDeltaFromType(delay_type, | 104 return GetNudgeDelayTimeDeltaFromType(delay_type, |
| 105 model_type, | 105 model_type, |
| 106 core); | 106 core); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 117 // Sync this change while syncing another change. | 117 // Sync this change while syncing another change. |
| 118 ACCOMPANY_ONLY, | 118 ACCOMPANY_ONLY, |
| 119 | 119 |
| 120 // The datatype does not use one of the predefined wait times but defines | 120 // The datatype does not use one of the predefined wait times but defines |
| 121 // its own wait time logic for nudge. | 121 // its own wait time logic for nudge. |
| 122 CUSTOM, | 122 CUSTOM, |
| 123 }; | 123 }; |
| 124 | 124 |
| 125 static NudgeDelayStrategy GetNudgeDelayStrategy(const ModelType& type) { | 125 static NudgeDelayStrategy GetNudgeDelayStrategy(const ModelType& type) { |
| 126 switch (type) { | 126 switch (type) { |
| 127 case syncer::AUTOFILL: | 127 case AUTOFILL: |
| 128 return ACCOMPANY_ONLY; | 128 return ACCOMPANY_ONLY; |
| 129 case syncer::PREFERENCES: | 129 case PREFERENCES: |
| 130 case syncer::SESSIONS: | 130 case SESSIONS: |
| 131 return CUSTOM; | 131 return CUSTOM; |
| 132 default: | 132 default: |
| 133 return IMMEDIATE; | 133 return IMMEDIATE; |
| 134 } | 134 } |
| 135 } | 135 } |
| 136 | 136 |
| 137 static TimeDelta GetNudgeDelayTimeDeltaFromType( | 137 static TimeDelta GetNudgeDelayTimeDeltaFromType( |
| 138 const NudgeDelayStrategy& delay_type, const ModelType& model_type, | 138 const NudgeDelayStrategy& delay_type, const ModelType& model_type, |
| 139 const SyncManagerImpl* core) { | 139 const SyncManagerImpl* core) { |
| 140 CHECK(core); | 140 CHECK(core); |
| 141 TimeDelta delay = TimeDelta::FromMilliseconds( | 141 TimeDelta delay = TimeDelta::FromMilliseconds( |
| 142 kDefaultNudgeDelayMilliseconds); | 142 kDefaultNudgeDelayMilliseconds); |
| 143 switch (delay_type) { | 143 switch (delay_type) { |
| 144 case IMMEDIATE: | 144 case IMMEDIATE: |
| 145 delay = TimeDelta::FromMilliseconds( | 145 delay = TimeDelta::FromMilliseconds( |
| 146 kDefaultNudgeDelayMilliseconds); | 146 kDefaultNudgeDelayMilliseconds); |
| 147 break; | 147 break; |
| 148 case ACCOMPANY_ONLY: | 148 case ACCOMPANY_ONLY: |
| 149 delay = TimeDelta::FromSeconds( | 149 delay = TimeDelta::FromSeconds(kDefaultShortPollIntervalSeconds); |
| 150 syncer::kDefaultShortPollIntervalSeconds); | |
| 151 break; | 150 break; |
| 152 case CUSTOM: | 151 case CUSTOM: |
| 153 switch (model_type) { | 152 switch (model_type) { |
| 154 case syncer::PREFERENCES: | 153 case PREFERENCES: |
| 155 delay = TimeDelta::FromMilliseconds( | 154 delay = TimeDelta::FromMilliseconds( |
| 156 kPreferencesNudgeDelayMilliseconds); | 155 kPreferencesNudgeDelayMilliseconds); |
| 157 break; | 156 break; |
| 158 case syncer::SESSIONS: | 157 case SESSIONS: |
| 159 delay = core->scheduler()->GetSessionsCommitDelay(); | 158 delay = core->scheduler()->GetSessionsCommitDelay(); |
| 160 break; | 159 break; |
| 161 default: | 160 default: |
| 162 NOTREACHED(); | 161 NOTREACHED(); |
| 163 } | 162 } |
| 164 break; | 163 break; |
| 165 default: | 164 default: |
| 166 NOTREACHED(); | 165 NOTREACHED(); |
| 167 } | 166 } |
| 168 return delay; | 167 return delay; |
| 169 } | 168 } |
| 170 }; | 169 }; |
| 171 | 170 |
| 172 SyncManagerImpl::SyncManagerImpl(const std::string& name) | 171 SyncManagerImpl::SyncManagerImpl(const std::string& name) |
| 173 : name_(name), | 172 : name_(name), |
| 174 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 173 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 175 change_delegate_(NULL), | 174 change_delegate_(NULL), |
| 176 initialized_(false), | 175 initialized_(false), |
| 177 observing_ip_address_changes_(false), | 176 observing_ip_address_changes_(false), |
| 178 throttled_data_type_tracker_(&allstatus_), | 177 throttled_data_type_tracker_(&allstatus_), |
| 179 traffic_recorder_(kMaxMessagesToRecord, kMaxMessageSizeToRecord), | 178 traffic_recorder_(kMaxMessagesToRecord, kMaxMessageSizeToRecord), |
| 180 encryptor_(NULL), | 179 encryptor_(NULL), |
| 181 unrecoverable_error_handler_(NULL), | 180 unrecoverable_error_handler_(NULL), |
| 182 report_unrecoverable_error_function_(NULL), | 181 report_unrecoverable_error_function_(NULL), |
| 183 nigori_overwrite_count_(0) { | 182 nigori_overwrite_count_(0) { |
| 184 // Pre-fill |notification_info_map_|. | 183 // Pre-fill |notification_info_map_|. |
| 185 for (int i = syncer::FIRST_REAL_MODEL_TYPE; | 184 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { |
| 186 i < syncer::MODEL_TYPE_COUNT; ++i) { | |
| 187 notification_info_map_.insert( | 185 notification_info_map_.insert( |
| 188 std::make_pair(syncer::ModelTypeFromInt(i), NotificationInfo())); | 186 std::make_pair(ModelTypeFromInt(i), NotificationInfo())); |
| 189 } | 187 } |
| 190 | 188 |
| 191 // Bind message handlers. | 189 // Bind message handlers. |
| 192 BindJsMessageHandler( | 190 BindJsMessageHandler( |
| 193 "getNotificationState", | 191 "getNotificationState", |
| 194 &SyncManagerImpl::GetNotificationState); | 192 &SyncManagerImpl::GetNotificationState); |
| 195 BindJsMessageHandler( | 193 BindJsMessageHandler( |
| 196 "getNotificationInfo", | 194 "getNotificationInfo", |
| 197 &SyncManagerImpl::GetNotificationInfo); | 195 &SyncManagerImpl::GetNotificationInfo); |
| 198 BindJsMessageHandler( | 196 BindJsMessageHandler( |
| (...skipping 30 matching lines...) Expand all Loading... |
| 229 value->SetString("payload", payload); | 227 value->SetString("payload", payload); |
| 230 return value; | 228 return value; |
| 231 } | 229 } |
| 232 | 230 |
| 233 bool SyncManagerImpl::VisiblePositionsDiffer( | 231 bool SyncManagerImpl::VisiblePositionsDiffer( |
| 234 const syncable::EntryKernelMutation& mutation) const { | 232 const syncable::EntryKernelMutation& mutation) const { |
| 235 const syncable::EntryKernel& a = mutation.original; | 233 const syncable::EntryKernel& a = mutation.original; |
| 236 const syncable::EntryKernel& b = mutation.mutated; | 234 const syncable::EntryKernel& b = mutation.mutated; |
| 237 // If the datatype isn't one where the browser model cares about position, | 235 // If the datatype isn't one where the browser model cares about position, |
| 238 // don't bother notifying that data model of position-only changes. | 236 // don't bother notifying that data model of position-only changes. |
| 239 if (!ShouldMaintainPosition( | 237 if (!ShouldMaintainPosition(GetModelTypeFromSpecifics(b.ref(SPECIFICS)))) { |
| 240 syncer::GetModelTypeFromSpecifics(b.ref(SPECIFICS)))) { | |
| 241 return false; | 238 return false; |
| 242 } | 239 } |
| 243 if (a.ref(syncable::NEXT_ID) != b.ref(syncable::NEXT_ID)) | 240 if (a.ref(syncable::NEXT_ID) != b.ref(syncable::NEXT_ID)) |
| 244 return true; | 241 return true; |
| 245 if (a.ref(syncable::PARENT_ID) != b.ref(syncable::PARENT_ID)) | 242 if (a.ref(syncable::PARENT_ID) != b.ref(syncable::PARENT_ID)) |
| 246 return true; | 243 return true; |
| 247 return false; | 244 return false; |
| 248 } | 245 } |
| 249 | 246 |
| 250 bool SyncManagerImpl::VisiblePropertiesDiffer( | 247 bool SyncManagerImpl::VisiblePropertiesDiffer( |
| 251 const syncable::EntryKernelMutation& mutation, | 248 const syncable::EntryKernelMutation& mutation, |
| 252 Cryptographer* cryptographer) const { | 249 Cryptographer* cryptographer) const { |
| 253 const syncable::EntryKernel& a = mutation.original; | 250 const syncable::EntryKernel& a = mutation.original; |
| 254 const syncable::EntryKernel& b = mutation.mutated; | 251 const syncable::EntryKernel& b = mutation.mutated; |
| 255 const sync_pb::EntitySpecifics& a_specifics = a.ref(SPECIFICS); | 252 const sync_pb::EntitySpecifics& a_specifics = a.ref(SPECIFICS); |
| 256 const sync_pb::EntitySpecifics& b_specifics = b.ref(SPECIFICS); | 253 const sync_pb::EntitySpecifics& b_specifics = b.ref(SPECIFICS); |
| 257 DCHECK_EQ(syncer::GetModelTypeFromSpecifics(a_specifics), | 254 DCHECK_EQ(GetModelTypeFromSpecifics(a_specifics), |
| 258 syncer::GetModelTypeFromSpecifics(b_specifics)); | 255 GetModelTypeFromSpecifics(b_specifics)); |
| 259 syncer::ModelType model_type = | 256 ModelType model_type = GetModelTypeFromSpecifics(b_specifics); |
| 260 syncer::GetModelTypeFromSpecifics(b_specifics); | |
| 261 // Suppress updates to items that aren't tracked by any browser model. | 257 // Suppress updates to items that aren't tracked by any browser model. |
| 262 if (model_type < syncer::FIRST_REAL_MODEL_TYPE || | 258 if (model_type < FIRST_REAL_MODEL_TYPE || |
| 263 !a.ref(syncable::UNIQUE_SERVER_TAG).empty()) { | 259 !a.ref(syncable::UNIQUE_SERVER_TAG).empty()) { |
| 264 return false; | 260 return false; |
| 265 } | 261 } |
| 266 if (a.ref(syncable::IS_DIR) != b.ref(syncable::IS_DIR)) | 262 if (a.ref(syncable::IS_DIR) != b.ref(syncable::IS_DIR)) |
| 267 return true; | 263 return true; |
| 268 if (!AreSpecificsEqual(cryptographer, | 264 if (!AreSpecificsEqual(cryptographer, |
| 269 a.ref(syncable::SPECIFICS), | 265 a.ref(syncable::SPECIFICS), |
| 270 b.ref(syncable::SPECIFICS))) { | 266 b.ref(syncable::SPECIFICS))) { |
| 271 return true; | 267 return true; |
| 272 } | 268 } |
| 273 // We only care if the name has changed if neither specifics is encrypted | 269 // We only care if the name has changed if neither specifics is encrypted |
| 274 // (encrypted nodes blow away the NON_UNIQUE_NAME). | 270 // (encrypted nodes blow away the NON_UNIQUE_NAME). |
| 275 if (!a_specifics.has_encrypted() && !b_specifics.has_encrypted() && | 271 if (!a_specifics.has_encrypted() && !b_specifics.has_encrypted() && |
| 276 a.ref(syncable::NON_UNIQUE_NAME) != b.ref(syncable::NON_UNIQUE_NAME)) | 272 a.ref(syncable::NON_UNIQUE_NAME) != b.ref(syncable::NON_UNIQUE_NAME)) |
| 277 return true; | 273 return true; |
| 278 if (VisiblePositionsDiffer(mutation)) | 274 if (VisiblePositionsDiffer(mutation)) |
| 279 return true; | 275 return true; |
| 280 return false; | 276 return false; |
| 281 } | 277 } |
| 282 | 278 |
| 283 bool SyncManagerImpl::ChangeBuffersAreEmpty() { | 279 bool SyncManagerImpl::ChangeBuffersAreEmpty() { |
| 284 for (int i = 0; i < syncer::MODEL_TYPE_COUNT; ++i) { | 280 for (int i = 0; i < MODEL_TYPE_COUNT; ++i) { |
| 285 if (!change_buffers_[i].IsEmpty()) | 281 if (!change_buffers_[i].IsEmpty()) |
| 286 return false; | 282 return false; |
| 287 } | 283 } |
| 288 return true; | 284 return true; |
| 289 } | 285 } |
| 290 | 286 |
| 291 void SyncManagerImpl::ThrowUnrecoverableError() { | 287 void SyncManagerImpl::ThrowUnrecoverableError() { |
| 292 DCHECK(thread_checker_.CalledOnValidThread()); | 288 DCHECK(thread_checker_.CalledOnValidThread()); |
| 293 ReadTransaction trans(FROM_HERE, GetUserShare()); | 289 ReadTransaction trans(FROM_HERE, GetUserShare()); |
| 294 trans.GetWrappedTrans()->OnUnrecoverableError( | 290 trans.GetWrappedTrans()->OnUnrecoverableError( |
| 295 FROM_HERE, "Simulating unrecoverable error for testing purposes."); | 291 FROM_HERE, "Simulating unrecoverable error for testing purposes."); |
| 296 } | 292 } |
| 297 | 293 |
| 298 syncer::ModelTypeSet SyncManagerImpl::InitialSyncEndedTypes() { | 294 ModelTypeSet SyncManagerImpl::InitialSyncEndedTypes() { |
| 299 DCHECK(initialized_); | 295 DCHECK(initialized_); |
| 300 return directory()->initial_sync_ended_types(); | 296 return directory()->initial_sync_ended_types(); |
| 301 } | 297 } |
| 302 | 298 |
| 303 syncer::ModelTypeSet SyncManagerImpl::GetTypesWithEmptyProgressMarkerToken( | 299 ModelTypeSet SyncManagerImpl::GetTypesWithEmptyProgressMarkerToken( |
| 304 syncer::ModelTypeSet types) { | 300 ModelTypeSet types) { |
| 305 DCHECK(initialized_); | 301 DCHECK(initialized_); |
| 306 syncer::ModelTypeSet result; | 302 ModelTypeSet result; |
| 307 for (syncer::ModelTypeSet::Iterator i = types.First(); | 303 for (ModelTypeSet::Iterator i = types.First(); i.Good(); i.Inc()) { |
| 308 i.Good(); i.Inc()) { | |
| 309 sync_pb::DataTypeProgressMarker marker; | 304 sync_pb::DataTypeProgressMarker marker; |
| 310 directory()->GetDownloadProgress(i.Get(), &marker); | 305 directory()->GetDownloadProgress(i.Get(), &marker); |
| 311 | 306 |
| 312 if (marker.token().empty()) | 307 if (marker.token().empty()) |
| 313 result.Put(i.Get()); | 308 result.Put(i.Get()); |
| 314 | 309 |
| 315 } | 310 } |
| 316 return result; | 311 return result; |
| 317 } | 312 } |
| 318 | 313 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 334 RefreshEncryption(); | 329 RefreshEncryption(); |
| 335 } | 330 } |
| 336 | 331 |
| 337 bool SyncManagerImpl::EncryptEverythingEnabledForTest() { | 332 bool SyncManagerImpl::EncryptEverythingEnabledForTest() { |
| 338 ReadTransaction trans(FROM_HERE, GetUserShare()); | 333 ReadTransaction trans(FROM_HERE, GetUserShare()); |
| 339 return trans.GetCryptographer()->encrypt_everything(); | 334 return trans.GetCryptographer()->encrypt_everything(); |
| 340 } | 335 } |
| 341 | 336 |
| 342 void SyncManagerImpl::ConfigureSyncer( | 337 void SyncManagerImpl::ConfigureSyncer( |
| 343 ConfigureReason reason, | 338 ConfigureReason reason, |
| 344 const syncer::ModelTypeSet& types_to_config, | 339 const ModelTypeSet& types_to_config, |
| 345 const syncer::ModelSafeRoutingInfo& new_routing_info, | 340 const ModelSafeRoutingInfo& new_routing_info, |
| 346 const base::Closure& ready_task, | 341 const base::Closure& ready_task, |
| 347 const base::Closure& retry_task) { | 342 const base::Closure& retry_task) { |
| 348 DCHECK(thread_checker_.CalledOnValidThread()); | 343 DCHECK(thread_checker_.CalledOnValidThread()); |
| 349 DCHECK(!ready_task.is_null()); | 344 DCHECK(!ready_task.is_null()); |
| 350 DCHECK(!retry_task.is_null()); | 345 DCHECK(!retry_task.is_null()); |
| 351 | 346 |
| 352 // TODO(zea): set this based on whether cryptographer has keystore | 347 // TODO(zea): set this based on whether cryptographer has keystore |
| 353 // encryption key or not (requires opening a transaction). crbug.com/129665. | 348 // encryption key or not (requires opening a transaction). crbug.com/129665. |
| 354 ConfigurationParams::KeystoreKeyStatus keystore_key_status = | 349 ConfigurationParams::KeystoreKeyStatus keystore_key_status = |
| 355 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY; | 350 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY; |
| 356 | 351 |
| 357 ConfigurationParams params(GetSourceFromReason(reason), | 352 ConfigurationParams params(GetSourceFromReason(reason), |
| 358 types_to_config, | 353 types_to_config, |
| 359 new_routing_info, | 354 new_routing_info, |
| 360 keystore_key_status, | 355 keystore_key_status, |
| 361 ready_task); | 356 ready_task); |
| 362 | 357 |
| 363 scheduler_->Start(syncer::SyncScheduler::CONFIGURATION_MODE); | 358 scheduler_->Start(SyncScheduler::CONFIGURATION_MODE); |
| 364 if (!scheduler_->ScheduleConfiguration(params)) | 359 if (!scheduler_->ScheduleConfiguration(params)) |
| 365 retry_task.Run(); | 360 retry_task.Run(); |
| 366 | 361 |
| 367 } | 362 } |
| 368 | 363 |
| 369 bool SyncManagerImpl::Init( | 364 bool SyncManagerImpl::Init( |
| 370 const FilePath& database_location, | 365 const FilePath& database_location, |
| 371 const WeakHandle<JsEventHandler>& event_handler, | 366 const WeakHandle<JsEventHandler>& event_handler, |
| 372 const std::string& sync_server_and_path, | 367 const std::string& sync_server_and_path, |
| 373 int port, | 368 int port, |
| 374 bool use_ssl, | 369 bool use_ssl, |
| 375 const scoped_refptr<base::TaskRunner>& blocking_task_runner, | 370 const scoped_refptr<base::TaskRunner>& blocking_task_runner, |
| 376 scoped_ptr<HttpPostProviderFactory> post_factory, | 371 scoped_ptr<HttpPostProviderFactory> post_factory, |
| 377 const syncer::ModelSafeRoutingInfo& model_safe_routing_info, | 372 const ModelSafeRoutingInfo& model_safe_routing_info, |
| 378 const std::vector<syncer::ModelSafeWorker*>& workers, | 373 const std::vector<ModelSafeWorker*>& workers, |
| 379 syncer::ExtensionsActivityMonitor* extensions_activity_monitor, | 374 ExtensionsActivityMonitor* extensions_activity_monitor, |
| 380 SyncManager::ChangeDelegate* change_delegate, | 375 SyncManager::ChangeDelegate* change_delegate, |
| 381 const SyncCredentials& credentials, | 376 const SyncCredentials& credentials, |
| 382 scoped_ptr<syncer::SyncNotifier> sync_notifier, | 377 scoped_ptr<SyncNotifier> sync_notifier, |
| 383 const std::string& restored_key_for_bootstrapping, | 378 const std::string& restored_key_for_bootstrapping, |
| 384 scoped_ptr<InternalComponentsFactory> internal_components_factory, | 379 scoped_ptr<InternalComponentsFactory> internal_components_factory, |
| 385 Encryptor* encryptor, | 380 Encryptor* encryptor, |
| 386 UnrecoverableErrorHandler* unrecoverable_error_handler, | 381 UnrecoverableErrorHandler* unrecoverable_error_handler, |
| 387 ReportUnrecoverableErrorFunction report_unrecoverable_error_function) { | 382 ReportUnrecoverableErrorFunction report_unrecoverable_error_function) { |
| 388 CHECK(!initialized_); | 383 CHECK(!initialized_); |
| 389 DCHECK(thread_checker_.CalledOnValidThread()); | 384 DCHECK(thread_checker_.CalledOnValidThread()); |
| 390 DCHECK(post_factory.get()); | 385 DCHECK(post_factory.get()); |
| 391 DVLOG(1) << "SyncManager starting Init..."; | 386 DVLOG(1) << "SyncManager starting Init..."; |
| 392 | 387 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 listeners, | 440 listeners, |
| 446 &debug_info_event_listener_, | 441 &debug_info_event_listener_, |
| 447 &traffic_recorder_).Pass(); | 442 &traffic_recorder_).Pass(); |
| 448 session_context_->set_account_name(credentials.email); | 443 session_context_->set_account_name(credentials.email); |
| 449 scheduler_ = internal_components_factory->BuildScheduler( | 444 scheduler_ = internal_components_factory->BuildScheduler( |
| 450 name_, session_context_.get()).Pass(); | 445 name_, session_context_.get()).Pass(); |
| 451 | 446 |
| 452 bool success = SignIn(credentials); | 447 bool success = SignIn(credentials); |
| 453 | 448 |
| 454 if (success) { | 449 if (success) { |
| 455 scheduler_->Start(syncer::SyncScheduler::CONFIGURATION_MODE); | 450 scheduler_->Start(SyncScheduler::CONFIGURATION_MODE); |
| 456 | 451 |
| 457 initialized_ = true; | 452 initialized_ = true; |
| 458 | 453 |
| 459 // Unapplied datatypes (those that do not have initial sync ended set) get | 454 // Unapplied datatypes (those that do not have initial sync ended set) get |
| 460 // re-downloaded during any configuration. But, it's possible for a datatype | 455 // re-downloaded during any configuration. But, it's possible for a datatype |
| 461 // to have a progress marker but not have initial sync ended yet, making | 456 // to have a progress marker but not have initial sync ended yet, making |
| 462 // it a candidate for migration. This is a problem, as the DataTypeManager | 457 // it a candidate for migration. This is a problem, as the DataTypeManager |
| 463 // does not support a migration while it's already in the middle of a | 458 // does not support a migration while it's already in the middle of a |
| 464 // configuration. As a result, any partially synced datatype can stall the | 459 // configuration. As a result, any partially synced datatype can stall the |
| 465 // DTM, waiting for the configuration to complete, which it never will due | 460 // DTM, waiting for the configuration to complete, which it never will due |
| (...skipping 27 matching lines...) Expand all Loading... |
| 493 | 488 |
| 494 sync_notifier_->AddObserver(this); | 489 sync_notifier_->AddObserver(this); |
| 495 | 490 |
| 496 return success; | 491 return success; |
| 497 } | 492 } |
| 498 | 493 |
| 499 void SyncManagerImpl::RefreshNigori(const std::string& chrome_version, | 494 void SyncManagerImpl::RefreshNigori(const std::string& chrome_version, |
| 500 const base::Closure& done_callback) { | 495 const base::Closure& done_callback) { |
| 501 DCHECK(initialized_); | 496 DCHECK(initialized_); |
| 502 DCHECK(thread_checker_.CalledOnValidThread()); | 497 DCHECK(thread_checker_.CalledOnValidThread()); |
| 503 syncer::GetSessionName( | 498 GetSessionName( |
| 504 blocking_task_runner_, | 499 blocking_task_runner_, |
| 505 base::Bind( | 500 base::Bind( |
| 506 &SyncManagerImpl::UpdateCryptographerAndNigoriCallback, | 501 &SyncManagerImpl::UpdateCryptographerAndNigoriCallback, |
| 507 weak_ptr_factory_.GetWeakPtr(), | 502 weak_ptr_factory_.GetWeakPtr(), |
| 508 chrome_version, | 503 chrome_version, |
| 509 done_callback)); | 504 done_callback)); |
| 510 } | 505 } |
| 511 | 506 |
| 512 void SyncManagerImpl::UpdateNigoriEncryptionState( | 507 void SyncManagerImpl::UpdateNigoriEncryptionState( |
| 513 Cryptographer* cryptographer, | 508 Cryptographer* cryptographer, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 540 cryptographer->UpdateNigoriFromEncryptedTypes(&nigori); | 535 cryptographer->UpdateNigoriFromEncryptedTypes(&nigori); |
| 541 | 536 |
| 542 // If nothing has changed, this is a no-op. | 537 // If nothing has changed, this is a no-op. |
| 543 nigori_node->SetNigoriSpecifics(nigori); | 538 nigori_node->SetNigoriSpecifics(nigori); |
| 544 } | 539 } |
| 545 | 540 |
| 546 void SyncManagerImpl::UpdateCryptographerAndNigoriCallback( | 541 void SyncManagerImpl::UpdateCryptographerAndNigoriCallback( |
| 547 const std::string& chrome_version, | 542 const std::string& chrome_version, |
| 548 const base::Closure& done_callback, | 543 const base::Closure& done_callback, |
| 549 const std::string& session_name) { | 544 const std::string& session_name) { |
| 550 if (!directory()->initial_sync_ended_for_type(syncer::NIGORI)) { | 545 if (!directory()->initial_sync_ended_for_type(NIGORI)) { |
| 551 done_callback.Run(); // Should only happen during first time sync. | 546 done_callback.Run(); // Should only happen during first time sync. |
| 552 return; | 547 return; |
| 553 } | 548 } |
| 554 | 549 |
| 555 bool success = false; | 550 bool success = false; |
| 556 { | 551 { |
| 557 WriteTransaction trans(FROM_HERE, GetUserShare()); | 552 WriteTransaction trans(FROM_HERE, GetUserShare()); |
| 558 Cryptographer* cryptographer = trans.GetCryptographer(); | 553 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 559 WriteNode node(&trans); | 554 WriteNode node(&trans); |
| 560 | 555 |
| 561 if (node.InitByTagLookup(kNigoriTag) == syncer::BaseNode::INIT_OK) { | 556 if (node.InitByTagLookup(kNigoriTag) == BaseNode::INIT_OK) { |
| 562 sync_pb::NigoriSpecifics nigori(node.GetNigoriSpecifics()); | 557 sync_pb::NigoriSpecifics nigori(node.GetNigoriSpecifics()); |
| 563 Cryptographer::UpdateResult result = cryptographer->Update(nigori); | 558 Cryptographer::UpdateResult result = cryptographer->Update(nigori); |
| 564 if (result == Cryptographer::NEEDS_PASSPHRASE) { | 559 if (result == Cryptographer::NEEDS_PASSPHRASE) { |
| 565 sync_pb::EncryptedData pending_keys; | 560 sync_pb::EncryptedData pending_keys; |
| 566 if (cryptographer->has_pending_keys()) | 561 if (cryptographer->has_pending_keys()) |
| 567 pending_keys = cryptographer->GetPendingKeys(); | 562 pending_keys = cryptographer->GetPendingKeys(); |
| 568 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 563 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| 569 OnPassphraseRequired(syncer::REASON_DECRYPTION, | 564 OnPassphraseRequired(REASON_DECRYPTION, |
| 570 pending_keys)); | 565 pending_keys)); |
| 571 } | 566 } |
| 572 | 567 |
| 573 // Add or update device information. | 568 // Add or update device information. |
| 574 bool contains_this_device = false; | 569 bool contains_this_device = false; |
| 575 for (int i = 0; i < nigori.device_information_size(); ++i) { | 570 for (int i = 0; i < nigori.device_information_size(); ++i) { |
| 576 const sync_pb::DeviceInformation& device_information = | 571 const sync_pb::DeviceInformation& device_information = |
| 577 nigori.device_information(i); | 572 nigori.device_information(i); |
| 578 if (device_information.cache_guid() == directory()->cache_guid()) { | 573 if (device_information.cache_guid() == directory()->cache_guid()) { |
| 579 // Update the version number in case it changed due to an update. | 574 // Update the version number in case it changed due to an update. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 627 // TODO(lipalani): Explore the possibility of hooking this up to | 622 // TODO(lipalani): Explore the possibility of hooking this up to |
| 628 // SyncManager::Observer and making |AllStatus| a listener for that. | 623 // SyncManager::Observer and making |AllStatus| a listener for that. |
| 629 allstatus_.SetCryptographerReady(cryptographer->is_ready()); | 624 allstatus_.SetCryptographerReady(cryptographer->is_ready()); |
| 630 allstatus_.SetCryptoHasPendingKeys(cryptographer->has_pending_keys()); | 625 allstatus_.SetCryptoHasPendingKeys(cryptographer->has_pending_keys()); |
| 631 debug_info_event_listener_.SetCryptographerReady(cryptographer->is_ready()); | 626 debug_info_event_listener_.SetCryptographerReady(cryptographer->is_ready()); |
| 632 debug_info_event_listener_.SetCrytographerHasPendingKeys( | 627 debug_info_event_listener_.SetCrytographerHasPendingKeys( |
| 633 cryptographer->has_pending_keys()); | 628 cryptographer->has_pending_keys()); |
| 634 } | 629 } |
| 635 | 630 |
| 636 void SyncManagerImpl::StartSyncingNormally( | 631 void SyncManagerImpl::StartSyncingNormally( |
| 637 const syncer::ModelSafeRoutingInfo& routing_info) { | 632 const ModelSafeRoutingInfo& routing_info) { |
| 638 // Start the sync scheduler. | 633 // Start the sync scheduler. |
| 639 // TODO(sync): We always want the newest set of routes when we switch back | 634 // TODO(sync): We always want the newest set of routes when we switch back |
| 640 // to normal mode. Figure out how to enforce set_routing_info is always | 635 // to normal mode. Figure out how to enforce set_routing_info is always |
| 641 // appropriately set and that it's only modified when switching to normal | 636 // appropriately set and that it's only modified when switching to normal |
| 642 // mode. | 637 // mode. |
| 643 DCHECK(thread_checker_.CalledOnValidThread()); | 638 DCHECK(thread_checker_.CalledOnValidThread()); |
| 644 session_context_->set_routing_info(routing_info); | 639 session_context_->set_routing_info(routing_info); |
| 645 scheduler_->Start(SyncScheduler::NORMAL_MODE); | 640 scheduler_->Start(SyncScheduler::NORMAL_MODE); |
| 646 } | 641 } |
| 647 | 642 |
| 648 syncable::Directory* SyncManagerImpl::directory() { | 643 syncable::Directory* SyncManagerImpl::directory() { |
| 649 return share_.directory.get(); | 644 return share_.directory.get(); |
| 650 } | 645 } |
| 651 | 646 |
| 652 const SyncScheduler* SyncManagerImpl::scheduler() const { | 647 const SyncScheduler* SyncManagerImpl::scheduler() const { |
| 653 return scheduler_.get(); | 648 return scheduler_.get(); |
| 654 } | 649 } |
| 655 | 650 |
| 656 bool SyncManagerImpl::OpenDirectory() { | 651 bool SyncManagerImpl::OpenDirectory() { |
| 657 DCHECK(!initialized_) << "Should only happen once"; | 652 DCHECK(!initialized_) << "Should only happen once"; |
| 658 | 653 |
| 659 // Set before Open(). | 654 // Set before Open(). |
| 660 change_observer_ = | 655 change_observer_ = MakeWeakHandle(js_mutation_event_observer_.AsWeakPtr()); |
| 661 syncer::MakeWeakHandle(js_mutation_event_observer_.AsWeakPtr()); | |
| 662 WeakHandle<syncable::TransactionObserver> transaction_observer( | 656 WeakHandle<syncable::TransactionObserver> transaction_observer( |
| 663 syncer::MakeWeakHandle(js_mutation_event_observer_.AsWeakPtr())); | 657 MakeWeakHandle(js_mutation_event_observer_.AsWeakPtr())); |
| 664 | 658 |
| 665 syncable::DirOpenResult open_result = syncable::NOT_INITIALIZED; | 659 syncable::DirOpenResult open_result = syncable::NOT_INITIALIZED; |
| 666 open_result = directory()->Open(username_for_share(), this, | 660 open_result = directory()->Open(username_for_share(), this, |
| 667 transaction_observer); | 661 transaction_observer); |
| 668 if (open_result != syncable::OPENED) { | 662 if (open_result != syncable::OPENED) { |
| 669 LOG(ERROR) << "Could not open share for:" << username_for_share(); | 663 LOG(ERROR) << "Could not open share for:" << username_for_share(); |
| 670 return false; | 664 return false; |
| 671 } | 665 } |
| 672 | 666 |
| 673 connection_manager_->set_client_id(directory()->cache_guid()); | 667 connection_manager_->set_client_id(directory()->cache_guid()); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 697 sync_notifier_->SetUniqueId(unique_id); | 691 sync_notifier_->SetUniqueId(unique_id); |
| 698 // TODO(tim): Remove once invalidation state has been migrated to new | 692 // TODO(tim): Remove once invalidation state has been migrated to new |
| 699 // InvalidationStateTracker store. Bug 124140. | 693 // InvalidationStateTracker store. Bug 124140. |
| 700 sync_notifier_->SetStateDeprecated(state); | 694 sync_notifier_->SetStateDeprecated(state); |
| 701 | 695 |
| 702 UpdateCredentials(credentials); | 696 UpdateCredentials(credentials); |
| 703 return true; | 697 return true; |
| 704 } | 698 } |
| 705 | 699 |
| 706 bool SyncManagerImpl::PurgePartiallySyncedTypes() { | 700 bool SyncManagerImpl::PurgePartiallySyncedTypes() { |
| 707 syncer::ModelTypeSet partially_synced_types = | 701 ModelTypeSet partially_synced_types = ModelTypeSet::All(); |
| 708 syncer::ModelTypeSet::All(); | |
| 709 partially_synced_types.RemoveAll(InitialSyncEndedTypes()); | 702 partially_synced_types.RemoveAll(InitialSyncEndedTypes()); |
| 710 partially_synced_types.RemoveAll(GetTypesWithEmptyProgressMarkerToken( | 703 partially_synced_types.RemoveAll(GetTypesWithEmptyProgressMarkerToken( |
| 711 syncer::ModelTypeSet::All())); | 704 ModelTypeSet::All())); |
| 712 | 705 |
| 713 UMA_HISTOGRAM_COUNTS("Sync.PartiallySyncedTypes", | 706 UMA_HISTOGRAM_COUNTS("Sync.PartiallySyncedTypes", |
| 714 partially_synced_types.Size()); | 707 partially_synced_types.Size()); |
| 715 if (partially_synced_types.Empty()) | 708 if (partially_synced_types.Empty()) |
| 716 return true; | 709 return true; |
| 717 return directory()->PurgeEntriesWithTypeIn(partially_synced_types); | 710 return directory()->PurgeEntriesWithTypeIn(partially_synced_types); |
| 718 } | 711 } |
| 719 | 712 |
| 720 void SyncManagerImpl::UpdateCredentials( | 713 void SyncManagerImpl::UpdateCredentials( |
| 721 const SyncCredentials& credentials) { | 714 const SyncCredentials& credentials) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 748 if (passphrase.empty()) { | 741 if (passphrase.empty()) { |
| 749 NOTREACHED() << "Cannot encrypt with an empty passphrase."; | 742 NOTREACHED() << "Cannot encrypt with an empty passphrase."; |
| 750 return; | 743 return; |
| 751 } | 744 } |
| 752 | 745 |
| 753 // All accesses to the cryptographer are protected by a transaction. | 746 // All accesses to the cryptographer are protected by a transaction. |
| 754 WriteTransaction trans(FROM_HERE, GetUserShare()); | 747 WriteTransaction trans(FROM_HERE, GetUserShare()); |
| 755 Cryptographer* cryptographer = trans.GetCryptographer(); | 748 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 756 KeyParams key_params = {"localhost", "dummy", passphrase}; | 749 KeyParams key_params = {"localhost", "dummy", passphrase}; |
| 757 WriteNode node(&trans); | 750 WriteNode node(&trans); |
| 758 if (node.InitByTagLookup(kNigoriTag) != syncer::BaseNode::INIT_OK) { | 751 if (node.InitByTagLookup(kNigoriTag) != BaseNode::INIT_OK) { |
| 759 // TODO(albertb): Plumb an UnrecoverableError all the way back to the PSS. | 752 // TODO(albertb): Plumb an UnrecoverableError all the way back to the PSS. |
| 760 NOTREACHED(); | 753 NOTREACHED(); |
| 761 return; | 754 return; |
| 762 } | 755 } |
| 763 | 756 |
| 764 bool nigori_has_explicit_passphrase = | 757 bool nigori_has_explicit_passphrase = |
| 765 node.GetNigoriSpecifics().using_explicit_passphrase(); | 758 node.GetNigoriSpecifics().using_explicit_passphrase(); |
| 766 std::string bootstrap_token; | 759 std::string bootstrap_token; |
| 767 sync_pb::EncryptedData pending_keys; | 760 sync_pb::EncryptedData pending_keys; |
| 768 if (cryptographer->has_pending_keys()) | 761 if (cryptographer->has_pending_keys()) |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 863 if (passphrase.empty()) { | 856 if (passphrase.empty()) { |
| 864 NOTREACHED() << "Cannot decrypt with an empty passphrase."; | 857 NOTREACHED() << "Cannot decrypt with an empty passphrase."; |
| 865 return; | 858 return; |
| 866 } | 859 } |
| 867 | 860 |
| 868 // All accesses to the cryptographer are protected by a transaction. | 861 // All accesses to the cryptographer are protected by a transaction. |
| 869 WriteTransaction trans(FROM_HERE, GetUserShare()); | 862 WriteTransaction trans(FROM_HERE, GetUserShare()); |
| 870 Cryptographer* cryptographer = trans.GetCryptographer(); | 863 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 871 KeyParams key_params = {"localhost", "dummy", passphrase}; | 864 KeyParams key_params = {"localhost", "dummy", passphrase}; |
| 872 WriteNode node(&trans); | 865 WriteNode node(&trans); |
| 873 if (node.InitByTagLookup(kNigoriTag) != syncer::BaseNode::INIT_OK) { | 866 if (node.InitByTagLookup(kNigoriTag) != BaseNode::INIT_OK) { |
| 874 // TODO(albertb): Plumb an UnrecoverableError all the way back to the PSS. | 867 // TODO(albertb): Plumb an UnrecoverableError all the way back to the PSS. |
| 875 NOTREACHED(); | 868 NOTREACHED(); |
| 876 return; | 869 return; |
| 877 } | 870 } |
| 878 | 871 |
| 879 if (!cryptographer->has_pending_keys()) { | 872 if (!cryptographer->has_pending_keys()) { |
| 880 // Note that this *can* happen in a rare situation where data is | 873 // Note that this *can* happen in a rare situation where data is |
| 881 // re-encrypted on another client while a SetDecryptionPassphrase() call is | 874 // re-encrypted on another client while a SetDecryptionPassphrase() call is |
| 882 // in-flight on this client. It is rare enough that we choose to do nothing. | 875 // in-flight on this client. It is rare enough that we choose to do nothing. |
| 883 NOTREACHED() << "Attempt to set decryption passphrase failed because there " | 876 NOTREACHED() << "Attempt to set decryption passphrase failed because there " |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1016 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 1009 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| 1017 OnBootstrapTokenUpdated(bootstrap_token)); | 1010 OnBootstrapTokenUpdated(bootstrap_token)); |
| 1018 } | 1011 } |
| 1019 | 1012 |
| 1020 if (!success) { | 1013 if (!success) { |
| 1021 if (cryptographer->is_ready()) { | 1014 if (cryptographer->is_ready()) { |
| 1022 LOG(ERROR) << "Attempt to change passphrase failed while cryptographer " | 1015 LOG(ERROR) << "Attempt to change passphrase failed while cryptographer " |
| 1023 << "was ready."; | 1016 << "was ready."; |
| 1024 } else if (cryptographer->has_pending_keys()) { | 1017 } else if (cryptographer->has_pending_keys()) { |
| 1025 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 1018 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| 1026 OnPassphraseRequired(syncer::REASON_DECRYPTION, | 1019 OnPassphraseRequired(REASON_DECRYPTION, |
| 1027 cryptographer->GetPendingKeys())); | 1020 cryptographer->GetPendingKeys())); |
| 1028 } else { | 1021 } else { |
| 1029 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 1022 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| 1030 OnPassphraseRequired(syncer::REASON_ENCRYPTION, | 1023 OnPassphraseRequired(REASON_ENCRYPTION, |
| 1031 sync_pb::EncryptedData())); | 1024 sync_pb::EncryptedData())); |
| 1032 } | 1025 } |
| 1033 return; | 1026 return; |
| 1034 } | 1027 } |
| 1035 | 1028 |
| 1036 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 1029 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| 1037 OnPassphraseAccepted()); | 1030 OnPassphraseAccepted()); |
| 1038 DCHECK(cryptographer->is_ready()); | 1031 DCHECK(cryptographer->is_ready()); |
| 1039 | 1032 |
| 1040 // TODO(tim): Bug 58231. It would be nice if setting a passphrase didn't | 1033 // TODO(tim): Bug 58231. It would be nice if setting a passphrase didn't |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1052 nigori_node->SetNigoriSpecifics(specifics); | 1045 nigori_node->SetNigoriSpecifics(specifics); |
| 1053 | 1046 |
| 1054 // Does nothing if everything is already encrypted or the cryptographer has | 1047 // Does nothing if everything is already encrypted or the cryptographer has |
| 1055 // pending keys. | 1048 // pending keys. |
| 1056 ReEncryptEverything(trans); | 1049 ReEncryptEverything(trans); |
| 1057 } | 1050 } |
| 1058 | 1051 |
| 1059 bool SyncManagerImpl::IsUsingExplicitPassphrase() { | 1052 bool SyncManagerImpl::IsUsingExplicitPassphrase() { |
| 1060 ReadTransaction trans(FROM_HERE, &share_); | 1053 ReadTransaction trans(FROM_HERE, &share_); |
| 1061 ReadNode node(&trans); | 1054 ReadNode node(&trans); |
| 1062 if (node.InitByTagLookup(kNigoriTag) != syncer::BaseNode::INIT_OK) { | 1055 if (node.InitByTagLookup(kNigoriTag) != BaseNode::INIT_OK) { |
| 1063 // TODO(albertb): Plumb an UnrecoverableError all the way back to the PSS. | 1056 // TODO(albertb): Plumb an UnrecoverableError all the way back to the PSS. |
| 1064 NOTREACHED(); | 1057 NOTREACHED(); |
| 1065 return false; | 1058 return false; |
| 1066 } | 1059 } |
| 1067 | 1060 |
| 1068 return node.GetNigoriSpecifics().using_explicit_passphrase(); | 1061 return node.GetNigoriSpecifics().using_explicit_passphrase(); |
| 1069 } | 1062 } |
| 1070 | 1063 |
| 1071 void SyncManagerImpl::RefreshEncryption() { | 1064 void SyncManagerImpl::RefreshEncryption() { |
| 1072 DCHECK(initialized_); | 1065 DCHECK(initialized_); |
| 1073 | 1066 |
| 1074 WriteTransaction trans(FROM_HERE, GetUserShare()); | 1067 WriteTransaction trans(FROM_HERE, GetUserShare()); |
| 1075 WriteNode node(&trans); | 1068 WriteNode node(&trans); |
| 1076 if (node.InitByTagLookup(kNigoriTag) != syncer::BaseNode::INIT_OK) { | 1069 if (node.InitByTagLookup(kNigoriTag) != BaseNode::INIT_OK) { |
| 1077 NOTREACHED() << "Unable to set encrypted datatypes because Nigori node not " | 1070 NOTREACHED() << "Unable to set encrypted datatypes because Nigori node not " |
| 1078 << "found."; | 1071 << "found."; |
| 1079 return; | 1072 return; |
| 1080 } | 1073 } |
| 1081 | 1074 |
| 1082 Cryptographer* cryptographer = trans.GetCryptographer(); | 1075 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 1083 | 1076 |
| 1084 if (!cryptographer->is_ready()) { | 1077 if (!cryptographer->is_ready()) { |
| 1085 DVLOG(1) << "Attempting to encrypt datatypes when cryptographer not " | 1078 DVLOG(1) << "Attempting to encrypt datatypes when cryptographer not " |
| 1086 << "initialized, prompting for passphrase."; | 1079 << "initialized, prompting for passphrase."; |
| 1087 // TODO(zea): this isn't really decryption, but that's the only way we have | 1080 // TODO(zea): this isn't really decryption, but that's the only way we have |
| 1088 // to prompt the user for a passsphrase. See http://crbug.com/91379. | 1081 // to prompt the user for a passsphrase. See http://crbug.com/91379. |
| 1089 sync_pb::EncryptedData pending_keys; | 1082 sync_pb::EncryptedData pending_keys; |
| 1090 if (cryptographer->has_pending_keys()) | 1083 if (cryptographer->has_pending_keys()) |
| 1091 pending_keys = cryptographer->GetPendingKeys(); | 1084 pending_keys = cryptographer->GetPendingKeys(); |
| 1092 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 1085 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| 1093 OnPassphraseRequired(syncer::REASON_DECRYPTION, | 1086 OnPassphraseRequired(REASON_DECRYPTION, |
| 1094 pending_keys)); | 1087 pending_keys)); |
| 1095 return; | 1088 return; |
| 1096 } | 1089 } |
| 1097 | 1090 |
| 1098 UpdateNigoriEncryptionState(cryptographer, &node); | 1091 UpdateNigoriEncryptionState(cryptographer, &node); |
| 1099 | 1092 |
| 1100 allstatus_.SetEncryptedTypes(cryptographer->GetEncryptedTypes()); | 1093 allstatus_.SetEncryptedTypes(cryptographer->GetEncryptedTypes()); |
| 1101 | 1094 |
| 1102 // We reencrypt everything regardless of whether the set of encrypted | 1095 // We reencrypt everything regardless of whether the set of encrypted |
| 1103 // types changed to ensure that any stray unencrypted entries are overwritten. | 1096 // types changed to ensure that any stray unencrypted entries are overwritten. |
| 1104 ReEncryptEverything(&trans); | 1097 ReEncryptEverything(&trans); |
| 1105 } | 1098 } |
| 1106 | 1099 |
| 1107 // This function iterates over all encrypted types. There are many scenarios in | 1100 // This function iterates over all encrypted types. There are many scenarios in |
| 1108 // which data for some or all types is not currently available. In that case, | 1101 // which data for some or all types is not currently available. In that case, |
| 1109 // the lookup of the root node will fail and we will skip encryption for that | 1102 // the lookup of the root node will fail and we will skip encryption for that |
| 1110 // type. | 1103 // type. |
| 1111 void SyncManagerImpl::ReEncryptEverything( | 1104 void SyncManagerImpl::ReEncryptEverything( |
| 1112 WriteTransaction* trans) { | 1105 WriteTransaction* trans) { |
| 1113 Cryptographer* cryptographer = trans->GetCryptographer(); | 1106 Cryptographer* cryptographer = trans->GetCryptographer(); |
| 1114 if (!cryptographer || !cryptographer->is_ready()) | 1107 if (!cryptographer || !cryptographer->is_ready()) |
| 1115 return; | 1108 return; |
| 1116 syncer::ModelTypeSet encrypted_types = GetEncryptedTypes(trans); | 1109 ModelTypeSet encrypted_types = GetEncryptedTypes(trans); |
| 1117 for (syncer::ModelTypeSet::Iterator iter = encrypted_types.First(); | 1110 for (ModelTypeSet::Iterator iter = encrypted_types.First(); |
| 1118 iter.Good(); iter.Inc()) { | 1111 iter.Good(); iter.Inc()) { |
| 1119 if (iter.Get() == syncer::PASSWORDS || iter.Get() == syncer::NIGORI) | 1112 if (iter.Get() == PASSWORDS || iter.Get() == NIGORI) |
| 1120 continue; // These types handle encryption differently. | 1113 continue; // These types handle encryption differently. |
| 1121 | 1114 |
| 1122 ReadNode type_root(trans); | 1115 ReadNode type_root(trans); |
| 1123 std::string tag = syncer::ModelTypeToRootTag(iter.Get()); | 1116 std::string tag = ModelTypeToRootTag(iter.Get()); |
| 1124 if (type_root.InitByTagLookup(tag) != syncer::BaseNode::INIT_OK) | 1117 if (type_root.InitByTagLookup(tag) != BaseNode::INIT_OK) |
| 1125 continue; // Don't try to reencrypt if the type's data is unavailable. | 1118 continue; // Don't try to reencrypt if the type's data is unavailable. |
| 1126 | 1119 |
| 1127 // Iterate through all children of this datatype. | 1120 // Iterate through all children of this datatype. |
| 1128 std::queue<int64> to_visit; | 1121 std::queue<int64> to_visit; |
| 1129 int64 child_id = type_root.GetFirstChildId(); | 1122 int64 child_id = type_root.GetFirstChildId(); |
| 1130 to_visit.push(child_id); | 1123 to_visit.push(child_id); |
| 1131 while (!to_visit.empty()) { | 1124 while (!to_visit.empty()) { |
| 1132 child_id = to_visit.front(); | 1125 child_id = to_visit.front(); |
| 1133 to_visit.pop(); | 1126 to_visit.pop(); |
| 1134 if (child_id == kInvalidId) | 1127 if (child_id == kInvalidId) |
| 1135 continue; | 1128 continue; |
| 1136 | 1129 |
| 1137 WriteNode child(trans); | 1130 WriteNode child(trans); |
| 1138 if (child.InitByIdLookup(child_id) != syncer::BaseNode::INIT_OK) { | 1131 if (child.InitByIdLookup(child_id) != BaseNode::INIT_OK) { |
| 1139 NOTREACHED(); | 1132 NOTREACHED(); |
| 1140 continue; | 1133 continue; |
| 1141 } | 1134 } |
| 1142 if (child.GetIsFolder()) { | 1135 if (child.GetIsFolder()) { |
| 1143 to_visit.push(child.GetFirstChildId()); | 1136 to_visit.push(child.GetFirstChildId()); |
| 1144 } | 1137 } |
| 1145 if (child.GetEntry()->Get(syncable::UNIQUE_SERVER_TAG).empty()) { | 1138 if (child.GetEntry()->Get(syncable::UNIQUE_SERVER_TAG).empty()) { |
| 1146 // Rewrite the specifics of the node with encrypted data if necessary | 1139 // Rewrite the specifics of the node with encrypted data if necessary |
| 1147 // (only rewrite the non-unique folders). | 1140 // (only rewrite the non-unique folders). |
| 1148 child.ResetFromSpecifics(); | 1141 child.ResetFromSpecifics(); |
| 1149 } | 1142 } |
| 1150 to_visit.push(child.GetSuccessorId()); | 1143 to_visit.push(child.GetSuccessorId()); |
| 1151 } | 1144 } |
| 1152 } | 1145 } |
| 1153 | 1146 |
| 1154 // Passwords are encrypted with their own legacy scheme. Passwords are always | 1147 // Passwords are encrypted with their own legacy scheme. Passwords are always |
| 1155 // encrypted so we don't need to check GetEncryptedTypes() here. | 1148 // encrypted so we don't need to check GetEncryptedTypes() here. |
| 1156 ReadNode passwords_root(trans); | 1149 ReadNode passwords_root(trans); |
| 1157 std::string passwords_tag = syncer::ModelTypeToRootTag(syncer::PASSWORDS); | 1150 std::string passwords_tag = ModelTypeToRootTag(PASSWORDS); |
| 1158 if (passwords_root.InitByTagLookup(passwords_tag) == | 1151 if (passwords_root.InitByTagLookup(passwords_tag) == BaseNode::INIT_OK) { |
| 1159 syncer::BaseNode::INIT_OK) { | |
| 1160 int64 child_id = passwords_root.GetFirstChildId(); | 1152 int64 child_id = passwords_root.GetFirstChildId(); |
| 1161 while (child_id != kInvalidId) { | 1153 while (child_id != kInvalidId) { |
| 1162 WriteNode child(trans); | 1154 WriteNode child(trans); |
| 1163 if (child.InitByIdLookup(child_id) != syncer::BaseNode::INIT_OK) { | 1155 if (child.InitByIdLookup(child_id) != BaseNode::INIT_OK) { |
| 1164 NOTREACHED(); | 1156 NOTREACHED(); |
| 1165 return; | 1157 return; |
| 1166 } | 1158 } |
| 1167 child.SetPasswordSpecifics(child.GetPasswordSpecifics()); | 1159 child.SetPasswordSpecifics(child.GetPasswordSpecifics()); |
| 1168 child_id = child.GetSuccessorId(); | 1160 child_id = child.GetSuccessorId(); |
| 1169 } | 1161 } |
| 1170 } | 1162 } |
| 1171 | 1163 |
| 1172 // NOTE: We notify from within a transaction. | 1164 // NOTE: We notify from within a transaction. |
| 1173 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 1165 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1254 | 1246 |
| 1255 void SyncManagerImpl::OnIPAddressChangedImpl() { | 1247 void SyncManagerImpl::OnIPAddressChangedImpl() { |
| 1256 DCHECK(thread_checker_.CalledOnValidThread()); | 1248 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1257 scheduler_->OnConnectionStatusChange(); | 1249 scheduler_->OnConnectionStatusChange(); |
| 1258 } | 1250 } |
| 1259 | 1251 |
| 1260 void SyncManagerImpl::OnServerConnectionEvent( | 1252 void SyncManagerImpl::OnServerConnectionEvent( |
| 1261 const ServerConnectionEvent& event) { | 1253 const ServerConnectionEvent& event) { |
| 1262 DCHECK(thread_checker_.CalledOnValidThread()); | 1254 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1263 if (event.connection_code == | 1255 if (event.connection_code == |
| 1264 syncer::HttpResponse::SERVER_CONNECTION_OK) { | 1256 HttpResponse::SERVER_CONNECTION_OK) { |
| 1265 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 1257 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| 1266 OnConnectionStatusChange(CONNECTION_OK)); | 1258 OnConnectionStatusChange(CONNECTION_OK)); |
| 1267 } | 1259 } |
| 1268 | 1260 |
| 1269 if (event.connection_code == syncer::HttpResponse::SYNC_AUTH_ERROR) { | 1261 if (event.connection_code == HttpResponse::SYNC_AUTH_ERROR) { |
| 1270 observing_ip_address_changes_ = false; | 1262 observing_ip_address_changes_ = false; |
| 1271 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 1263 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| 1272 OnConnectionStatusChange(CONNECTION_AUTH_ERROR)); | 1264 OnConnectionStatusChange(CONNECTION_AUTH_ERROR)); |
| 1273 } | 1265 } |
| 1274 | 1266 |
| 1275 if (event.connection_code == | 1267 if (event.connection_code == HttpResponse::SYNC_SERVER_ERROR) { |
| 1276 syncer::HttpResponse::SYNC_SERVER_ERROR) { | |
| 1277 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 1268 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| 1278 OnConnectionStatusChange(CONNECTION_SERVER_ERROR)); | 1269 OnConnectionStatusChange(CONNECTION_SERVER_ERROR)); |
| 1279 } | 1270 } |
| 1280 } | 1271 } |
| 1281 | 1272 |
| 1282 void SyncManagerImpl::HandleTransactionCompleteChangeEvent( | 1273 void SyncManagerImpl::HandleTransactionCompleteChangeEvent( |
| 1283 ModelTypeSet models_with_changes) { | 1274 ModelTypeSet models_with_changes) { |
| 1284 // This notification happens immediately after the transaction mutex is | 1275 // This notification happens immediately after the transaction mutex is |
| 1285 // released. This allows work to be performed without blocking other threads | 1276 // released. This allows work to be performed without blocking other threads |
| 1286 // from acquiring a transaction. | 1277 // from acquiring a transaction. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1308 if (!change_delegate_ || ChangeBuffersAreEmpty()) | 1299 if (!change_delegate_ || ChangeBuffersAreEmpty()) |
| 1309 return ModelTypeSet(); | 1300 return ModelTypeSet(); |
| 1310 | 1301 |
| 1311 // This will continue the WriteTransaction using a read only wrapper. | 1302 // This will continue the WriteTransaction using a read only wrapper. |
| 1312 // This is the last chance for read to occur in the WriteTransaction | 1303 // This is the last chance for read to occur in the WriteTransaction |
| 1313 // that's closing. This special ReadTransaction will not close the | 1304 // that's closing. This special ReadTransaction will not close the |
| 1314 // underlying transaction. | 1305 // underlying transaction. |
| 1315 ReadTransaction read_trans(GetUserShare(), trans); | 1306 ReadTransaction read_trans(GetUserShare(), trans); |
| 1316 | 1307 |
| 1317 ModelTypeSet models_with_changes; | 1308 ModelTypeSet models_with_changes; |
| 1318 for (int i = syncer::FIRST_REAL_MODEL_TYPE; | 1309 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { |
| 1319 i < syncer::MODEL_TYPE_COUNT; ++i) { | 1310 const ModelType type = ModelTypeFromInt(i); |
| 1320 const syncer::ModelType type = syncer::ModelTypeFromInt(i); | |
| 1321 if (change_buffers_[type].IsEmpty()) | 1311 if (change_buffers_[type].IsEmpty()) |
| 1322 continue; | 1312 continue; |
| 1323 | 1313 |
| 1324 ImmutableChangeRecordList ordered_changes; | 1314 ImmutableChangeRecordList ordered_changes; |
| 1325 // TODO(akalin): Propagate up the error further (see | 1315 // TODO(akalin): Propagate up the error further (see |
| 1326 // http://crbug.com/100907). | 1316 // http://crbug.com/100907). |
| 1327 CHECK(change_buffers_[type].GetAllChangesInTreeOrder(&read_trans, | 1317 CHECK(change_buffers_[type].GetAllChangesInTreeOrder(&read_trans, |
| 1328 &ordered_changes)); | 1318 &ordered_changes)); |
| 1329 if (!ordered_changes.Get().empty()) { | 1319 if (!ordered_changes.Get().empty()) { |
| 1330 change_delegate_-> | 1320 change_delegate_-> |
| 1331 OnChangesApplied(type, &read_trans, ordered_changes); | 1321 OnChangesApplied(type, &read_trans, ordered_changes); |
| 1332 change_observer_.Call(FROM_HERE, | 1322 change_observer_.Call(FROM_HERE, |
| 1333 &SyncManager::ChangeObserver::OnChangesApplied, | 1323 &SyncManager::ChangeObserver::OnChangesApplied, |
| 1334 type, write_transaction_info.Get().id, ordered_changes); | 1324 type, write_transaction_info.Get().id, ordered_changes); |
| 1335 models_with_changes.Put(type); | 1325 models_with_changes.Put(type); |
| 1336 } | 1326 } |
| 1337 change_buffers_[i].Clear(); | 1327 change_buffers_[i].Clear(); |
| 1338 } | 1328 } |
| 1339 return models_with_changes; | 1329 return models_with_changes; |
| 1340 } | 1330 } |
| 1341 | 1331 |
| 1342 void SyncManagerImpl::HandleCalculateChangesChangeEventFromSyncApi( | 1332 void SyncManagerImpl::HandleCalculateChangesChangeEventFromSyncApi( |
| 1343 const ImmutableWriteTransactionInfo& write_transaction_info, | 1333 const ImmutableWriteTransactionInfo& write_transaction_info, |
| 1344 syncable::BaseTransaction* trans) { | 1334 syncable::BaseTransaction* trans) { |
| 1345 // We have been notified about a user action changing a sync model. | 1335 // We have been notified about a user action changing a sync model. |
| 1346 LOG_IF(WARNING, !ChangeBuffersAreEmpty()) << | 1336 LOG_IF(WARNING, !ChangeBuffersAreEmpty()) << |
| 1347 "CALCULATE_CHANGES called with unapplied old changes."; | 1337 "CALCULATE_CHANGES called with unapplied old changes."; |
| 1348 | 1338 |
| 1349 // The mutated model type, or UNSPECIFIED if nothing was mutated. | 1339 // The mutated model type, or UNSPECIFIED if nothing was mutated. |
| 1350 syncer::ModelTypeSet mutated_model_types; | 1340 ModelTypeSet mutated_model_types; |
| 1351 | 1341 |
| 1352 const syncable::ImmutableEntryKernelMutationMap& mutations = | 1342 const syncable::ImmutableEntryKernelMutationMap& mutations = |
| 1353 write_transaction_info.Get().mutations; | 1343 write_transaction_info.Get().mutations; |
| 1354 for (syncable::EntryKernelMutationMap::const_iterator it = | 1344 for (syncable::EntryKernelMutationMap::const_iterator it = |
| 1355 mutations.Get().begin(); it != mutations.Get().end(); ++it) { | 1345 mutations.Get().begin(); it != mutations.Get().end(); ++it) { |
| 1356 if (!it->second.mutated.ref(syncable::IS_UNSYNCED)) { | 1346 if (!it->second.mutated.ref(syncable::IS_UNSYNCED)) { |
| 1357 continue; | 1347 continue; |
| 1358 } | 1348 } |
| 1359 | 1349 |
| 1360 syncer::ModelType model_type = | 1350 ModelType model_type = |
| 1361 syncer::GetModelTypeFromSpecifics( | 1351 GetModelTypeFromSpecifics(it->second.mutated.ref(SPECIFICS)); |
| 1362 it->second.mutated.ref(SPECIFICS)); | 1352 if (model_type < FIRST_REAL_MODEL_TYPE) { |
| 1363 if (model_type < syncer::FIRST_REAL_MODEL_TYPE) { | |
| 1364 NOTREACHED() << "Permanent or underspecified item changed via syncapi."; | 1353 NOTREACHED() << "Permanent or underspecified item changed via syncapi."; |
| 1365 continue; | 1354 continue; |
| 1366 } | 1355 } |
| 1367 | 1356 |
| 1368 // Found real mutation. | 1357 // Found real mutation. |
| 1369 if (model_type != syncer::UNSPECIFIED) { | 1358 if (model_type != UNSPECIFIED) { |
| 1370 mutated_model_types.Put(model_type); | 1359 mutated_model_types.Put(model_type); |
| 1371 } | 1360 } |
| 1372 } | 1361 } |
| 1373 | 1362 |
| 1374 // Nudge if necessary. | 1363 // Nudge if necessary. |
| 1375 if (!mutated_model_types.Empty()) { | 1364 if (!mutated_model_types.Empty()) { |
| 1376 if (weak_handle_this_.IsInitialized()) { | 1365 if (weak_handle_this_.IsInitialized()) { |
| 1377 weak_handle_this_.Call(FROM_HERE, | 1366 weak_handle_this_.Call(FROM_HERE, |
| 1378 &SyncManagerImpl::RequestNudgeForDataTypes, | 1367 &SyncManagerImpl::RequestNudgeForDataTypes, |
| 1379 FROM_HERE, | 1368 FROM_HERE, |
| 1380 mutated_model_types); | 1369 mutated_model_types); |
| 1381 } else { | 1370 } else { |
| 1382 NOTREACHED(); | 1371 NOTREACHED(); |
| 1383 } | 1372 } |
| 1384 } | 1373 } |
| 1385 } | 1374 } |
| 1386 | 1375 |
| 1387 void SyncManagerImpl::SetExtraChangeRecordData(int64 id, | 1376 void SyncManagerImpl::SetExtraChangeRecordData(int64 id, |
| 1388 syncer::ModelType type, ChangeReorderBuffer* buffer, | 1377 ModelType type, ChangeReorderBuffer* buffer, |
| 1389 Cryptographer* cryptographer, const syncable::EntryKernel& original, | 1378 Cryptographer* cryptographer, const syncable::EntryKernel& original, |
| 1390 bool existed_before, bool exists_now) { | 1379 bool existed_before, bool exists_now) { |
| 1391 // If this is a deletion and the datatype was encrypted, we need to decrypt it | 1380 // If this is a deletion and the datatype was encrypted, we need to decrypt it |
| 1392 // and attach it to the buffer. | 1381 // and attach it to the buffer. |
| 1393 if (!exists_now && existed_before) { | 1382 if (!exists_now && existed_before) { |
| 1394 sync_pb::EntitySpecifics original_specifics(original.ref(SPECIFICS)); | 1383 sync_pb::EntitySpecifics original_specifics(original.ref(SPECIFICS)); |
| 1395 if (type == syncer::PASSWORDS) { | 1384 if (type == PASSWORDS) { |
| 1396 // Passwords must use their own legacy ExtraPasswordChangeRecordData. | 1385 // Passwords must use their own legacy ExtraPasswordChangeRecordData. |
| 1397 scoped_ptr<sync_pb::PasswordSpecificsData> data( | 1386 scoped_ptr<sync_pb::PasswordSpecificsData> data( |
| 1398 DecryptPasswordSpecifics(original_specifics, cryptographer)); | 1387 DecryptPasswordSpecifics(original_specifics, cryptographer)); |
| 1399 if (!data.get()) { | 1388 if (!data.get()) { |
| 1400 NOTREACHED(); | 1389 NOTREACHED(); |
| 1401 return; | 1390 return; |
| 1402 } | 1391 } |
| 1403 buffer->SetExtraDataForId(id, new ExtraPasswordChangeRecordData(*data)); | 1392 buffer->SetExtraDataForId(id, new ExtraPasswordChangeRecordData(*data)); |
| 1404 } else if (original_specifics.has_encrypted()) { | 1393 } else if (original_specifics.has_encrypted()) { |
| 1405 // All other datatypes can just create a new unencrypted specifics and | 1394 // All other datatypes can just create a new unencrypted specifics and |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1424 | 1413 |
| 1425 Cryptographer* crypto = directory()->GetCryptographer(trans); | 1414 Cryptographer* crypto = directory()->GetCryptographer(trans); |
| 1426 const syncable::ImmutableEntryKernelMutationMap& mutations = | 1415 const syncable::ImmutableEntryKernelMutationMap& mutations = |
| 1427 write_transaction_info.Get().mutations; | 1416 write_transaction_info.Get().mutations; |
| 1428 for (syncable::EntryKernelMutationMap::const_iterator it = | 1417 for (syncable::EntryKernelMutationMap::const_iterator it = |
| 1429 mutations.Get().begin(); it != mutations.Get().end(); ++it) { | 1418 mutations.Get().begin(); it != mutations.Get().end(); ++it) { |
| 1430 bool existed_before = !it->second.original.ref(syncable::IS_DEL); | 1419 bool existed_before = !it->second.original.ref(syncable::IS_DEL); |
| 1431 bool exists_now = !it->second.mutated.ref(syncable::IS_DEL); | 1420 bool exists_now = !it->second.mutated.ref(syncable::IS_DEL); |
| 1432 | 1421 |
| 1433 // Omit items that aren't associated with a model. | 1422 // Omit items that aren't associated with a model. |
| 1434 syncer::ModelType type = | 1423 ModelType type = |
| 1435 syncer::GetModelTypeFromSpecifics( | 1424 GetModelTypeFromSpecifics(it->second.mutated.ref(SPECIFICS)); |
| 1436 it->second.mutated.ref(SPECIFICS)); | 1425 if (type < FIRST_REAL_MODEL_TYPE) |
| 1437 if (type < syncer::FIRST_REAL_MODEL_TYPE) | |
| 1438 continue; | 1426 continue; |
| 1439 | 1427 |
| 1440 int64 handle = it->first; | 1428 int64 handle = it->first; |
| 1441 if (exists_now && !existed_before) | 1429 if (exists_now && !existed_before) |
| 1442 change_buffers_[type].PushAddedItem(handle); | 1430 change_buffers_[type].PushAddedItem(handle); |
| 1443 else if (!exists_now && existed_before) | 1431 else if (!exists_now && existed_before) |
| 1444 change_buffers_[type].PushDeletedItem(handle); | 1432 change_buffers_[type].PushDeletedItem(handle); |
| 1445 else if (exists_now && existed_before && | 1433 else if (exists_now && existed_before && |
| 1446 VisiblePropertiesDiffer(it->second, crypto)) { | 1434 VisiblePropertiesDiffer(it->second, crypto)) { |
| 1447 change_buffers_[type].PushUpdatedItem( | 1435 change_buffers_[type].PushUpdatedItem( |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1461 void SyncManagerImpl::RequestNudgeForDataTypes( | 1449 void SyncManagerImpl::RequestNudgeForDataTypes( |
| 1462 const tracked_objects::Location& nudge_location, | 1450 const tracked_objects::Location& nudge_location, |
| 1463 ModelTypeSet types) { | 1451 ModelTypeSet types) { |
| 1464 debug_info_event_listener_.OnNudgeFromDatatype(types.First().Get()); | 1452 debug_info_event_listener_.OnNudgeFromDatatype(types.First().Get()); |
| 1465 | 1453 |
| 1466 // TODO(lipalani) : Calculate the nudge delay based on all types. | 1454 // TODO(lipalani) : Calculate the nudge delay based on all types. |
| 1467 base::TimeDelta nudge_delay = NudgeStrategy::GetNudgeDelayTimeDelta( | 1455 base::TimeDelta nudge_delay = NudgeStrategy::GetNudgeDelayTimeDelta( |
| 1468 types.First().Get(), | 1456 types.First().Get(), |
| 1469 this); | 1457 this); |
| 1470 scheduler_->ScheduleNudgeAsync(nudge_delay, | 1458 scheduler_->ScheduleNudgeAsync(nudge_delay, |
| 1471 syncer::NUDGE_SOURCE_LOCAL, | 1459 NUDGE_SOURCE_LOCAL, |
| 1472 types, | 1460 types, |
| 1473 nudge_location); | 1461 nudge_location); |
| 1474 } | 1462 } |
| 1475 | 1463 |
| 1476 void SyncManagerImpl::OnSyncEngineEvent(const SyncEngineEvent& event) { | 1464 void SyncManagerImpl::OnSyncEngineEvent(const SyncEngineEvent& event) { |
| 1477 DCHECK(thread_checker_.CalledOnValidThread()); | 1465 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1478 // Only send an event if this is due to a cycle ending and this cycle | 1466 // Only send an event if this is due to a cycle ending and this cycle |
| 1479 // concludes a canonical "sync" process; that is, based on what is known | 1467 // concludes a canonical "sync" process; that is, based on what is known |
| 1480 // locally we are "all happy" and up-to-date. There may be new changes on | 1468 // locally we are "all happy" and up-to-date. There may be new changes on |
| 1481 // the server, but we'll get them on a subsequent sync. | 1469 // the server, but we'll get them on a subsequent sync. |
| 1482 // | 1470 // |
| 1483 // Notifications are sent at the end of every sync cycle, regardless of | 1471 // Notifications are sent at the end of every sync cycle, regardless of |
| 1484 // whether we should sync again. | 1472 // whether we should sync again. |
| 1485 if (event.what_happened == SyncEngineEvent::SYNC_CYCLE_ENDED) { | 1473 if (event.what_happened == SyncEngineEvent::SYNC_CYCLE_ENDED) { |
| 1486 { | 1474 { |
| 1487 // Check to see if we need to notify the frontend that we have newly | 1475 // Check to see if we need to notify the frontend that we have newly |
| 1488 // encrypted types or that we require a passphrase. | 1476 // encrypted types or that we require a passphrase. |
| 1489 ReadTransaction trans(FROM_HERE, GetUserShare()); | 1477 ReadTransaction trans(FROM_HERE, GetUserShare()); |
| 1490 Cryptographer* cryptographer = trans.GetCryptographer(); | 1478 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 1491 // If we've completed a sync cycle and the cryptographer isn't ready | 1479 // If we've completed a sync cycle and the cryptographer isn't ready |
| 1492 // yet, prompt the user for a passphrase. | 1480 // yet, prompt the user for a passphrase. |
| 1493 if (cryptographer->has_pending_keys()) { | 1481 if (cryptographer->has_pending_keys()) { |
| 1494 DVLOG(1) << "OnPassPhraseRequired Sent"; | 1482 DVLOG(1) << "OnPassPhraseRequired Sent"; |
| 1495 sync_pb::EncryptedData pending_keys = cryptographer->GetPendingKeys(); | 1483 sync_pb::EncryptedData pending_keys = cryptographer->GetPendingKeys(); |
| 1496 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 1484 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| 1497 OnPassphraseRequired(syncer::REASON_DECRYPTION, | 1485 OnPassphraseRequired(REASON_DECRYPTION, |
| 1498 pending_keys)); | 1486 pending_keys)); |
| 1499 } else if (!cryptographer->is_ready() && | 1487 } else if (!cryptographer->is_ready() && |
| 1500 event.snapshot.initial_sync_ended().Has(syncer::NIGORI)) { | 1488 event.snapshot.initial_sync_ended().Has(NIGORI)) { |
| 1501 DVLOG(1) << "OnPassphraseRequired sent because cryptographer is not " | 1489 DVLOG(1) << "OnPassphraseRequired sent because cryptographer is not " |
| 1502 << "ready"; | 1490 << "ready"; |
| 1503 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 1491 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| 1504 OnPassphraseRequired(syncer::REASON_ENCRYPTION, | 1492 OnPassphraseRequired(REASON_ENCRYPTION, |
| 1505 sync_pb::EncryptedData())); | 1493 sync_pb::EncryptedData())); |
| 1506 } | 1494 } |
| 1507 | 1495 |
| 1508 NotifyCryptographerState(cryptographer); | 1496 NotifyCryptographerState(cryptographer); |
| 1509 allstatus_.SetEncryptedTypes(cryptographer->GetEncryptedTypes()); | 1497 allstatus_.SetEncryptedTypes(cryptographer->GetEncryptedTypes()); |
| 1510 } | 1498 } |
| 1511 | 1499 |
| 1512 if (!initialized_) { | 1500 if (!initialized_) { |
| 1513 LOG(INFO) << "OnSyncCycleCompleted not sent because sync api is not " | 1501 LOG(INFO) << "OnSyncCycleCompleted not sent because sync api is not " |
| 1514 << "initialized"; | 1502 << "initialized"; |
| 1515 return; | 1503 return; |
| 1516 } | 1504 } |
| 1517 | 1505 |
| 1518 if (!event.snapshot.has_more_to_sync()) { | 1506 if (!event.snapshot.has_more_to_sync()) { |
| 1519 // To account for a nigori node arriving with stale/bad data, we ensure | 1507 // To account for a nigori node arriving with stale/bad data, we ensure |
| 1520 // that the nigori node is up to date at the end of each cycle. | 1508 // that the nigori node is up to date at the end of each cycle. |
| 1521 WriteTransaction trans(FROM_HERE, GetUserShare()); | 1509 WriteTransaction trans(FROM_HERE, GetUserShare()); |
| 1522 WriteNode nigori_node(&trans); | 1510 WriteNode nigori_node(&trans); |
| 1523 if (nigori_node.InitByTagLookup(kNigoriTag) == | 1511 if (nigori_node.InitByTagLookup(kNigoriTag) == BaseNode::INIT_OK) { |
| 1524 syncer::BaseNode::INIT_OK) { | |
| 1525 Cryptographer* cryptographer = trans.GetCryptographer(); | 1512 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 1526 UpdateNigoriEncryptionState(cryptographer, &nigori_node); | 1513 UpdateNigoriEncryptionState(cryptographer, &nigori_node); |
| 1527 } | 1514 } |
| 1528 | 1515 |
| 1529 DVLOG(1) << "Sending OnSyncCycleCompleted"; | 1516 DVLOG(1) << "Sending OnSyncCycleCompleted"; |
| 1530 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 1517 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| 1531 OnSyncCycleCompleted(event.snapshot)); | 1518 OnSyncCycleCompleted(event.snapshot)); |
| 1532 } | 1519 } |
| 1533 | 1520 |
| 1534 // This is here for tests, which are still using p2p notifications. | 1521 // This is here for tests, which are still using p2p notifications. |
| 1535 // | 1522 // |
| 1536 // TODO(chron): Consider changing this back to track has_more_to_sync | 1523 // TODO(chron): Consider changing this back to track has_more_to_sync |
| 1537 // only notify peers if a successful commit has occurred. | 1524 // only notify peers if a successful commit has occurred. |
| 1538 bool is_notifiable_commit = | 1525 bool is_notifiable_commit = |
| 1539 (event.snapshot.model_neutral_state().num_successful_commits > 0); | 1526 (event.snapshot.model_neutral_state().num_successful_commits > 0); |
| 1540 if (is_notifiable_commit) { | 1527 if (is_notifiable_commit) { |
| 1541 if (sync_notifier_.get()) { | 1528 if (sync_notifier_.get()) { |
| 1542 const ModelTypeSet changed_types = | 1529 const ModelTypeSet changed_types = |
| 1543 syncer::ModelTypePayloadMapToEnumSet( | 1530 ModelTypePayloadMapToEnumSet(event.snapshot.source().types); |
| 1544 event.snapshot.source().types); | |
| 1545 sync_notifier_->SendNotification(changed_types); | 1531 sync_notifier_->SendNotification(changed_types); |
| 1546 } else { | 1532 } else { |
| 1547 DVLOG(1) << "Not sending notification: sync_notifier_ is NULL"; | 1533 DVLOG(1) << "Not sending notification: sync_notifier_ is NULL"; |
| 1548 } | 1534 } |
| 1549 } | 1535 } |
| 1550 } | 1536 } |
| 1551 | 1537 |
| 1552 if (event.what_happened == SyncEngineEvent::STOP_SYNCING_PERMANENTLY) { | 1538 if (event.what_happened == SyncEngineEvent::STOP_SYNCING_PERMANENTLY) { |
| 1553 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 1539 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| 1554 OnStopSyncingPermanently()); | 1540 OnStopSyncingPermanently()); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1610 js_message_handlers_[name] = | 1596 js_message_handlers_[name] = |
| 1611 base::Bind(unbound_message_handler, base::Unretained(this)); | 1597 base::Bind(unbound_message_handler, base::Unretained(this)); |
| 1612 } | 1598 } |
| 1613 | 1599 |
| 1614 DictionaryValue* SyncManagerImpl::NotificationInfoToValue( | 1600 DictionaryValue* SyncManagerImpl::NotificationInfoToValue( |
| 1615 const NotificationInfoMap& notification_info) { | 1601 const NotificationInfoMap& notification_info) { |
| 1616 DictionaryValue* value = new DictionaryValue(); | 1602 DictionaryValue* value = new DictionaryValue(); |
| 1617 | 1603 |
| 1618 for (NotificationInfoMap::const_iterator it = notification_info.begin(); | 1604 for (NotificationInfoMap::const_iterator it = notification_info.begin(); |
| 1619 it != notification_info.end(); ++it) { | 1605 it != notification_info.end(); ++it) { |
| 1620 const std::string& model_type_str = | 1606 const std::string& model_type_str = ModelTypeToString(it->first); |
| 1621 syncer::ModelTypeToString(it->first); | |
| 1622 value->Set(model_type_str, it->second.ToValue()); | 1607 value->Set(model_type_str, it->second.ToValue()); |
| 1623 } | 1608 } |
| 1624 | 1609 |
| 1625 return value; | 1610 return value; |
| 1626 } | 1611 } |
| 1627 | 1612 |
| 1628 JsArgList SyncManagerImpl::GetNotificationState( | 1613 JsArgList SyncManagerImpl::GetNotificationState( |
| 1629 const JsArgList& args) { | 1614 const JsArgList& args) { |
| 1630 bool notifications_enabled = allstatus_.status().notifications_enabled; | 1615 bool notifications_enabled = allstatus_.status().notifications_enabled; |
| 1631 ListValue return_args; | 1616 ListValue return_args; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1683 ListValue* id_list = NULL; | 1668 ListValue* id_list = NULL; |
| 1684 ReadTransaction trans(FROM_HERE, user_share); | 1669 ReadTransaction trans(FROM_HERE, user_share); |
| 1685 if (args.Get().GetList(0, &id_list)) { | 1670 if (args.Get().GetList(0, &id_list)) { |
| 1686 CHECK(id_list); | 1671 CHECK(id_list); |
| 1687 for (size_t i = 0; i < id_list->GetSize(); ++i) { | 1672 for (size_t i = 0; i < id_list->GetSize(); ++i) { |
| 1688 int64 id = GetId(*id_list, i); | 1673 int64 id = GetId(*id_list, i); |
| 1689 if (id == kInvalidId) { | 1674 if (id == kInvalidId) { |
| 1690 continue; | 1675 continue; |
| 1691 } | 1676 } |
| 1692 ReadNode node(&trans); | 1677 ReadNode node(&trans); |
| 1693 if (node.InitByIdLookup(id) != syncer::BaseNode::INIT_OK) { | 1678 if (node.InitByIdLookup(id) != BaseNode::INIT_OK) { |
| 1694 continue; | 1679 continue; |
| 1695 } | 1680 } |
| 1696 node_summaries->Append((node.*info_getter)()); | 1681 node_summaries->Append((node.*info_getter)()); |
| 1697 } | 1682 } |
| 1698 } | 1683 } |
| 1699 return JsArgList(&return_args); | 1684 return JsArgList(&return_args); |
| 1700 } | 1685 } |
| 1701 | 1686 |
| 1702 } // namespace | 1687 } // namespace |
| 1703 | 1688 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1740 for (syncable::Directory::ChildHandles::const_iterator it = | 1725 for (syncable::Directory::ChildHandles::const_iterator it = |
| 1741 child_handles.begin(); it != child_handles.end(); ++it) { | 1726 child_handles.begin(); it != child_handles.end(); ++it) { |
| 1742 child_ids->Append(Value::CreateStringValue( | 1727 child_ids->Append(Value::CreateStringValue( |
| 1743 base::Int64ToString(*it))); | 1728 base::Int64ToString(*it))); |
| 1744 } | 1729 } |
| 1745 } | 1730 } |
| 1746 return JsArgList(&return_args); | 1731 return JsArgList(&return_args); |
| 1747 } | 1732 } |
| 1748 | 1733 |
| 1749 void SyncManagerImpl::OnEncryptedTypesChanged( | 1734 void SyncManagerImpl::OnEncryptedTypesChanged( |
| 1750 syncer::ModelTypeSet encrypted_types, | 1735 ModelTypeSet encrypted_types, |
| 1751 bool encrypt_everything) { | 1736 bool encrypt_everything) { |
| 1752 // NOTE: We're in a transaction. | 1737 // NOTE: We're in a transaction. |
| 1753 FOR_EACH_OBSERVER( | 1738 FOR_EACH_OBSERVER( |
| 1754 SyncManager::Observer, observers_, | 1739 SyncManager::Observer, observers_, |
| 1755 OnEncryptedTypesChanged(encrypted_types, encrypt_everything)); | 1740 OnEncryptedTypesChanged(encrypted_types, encrypt_everything)); |
| 1756 } | 1741 } |
| 1757 | 1742 |
| 1758 void SyncManagerImpl::UpdateNotificationInfo( | 1743 void SyncManagerImpl::UpdateNotificationInfo( |
| 1759 const syncer::ModelTypePayloadMap& type_payloads) { | 1744 const ModelTypePayloadMap& type_payloads) { |
| 1760 for (syncer::ModelTypePayloadMap::const_iterator it = type_payloads.begin(); | 1745 for (ModelTypePayloadMap::const_iterator it = type_payloads.begin(); |
| 1761 it != type_payloads.end(); ++it) { | 1746 it != type_payloads.end(); ++it) { |
| 1762 NotificationInfo* info = ¬ification_info_map_[it->first]; | 1747 NotificationInfo* info = ¬ification_info_map_[it->first]; |
| 1763 info->total_count++; | 1748 info->total_count++; |
| 1764 info->payload = it->second; | 1749 info->payload = it->second; |
| 1765 } | 1750 } |
| 1766 } | 1751 } |
| 1767 | 1752 |
| 1768 void SyncManagerImpl::OnNotificationsEnabled() { | 1753 void SyncManagerImpl::OnNotificationsEnabled() { |
| 1769 DVLOG(1) << "Notifications enabled"; | 1754 DVLOG(1) << "Notifications enabled"; |
| 1770 allstatus_.SetNotificationsEnabled(true); | 1755 allstatus_.SetNotificationsEnabled(true); |
| 1771 scheduler_->SetNotificationsEnabled(true); | 1756 scheduler_->SetNotificationsEnabled(true); |
| 1772 | 1757 |
| 1773 // TODO(akalin): Separate onNotificationStateChange into | 1758 // TODO(akalin): Separate onNotificationStateChange into |
| 1774 // enabled/disabled events. | 1759 // enabled/disabled events. |
| 1775 if (js_event_handler_.IsInitialized()) { | 1760 if (js_event_handler_.IsInitialized()) { |
| 1776 DictionaryValue details; | 1761 DictionaryValue details; |
| 1777 details.Set("enabled", Value::CreateBooleanValue(true)); | 1762 details.Set("enabled", Value::CreateBooleanValue(true)); |
| 1778 js_event_handler_.Call(FROM_HERE, | 1763 js_event_handler_.Call(FROM_HERE, |
| 1779 &JsEventHandler::HandleJsEvent, | 1764 &JsEventHandler::HandleJsEvent, |
| 1780 "onNotificationStateChange", | 1765 "onNotificationStateChange", |
| 1781 JsEventDetails(&details)); | 1766 JsEventDetails(&details)); |
| 1782 } | 1767 } |
| 1783 } | 1768 } |
| 1784 | 1769 |
| 1785 void SyncManagerImpl::OnNotificationsDisabled( | 1770 void SyncManagerImpl::OnNotificationsDisabled( |
| 1786 syncer::NotificationsDisabledReason reason) { | 1771 NotificationsDisabledReason reason) { |
| 1787 DVLOG(1) << "Notifications disabled with reason " | 1772 DVLOG(1) << "Notifications disabled with reason " |
| 1788 << syncer::NotificationsDisabledReasonToString(reason); | 1773 << NotificationsDisabledReasonToString(reason); |
| 1789 allstatus_.SetNotificationsEnabled(false); | 1774 allstatus_.SetNotificationsEnabled(false); |
| 1790 scheduler_->SetNotificationsEnabled(false); | 1775 scheduler_->SetNotificationsEnabled(false); |
| 1791 if (js_event_handler_.IsInitialized()) { | 1776 if (js_event_handler_.IsInitialized()) { |
| 1792 DictionaryValue details; | 1777 DictionaryValue details; |
| 1793 details.Set("enabled", Value::CreateBooleanValue(false)); | 1778 details.Set("enabled", Value::CreateBooleanValue(false)); |
| 1794 js_event_handler_.Call(FROM_HERE, | 1779 js_event_handler_.Call(FROM_HERE, |
| 1795 &JsEventHandler::HandleJsEvent, | 1780 &JsEventHandler::HandleJsEvent, |
| 1796 "onNotificationStateChange", | 1781 "onNotificationStateChange", |
| 1797 JsEventDetails(&details)); | 1782 JsEventDetails(&details)); |
| 1798 } | 1783 } |
| 1799 // TODO(akalin): Treat a CREDENTIALS_REJECTED state as an auth | 1784 // TODO(akalin): Treat a CREDENTIALS_REJECTED state as an auth |
| 1800 // error. | 1785 // error. |
| 1801 } | 1786 } |
| 1802 | 1787 |
| 1803 void SyncManagerImpl::OnIncomingNotification( | 1788 void SyncManagerImpl::OnIncomingNotification( |
| 1804 const syncer::ModelTypePayloadMap& type_payloads, | 1789 const ModelTypePayloadMap& type_payloads, |
| 1805 syncer::IncomingNotificationSource source) { | 1790 IncomingNotificationSource source) { |
| 1806 DCHECK(thread_checker_.CalledOnValidThread()); | 1791 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1807 if (source == syncer::LOCAL_NOTIFICATION) { | 1792 if (source == LOCAL_NOTIFICATION) { |
| 1808 scheduler_->ScheduleNudgeWithPayloadsAsync( | 1793 scheduler_->ScheduleNudgeWithPayloadsAsync( |
| 1809 TimeDelta::FromMilliseconds(kSyncRefreshDelayMsec), | 1794 TimeDelta::FromMilliseconds(kSyncRefreshDelayMsec), |
| 1810 syncer::NUDGE_SOURCE_LOCAL_REFRESH, | 1795 NUDGE_SOURCE_LOCAL_REFRESH, |
| 1811 type_payloads, FROM_HERE); | 1796 type_payloads, FROM_HERE); |
| 1812 } else if (!type_payloads.empty()) { | 1797 } else if (!type_payloads.empty()) { |
| 1813 scheduler_->ScheduleNudgeWithPayloadsAsync( | 1798 scheduler_->ScheduleNudgeWithPayloadsAsync( |
| 1814 TimeDelta::FromMilliseconds(kSyncSchedulerDelayMsec), | 1799 TimeDelta::FromMilliseconds(kSyncSchedulerDelayMsec), |
| 1815 syncer::NUDGE_SOURCE_NOTIFICATION, | 1800 NUDGE_SOURCE_NOTIFICATION, |
| 1816 type_payloads, FROM_HERE); | 1801 type_payloads, FROM_HERE); |
| 1817 allstatus_.IncrementNotificationsReceived(); | 1802 allstatus_.IncrementNotificationsReceived(); |
| 1818 UpdateNotificationInfo(type_payloads); | 1803 UpdateNotificationInfo(type_payloads); |
| 1819 debug_info_event_listener_.OnIncomingNotification(type_payloads); | 1804 debug_info_event_listener_.OnIncomingNotification(type_payloads); |
| 1820 } else { | 1805 } else { |
| 1821 LOG(WARNING) << "Sync received notification without any type information."; | 1806 LOG(WARNING) << "Sync received notification without any type information."; |
| 1822 } | 1807 } |
| 1823 | 1808 |
| 1824 if (js_event_handler_.IsInitialized()) { | 1809 if (js_event_handler_.IsInitialized()) { |
| 1825 DictionaryValue details; | 1810 DictionaryValue details; |
| 1826 ListValue* changed_types = new ListValue(); | 1811 ListValue* changed_types = new ListValue(); |
| 1827 details.Set("changedTypes", changed_types); | 1812 details.Set("changedTypes", changed_types); |
| 1828 for (syncer::ModelTypePayloadMap::const_iterator | 1813 for (ModelTypePayloadMap::const_iterator it = type_payloads.begin(); |
| 1829 it = type_payloads.begin(); | |
| 1830 it != type_payloads.end(); ++it) { | 1814 it != type_payloads.end(); ++it) { |
| 1831 const std::string& model_type_str = | 1815 const std::string& model_type_str = |
| 1832 syncer::ModelTypeToString(it->first); | 1816 ModelTypeToString(it->first); |
| 1833 changed_types->Append(Value::CreateStringValue(model_type_str)); | 1817 changed_types->Append(Value::CreateStringValue(model_type_str)); |
| 1834 } | 1818 } |
| 1835 details.SetString("source", (source == syncer::LOCAL_NOTIFICATION) ? | 1819 details.SetString("source", (source == LOCAL_NOTIFICATION) ? |
| 1836 "LOCAL_NOTIFICATION" : "REMOTE_NOTIFICATION"); | 1820 "LOCAL_NOTIFICATION" : "REMOTE_NOTIFICATION"); |
| 1837 js_event_handler_.Call(FROM_HERE, | 1821 js_event_handler_.Call(FROM_HERE, |
| 1838 &JsEventHandler::HandleJsEvent, | 1822 &JsEventHandler::HandleJsEvent, |
| 1839 "onIncomingNotification", | 1823 "onIncomingNotification", |
| 1840 JsEventDetails(&details)); | 1824 JsEventDetails(&details)); |
| 1841 } | 1825 } |
| 1842 } | 1826 } |
| 1843 | 1827 |
| 1844 SyncStatus SyncManagerImpl::GetDetailedStatus() const { | 1828 SyncStatus SyncManagerImpl::GetDetailedStatus() const { |
| 1845 return allstatus_.status(); | 1829 return allstatus_.status(); |
| 1846 } | 1830 } |
| 1847 | 1831 |
| 1848 void SyncManagerImpl::SaveChanges() { | 1832 void SyncManagerImpl::SaveChanges() { |
| 1849 directory()->SaveChanges(); | 1833 directory()->SaveChanges(); |
| 1850 } | 1834 } |
| 1851 | 1835 |
| 1852 const std::string& SyncManagerImpl::username_for_share() const { | 1836 const std::string& SyncManagerImpl::username_for_share() const { |
| 1853 return share_.name; | 1837 return share_.name; |
| 1854 } | 1838 } |
| 1855 | 1839 |
| 1856 UserShare* SyncManagerImpl::GetUserShare() { | 1840 UserShare* SyncManagerImpl::GetUserShare() { |
| 1857 DCHECK(initialized_); | 1841 DCHECK(initialized_); |
| 1858 return &share_; | 1842 return &share_; |
| 1859 } | 1843 } |
| 1860 | 1844 |
| 1861 syncer::ModelTypeSet SyncManagerImpl::GetEncryptedDataTypesForTest() { | 1845 ModelTypeSet SyncManagerImpl::GetEncryptedDataTypesForTest() { |
| 1862 ReadTransaction trans(FROM_HERE, GetUserShare()); | 1846 ReadTransaction trans(FROM_HERE, GetUserShare()); |
| 1863 return GetEncryptedTypes(&trans); | 1847 return GetEncryptedTypes(&trans); |
| 1864 } | 1848 } |
| 1865 | 1849 |
| 1866 bool SyncManagerImpl::ReceivedExperiment(syncer::Experiments* experiments) { | 1850 bool SyncManagerImpl::ReceivedExperiment(Experiments* experiments) { |
| 1867 ReadTransaction trans(FROM_HERE, GetUserShare()); | 1851 ReadTransaction trans(FROM_HERE, GetUserShare()); |
| 1868 ReadNode node(&trans); | 1852 ReadNode node(&trans); |
| 1869 if (node.InitByTagLookup(kNigoriTag) != syncer::BaseNode::INIT_OK) { | 1853 if (node.InitByTagLookup(kNigoriTag) != BaseNode::INIT_OK) { |
| 1870 DVLOG(1) << "Couldn't find Nigori node."; | 1854 DVLOG(1) << "Couldn't find Nigori node."; |
| 1871 return false; | 1855 return false; |
| 1872 } | 1856 } |
| 1873 bool found_experiment = false; | 1857 bool found_experiment = false; |
| 1874 if (node.GetNigoriSpecifics().sync_tab_favicons()) { | 1858 if (node.GetNigoriSpecifics().sync_tab_favicons()) { |
| 1875 experiments->sync_tab_favicons = true; | 1859 experiments->sync_tab_favicons = true; |
| 1876 found_experiment = true; | 1860 found_experiment = true; |
| 1877 } | 1861 } |
| 1878 return found_experiment; | 1862 return found_experiment; |
| 1879 } | 1863 } |
| 1880 | 1864 |
| 1881 bool SyncManagerImpl::HasUnsyncedItems() { | 1865 bool SyncManagerImpl::HasUnsyncedItems() { |
| 1882 syncer::ReadTransaction trans(FROM_HERE, GetUserShare()); | 1866 ReadTransaction trans(FROM_HERE, GetUserShare()); |
| 1883 return (trans.GetWrappedTrans()->directory()->unsynced_entity_count() != 0); | 1867 return (trans.GetWrappedTrans()->directory()->unsynced_entity_count() != 0); |
| 1884 } | 1868 } |
| 1885 | 1869 |
| 1886 void SyncManagerImpl::SimulateEnableNotificationsForTest() { | 1870 void SyncManagerImpl::SimulateEnableNotificationsForTest() { |
| 1887 DCHECK(thread_checker_.CalledOnValidThread()); | 1871 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1888 OnNotificationsEnabled(); | 1872 OnNotificationsEnabled(); |
| 1889 } | 1873 } |
| 1890 | 1874 |
| 1891 void SyncManagerImpl::SimulateDisableNotificationsForTest(int reason) { | 1875 void SyncManagerImpl::SimulateDisableNotificationsForTest(int reason) { |
| 1892 DCHECK(thread_checker_.CalledOnValidThread()); | 1876 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1893 OnNotificationsDisabled( | 1877 OnNotificationsDisabled(static_cast<NotificationsDisabledReason>(reason)); |
| 1894 static_cast<syncer::NotificationsDisabledReason>(reason)); | |
| 1895 } | 1878 } |
| 1896 | 1879 |
| 1897 void SyncManagerImpl::TriggerOnIncomingNotificationForTest( | 1880 void SyncManagerImpl::TriggerOnIncomingNotificationForTest( |
| 1898 ModelTypeSet model_types) { | 1881 ModelTypeSet model_types) { |
| 1899 DCHECK(thread_checker_.CalledOnValidThread()); | 1882 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1900 syncer::ModelTypePayloadMap model_types_with_payloads = | 1883 ModelTypePayloadMap model_types_with_payloads = |
| 1901 syncer::ModelTypePayloadMapFromEnumSet(model_types, | 1884 ModelTypePayloadMapFromEnumSet(model_types, |
| 1902 std::string()); | 1885 std::string()); |
| 1903 | 1886 |
| 1904 OnIncomingNotification(model_types_with_payloads, | 1887 OnIncomingNotification(model_types_with_payloads, REMOTE_NOTIFICATION); |
| 1905 syncer::REMOTE_NOTIFICATION); | |
| 1906 } | 1888 } |
| 1907 | 1889 |
| 1908 // static. | 1890 // static. |
| 1909 int SyncManagerImpl::GetDefaultNudgeDelay() { | 1891 int SyncManagerImpl::GetDefaultNudgeDelay() { |
| 1910 return kDefaultNudgeDelayMilliseconds; | 1892 return kDefaultNudgeDelayMilliseconds; |
| 1911 } | 1893 } |
| 1912 | 1894 |
| 1913 // static. | 1895 // static. |
| 1914 int SyncManagerImpl::GetPreferencesNudgeDelay() { | 1896 int SyncManagerImpl::GetPreferencesNudgeDelay() { |
| 1915 return kPreferencesNudgeDelayMilliseconds; | 1897 return kPreferencesNudgeDelayMilliseconds; |
| 1916 } | 1898 } |
| 1917 | 1899 |
| 1918 } // namespace syncer | 1900 } // namespace syncer |
| OLD | NEW |