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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "build/build_config.h" | 6 #include "build/build_config.h" |
7 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 7 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
8 #include "chrome/browser/bookmarks/enhanced_bookmarks_features.h" | 8 #include "chrome/browser/bookmarks/enhanced_bookmarks_features.h" |
9 #include "chrome/browser/dom_distiller/dom_distiller_service_factory.h" | 9 #include "chrome/browser/dom_distiller/dom_distiller_service_factory.h" |
10 #include "chrome/browser/history/history_service.h" | 10 #include "chrome/browser/history/history_service.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 #include "components/password_manager/core/browser/password_store.h" | 53 #include "components/password_manager/core/browser/password_store.h" |
54 #include "components/signin/core/browser/signin_manager.h" | 54 #include "components/signin/core/browser/signin_manager.h" |
55 #include "components/sync_driver/data_type_manager_impl.h" | 55 #include "components/sync_driver/data_type_manager_impl.h" |
56 #include "components/sync_driver/data_type_manager_observer.h" | 56 #include "components/sync_driver/data_type_manager_observer.h" |
57 #include "components/sync_driver/generic_change_processor.h" | 57 #include "components/sync_driver/generic_change_processor.h" |
58 #include "components/sync_driver/proxy_data_type_controller.h" | 58 #include "components/sync_driver/proxy_data_type_controller.h" |
59 #include "components/sync_driver/shared_change_processor.h" | 59 #include "components/sync_driver/shared_change_processor.h" |
60 #include "components/sync_driver/ui_data_type_controller.h" | 60 #include "components/sync_driver/ui_data_type_controller.h" |
61 #include "content/public/browser/browser_thread.h" | 61 #include "content/public/browser/browser_thread.h" |
62 #include "extensions/browser/extension_system.h" | 62 #include "extensions/browser/extension_system.h" |
| 63 #include "google_apis/gaia/oauth2_token_service_request.h" |
| 64 #include "net/url_request/url_request_context_getter.h" |
63 #include "sync/api/attachments/attachment_service.h" | 65 #include "sync/api/attachments/attachment_service.h" |
64 #include "sync/api/attachments/attachment_service_impl.h" | 66 #include "sync/api/attachments/attachment_service_impl.h" |
65 #include "sync/api/syncable_service.h" | 67 #include "sync/api/syncable_service.h" |
| 68 #include "sync/internal_api/public/attachments/attachment_uploader_impl.h" |
66 #include "sync/internal_api/public/attachments/fake_attachment_downloader.h" | 69 #include "sync/internal_api/public/attachments/fake_attachment_downloader.h" |
67 #include "sync/internal_api/public/attachments/fake_attachment_store.h" | 70 #include "sync/internal_api/public/attachments/fake_attachment_store.h" |
68 #include "sync/internal_api/public/attachments/fake_attachment_uploader.h" | |
69 | 71 |
70 #if defined(ENABLE_EXTENSIONS) | 72 #if defined(ENABLE_EXTENSIONS) |
71 #include "chrome/browser/extensions/api/storage/settings_sync_util.h" | 73 #include "chrome/browser/extensions/api/storage/settings_sync_util.h" |
72 #include "chrome/browser/extensions/api/synced_notifications_private/synced_noti
fications_shim.h" | 74 #include "chrome/browser/extensions/api/synced_notifications_private/synced_noti
fications_shim.h" |
73 #include "chrome/browser/extensions/extension_sync_service.h" | 75 #include "chrome/browser/extensions/extension_sync_service.h" |
74 #endif | 76 #endif |
75 | 77 |
76 #if defined(ENABLE_APP_LIST) | 78 #if defined(ENABLE_APP_LIST) |
77 #include "chrome/browser/ui/app_list/app_list_syncable_service.h" | 79 #include "chrome/browser/ui/app_list/app_list_syncable_service.h" |
78 #include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h" | 80 #include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 using browser_sync::SyncBackendHost; | 116 using browser_sync::SyncBackendHost; |
115 using browser_sync::ThemeDataTypeController; | 117 using browser_sync::ThemeDataTypeController; |
116 using browser_sync::TypedUrlChangeProcessor; | 118 using browser_sync::TypedUrlChangeProcessor; |
117 using browser_sync::TypedUrlDataTypeController; | 119 using browser_sync::TypedUrlDataTypeController; |
118 using browser_sync::TypedUrlModelAssociator; | 120 using browser_sync::TypedUrlModelAssociator; |
119 using browser_sync::UIDataTypeController; | 121 using browser_sync::UIDataTypeController; |
120 using content::BrowserThread; | 122 using content::BrowserThread; |
121 | 123 |
122 namespace { | 124 namespace { |
123 | 125 |
| 126 const char kAttachmentsPath[] = "/attachments/"; |
| 127 |
124 syncer::ModelTypeSet GetDisabledTypesFromCommandLine( | 128 syncer::ModelTypeSet GetDisabledTypesFromCommandLine( |
125 const CommandLine& command_line) { | 129 const CommandLine& command_line) { |
126 syncer::ModelTypeSet disabled_types; | 130 syncer::ModelTypeSet disabled_types; |
127 std::string disabled_types_str = | 131 std::string disabled_types_str = |
128 command_line.GetSwitchValueASCII(switches::kDisableSyncTypes); | 132 command_line.GetSwitchValueASCII(switches::kDisableSyncTypes); |
129 disabled_types = syncer::ModelTypeSetFromString(disabled_types_str); | 133 disabled_types = syncer::ModelTypeSetFromString(disabled_types_str); |
130 return disabled_types; | 134 return disabled_types; |
131 } | 135 } |
132 | 136 |
133 syncer::ModelTypeSet GetEnabledTypesFromCommandLine( | 137 syncer::ModelTypeSet GetEnabledTypesFromCommandLine( |
134 const CommandLine& command_line) { | 138 const CommandLine& command_line) { |
135 syncer::ModelTypeSet enabled_types; | 139 syncer::ModelTypeSet enabled_types; |
136 if (command_line.HasSwitch(switches::kEnableSyncSyncedNotifications)) { | 140 if (command_line.HasSwitch(switches::kEnableSyncSyncedNotifications)) { |
137 enabled_types.Put(syncer::SYNCED_NOTIFICATIONS); | 141 enabled_types.Put(syncer::SYNCED_NOTIFICATIONS); |
138 } | 142 } |
139 return enabled_types; | 143 return enabled_types; |
140 } | 144 } |
141 | 145 |
| 146 // Returns the base URL for attachments. |
| 147 std::string GetSyncServiceAttachmentsURL(const GURL& sync_service_url) { |
| 148 return sync_service_url.spec() + kAttachmentsPath; |
| 149 } |
| 150 |
142 } // namespace | 151 } // namespace |
143 | 152 |
144 ProfileSyncComponentsFactoryImpl::ProfileSyncComponentsFactoryImpl( | 153 ProfileSyncComponentsFactoryImpl::ProfileSyncComponentsFactoryImpl( |
145 Profile* profile, CommandLine* command_line) | 154 Profile* profile, |
| 155 CommandLine* command_line, |
| 156 const GURL& sync_service_url, |
| 157 const std::string& account_id, |
| 158 const OAuth2TokenService::ScopeSet& scope_set, |
| 159 OAuth2TokenService* token_service, |
| 160 net::URLRequestContextGetter* url_request_context_getter) |
146 : profile_(profile), | 161 : profile_(profile), |
147 command_line_(command_line), | 162 command_line_(command_line), |
148 extension_system_(extensions::ExtensionSystem::Get(profile)), | 163 extension_system_(extensions::ExtensionSystem::Get(profile)), |
149 web_data_service_( | 164 web_data_service_(WebDataServiceFactory::GetAutofillWebDataForProfile( |
150 WebDataServiceFactory::GetAutofillWebDataForProfile( | 165 profile_, Profile::EXPLICIT_ACCESS)), |
151 profile_, Profile::EXPLICIT_ACCESS)), | 166 sync_service_url_(sync_service_url), |
| 167 account_id_(account_id), |
| 168 scope_set_(scope_set), |
| 169 token_service_(token_service), |
| 170 url_request_context_getter_(url_request_context_getter), |
152 weak_factory_(this) { | 171 weak_factory_(this) { |
| 172 DCHECK(token_service_); |
| 173 DCHECK(url_request_context_getter_); |
153 } | 174 } |
154 | 175 |
155 ProfileSyncComponentsFactoryImpl::~ProfileSyncComponentsFactoryImpl() { | 176 ProfileSyncComponentsFactoryImpl::~ProfileSyncComponentsFactoryImpl() { |
156 } | 177 } |
157 | 178 |
158 void ProfileSyncComponentsFactoryImpl::RegisterDataTypes( | 179 void ProfileSyncComponentsFactoryImpl::RegisterDataTypes( |
159 ProfileSyncService* pss) { | 180 ProfileSyncService* pss) { |
160 syncer::ModelTypeSet disabled_types = | 181 syncer::ModelTypeSet disabled_types = |
161 GetDisabledTypesFromCommandLine(*command_line_); | 182 GetDisabledTypesFromCommandLine(*command_line_); |
162 syncer::ModelTypeSet enabled_types = | 183 syncer::ModelTypeSet enabled_types = |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
569 default: | 590 default: |
570 // The following datatypes still need to be transitioned to the | 591 // The following datatypes still need to be transitioned to the |
571 // syncer::SyncableService API: | 592 // syncer::SyncableService API: |
572 // Bookmarks | 593 // Bookmarks |
573 // Typed URLs | 594 // Typed URLs |
574 NOTREACHED(); | 595 NOTREACHED(); |
575 return base::WeakPtr<syncer::SyncableService>(); | 596 return base::WeakPtr<syncer::SyncableService>(); |
576 } | 597 } |
577 } | 598 } |
578 | 599 |
| 600 class TokenServiceProvider |
| 601 : public OAuth2TokenServiceRequest::TokenServiceProvider { |
| 602 public: |
| 603 TokenServiceProvider( |
| 604 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 605 OAuth2TokenService* token_service); |
| 606 virtual ~TokenServiceProvider(); |
| 607 |
| 608 // OAuth2TokenServiceRequest::TokenServiceProvider implementation. |
| 609 virtual scoped_refptr<base::SingleThreadTaskRunner> |
| 610 GetTokenServiceTaskRunner() OVERRIDE; |
| 611 virtual OAuth2TokenService* GetTokenService() OVERRIDE; |
| 612 |
| 613 private: |
| 614 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 615 OAuth2TokenService* token_service_; |
| 616 }; |
| 617 |
| 618 TokenServiceProvider::TokenServiceProvider( |
| 619 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 620 OAuth2TokenService* token_service) |
| 621 : task_runner_(task_runner), token_service_(token_service) { |
| 622 } |
| 623 |
| 624 TokenServiceProvider::~TokenServiceProvider() { |
| 625 } |
| 626 |
| 627 scoped_refptr<base::SingleThreadTaskRunner> |
| 628 TokenServiceProvider::GetTokenServiceTaskRunner() { |
| 629 return task_runner_; |
| 630 } |
| 631 |
| 632 OAuth2TokenService* TokenServiceProvider::GetTokenService() { |
| 633 return token_service_; |
| 634 } |
| 635 |
579 scoped_ptr<syncer::AttachmentService> | 636 scoped_ptr<syncer::AttachmentService> |
580 ProfileSyncComponentsFactoryImpl::CreateAttachmentService( | 637 ProfileSyncComponentsFactoryImpl::CreateAttachmentService( |
581 syncer::AttachmentService::Delegate* delegate) { | 638 syncer::AttachmentService::Delegate* delegate) { |
582 // TODO(maniscalco): Use a shared (one per profile) thread-safe instances of | 639 std::string url_prefix = GetSyncServiceAttachmentsURL(sync_service_url_); |
| 640 scoped_ptr<OAuth2TokenServiceRequest::TokenServiceProvider> |
| 641 token_service_provider(new TokenServiceProvider( |
| 642 content::BrowserThread::GetMessageLoopProxyForThread( |
| 643 content::BrowserThread::UI), |
| 644 token_service_)); |
| 645 |
| 646 // TODO(maniscalco): Use shared (one per profile) thread-safe instances of |
583 // AttachmentUploader and AttachmentDownloader instead of creating a new one | 647 // AttachmentUploader and AttachmentDownloader instead of creating a new one |
584 // per AttachmentService (bug 369536). | 648 // per AttachmentService (bug 369536). |
585 scoped_ptr<syncer::AttachmentUploader> attachment_uploader( | 649 scoped_ptr<syncer::AttachmentUploader> attachment_uploader( |
586 new syncer::FakeAttachmentUploader); | 650 new syncer::AttachmentUploaderImpl(url_prefix, |
| 651 url_request_context_getter_, |
| 652 account_id_, |
| 653 scope_set_, |
| 654 token_service_provider.Pass())); |
| 655 |
587 scoped_ptr<syncer::AttachmentDownloader> attachment_downloader( | 656 scoped_ptr<syncer::AttachmentDownloader> attachment_downloader( |
588 new syncer::FakeAttachmentDownloader()); | 657 new syncer::FakeAttachmentDownloader()); |
589 | 658 |
590 scoped_ptr<syncer::AttachmentStore> attachment_store( | 659 scoped_ptr<syncer::AttachmentStore> attachment_store( |
591 new syncer::FakeAttachmentStore( | 660 new syncer::FakeAttachmentStore( |
592 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE))); | 661 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE))); |
593 | 662 |
594 scoped_ptr<syncer::AttachmentService> attachment_service( | 663 scoped_ptr<syncer::AttachmentService> attachment_service( |
595 new syncer::AttachmentServiceImpl(attachment_store.Pass(), | 664 new syncer::AttachmentServiceImpl(attachment_store.Pass(), |
596 attachment_uploader.Pass(), | 665 attachment_uploader.Pass(), |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
635 new TypedUrlModelAssociator(profile_sync_service, | 704 new TypedUrlModelAssociator(profile_sync_service, |
636 history_backend, | 705 history_backend, |
637 error_handler); | 706 error_handler); |
638 TypedUrlChangeProcessor* change_processor = | 707 TypedUrlChangeProcessor* change_processor = |
639 new TypedUrlChangeProcessor(profile_, | 708 new TypedUrlChangeProcessor(profile_, |
640 model_associator, | 709 model_associator, |
641 history_backend, | 710 history_backend, |
642 error_handler); | 711 error_handler); |
643 return SyncComponents(model_associator, change_processor); | 712 return SyncComponents(model_associator, change_processor); |
644 } | 713 } |
OLD | NEW |