1 // Copyright 2014 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.
5 #include "chrome/browser/domain_reliability/service_factory.h"
7 #include "base/command_line.h"
8 #include "base/metrics/field_trial.h"
9 #include "base/prefs/pref_service.h"
10 #include "chrome/browser/browser_process.h"
11 #include "chrome/common/chrome_switches.h"
12 #include "chrome/common/pref_names.h"
13 #include "components/domain_reliability/service.h"
14 #include "components/keyed_service/content/browser_context_dependency_manager.h"
15 #include "content/public/browser/browser_context.h"
17 namespace domain_reliability
{
21 // Identifies Chrome as the source of Domain Reliability uploads it sends.
22 const char* kDomainReliabilityUploadReporterString
= "chrome";
24 bool IsDomainReliabilityMonitoringEnabled() {
25 CommandLine
* command_line
= CommandLine::ForCurrentProcess();
26 if (command_line
->HasSwitch(switches::kDisableDomainReliability
))
28 if (command_line
->HasSwitch(switches::kEnableDomainReliability
))
30 return base::FieldTrialList::FindFullName("DomRel-Enable") == "enable";
36 DomainReliabilityService
*
37 DomainReliabilityServiceFactory::GetForBrowserContext(
38 content::BrowserContext
* context
) {
39 return static_cast<DomainReliabilityService
*>(
40 GetInstance()->GetServiceForBrowserContext(context
,
41 /* create = */ true));
45 DomainReliabilityServiceFactory
*
46 DomainReliabilityServiceFactory::GetInstance() {
47 return Singleton
<DomainReliabilityServiceFactory
>::get();
50 DomainReliabilityServiceFactory::DomainReliabilityServiceFactory()
51 : BrowserContextKeyedServiceFactory(
52 "DomainReliabilityService",
53 BrowserContextDependencyManager::GetInstance()) {}
55 DomainReliabilityServiceFactory::~DomainReliabilityServiceFactory() {}
57 KeyedService
* DomainReliabilityServiceFactory::BuildServiceInstanceFor(
58 content::BrowserContext
* context
) const {
59 if (!IsDomainReliabilityMonitoringEnabled())
62 if (!g_browser_process
->local_state()->GetBoolean(
63 prefs::kMetricsReportingEnabled
)) {
67 return DomainReliabilityService::Create(
68 kDomainReliabilityUploadReporterString
);
71 } // namespace domain_reliability