| 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/browser/profile_sync_components_factory_impl.h
" | 5 #include "components/browser_sync/browser/profile_sync_components_factory_impl.h
" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/memory/ptr_util.h" |
| 10 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 11 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 12 #include "components/autofill/core/browser/autofill_wallet_data_type_controller.
h" | 13 #include "components/autofill/core/browser/autofill_wallet_data_type_controller.
h" |
| 13 #include "components/autofill/core/browser/webdata/autofill_data_type_controller
.h" | 14 #include "components/autofill/core/browser/webdata/autofill_data_type_controller
.h" |
| 14 #include "components/autofill/core/browser/webdata/autofill_profile_data_type_co
ntroller.h" | 15 #include "components/autofill/core/browser/webdata/autofill_profile_data_type_co
ntroller.h" |
| 15 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" | 16 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" |
| 16 #include "components/autofill/core/common/autofill_pref_names.h" | 17 #include "components/autofill/core/common/autofill_pref_names.h" |
| 17 #include "components/autofill/core/common/autofill_switches.h" | 18 #include "components/autofill/core/common/autofill_switches.h" |
| 18 #include "components/browser_sync/browser/profile_sync_service.h" | 19 #include "components/browser_sync/browser/profile_sync_service.h" |
| 19 #include "components/browser_sync/common/browser_sync_switches.h" | 20 #include "components/browser_sync/common/browser_sync_switches.h" |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 browser_sync::SyncBackendHost* | 272 browser_sync::SyncBackendHost* |
| 272 ProfileSyncComponentsFactoryImpl::CreateSyncBackendHost( | 273 ProfileSyncComponentsFactoryImpl::CreateSyncBackendHost( |
| 273 const std::string& name, | 274 const std::string& name, |
| 274 invalidation::InvalidationService* invalidator, | 275 invalidation::InvalidationService* invalidator, |
| 275 const base::WeakPtr<sync_driver::SyncPrefs>& sync_prefs, | 276 const base::WeakPtr<sync_driver::SyncPrefs>& sync_prefs, |
| 276 const base::FilePath& sync_folder) { | 277 const base::FilePath& sync_folder) { |
| 277 return new browser_sync::SyncBackendHostImpl( | 278 return new browser_sync::SyncBackendHostImpl( |
| 278 name, sync_client_, ui_thread_, invalidator, sync_prefs, sync_folder); | 279 name, sync_client_, ui_thread_, invalidator, sync_prefs, sync_folder); |
| 279 } | 280 } |
| 280 | 281 |
| 281 scoped_ptr<sync_driver::LocalDeviceInfoProvider> | 282 std::unique_ptr<sync_driver::LocalDeviceInfoProvider> |
| 282 ProfileSyncComponentsFactoryImpl::CreateLocalDeviceInfoProvider() { | 283 ProfileSyncComponentsFactoryImpl::CreateLocalDeviceInfoProvider() { |
| 283 return scoped_ptr<sync_driver::LocalDeviceInfoProvider>( | 284 return base::WrapUnique( |
| 284 new browser_sync::LocalDeviceInfoProviderImpl(channel_, version_, | 285 new browser_sync::LocalDeviceInfoProviderImpl(channel_, version_, |
| 285 is_tablet_)); | 286 is_tablet_)); |
| 286 } | 287 } |
| 287 | 288 |
| 288 class TokenServiceProvider | 289 class TokenServiceProvider |
| 289 : public OAuth2TokenServiceRequest::TokenServiceProvider { | 290 : public OAuth2TokenServiceRequest::TokenServiceProvider { |
| 290 public: | 291 public: |
| 291 TokenServiceProvider( | 292 TokenServiceProvider( |
| 292 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 293 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 293 OAuth2TokenService* token_service); | 294 OAuth2TokenService* token_service); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 313 | 314 |
| 314 scoped_refptr<base::SingleThreadTaskRunner> | 315 scoped_refptr<base::SingleThreadTaskRunner> |
| 315 TokenServiceProvider::GetTokenServiceTaskRunner() { | 316 TokenServiceProvider::GetTokenServiceTaskRunner() { |
| 316 return task_runner_; | 317 return task_runner_; |
| 317 } | 318 } |
| 318 | 319 |
| 319 OAuth2TokenService* TokenServiceProvider::GetTokenService() { | 320 OAuth2TokenService* TokenServiceProvider::GetTokenService() { |
| 320 return token_service_; | 321 return token_service_; |
| 321 } | 322 } |
| 322 | 323 |
| 323 scoped_ptr<syncer::AttachmentService> | 324 std::unique_ptr<syncer::AttachmentService> |
| 324 ProfileSyncComponentsFactoryImpl::CreateAttachmentService( | 325 ProfileSyncComponentsFactoryImpl::CreateAttachmentService( |
| 325 scoped_ptr<syncer::AttachmentStoreForSync> attachment_store, | 326 std::unique_ptr<syncer::AttachmentStoreForSync> attachment_store, |
| 326 const syncer::UserShare& user_share, | 327 const syncer::UserShare& user_share, |
| 327 const std::string& store_birthday, | 328 const std::string& store_birthday, |
| 328 syncer::ModelType model_type, | 329 syncer::ModelType model_type, |
| 329 syncer::AttachmentService::Delegate* delegate) { | 330 syncer::AttachmentService::Delegate* delegate) { |
| 330 scoped_ptr<syncer::AttachmentUploader> attachment_uploader; | 331 std::unique_ptr<syncer::AttachmentUploader> attachment_uploader; |
| 331 scoped_ptr<syncer::AttachmentDownloader> attachment_downloader; | 332 std::unique_ptr<syncer::AttachmentDownloader> attachment_downloader; |
| 332 // Only construct an AttachmentUploader and AttachmentDownload if we have sync | 333 // Only construct an AttachmentUploader and AttachmentDownload if we have sync |
| 333 // credentials. We may not have sync credentials because there may not be a | 334 // credentials. We may not have sync credentials because there may not be a |
| 334 // signed in sync user. | 335 // signed in sync user. |
| 335 if (!user_share.sync_credentials.account_id.empty() && | 336 if (!user_share.sync_credentials.account_id.empty() && |
| 336 !user_share.sync_credentials.scope_set.empty()) { | 337 !user_share.sync_credentials.scope_set.empty()) { |
| 337 scoped_refptr<OAuth2TokenServiceRequest::TokenServiceProvider> | 338 scoped_refptr<OAuth2TokenServiceRequest::TokenServiceProvider> |
| 338 token_service_provider( | 339 token_service_provider( |
| 339 new TokenServiceProvider(ui_thread_, token_service_)); | 340 new TokenServiceProvider(ui_thread_, token_service_)); |
| 340 // TODO(maniscalco): Use shared (one per profile) thread-safe instances of | 341 // TODO(maniscalco): Use shared (one per profile) thread-safe instances of |
| 341 // AttachmentUploader and AttachmentDownloader instead of creating a new one | 342 // AttachmentUploader and AttachmentDownloader instead of creating a new one |
| (...skipping 13 matching lines...) Expand all Loading... |
| 355 store_birthday, model_type); | 356 store_birthday, model_type); |
| 356 } | 357 } |
| 357 | 358 |
| 358 // It is important that the initial backoff delay is relatively large. For | 359 // It is important that the initial backoff delay is relatively large. For |
| 359 // whatever reason, the server may fail all requests for a short period of | 360 // whatever reason, the server may fail all requests for a short period of |
| 360 // time. When this happens we don't want to overwhelm the server with | 361 // time. When this happens we don't want to overwhelm the server with |
| 361 // requests so we use a large initial backoff. | 362 // requests so we use a large initial backoff. |
| 362 const base::TimeDelta initial_backoff_delay = | 363 const base::TimeDelta initial_backoff_delay = |
| 363 base::TimeDelta::FromMinutes(30); | 364 base::TimeDelta::FromMinutes(30); |
| 364 const base::TimeDelta max_backoff_delay = base::TimeDelta::FromHours(4); | 365 const base::TimeDelta max_backoff_delay = base::TimeDelta::FromHours(4); |
| 365 scoped_ptr<syncer::AttachmentService> attachment_service( | 366 std::unique_ptr<syncer::AttachmentService> attachment_service( |
| 366 new syncer::AttachmentServiceImpl( | 367 new syncer::AttachmentServiceImpl( |
| 367 std::move(attachment_store), std::move(attachment_uploader), | 368 std::move(attachment_store), std::move(attachment_uploader), |
| 368 std::move(attachment_downloader), delegate, initial_backoff_delay, | 369 std::move(attachment_downloader), delegate, initial_backoff_delay, |
| 369 max_backoff_delay)); | 370 max_backoff_delay)); |
| 370 return attachment_service; | 371 return attachment_service; |
| 371 } | 372 } |
| 372 | 373 |
| 373 sync_driver::SyncApiComponentFactory::SyncComponents | 374 sync_driver::SyncApiComponentFactory::SyncComponents |
| 374 ProfileSyncComponentsFactoryImpl::CreateBookmarkSyncComponents( | 375 ProfileSyncComponentsFactoryImpl::CreateBookmarkSyncComponents( |
| 375 sync_driver::SyncService* sync_service, | 376 sync_driver::SyncService* sync_service, |
| 376 sync_driver::DataTypeErrorHandler* error_handler) { | 377 sync_driver::DataTypeErrorHandler* error_handler) { |
| 377 BookmarkModel* bookmark_model = | 378 BookmarkModel* bookmark_model = |
| 378 sync_service->GetSyncClient()->GetBookmarkModel(); | 379 sync_service->GetSyncClient()->GetBookmarkModel(); |
| 379 syncer::UserShare* user_share = sync_service->GetUserShare(); | 380 syncer::UserShare* user_share = sync_service->GetUserShare(); |
| 380 // TODO(akalin): We may want to propagate this switch up eventually. | 381 // TODO(akalin): We may want to propagate this switch up eventually. |
| 381 #if defined(OS_ANDROID) || defined(OS_IOS) | 382 #if defined(OS_ANDROID) || defined(OS_IOS) |
| 382 const bool kExpectMobileBookmarksFolder = true; | 383 const bool kExpectMobileBookmarksFolder = true; |
| 383 #else | 384 #else |
| 384 const bool kExpectMobileBookmarksFolder = false; | 385 const bool kExpectMobileBookmarksFolder = false; |
| 385 #endif | 386 #endif |
| 386 BookmarkModelAssociator* model_associator = new BookmarkModelAssociator( | 387 BookmarkModelAssociator* model_associator = new BookmarkModelAssociator( |
| 387 bookmark_model, sync_service->GetSyncClient(), user_share, error_handler, | 388 bookmark_model, sync_service->GetSyncClient(), user_share, error_handler, |
| 388 kExpectMobileBookmarksFolder); | 389 kExpectMobileBookmarksFolder); |
| 389 BookmarkChangeProcessor* change_processor = new BookmarkChangeProcessor( | 390 BookmarkChangeProcessor* change_processor = new BookmarkChangeProcessor( |
| 390 sync_service->GetSyncClient(), model_associator, error_handler); | 391 sync_service->GetSyncClient(), model_associator, error_handler); |
| 391 return SyncComponents(model_associator, change_processor); | 392 return SyncComponents(model_associator, change_processor); |
| 392 } | 393 } |
| OLD | NEW |