blob: 061a33e5c4fd005fec6e60f6caa0dd69c25f3f52 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/domain_reliability/service_factory.h"
#include "base/command_line.h"
#include "base/metrics/field_trial.h"
#include "build/build_config.h"
#include "chrome/browser/metrics/chrome_metrics_service_accessor.h"
#include "chrome/common/chrome_switches.h"
#include "components/domain_reliability/service.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "content/public/browser/browser_context.h"
#if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/settings/cros_settings.h"
#endif // defined(OS_CHROMEOS)
namespace domain_reliability {
namespace {
// If Domain Reliability is enabled in the absence of a flag or field trial.
const bool kDefaultEnabled = true;
// The name and value of the field trial to turn Domain Reliability on.
const char kFieldTrialName[] = "DomRel-Enable";
const char kFieldTrialValueEnable[] = "enable";
// Identifies Chrome as the source of Domain Reliability uploads it sends.
const char kUploadReporterString[] = "chrome";
} // namespace
// static
DomainReliabilityService*
DomainReliabilityServiceFactory::GetForBrowserContext(
content::BrowserContext* context) {
return static_cast<DomainReliabilityService*>(
GetInstance()->GetServiceForBrowserContext(context,
/* create = */ true));
}
// static
DomainReliabilityServiceFactory*
DomainReliabilityServiceFactory::GetInstance() {
return base::Singleton<DomainReliabilityServiceFactory>::get();
}
DomainReliabilityServiceFactory::DomainReliabilityServiceFactory()
: BrowserContextKeyedServiceFactory(
"DomainReliabilityService",
BrowserContextDependencyManager::GetInstance()) {}
DomainReliabilityServiceFactory::~DomainReliabilityServiceFactory() {}
KeyedService* DomainReliabilityServiceFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
if (!ShouldCreateService())
return NULL;
return DomainReliabilityService::Create(kUploadReporterString);
}
bool DomainReliabilityServiceFactory::ShouldCreateService() const {
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(switches::kDisableDomainReliability))
return false;
if (command_line->HasSwitch(switches::kEnableDomainReliability))
return true;
if (!ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled())
return false;
if (base::FieldTrialList::TrialExists(kFieldTrialName)) {
std::string value = base::FieldTrialList::FindFullName(kFieldTrialName);
return (value == kFieldTrialValueEnable);
}
return kDefaultEnabled;
}
} // namespace domain_reliability
|