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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
175 file_metrics_provider->RegisterSource( | 175 file_metrics_provider->RegisterSource( |
176 program_dir.AppendASCII(installer::kSetupHistogramAllocatorName), | 176 program_dir.AppendASCII(installer::kSetupHistogramAllocatorName), |
177 metrics::FileMetricsProvider::SOURCE_HISTOGRAMS_ATOMIC_DIR, | 177 metrics::FileMetricsProvider::SOURCE_HISTOGRAMS_ATOMIC_DIR, |
178 metrics::FileMetricsProvider::ASSOCIATE_CURRENT_RUN, | 178 metrics::FileMetricsProvider::ASSOCIATE_CURRENT_RUN, |
179 installer::kSetupHistogramAllocatorName); | 179 installer::kSetupHistogramAllocatorName); |
180 #endif | 180 #endif |
181 | 181 |
182 return file_metrics_provider; | 182 return file_metrics_provider; |
183 } | 183 } |
184 | 184 |
185 void CleanupGlobalPersistentHistogramStorage() { | |
Ilya Sherman
2016/06/17 19:54:32
nit: s/Cleanup/CleanUp
bcwhite
2016/06/20 16:21:28
Done.
| |
186 // If there is a global metrics file being updated on disk, mark it to be | |
187 // deleted when the process exits. A normal shutdown is almost complete | |
188 // so there is no benefit in keeping a file with no new data to be processed | |
189 // during the next startup sequence. | |
Ilya Sherman
2016/06/17 19:54:32
To clarify: Is there any harm in keeping the file?
bcwhite
2016/06/20 16:21:28
It's very important so that startup doesn't proces
| |
190 base::GlobalHistogramAllocator* allocator = | |
191 base::GlobalHistogramAllocator::Get(); | |
192 if (allocator) { | |
193 const base::FilePath& path = allocator->GetPersistentLocation(); | |
194 if (!path.empty()) { | |
195 base::File file(path, base::File::FLAG_OPEN | base::File::FLAG_READ | | |
196 base::File::FLAG_DELETE_ON_CLOSE); | |
Ilya Sherman
2016/06/17 19:54:32
nit: This seems like a somewhat indirect way to de
bcwhite
2016/06/20 16:21:28
Unfortunately no. base::DeleteFile() won't work o
| |
197 } | |
198 } | |
199 } | |
200 | |
185 } // namespace | 201 } // namespace |
186 | 202 |
187 | 203 |
188 const char ChromeMetricsServiceClient::kBrowserMetricsName[] = "BrowserMetrics"; | 204 const char ChromeMetricsServiceClient::kBrowserMetricsName[] = "BrowserMetrics"; |
189 | 205 |
190 ChromeMetricsServiceClient::ChromeMetricsServiceClient( | 206 ChromeMetricsServiceClient::ChromeMetricsServiceClient( |
191 metrics::MetricsStateManager* state_manager) | 207 metrics::MetricsStateManager* state_manager) |
192 : metrics_state_manager_(state_manager), | 208 : metrics_state_manager_(state_manager), |
193 #if defined(OS_CHROMEOS) | 209 #if defined(OS_CHROMEOS) |
194 chromeos_metrics_provider_(nullptr), | 210 chromeos_metrics_provider_(nullptr), |
(...skipping 11 matching lines...) Expand all Loading... | |
206 start_time_(base::TimeTicks::Now()), | 222 start_time_(base::TimeTicks::Now()), |
207 has_uploaded_profiler_data_(false), | 223 has_uploaded_profiler_data_(false), |
208 weak_ptr_factory_(this) { | 224 weak_ptr_factory_(this) { |
209 DCHECK(thread_checker_.CalledOnValidThread()); | 225 DCHECK(thread_checker_.CalledOnValidThread()); |
210 RecordCommandLineMetrics(); | 226 RecordCommandLineMetrics(); |
211 RegisterForNotifications(); | 227 RegisterForNotifications(); |
212 } | 228 } |
213 | 229 |
214 ChromeMetricsServiceClient::~ChromeMetricsServiceClient() { | 230 ChromeMetricsServiceClient::~ChromeMetricsServiceClient() { |
215 DCHECK(thread_checker_.CalledOnValidThread()); | 231 DCHECK(thread_checker_.CalledOnValidThread()); |
232 CleanupGlobalPersistentHistogramStorage(); | |
216 } | 233 } |
217 | 234 |
218 // static | 235 // static |
219 std::unique_ptr<ChromeMetricsServiceClient> ChromeMetricsServiceClient::Create( | 236 std::unique_ptr<ChromeMetricsServiceClient> ChromeMetricsServiceClient::Create( |
220 metrics::MetricsStateManager* state_manager, | 237 metrics::MetricsStateManager* state_manager, |
221 PrefService* local_state) { | 238 PrefService* local_state) { |
222 // Perform two-phase initialization so that |client->metrics_service_| only | 239 // Perform two-phase initialization so that |client->metrics_service_| only |
223 // receives pointers to fully constructed objects. | 240 // receives pointers to fully constructed objects. |
224 std::unique_ptr<ChromeMetricsServiceClient> client( | 241 std::unique_ptr<ChromeMetricsServiceClient> client( |
225 new ChromeMetricsServiceClient(state_manager)); | 242 new ChromeMetricsServiceClient(state_manager)); |
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
733 } | 750 } |
734 } | 751 } |
735 | 752 |
736 void ChromeMetricsServiceClient::OnURLOpenedFromOmnibox(OmniboxLog* log) { | 753 void ChromeMetricsServiceClient::OnURLOpenedFromOmnibox(OmniboxLog* log) { |
737 metrics_service_->OnApplicationNotIdle(); | 754 metrics_service_->OnApplicationNotIdle(); |
738 } | 755 } |
739 | 756 |
740 bool ChromeMetricsServiceClient::IsUMACellularUploadLogicEnabled() { | 757 bool ChromeMetricsServiceClient::IsUMACellularUploadLogicEnabled() { |
741 return metrics::IsCellularLogicEnabled(); | 758 return metrics::IsCellularLogicEnabled(); |
742 } | 759 } |
OLD | NEW |