Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / chrome / browser / domain_reliability / service_factory.cc
blobcd1ee3b9b7535fa904668db7faf0df07c9adf1df
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 #if defined(OS_CHROMEOS)
18 #include "chrome/browser/chromeos/settings/cros_settings.h"
19 #endif // defined(OS_CHROMEOS)
21 namespace domain_reliability {
23 namespace {
25 // If Domain Reliability is enabled in the absence of a flag or field trial.
26 const bool kDefaultEnabled = true;
28 // The name and value of the field trial to turn Domain Reliability on.
29 const char kFieldTrialName[] = "DomRel-Enable";
30 const char kFieldTrialValueEnable[] = "enable";
32 // Identifies Chrome as the source of Domain Reliability uploads it sends.
33 const char kUploadReporterString[] = "chrome";
35 bool IsDomainReliabilityMonitoringEnabled() {
36 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
37 if (command_line->HasSwitch(switches::kDisableDomainReliability))
38 return false;
39 if (command_line->HasSwitch(switches::kEnableDomainReliability))
40 return true;
42 if (base::FieldTrialList::TrialExists(kFieldTrialName)) {
43 std::string value = base::FieldTrialList::FindFullName(kFieldTrialName);
44 return value == kFieldTrialValueEnable;
47 return kDefaultEnabled;
50 bool IsMetricsReportingEnabled() {
51 #if defined(OS_CHROMEOS)
52 bool enabled;
53 bool res = chromeos::CrosSettings::Get()->GetBoolean(
54 chromeos::kStatsReportingPref, &enabled);
55 return res && enabled;
56 #elif defined(OS_ANDROID)
57 return g_browser_process->local_state()->GetBoolean(
58 prefs::kCrashReportingEnabled);
59 #else
60 return g_browser_process->local_state()->GetBoolean(
61 prefs::kMetricsReportingEnabled);
62 #endif
65 } // namespace
67 // static
68 DomainReliabilityService*
69 DomainReliabilityServiceFactory::GetForBrowserContext(
70 content::BrowserContext* context) {
71 return static_cast<DomainReliabilityService*>(
72 GetInstance()->GetServiceForBrowserContext(context,
73 /* create = */ true));
76 // static
77 DomainReliabilityServiceFactory*
78 DomainReliabilityServiceFactory::GetInstance() {
79 return Singleton<DomainReliabilityServiceFactory>::get();
82 DomainReliabilityServiceFactory::DomainReliabilityServiceFactory()
83 : BrowserContextKeyedServiceFactory(
84 "DomainReliabilityService",
85 BrowserContextDependencyManager::GetInstance()) {}
87 DomainReliabilityServiceFactory::~DomainReliabilityServiceFactory() {}
89 KeyedService* DomainReliabilityServiceFactory::BuildServiceInstanceFor(
90 content::BrowserContext* context) const {
91 if (!IsDomainReliabilityMonitoringEnabled())
92 return NULL;
94 if (!IsMetricsReportingEnabled())
95 return NULL;
97 return DomainReliabilityService::Create(kUploadReporterString);
100 } // namespace domain_reliability