| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/user_event_service_factory.h" | 5 #include "chrome/browser/sync/user_event_service_factory.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "chrome/browser/profiles/incognito_helpers.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/sync/profile_sync_service_factory.h" | 13 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 13 #include "chrome/common/channel_info.h" | 14 #include "chrome/common/channel_info.h" |
| 14 #include "components/browser_sync/profile_sync_service.h" | 15 #include "components/browser_sync/profile_sync_service.h" |
| 15 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 16 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
| 16 #include "components/sync/base/model_type.h" | 17 #include "components/sync/base/model_type.h" |
| 17 #include "components/sync/base/report_unrecoverable_error.h" | 18 #include "components/sync/base/report_unrecoverable_error.h" |
| 18 #include "components/sync/user_events/user_event_service.h" | 19 #include "components/sync/user_events/no_op_user_event_service.h" |
| 20 #include "components/sync/user_events/user_event_service_impl.h" |
| 19 #include "components/sync/user_events/user_event_sync_bridge.h" | 21 #include "components/sync/user_events/user_event_sync_bridge.h" |
| 20 | 22 |
| 21 namespace browser_sync { | 23 namespace browser_sync { |
| 22 | 24 |
| 23 // static | 25 // static |
| 24 UserEventServiceFactory* UserEventServiceFactory::GetInstance() { | 26 UserEventServiceFactory* UserEventServiceFactory::GetInstance() { |
| 25 return base::Singleton<UserEventServiceFactory>::get(); | 27 return base::Singleton<UserEventServiceFactory>::get(); |
| 26 } | 28 } |
| 27 | 29 |
| 28 // static | 30 // static |
| 29 syncer::UserEventService* UserEventServiceFactory::GetForProfile( | 31 syncer::UserEventService* UserEventServiceFactory::GetForProfile( |
| 30 Profile* profile) { | 32 Profile* profile) { |
| 31 return static_cast<syncer::UserEventService*>( | 33 return static_cast<syncer::UserEventService*>( |
| 32 GetInstance()->GetServiceForBrowserContext(profile, true)); | 34 GetInstance()->GetServiceForBrowserContext(profile, true)); |
| 33 } | 35 } |
| 34 | 36 |
| 35 UserEventServiceFactory::UserEventServiceFactory() | 37 UserEventServiceFactory::UserEventServiceFactory() |
| 36 : BrowserContextKeyedServiceFactory( | 38 : BrowserContextKeyedServiceFactory( |
| 37 "UserEventService", | 39 "UserEventService", |
| 38 BrowserContextDependencyManager::GetInstance()) {} | 40 BrowserContextDependencyManager::GetInstance()) {} |
| 39 | 41 |
| 40 UserEventServiceFactory::~UserEventServiceFactory() {} | 42 UserEventServiceFactory::~UserEventServiceFactory() {} |
| 41 | 43 |
| 42 KeyedService* UserEventServiceFactory::BuildServiceInstanceFor( | 44 KeyedService* UserEventServiceFactory::BuildServiceInstanceFor( |
| 43 content::BrowserContext* context) const { | 45 content::BrowserContext* context) const { |
| 46 if (context->IsOffTheRecord()) { |
| 47 return new syncer::NoOpUserEventService(); |
| 48 } |
| 49 |
| 44 Profile* profile = Profile::FromBrowserContext(context); | 50 Profile* profile = Profile::FromBrowserContext(context); |
| 45 syncer::ModelTypeStoreFactory store_factory = | 51 syncer::ModelTypeStoreFactory store_factory = |
| 46 browser_sync::ProfileSyncService::GetModelTypeStoreFactory( | 52 browser_sync::ProfileSyncService::GetModelTypeStoreFactory( |
| 47 syncer::USER_EVENTS, profile->GetPath()); | 53 syncer::USER_EVENTS, profile->GetPath()); |
| 48 syncer::ModelTypeSyncBridge::ChangeProcessorFactory processor_factory = | 54 syncer::ModelTypeSyncBridge::ChangeProcessorFactory processor_factory = |
| 49 base::BindRepeating(&syncer::ModelTypeChangeProcessor::Create, | 55 base::BindRepeating(&syncer::ModelTypeChangeProcessor::Create, |
| 50 base::BindRepeating(&syncer::ReportUnrecoverableError, | 56 base::BindRepeating(&syncer::ReportUnrecoverableError, |
| 51 chrome::GetChannel())); | 57 chrome::GetChannel())); |
| 52 auto bridge = base::MakeUnique<syncer::UserEventSyncBridge>( | 58 auto bridge = base::MakeUnique<syncer::UserEventSyncBridge>( |
| 53 std::move(store_factory), std::move(processor_factory)); | 59 std::move(store_factory), std::move(processor_factory)); |
| 54 return new syncer::UserEventService( | 60 return new syncer::UserEventServiceImpl( |
| 55 ProfileSyncServiceFactory::GetForProfile(profile), std::move(bridge)); | 61 ProfileSyncServiceFactory::GetForProfile(profile), std::move(bridge)); |
| 56 } | 62 } |
| 57 | 63 |
| 64 content::BrowserContext* UserEventServiceFactory::GetBrowserContextToUse( |
| 65 content::BrowserContext* context) const { |
| 66 return chrome::GetBrowserContextOwnInstanceInIncognito(context); |
| 67 } |
| 68 |
| 58 } // namespace browser_sync | 69 } // namespace browser_sync |
| OLD | NEW |