Chromium Code Reviews| 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 namespace domain_reliability { | 17 namespace domain_reliability { |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 // If Domain Reliability is enabled in the absence of a flag or field trial. | |
| 22 const bool kDefaultEnabled = true; | |
| 23 | |
| 24 // The name and value of the field trial to turn Domain Reliability on. | |
| 25 const char* kFieldTrialName = "DomRel-Enable"; | |
|
Bernhard Bauer
2015/02/09 18:19:05
const char kFieldTrialName[] = "..." etc.?
Deprecated (see juliatuttle)
2015/02/09 18:35:11
Done.
| |
| 26 const char* kFieldTrialValueEnable = "enable"; | |
| 27 | |
| 21 // Identifies Chrome as the source of Domain Reliability uploads it sends. | 28 // Identifies Chrome as the source of Domain Reliability uploads it sends. |
| 22 const char* kDomainReliabilityUploadReporterString = "chrome"; | 29 const char* kUploadReporterString = "chrome"; |
| 23 | 30 |
| 24 bool IsDomainReliabilityMonitoringEnabled() { | 31 bool IsDomainReliabilityMonitoringEnabled() { |
| 25 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 32 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 26 if (command_line->HasSwitch(switches::kDisableDomainReliability)) | 33 if (command_line->HasSwitch(switches::kDisableDomainReliability)) |
| 27 return false; | 34 return false; |
| 28 if (command_line->HasSwitch(switches::kEnableDomainReliability)) | 35 if (command_line->HasSwitch(switches::kEnableDomainReliability)) |
| 29 return true; | 36 return true; |
| 30 return base::FieldTrialList::FindFullName("DomRel-Enable") == "enable"; | 37 |
| 38 if (base::FieldTrialList::TrialExists(kFieldTrialName)) { | |
| 39 std::string value = base::FieldTrialList::FindFullName(kFieldTrialName); | |
| 40 return value == kFieldTrialValueEnable; | |
| 41 } | |
| 42 | |
| 43 return kDefaultEnabled; | |
| 31 } | 44 } |
| 32 | 45 |
| 33 } // namespace | 46 } // namespace |
| 34 | 47 |
| 35 // static | 48 // static |
| 36 DomainReliabilityService* | 49 DomainReliabilityService* |
| 37 DomainReliabilityServiceFactory::GetForBrowserContext( | 50 DomainReliabilityServiceFactory::GetForBrowserContext( |
| 38 content::BrowserContext* context) { | 51 content::BrowserContext* context) { |
| 39 return static_cast<DomainReliabilityService*>( | 52 return static_cast<DomainReliabilityService*>( |
| 40 GetInstance()->GetServiceForBrowserContext(context, | 53 GetInstance()->GetServiceForBrowserContext(context, |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 57 KeyedService* DomainReliabilityServiceFactory::BuildServiceInstanceFor( | 70 KeyedService* DomainReliabilityServiceFactory::BuildServiceInstanceFor( |
| 58 content::BrowserContext* context) const { | 71 content::BrowserContext* context) const { |
| 59 if (!IsDomainReliabilityMonitoringEnabled()) | 72 if (!IsDomainReliabilityMonitoringEnabled()) |
| 60 return NULL; | 73 return NULL; |
| 61 | 74 |
| 62 if (!g_browser_process->local_state()->GetBoolean( | 75 if (!g_browser_process->local_state()->GetBoolean( |
| 63 prefs::kMetricsReportingEnabled)) { | 76 prefs::kMetricsReportingEnabled)) { |
| 64 return NULL; | 77 return NULL; |
| 65 } | 78 } |
| 66 | 79 |
| 67 return DomainReliabilityService::Create( | 80 return DomainReliabilityService::Create(kUploadReporterString); |
| 68 kDomainReliabilityUploadReporterString); | |
| 69 } | 81 } |
| 70 | 82 |
| 71 } // namespace domain_reliability | 83 } // namespace domain_reliability |
| OLD | NEW |