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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 file_metrics_provider->RegisterSource( | 173 file_metrics_provider->RegisterSource( |
174 program_dir.AppendASCII(installer::kSetupHistogramAllocatorName), | 174 program_dir.AppendASCII(installer::kSetupHistogramAllocatorName), |
175 metrics::FileMetricsProvider::SOURCE_HISTOGRAMS_ATOMIC_DIR, | 175 metrics::FileMetricsProvider::SOURCE_HISTOGRAMS_ATOMIC_DIR, |
176 metrics::FileMetricsProvider::ASSOCIATE_CURRENT_RUN, | 176 metrics::FileMetricsProvider::ASSOCIATE_CURRENT_RUN, |
177 installer::kSetupHistogramAllocatorName); | 177 installer::kSetupHistogramAllocatorName); |
178 #endif | 178 #endif |
179 | 179 |
180 return file_metrics_provider; | 180 return file_metrics_provider; |
181 } | 181 } |
182 | 182 |
| 183 // If there is a global metrics file being updated on disk, mark it to be |
| 184 // deleted when the process exits. A normal shutdown is almost complete |
| 185 // so there is no benefit in keeping a file with no new data to be processed |
| 186 // during the next startup sequence. Deleting the file during shutdown adds |
| 187 // an extra disk-access or two to shutdown but eliminates the unnecessary |
| 188 // processing of the contents during startup only to find nothing. |
| 189 void CleanUpGlobalPersistentHistogramStorage() { |
| 190 base::GlobalHistogramAllocator* allocator = |
| 191 base::GlobalHistogramAllocator::Get(); |
| 192 if (!allocator) |
| 193 return; |
| 194 |
| 195 const base::FilePath& path = allocator->GetPersistentLocation(); |
| 196 if (path.empty()) |
| 197 return; |
| 198 |
| 199 // Open (with delete) and then immediately close the file by going out of |
| 200 // scope. This is the only cross-platform safe way to delete a file that may |
| 201 // be open elsewhere. |
| 202 base::File file(path, base::File::FLAG_OPEN | base::File::FLAG_READ | |
| 203 base::File::FLAG_DELETE_ON_CLOSE); |
| 204 } |
| 205 |
183 } // namespace | 206 } // namespace |
184 | 207 |
185 | 208 |
186 const char ChromeMetricsServiceClient::kBrowserMetricsName[] = "BrowserMetrics"; | 209 const char ChromeMetricsServiceClient::kBrowserMetricsName[] = "BrowserMetrics"; |
187 | 210 |
188 ChromeMetricsServiceClient::ChromeMetricsServiceClient( | 211 ChromeMetricsServiceClient::ChromeMetricsServiceClient( |
189 metrics::MetricsStateManager* state_manager) | 212 metrics::MetricsStateManager* state_manager) |
190 : metrics_state_manager_(state_manager), | 213 : metrics_state_manager_(state_manager), |
191 #if defined(OS_CHROMEOS) | 214 #if defined(OS_CHROMEOS) |
192 chromeos_metrics_provider_(nullptr), | 215 chromeos_metrics_provider_(nullptr), |
(...skipping 11 matching lines...) Expand all Loading... |
204 start_time_(base::TimeTicks::Now()), | 227 start_time_(base::TimeTicks::Now()), |
205 has_uploaded_profiler_data_(false), | 228 has_uploaded_profiler_data_(false), |
206 weak_ptr_factory_(this) { | 229 weak_ptr_factory_(this) { |
207 DCHECK(thread_checker_.CalledOnValidThread()); | 230 DCHECK(thread_checker_.CalledOnValidThread()); |
208 RecordCommandLineMetrics(); | 231 RecordCommandLineMetrics(); |
209 RegisterForNotifications(); | 232 RegisterForNotifications(); |
210 } | 233 } |
211 | 234 |
212 ChromeMetricsServiceClient::~ChromeMetricsServiceClient() { | 235 ChromeMetricsServiceClient::~ChromeMetricsServiceClient() { |
213 DCHECK(thread_checker_.CalledOnValidThread()); | 236 DCHECK(thread_checker_.CalledOnValidThread()); |
| 237 CleanUpGlobalPersistentHistogramStorage(); |
214 } | 238 } |
215 | 239 |
216 // static | 240 // static |
217 std::unique_ptr<ChromeMetricsServiceClient> ChromeMetricsServiceClient::Create( | 241 std::unique_ptr<ChromeMetricsServiceClient> ChromeMetricsServiceClient::Create( |
218 metrics::MetricsStateManager* state_manager, | 242 metrics::MetricsStateManager* state_manager, |
219 PrefService* local_state) { | 243 PrefService* local_state) { |
220 // Perform two-phase initialization so that |client->metrics_service_| only | 244 // Perform two-phase initialization so that |client->metrics_service_| only |
221 // receives pointers to fully constructed objects. | 245 // receives pointers to fully constructed objects. |
222 std::unique_ptr<ChromeMetricsServiceClient> client( | 246 std::unique_ptr<ChromeMetricsServiceClient> client( |
223 new ChromeMetricsServiceClient(state_manager)); | 247 new ChromeMetricsServiceClient(state_manager)); |
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
710 } | 734 } |
711 } | 735 } |
712 | 736 |
713 void ChromeMetricsServiceClient::OnURLOpenedFromOmnibox(OmniboxLog* log) { | 737 void ChromeMetricsServiceClient::OnURLOpenedFromOmnibox(OmniboxLog* log) { |
714 metrics_service_->OnApplicationNotIdle(); | 738 metrics_service_->OnApplicationNotIdle(); |
715 } | 739 } |
716 | 740 |
717 bool ChromeMetricsServiceClient::IsUMACellularUploadLogicEnabled() { | 741 bool ChromeMetricsServiceClient::IsUMACellularUploadLogicEnabled() { |
718 return metrics::IsCellularLogicEnabled(); | 742 return metrics::IsCellularLogicEnabled(); |
719 } | 743 } |
OLD | NEW |