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 "components/browser_sync/profile_sync_service.h" | 5 #include "components/browser_sync/profile_sync_service.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <cstddef> | 9 #include <cstddef> |
10 #include <map> | 10 #include <map> |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 | 357 |
358 #if defined(OS_CHROMEOS) | 358 #if defined(OS_CHROMEOS) |
359 std::string bootstrap_token = sync_prefs_.GetEncryptionBootstrapToken(); | 359 std::string bootstrap_token = sync_prefs_.GetEncryptionBootstrapToken(); |
360 if (bootstrap_token.empty()) { | 360 if (bootstrap_token.empty()) { |
361 sync_prefs_.SetEncryptionBootstrapToken( | 361 sync_prefs_.SetEncryptionBootstrapToken( |
362 sync_prefs_.GetSpareBootstrapToken()); | 362 sync_prefs_.GetSpareBootstrapToken()); |
363 } | 363 } |
364 #endif | 364 #endif |
365 | 365 |
366 #if !defined(OS_ANDROID) | 366 #if !defined(OS_ANDROID) |
367 DCHECK(sync_error_controller_ == NULL) | 367 DCHECK(sync_error_controller_ == nullptr) |
368 << "Initialize() called more than once."; | 368 << "Initialize() called more than once."; |
369 sync_error_controller_ = base::MakeUnique<syncer::SyncErrorController>(this); | 369 sync_error_controller_ = base::MakeUnique<syncer::SyncErrorController>(this); |
370 AddObserver(sync_error_controller_.get()); | 370 AddObserver(sync_error_controller_.get()); |
371 #endif | 371 #endif |
372 | 372 |
373 memory_pressure_listener_ = base::MakeUnique<base::MemoryPressureListener>( | 373 memory_pressure_listener_ = base::MakeUnique<base::MemoryPressureListener>( |
374 base::Bind(&ProfileSyncService::OnMemoryPressure, | 374 base::Bind(&ProfileSyncService::OnMemoryPressure, |
375 sync_enabled_weak_factory_.GetWeakPtr())); | 375 sync_enabled_weak_factory_.GetWeakPtr())); |
376 startup_controller_->Reset(GetRegisteredDataTypes()); | 376 startup_controller_->Reset(GetRegisteredDataTypes()); |
377 | 377 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 DataTypeController::TypeMap::const_iterator iter = | 423 DataTypeController::TypeMap::const_iterator iter = |
424 data_type_controllers_.find(type); | 424 data_type_controllers_.find(type); |
425 if (iter == data_type_controllers_.end()) { | 425 if (iter == data_type_controllers_.end()) { |
426 return false; | 426 return false; |
427 } | 427 } |
428 return iter->second->state() == DataTypeController::RUNNING; | 428 return iter->second->state() == DataTypeController::RUNNING; |
429 } | 429 } |
430 | 430 |
431 sync_sessions::OpenTabsUIDelegate* ProfileSyncService::GetOpenTabsUIDelegate() { | 431 sync_sessions::OpenTabsUIDelegate* ProfileSyncService::GetOpenTabsUIDelegate() { |
432 if (!IsDataTypeControllerRunning(syncer::SESSIONS)) | 432 if (!IsDataTypeControllerRunning(syncer::SESSIONS)) |
433 return NULL; | 433 return nullptr; |
434 return sessions_sync_manager_.get(); | 434 return sessions_sync_manager_.get(); |
435 } | 435 } |
436 | 436 |
437 sync_sessions::FaviconCache* ProfileSyncService::GetFaviconCache() { | 437 sync_sessions::FaviconCache* ProfileSyncService::GetFaviconCache() { |
438 return sessions_sync_manager_->GetFaviconCache(); | 438 return sessions_sync_manager_->GetFaviconCache(); |
439 } | 439 } |
440 | 440 |
441 syncer::DeviceInfoTracker* ProfileSyncService::GetDeviceInfoTracker() const { | 441 syncer::DeviceInfoTracker* ProfileSyncService::GetDeviceInfoTracker() const { |
442 // One of the two should always be non-null after initialization is done. | 442 // One of the two should always be non-null after initialization is done. |
443 if (device_info_service_) { | 443 if (device_info_service_) { |
(...skipping 1330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1774 } | 1774 } |
1775 | 1775 |
1776 data_type_manager_->Configure(types, reason); | 1776 data_type_manager_->Configure(types, reason); |
1777 } | 1777 } |
1778 | 1778 |
1779 syncer::UserShare* ProfileSyncService::GetUserShare() const { | 1779 syncer::UserShare* ProfileSyncService::GetUserShare() const { |
1780 if (backend_.get() && backend_initialized_) { | 1780 if (backend_.get() && backend_initialized_) { |
1781 return backend_->GetUserShare(); | 1781 return backend_->GetUserShare(); |
1782 } | 1782 } |
1783 NOTREACHED(); | 1783 NOTREACHED(); |
1784 return NULL; | 1784 return nullptr; |
1785 } | 1785 } |
1786 | 1786 |
1787 syncer::SyncCycleSnapshot ProfileSyncService::GetLastCycleSnapshot() const { | 1787 syncer::SyncCycleSnapshot ProfileSyncService::GetLastCycleSnapshot() const { |
1788 if (backend_) | 1788 if (backend_) |
1789 return backend_->GetLastCycleSnapshot(); | 1789 return backend_->GetLastCycleSnapshot(); |
1790 return syncer::SyncCycleSnapshot(); | 1790 return syncer::SyncCycleSnapshot(); |
1791 } | 1791 } |
1792 | 1792 |
1793 bool ProfileSyncService::HasUnsyncedItems() const { | 1793 bool ProfileSyncService::HasUnsyncedItems() const { |
1794 if (HasSyncingBackend() && backend_initialized_) { | 1794 if (HasSyncingBackend() && backend_initialized_) { |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1930 | 1930 |
1931 // If we get here, we don't have pending keys (or at least, the passphrase | 1931 // If we get here, we don't have pending keys (or at least, the passphrase |
1932 // doesn't decrypt them) - just try to re-encrypt using the encryption | 1932 // doesn't decrypt them) - just try to re-encrypt using the encryption |
1933 // passphrase. | 1933 // passphrase. |
1934 if (!IsUsingSecondaryPassphrase()) | 1934 if (!IsUsingSecondaryPassphrase()) |
1935 SetEncryptionPassphrase(passphrase, IMPLICIT); | 1935 SetEncryptionPassphrase(passphrase, IMPLICIT); |
1936 } | 1936 } |
1937 | 1937 |
1938 void ProfileSyncService::RequestAccessToken() { | 1938 void ProfileSyncService::RequestAccessToken() { |
1939 // Only one active request at a time. | 1939 // Only one active request at a time. |
1940 if (access_token_request_ != NULL) | 1940 if (access_token_request_ != nullptr) |
1941 return; | 1941 return; |
1942 request_access_token_retry_timer_.Stop(); | 1942 request_access_token_retry_timer_.Stop(); |
1943 OAuth2TokenService::ScopeSet oauth2_scopes; | 1943 OAuth2TokenService::ScopeSet oauth2_scopes; |
1944 oauth2_scopes.insert(signin_->GetSyncScopeToUse()); | 1944 oauth2_scopes.insert(signin_->GetSyncScopeToUse()); |
1945 | 1945 |
1946 // Invalidate previous token, otherwise token service will return the same | 1946 // Invalidate previous token, otherwise token service will return the same |
1947 // token again. | 1947 // token again. |
1948 const std::string& account_id = signin_->GetAccountIdToUse(); | 1948 const std::string& account_id = signin_->GetAccountIdToUse(); |
1949 if (!access_token_.empty()) { | 1949 if (!access_token_.empty()) { |
1950 oauth2_token_service_->InvalidateAccessToken(account_id, oauth2_scopes, | 1950 oauth2_token_service_->InvalidateAccessToken(account_id, oauth2_scopes, |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2283 sync_prefs_.SetSyncRequested(false); | 2283 sync_prefs_.SetSyncRequested(false); |
2284 StopImpl(data_fate); | 2284 StopImpl(data_fate); |
2285 } | 2285 } |
2286 | 2286 |
2287 bool ProfileSyncService::IsSyncRequested() const { | 2287 bool ProfileSyncService::IsSyncRequested() const { |
2288 return sync_prefs_.IsSyncRequested(); | 2288 return sync_prefs_.IsSyncRequested(); |
2289 } | 2289 } |
2290 | 2290 |
2291 SigninManagerBase* ProfileSyncService::signin() const { | 2291 SigninManagerBase* ProfileSyncService::signin() const { |
2292 if (!signin_) | 2292 if (!signin_) |
2293 return NULL; | 2293 return nullptr; |
2294 return signin_->GetOriginal(); | 2294 return signin_->GetOriginal(); |
2295 } | 2295 } |
2296 | 2296 |
2297 void ProfileSyncService::RequestStart() { | 2297 void ProfileSyncService::RequestStart() { |
2298 if (!IsSyncAllowed()) { | 2298 if (!IsSyncAllowed()) { |
2299 // Sync cannot be requested if it's not allowed. | 2299 // Sync cannot be requested if it's not allowed. |
2300 return; | 2300 return; |
2301 } | 2301 } |
2302 DCHECK(sync_client_); | 2302 DCHECK(sync_client_); |
2303 if (!IsSyncRequested()) { | 2303 if (!IsSyncRequested()) { |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2386 status.next_token_request_time = next_token_request_time_; | 2386 status.next_token_request_time = next_token_request_time_; |
2387 return status; | 2387 return status; |
2388 } | 2388 } |
2389 | 2389 |
2390 void ProfileSyncService::OverrideNetworkResourcesForTest( | 2390 void ProfileSyncService::OverrideNetworkResourcesForTest( |
2391 std::unique_ptr<syncer::NetworkResources> network_resources) { | 2391 std::unique_ptr<syncer::NetworkResources> network_resources) { |
2392 network_resources_ = std::move(network_resources); | 2392 network_resources_ = std::move(network_resources); |
2393 } | 2393 } |
2394 | 2394 |
2395 bool ProfileSyncService::HasSyncingBackend() const { | 2395 bool ProfileSyncService::HasSyncingBackend() const { |
2396 return backend_ != NULL; | 2396 return backend_ != nullptr; |
2397 } | 2397 } |
2398 | 2398 |
2399 void ProfileSyncService::UpdateFirstSyncTimePref() { | 2399 void ProfileSyncService::UpdateFirstSyncTimePref() { |
2400 if (!IsSignedIn()) { | 2400 if (!IsSignedIn()) { |
2401 sync_prefs_.ClearFirstSyncTime(); | 2401 sync_prefs_.ClearFirstSyncTime(); |
2402 } else if (sync_prefs_.GetFirstSyncTime().is_null()) { | 2402 } else if (sync_prefs_.GetFirstSyncTime().is_null()) { |
2403 // Set if not set before and it's syncing now. | 2403 // Set if not set before and it's syncing now. |
2404 sync_prefs_.SetFirstSyncTime(base::Time::Now()); | 2404 sync_prefs_.SetFirstSyncTime(base::Time::Now()); |
2405 } | 2405 } |
2406 } | 2406 } |
2407 | 2407 |
2408 void ProfileSyncService::FlushDirectory() const { | 2408 void ProfileSyncService::FlushDirectory() const { |
2409 // backend_initialized_ implies backend_ isn't NULL and the manager exists. | 2409 // backend_initialized_ implies backend_ isn't null and the manager exists. |
2410 // If sync is not initialized yet, we fail silently. | 2410 // If sync is not initialized yet, we fail silently. |
2411 if (backend_initialized_) | 2411 if (backend_initialized_) |
2412 backend_->FlushDirectory(); | 2412 backend_->FlushDirectory(); |
2413 } | 2413 } |
2414 | 2414 |
2415 base::FilePath ProfileSyncService::GetDirectoryPathForTest() const { | 2415 base::FilePath ProfileSyncService::GetDirectoryPathForTest() const { |
2416 return directory_path_; | 2416 return directory_path_; |
2417 } | 2417 } |
2418 | 2418 |
2419 base::MessageLoop* ProfileSyncService::GetSyncLoopForTest() const { | 2419 base::MessageLoop* ProfileSyncService::GetSyncLoopForTest() const { |
2420 if (sync_thread_) { | 2420 if (sync_thread_) { |
2421 return sync_thread_->message_loop(); | 2421 return sync_thread_->message_loop(); |
2422 } else if (backend_) { | 2422 } else if (backend_) { |
2423 return backend_->GetSyncLoopForTesting(); | 2423 return backend_->GetSyncLoopForTesting(); |
2424 } else { | 2424 } else { |
2425 return NULL; | 2425 return nullptr; |
2426 } | 2426 } |
2427 } | 2427 } |
2428 | 2428 |
2429 void ProfileSyncService::RefreshTypesForTest(syncer::ModelTypeSet types) { | 2429 void ProfileSyncService::RefreshTypesForTest(syncer::ModelTypeSet types) { |
2430 if (backend_initialized_) | 2430 if (backend_initialized_) |
2431 backend_->RefreshTypesForTest(types); | 2431 backend_->RefreshTypesForTest(types); |
2432 } | 2432 } |
2433 | 2433 |
2434 void ProfileSyncService::RemoveClientFromServer() const { | 2434 void ProfileSyncService::RemoveClientFromServer() const { |
2435 if (!backend_initialized_) | 2435 if (!backend_initialized_) |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2496 | 2496 |
2497 DCHECK(startup_controller_->IsSetupInProgress()); | 2497 DCHECK(startup_controller_->IsSetupInProgress()); |
2498 startup_controller_->SetSetupInProgress(false); | 2498 startup_controller_->SetSetupInProgress(false); |
2499 | 2499 |
2500 if (IsBackendInitialized()) | 2500 if (IsBackendInitialized()) |
2501 ReconfigureDatatypeManager(); | 2501 ReconfigureDatatypeManager(); |
2502 NotifyObservers(); | 2502 NotifyObservers(); |
2503 } | 2503 } |
2504 | 2504 |
2505 } // namespace browser_sync | 2505 } // namespace browser_sync |
OLD | NEW |