| 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/metrics/chrome_metrics_service_client.h" | 5 #include "chrome/browser/metrics/chrome_metrics_service_client.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 #if !defined(OS_CHROMEOS) | 96 #if !defined(OS_CHROMEOS) |
| 97 #include "chrome/browser/signin/chrome_signin_status_metrics_provider_delegate.h
" | 97 #include "chrome/browser/signin/chrome_signin_status_metrics_provider_delegate.h
" |
| 98 #include "components/signin/core/browser/signin_status_metrics_provider.h" | 98 #include "components/signin/core/browser/signin_status_metrics_provider.h" |
| 99 #endif // !defined(OS_CHROMEOS) | 99 #endif // !defined(OS_CHROMEOS) |
| 100 | 100 |
| 101 namespace { | 101 namespace { |
| 102 | 102 |
| 103 // This specifies the amount of time to wait for all renderers to send their | 103 // This specifies the amount of time to wait for all renderers to send their |
| 104 // data. | 104 // data. |
| 105 const int kMaxHistogramGatheringWaitDuration = 60000; // 60 seconds. | 105 const int kMaxHistogramGatheringWaitDuration = 60000; // 60 seconds. |
| 106 const char kBrowserMetricsFileName[] = "SavedMetrics"; | |
| 107 | 106 |
| 108 // Checks whether it is the first time that cellular uploads logic should be | 107 // Checks whether it is the first time that cellular uploads logic should be |
| 109 // enabled based on whether the the preference for that logic is initialized. | 108 // enabled based on whether the the preference for that logic is initialized. |
| 110 // This should happen only once as the used preference will be initialized | 109 // This should happen only once as the used preference will be initialized |
| 111 // afterwards in |UmaSessionStats.java|. | 110 // afterwards in |UmaSessionStats.java|. |
| 112 bool ShouldClearSavedMetrics() { | 111 bool ShouldClearSavedMetrics() { |
| 113 #if BUILDFLAG(ANDROID_JAVA_UI) | 112 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 114 PrefService* local_state = g_browser_process->local_state(); | 113 PrefService* local_state = g_browser_process->local_state(); |
| 115 return !local_state->HasPrefPath(metrics::prefs::kMetricsReportingEnabled) && | 114 return !local_state->HasPrefPath(metrics::prefs::kMetricsReportingEnabled) && |
| 116 metrics::IsCellularLogicEnabled(); | 115 metrics::IsCellularLogicEnabled(); |
| 117 #else | 116 #else |
| 118 return false; | 117 return false; |
| 119 #endif | 118 #endif |
| 120 } | 119 } |
| 121 | 120 |
| 122 void RegisterInstallerFileMetricsPreferences(PrefRegistrySimple* registry) { | 121 void RegisterInstallerFileMetricsPreferences(PrefRegistrySimple* registry) { |
| 123 base::GlobalHistogramAllocator* allocator = | 122 metrics::FileMetricsProvider::RegisterPrefs( |
| 124 base::GlobalHistogramAllocator::GetEvenIfDisabled(); | 123 registry, ChromeMetricsServiceClient::kBrowserMetricsName); |
| 125 if (allocator) | |
| 126 metrics::FileMetricsProvider::RegisterPrefs(registry, allocator->Name()); | |
| 127 | 124 |
| 128 #if defined(OS_WIN) | 125 #if defined(OS_WIN) |
| 129 metrics::FileMetricsProvider::RegisterPrefs( | 126 metrics::FileMetricsProvider::RegisterPrefs( |
| 130 registry, installer::kSetupHistogramAllocatorName); | 127 registry, installer::kSetupHistogramAllocatorName); |
| 131 #endif | 128 #endif |
| 132 } | 129 } |
| 133 | 130 |
| 134 // A wrapper around base::DeleteFile that has no return value and thus can be | |
| 135 // used as a callback. | |
| 136 void LocalDeleteFile(const base::FilePath& path) { | |
| 137 base::DeleteFile(path, /*recursive=*/false); | |
| 138 } | |
| 139 | |
| 140 std::unique_ptr<metrics::FileMetricsProvider> | 131 std::unique_ptr<metrics::FileMetricsProvider> |
| 141 CreateInstallerFileMetricsProvider(bool metrics_reporting_enabled) { | 132 CreateInstallerFileMetricsProvider(bool metrics_reporting_enabled) { |
| 142 // Fetch a worker-pool for performing I/O tasks that are not allowed on | 133 // Fetch a worker-pool for performing I/O tasks that are not allowed on |
| 143 // the main UI thread. | 134 // the main UI thread. |
| 144 scoped_refptr<base::TaskRunner> task_runner = | 135 scoped_refptr<base::TaskRunner> task_runner = |
| 145 content::BrowserThread::GetBlockingPool() | 136 content::BrowserThread::GetBlockingPool() |
| 146 ->GetTaskRunnerWithShutdownBehavior( | 137 ->GetTaskRunnerWithShutdownBehavior( |
| 147 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); | 138 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); |
| 148 | 139 |
| 149 // Create an object to monitor files of metrics and include them in reports. | 140 // Create an object to monitor files of metrics and include them in reports. |
| 150 std::unique_ptr<metrics::FileMetricsProvider> file_metrics_provider( | 141 std::unique_ptr<metrics::FileMetricsProvider> file_metrics_provider( |
| 151 new metrics::FileMetricsProvider(task_runner, | 142 new metrics::FileMetricsProvider(task_runner, |
| 152 g_browser_process->local_state())); | 143 g_browser_process->local_state())); |
| 153 | 144 |
| 154 // Build the pathname for browser's persistent metrics file. Set it as the | 145 // Create the full pathname of the file holding browser metrics. |
| 155 // destination for the GlobalHistogramAllocator during process exit and add | |
| 156 // it to the file-metrics-provider so one written from a previous run will | |
| 157 // be loaded. | |
| 158 // TODO(bcwhite): Actually create those files. | |
| 159 base::FilePath metrics_file; | 146 base::FilePath metrics_file; |
| 160 if (base::PathService::Get(chrome::DIR_USER_DATA, &metrics_file)) { | 147 if (base::PathService::Get(chrome::DIR_USER_DATA, &metrics_file)) { |
| 161 metrics_file = | 148 metrics_file = |
| 162 metrics_file.AppendASCII(kBrowserMetricsFileName) | 149 metrics_file |
| 150 .AppendASCII(ChromeMetricsServiceClient::kBrowserMetricsName) |
| 163 .AddExtension(base::PersistentMemoryAllocator::kFileExtension); | 151 .AddExtension(base::PersistentMemoryAllocator::kFileExtension); |
| 152 |
| 164 if (metrics_reporting_enabled) { | 153 if (metrics_reporting_enabled) { |
| 165 // Metrics get persisted to disk when the process exits. Store the path | 154 // Enable reading any existing saved metrics. |
| 166 // to that file in the global allocator for use at exit time and tell | 155 file_metrics_provider->RegisterSource( |
| 167 // the FileMetricsProvider about that file so it can read one created | 156 metrics_file, |
| 168 // by the previous run. | 157 metrics::FileMetricsProvider::SOURCE_HISTOGRAMS_ATOMIC_FILE, |
| 169 base::GlobalHistogramAllocator* allocator = | 158 metrics::FileMetricsProvider::ASSOCIATE_PREVIOUS_RUN, |
| 170 base::GlobalHistogramAllocator::GetEvenIfDisabled(); | 159 ChromeMetricsServiceClient::kBrowserMetricsName); |
| 171 if (allocator) { | |
| 172 const char* allocator_name = allocator->Name(); | |
| 173 allocator->SetPersistentLocation(metrics_file); | |
| 174 file_metrics_provider->RegisterSource( | |
| 175 metrics_file, | |
| 176 metrics::FileMetricsProvider::SOURCE_HISTOGRAMS_ATOMIC_FILE, | |
| 177 metrics::FileMetricsProvider::ASSOCIATE_PREVIOUS_RUN, | |
| 178 allocator_name); | |
| 179 } | |
| 180 } else { | 160 } else { |
| 181 // When metrics reporting is not enabled, any existing file should be | 161 // When metrics reporting is not enabled, any existing file should be |
| 182 // deleted in order to preserve user privacy. | 162 // deleted in order to preserve user privacy. |
| 183 task_runner->PostTask(FROM_HERE, | 163 task_runner->PostTask(FROM_HERE, |
| 184 base::Bind(&LocalDeleteFile, metrics_file)); | 164 base::Bind(base::IgnoreResult(&base::DeleteFile), |
| 165 metrics_file, /*recursive=*/false)); |
| 185 } | 166 } |
| 186 } | 167 } |
| 187 | 168 |
| 188 #if defined(OS_WIN) | 169 #if defined(OS_WIN) |
| 189 // Read metrics file from setup.exe. | 170 // Read metrics file from setup.exe. |
| 190 base::FilePath program_dir; | 171 base::FilePath program_dir; |
| 191 base::PathService::Get(base::DIR_EXE, &program_dir); | 172 base::PathService::Get(base::DIR_EXE, &program_dir); |
| 192 file_metrics_provider->RegisterSource( | 173 file_metrics_provider->RegisterSource( |
| 193 program_dir.AppendASCII(installer::kSetupHistogramAllocatorName), | 174 program_dir.AppendASCII(installer::kSetupHistogramAllocatorName), |
| 194 metrics::FileMetricsProvider::SOURCE_HISTOGRAMS_ATOMIC_DIR, | 175 metrics::FileMetricsProvider::SOURCE_HISTOGRAMS_ATOMIC_DIR, |
| 195 metrics::FileMetricsProvider::ASSOCIATE_CURRENT_RUN, | 176 metrics::FileMetricsProvider::ASSOCIATE_CURRENT_RUN, |
| 196 installer::kSetupHistogramAllocatorName); | 177 installer::kSetupHistogramAllocatorName); |
| 197 #endif | 178 #endif |
| 198 | 179 |
| 199 return file_metrics_provider; | 180 return file_metrics_provider; |
| 200 } | 181 } |
| 201 | 182 |
| 202 } // namespace | 183 } // namespace |
| 203 | 184 |
| 204 | 185 |
| 186 const char ChromeMetricsServiceClient::kBrowserMetricsName[] = "BrowserMetrics"; |
| 187 |
| 205 ChromeMetricsServiceClient::ChromeMetricsServiceClient( | 188 ChromeMetricsServiceClient::ChromeMetricsServiceClient( |
| 206 metrics::MetricsStateManager* state_manager) | 189 metrics::MetricsStateManager* state_manager) |
| 207 : metrics_state_manager_(state_manager), | 190 : metrics_state_manager_(state_manager), |
| 208 #if defined(OS_CHROMEOS) | 191 #if defined(OS_CHROMEOS) |
| 209 chromeos_metrics_provider_(nullptr), | 192 chromeos_metrics_provider_(nullptr), |
| 210 #endif | 193 #endif |
| 211 waiting_for_collect_final_metrics_step_(false), | 194 waiting_for_collect_final_metrics_step_(false), |
| 212 num_async_histogram_fetches_in_progress_(0), | 195 num_async_histogram_fetches_in_progress_(0), |
| 213 profiler_metrics_provider_(nullptr), | 196 profiler_metrics_provider_(nullptr), |
| 214 #if defined(ENABLE_PLUGINS) | 197 #if defined(ENABLE_PLUGINS) |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 727 } | 710 } |
| 728 } | 711 } |
| 729 | 712 |
| 730 void ChromeMetricsServiceClient::OnURLOpenedFromOmnibox(OmniboxLog* log) { | 713 void ChromeMetricsServiceClient::OnURLOpenedFromOmnibox(OmniboxLog* log) { |
| 731 metrics_service_->OnApplicationNotIdle(); | 714 metrics_service_->OnApplicationNotIdle(); |
| 732 } | 715 } |
| 733 | 716 |
| 734 bool ChromeMetricsServiceClient::IsUMACellularUploadLogicEnabled() { | 717 bool ChromeMetricsServiceClient::IsUMACellularUploadLogicEnabled() { |
| 735 return metrics::IsCellularLogicEnabled(); | 718 return metrics::IsCellularLogicEnabled(); |
| 736 } | 719 } |
| OLD | NEW |