Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Side by Side Diff: chrome/browser/metrics/chrome_metrics_service_client.cc

Issue 2010173005: Support experiment to store persistent metrics in memory-mapped file. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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() {
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.
190 base::GlobalHistogramAllocator* allocator =
191 base::GlobalHistogramAllocator::Get();
192 if (allocator) {
Alexei Svitkine (slow) 2016/06/28 15:08:00 Nit: Use early returns instead.
bcwhite 2016/06/29 03:17:03 Done.
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);
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
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 516 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 } 759 }
743 } 760 }
744 761
745 void ChromeMetricsServiceClient::OnURLOpenedFromOmnibox(OmniboxLog* log) { 762 void ChromeMetricsServiceClient::OnURLOpenedFromOmnibox(OmniboxLog* log) {
746 metrics_service_->OnApplicationNotIdle(); 763 metrics_service_->OnApplicationNotIdle();
747 } 764 }
748 765
749 bool ChromeMetricsServiceClient::IsUMACellularUploadLogicEnabled() { 766 bool ChromeMetricsServiceClient::IsUMACellularUploadLogicEnabled() {
750 return metrics::IsCellularLogicEnabled(); 767 return metrics::IsCellularLogicEnabled();
751 } 768 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698