Refactor WebsiteSettings to operate on a SecurityInfo
[chromium-blink-merge.git] / chrome / browser / domain_reliability / service_factory.cc
blobbccd3d0cc4f3c54d97073126f582cc512774d2c1
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 "chrome/browser/metrics/chrome_metrics_service_accessor.h"
10 #include "chrome/common/chrome_switches.h"
11 #include "components/domain_reliability/service.h"
12 #include "components/keyed_service/content/browser_context_dependency_manager.h"
13 #include "content/public/browser/browser_context.h"
15 #if defined(OS_CHROMEOS)
16 #include "chrome/browser/chromeos/settings/cros_settings.h"
17 #endif // defined(OS_CHROMEOS)
19 namespace domain_reliability {
21 namespace {
23 // If Domain Reliability is enabled in the absence of a flag or field trial.
24 const bool kDefaultEnabled = true;
26 // The name and value of the field trial to turn Domain Reliability on.
27 const char kFieldTrialName[] = "DomRel-Enable";
28 const char kFieldTrialValueEnable[] = "enable";
30 // Identifies Chrome as the source of Domain Reliability uploads it sends.
31 const char kUploadReporterString[] = "chrome";
33 bool IsDomainReliabilityMonitoringEnabled() {
34 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
35 if (command_line->HasSwitch(switches::kDisableDomainReliability))
36 return false;
37 if (command_line->HasSwitch(switches::kEnableDomainReliability))
38 return true;
40 if (base::FieldTrialList::TrialExists(kFieldTrialName)) {
41 std::string value = base::FieldTrialList::FindFullName(kFieldTrialName);
42 return value == kFieldTrialValueEnable;
45 return kDefaultEnabled;
48 } // namespace
50 // static
51 DomainReliabilityService*
52 DomainReliabilityServiceFactory::GetForBrowserContext(
53 content::BrowserContext* context) {
54 return static_cast<DomainReliabilityService*>(
55 GetInstance()->GetServiceForBrowserContext(context,
56 /* create = */ true));
59 // static
60 DomainReliabilityServiceFactory*
61 DomainReliabilityServiceFactory::GetInstance() {
62 return base::Singleton<DomainReliabilityServiceFactory>::get();
65 DomainReliabilityServiceFactory::DomainReliabilityServiceFactory()
66 : BrowserContextKeyedServiceFactory(
67 "DomainReliabilityService",
68 BrowserContextDependencyManager::GetInstance()) {}
70 DomainReliabilityServiceFactory::~DomainReliabilityServiceFactory() {}
72 KeyedService* DomainReliabilityServiceFactory::BuildServiceInstanceFor(
73 content::BrowserContext* context) const {
74 if (!IsDomainReliabilityMonitoringEnabled())
75 return NULL;
76 // TODO(ttuttle): Move this check closer to where the data gets sent
77 // crbug.com/533486
78 if (!ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled())
79 return NULL;
81 return DomainReliabilityService::Create(kUploadReporterString);
84 } // namespace domain_reliability