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