|
| 1 | +// Copyright 2018 The Chromium Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style license that can be |
| 3 | +// found in the LICENSE file. |
| 4 | + |
| 5 | +#include "ios/chrome/browser/consent_auditor/consent_auditor_factory.h" |
| 6 | + |
| 7 | +#include "base/memory/ptr_util.h" |
| 8 | +#include "base/memory/singleton.h" |
| 9 | +#include "components/consent_auditor/consent_auditor.h" |
| 10 | +#include "components/keyed_service/ios/browser_state_dependency_manager.h" |
| 11 | +#include "components/pref_registry/pref_registry_syncable.h" |
| 12 | +#include "components/version_info/version_info.h" |
| 13 | +#include "ios/chrome/browser/application_context.h" |
| 14 | +#include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
| 15 | +#include "ios/chrome/browser/sync/ios_user_event_service_factory.h" |
| 16 | +#include "ios/web/public/browser_state.h" |
| 17 | + |
| 18 | +// static |
| 19 | +consent_auditor::ConsentAuditor* ConsentAuditorFactory::GetForBrowserState( |
| 20 | + ios::ChromeBrowserState* browser_state) { |
| 21 | + return static_cast<consent_auditor::ConsentAuditor*>( |
| 22 | + GetInstance()->GetServiceForBrowserState(browser_state, true)); |
| 23 | +} |
| 24 | + |
| 25 | +// static |
| 26 | +consent_auditor::ConsentAuditor* |
| 27 | +ConsentAuditorFactory::GetForBrowserStateIfExists( |
| 28 | + ios::ChromeBrowserState* browser_state) { |
| 29 | + return static_cast<consent_auditor::ConsentAuditor*>( |
| 30 | + GetInstance()->GetServiceForBrowserState(browser_state, false)); |
| 31 | +} |
| 32 | + |
| 33 | +// static |
| 34 | +ConsentAuditorFactory* ConsentAuditorFactory::GetInstance() { |
| 35 | + return base::Singleton<ConsentAuditorFactory>::get(); |
| 36 | +} |
| 37 | + |
| 38 | +ConsentAuditorFactory::ConsentAuditorFactory() |
| 39 | + : BrowserStateKeyedServiceFactory( |
| 40 | + "ConsentAuditor", |
| 41 | + BrowserStateDependencyManager::GetInstance()) { |
| 42 | + DependsOn(IOSUserEventServiceFactory::GetInstance()); |
| 43 | +} |
| 44 | + |
| 45 | +ConsentAuditorFactory::~ConsentAuditorFactory() {} |
| 46 | + |
| 47 | +std::unique_ptr<KeyedService> ConsentAuditorFactory::BuildServiceInstanceFor( |
| 48 | + web::BrowserState* browser_state) const { |
| 49 | + ios::ChromeBrowserState* ios_browser_state = |
| 50 | + ios::ChromeBrowserState::FromBrowserState(browser_state); |
| 51 | + syncer::UserEventService* const user_event_service = |
| 52 | + IOSUserEventServiceFactory::GetForBrowserState(ios_browser_state); |
| 53 | + return std::make_unique<consent_auditor::ConsentAuditor>( |
| 54 | + ios_browser_state->GetPrefs(), user_event_service, |
| 55 | + // The browser version and locale do not change runtime, so we can pass |
| 56 | + // them directly. |
| 57 | + version_info::GetVersionNumber(), |
| 58 | + GetApplicationContext()->GetApplicationLocale()); |
| 59 | +} |
| 60 | + |
| 61 | +bool ConsentAuditorFactory::ServiceIsNULLWhileTesting() const { |
| 62 | + return true; |
| 63 | +} |
| 64 | + |
| 65 | +void ConsentAuditorFactory::RegisterBrowserStatePrefs( |
| 66 | + user_prefs::PrefRegistrySyncable* registry) { |
| 67 | + consent_auditor::ConsentAuditor::RegisterProfilePrefs(registry); |
| 68 | +} |
0 commit comments