| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/domain_reliability/service_factory.h" | 5 #include "chrome/browser/domain_reliability/service_factory.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 11 #include "chrome/common/chrome_switches.h" | 11 #include "chrome/common/chrome_switches.h" |
| 12 #include "chrome/common/pref_names.h" | 12 #include "chrome/common/pref_names.h" |
| 13 #include "components/domain_reliability/service.h" | 13 #include "components/domain_reliability/service.h" |
| 14 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 14 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
| 15 #include "content/public/browser/browser_context.h" | 15 #include "content/public/browser/browser_context.h" |
| 16 | 16 |
| 17 #if defined(OS_CHROMEOS) | 17 #if defined(OS_CHROMEOS) |
| 18 #include "chrome/browser/chromeos/settings/cros_settings.h" | 18 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 19 #endif // defined(OS_CHROMEOS) | 19 #endif // defined(OS_CHROMEOS) |
| 20 | 20 |
| 21 namespace domain_reliability { | 21 namespace domain_reliability { |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 // If Domain Reliability is enabled in the absence of a flag or field trial. |
| 26 const bool kDefaultEnabled = true; |
| 27 |
| 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"; |
| 31 |
| 25 // Identifies Chrome as the source of Domain Reliability uploads it sends. | 32 // Identifies Chrome as the source of Domain Reliability uploads it sends. |
| 26 const char* kDomainReliabilityUploadReporterString = "chrome"; | 33 const char kUploadReporterString[] = "chrome"; |
| 27 | 34 |
| 28 bool IsDomainReliabilityMonitoringEnabled() { | 35 bool IsDomainReliabilityMonitoringEnabled() { |
| 29 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 36 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 30 if (command_line->HasSwitch(switches::kDisableDomainReliability)) | 37 if (command_line->HasSwitch(switches::kDisableDomainReliability)) |
| 31 return false; | 38 return false; |
| 32 if (command_line->HasSwitch(switches::kEnableDomainReliability)) | 39 if (command_line->HasSwitch(switches::kEnableDomainReliability)) |
| 33 return true; | 40 return true; |
| 34 return base::FieldTrialList::FindFullName("DomRel-Enable") == "enable"; | 41 |
| 42 if (base::FieldTrialList::TrialExists(kFieldTrialName)) { |
| 43 std::string value = base::FieldTrialList::FindFullName(kFieldTrialName); |
| 44 return value == kFieldTrialValueEnable; |
| 45 } |
| 46 |
| 47 return kDefaultEnabled; |
| 35 } | 48 } |
| 36 | 49 |
| 37 bool IsMetricsReportingEnabled() { | 50 bool IsMetricsReportingEnabled() { |
| 38 #if defined(OS_CHROMEOS) | 51 #if defined(OS_CHROMEOS) |
| 39 bool enabled; | 52 bool enabled; |
| 40 chromeos::CrosSettings::Get()->GetBoolean(chromeos::kStatsReportingPref, | 53 chromeos::CrosSettings::Get()->GetBoolean(chromeos::kStatsReportingPref, |
| 41 &enabled); | 54 &enabled); |
| 42 return enabled; | 55 return enabled; |
| 43 #elif defined(OS_ANDROID) | 56 #elif defined(OS_ANDROID) |
| 44 return g_browser_process->local_state()->GetBoolean( | 57 return g_browser_process->local_state()->GetBoolean( |
| (...skipping 29 matching lines...) Expand all Loading... |
| 74 DomainReliabilityServiceFactory::~DomainReliabilityServiceFactory() {} | 87 DomainReliabilityServiceFactory::~DomainReliabilityServiceFactory() {} |
| 75 | 88 |
| 76 KeyedService* DomainReliabilityServiceFactory::BuildServiceInstanceFor( | 89 KeyedService* DomainReliabilityServiceFactory::BuildServiceInstanceFor( |
| 77 content::BrowserContext* context) const { | 90 content::BrowserContext* context) const { |
| 78 if (!IsDomainReliabilityMonitoringEnabled()) | 91 if (!IsDomainReliabilityMonitoringEnabled()) |
| 79 return NULL; | 92 return NULL; |
| 80 | 93 |
| 81 if (!IsMetricsReportingEnabled()) | 94 if (!IsMetricsReportingEnabled()) |
| 82 return NULL; | 95 return NULL; |
| 83 | 96 |
| 84 return DomainReliabilityService::Create( | 97 return DomainReliabilityService::Create(kUploadReporterString); |
| 85 kDomainReliabilityUploadReporterString); | |
| 86 } | 98 } |
| 87 | 99 |
| 88 } // namespace domain_reliability | 100 } // namespace domain_reliability |
| OLD | NEW |