| 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 "chrome/browser/sync/profile_sync_service.h" | 5 #include "chrome/browser/sync/profile_sync_service.h" |
| 6 | 6 |
| 7 #include <cstddef> | 7 #include <cstddef> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 | 355 |
| 356 void ProfileSyncService::RegisterDataTypeController( | 356 void ProfileSyncService::RegisterDataTypeController( |
| 357 DataTypeController* data_type_controller) { | 357 DataTypeController* data_type_controller) { |
| 358 DCHECK_EQ(data_type_controllers_.count(data_type_controller->type()), 0U); | 358 DCHECK_EQ(data_type_controllers_.count(data_type_controller->type()), 0U); |
| 359 data_type_controllers_[data_type_controller->type()] = | 359 data_type_controllers_[data_type_controller->type()] = |
| 360 data_type_controller; | 360 data_type_controller; |
| 361 } | 361 } |
| 362 | 362 |
| 363 browser_sync::SessionModelAssociator* | 363 browser_sync::SessionModelAssociator* |
| 364 ProfileSyncService::GetSessionModelAssociatorDeprecated() { | 364 ProfileSyncService::GetSessionModelAssociatorDeprecated() { |
| 365 if (data_type_controllers_.find(syncer::SESSIONS) == | 365 if (!IsSessionsDataTypeControllerRunning()) |
| 366 data_type_controllers_.end() || | |
| 367 data_type_controllers_.find(syncer::SESSIONS)->second->state() != | |
| 368 DataTypeController::RUNNING) { | |
| 369 return NULL; | 366 return NULL; |
| 370 } | |
| 371 | 367 |
| 372 // If we're using sessions V2, there's no model associator. | 368 // If we're using sessions V2, there's no model associator. |
| 373 if (sessions_sync_manager_.get()) | 369 if (sessions_sync_manager_.get()) |
| 374 return NULL; | 370 return NULL; |
| 375 | 371 |
| 376 return static_cast<browser_sync::SessionDataTypeController*>( | 372 return static_cast<browser_sync::SessionDataTypeController*>( |
| 377 data_type_controllers_.find( | 373 data_type_controllers_.find( |
| 378 syncer::SESSIONS)->second.get())->GetModelAssociator(); | 374 syncer::SESSIONS)->second.get())->GetModelAssociator(); |
| 379 } | 375 } |
| 380 | 376 |
| 377 bool ProfileSyncService::IsSessionsDataTypeControllerRunning() const { |
| 378 return data_type_controllers_.find(syncer::SESSIONS) != |
| 379 data_type_controllers_.end() && |
| 380 data_type_controllers_.find(syncer::SESSIONS)->second->state() == |
| 381 DataTypeController::RUNNING; |
| 382 } |
| 383 |
| 381 browser_sync::OpenTabsUIDelegate* ProfileSyncService::GetOpenTabsUIDelegate() { | 384 browser_sync::OpenTabsUIDelegate* ProfileSyncService::GetOpenTabsUIDelegate() { |
| 382 if (data_type_controllers_.find(syncer::SESSIONS) == | 385 if (!IsSessionsDataTypeControllerRunning()) |
| 383 data_type_controllers_.end() || | |
| 384 data_type_controllers_.find(syncer::SESSIONS)->second->state() != | |
| 385 DataTypeController::RUNNING) { | |
| 386 return NULL; | 386 return NULL; |
| 387 } | |
| 388 | 387 |
| 389 if (CommandLine::ForCurrentProcess()->HasSwitch( | 388 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 390 switches::kEnableSyncSessionsV2)) { | 389 switches::kEnableSyncSessionsV2)) { |
| 391 return sessions_sync_manager_.get(); | 390 return sessions_sync_manager_.get(); |
| 392 } else { | 391 } else { |
| 393 return GetSessionModelAssociatorDeprecated(); | 392 return GetSessionModelAssociatorDeprecated(); |
| 394 } | 393 } |
| 395 } | 394 } |
| 396 | 395 |
| 397 browser_sync::FaviconCache* ProfileSyncService::GetFaviconCache() { | 396 browser_sync::FaviconCache* ProfileSyncService::GetFaviconCache() { |
| (...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1059 ConfigureDataTypeManager(); | 1058 ConfigureDataTypeManager(); |
| 1060 } else { | 1059 } else { |
| 1061 DCHECK(FirstSetupInProgress()); | 1060 DCHECK(FirstSetupInProgress()); |
| 1062 } | 1061 } |
| 1063 | 1062 |
| 1064 NotifyObservers(); | 1063 NotifyObservers(); |
| 1065 } | 1064 } |
| 1066 | 1065 |
| 1067 void ProfileSyncService::OnSyncCycleCompleted() { | 1066 void ProfileSyncService::OnSyncCycleCompleted() { |
| 1068 UpdateLastSyncedTime(); | 1067 UpdateLastSyncedTime(); |
| 1069 if (GetSessionModelAssociatorDeprecated()) { | 1068 if (IsSessionsDataTypeControllerRunning()) { |
| 1070 // Trigger garbage collection of old sessions now that we've downloaded | 1069 // Trigger garbage collection of old sessions now that we've downloaded |
| 1071 // any new session data. TODO(zea): Have this be a notification the session | 1070 // any new session data. |
| 1072 // model associator listens too. Also consider somehow plumbing the current | 1071 if (sessions_sync_manager_) { |
| 1073 // server time as last reported by CheckServerReachable, so we don't have to | 1072 // Sessions V2. |
| 1074 // rely on the local clock, which may be off significantly. | 1073 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind( |
| 1075 base::MessageLoop::current()->PostTask(FROM_HERE, | 1074 &browser_sync::SessionsSyncManager::DoGarbageCollection, |
| 1076 base::Bind(&browser_sync::SessionModelAssociator::DeleteStaleSessions, | 1075 base::AsWeakPtr(sessions_sync_manager_.get()))); |
| 1077 GetSessionModelAssociatorDeprecated()->AsWeakPtr())); | 1076 } else { |
| 1077 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind( |
| 1078 &browser_sync::SessionModelAssociator::DeleteStaleSessions, |
| 1079 GetSessionModelAssociatorDeprecated()->AsWeakPtr())); |
| 1080 } |
| 1078 } | 1081 } |
| 1079 DVLOG(2) << "Notifying observers sync cycle completed"; | 1082 DVLOG(2) << "Notifying observers sync cycle completed"; |
| 1080 NotifySyncCycleCompleted(); | 1083 NotifySyncCycleCompleted(); |
| 1081 } | 1084 } |
| 1082 | 1085 |
| 1083 void ProfileSyncService::OnExperimentsChanged( | 1086 void ProfileSyncService::OnExperimentsChanged( |
| 1084 const syncer::Experiments& experiments) { | 1087 const syncer::Experiments& experiments) { |
| 1085 if (current_experiments_.Matches(experiments)) | 1088 if (current_experiments_.Matches(experiments)) |
| 1086 return; | 1089 return; |
| 1087 | 1090 |
| (...skipping 1169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2257 SyncTokenStatus status; | 2260 SyncTokenStatus status; |
| 2258 status.connection_status_update_time = connection_status_update_time_; | 2261 status.connection_status_update_time = connection_status_update_time_; |
| 2259 status.connection_status = connection_status_; | 2262 status.connection_status = connection_status_; |
| 2260 status.token_request_time = token_request_time_; | 2263 status.token_request_time = token_request_time_; |
| 2261 status.token_receive_time = token_receive_time_; | 2264 status.token_receive_time = token_receive_time_; |
| 2262 status.last_get_token_error = last_get_token_error_; | 2265 status.last_get_token_error = last_get_token_error_; |
| 2263 if (request_access_token_retry_timer_.IsRunning()) | 2266 if (request_access_token_retry_timer_.IsRunning()) |
| 2264 status.next_token_request_time = next_token_request_time_; | 2267 status.next_token_request_time = next_token_request_time_; |
| 2265 return status; | 2268 return status; |
| 2266 } | 2269 } |
| OLD | NEW |