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

Side by Side Diff: base/metrics/statistics_recorder.cc

Issue 2036643004: Create ForTesting method rather than declaring a dozen "friend" classes. (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
« no previous file with comments | « base/metrics/statistics_recorder.h ('k') | base/metrics/statistics_recorder_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/metrics/statistics_recorder.h" 5 #include "base/metrics/statistics_recorder.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/at_exit.h" 9 #include "base/at_exit.h"
10 #include "base/debug/leak_annotations.h" 10 #include "base/debug/leak_annotations.h"
11 #include "base/json/string_escape.h" 11 #include "base/json/string_escape.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/ptr_util.h"
13 #include "base/metrics/histogram.h" 14 #include "base/metrics/histogram.h"
14 #include "base/metrics/metrics_hashes.h" 15 #include "base/metrics/metrics_hashes.h"
15 #include "base/metrics/persistent_histogram_allocator.h" 16 #include "base/metrics/persistent_histogram_allocator.h"
16 #include "base/stl_util.h" 17 #include "base/stl_util.h"
17 #include "base/strings/stringprintf.h" 18 #include "base/strings/stringprintf.h"
18 #include "base/synchronization/lock.h" 19 #include "base/synchronization/lock.h"
19 #include "base/values.h" 20 #include "base/values.h"
20 21
21 namespace { 22 namespace {
22 23
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 return histograms_->size(); 415 return histograms_->size();
415 } 416 }
416 417
417 // static 418 // static
418 void StatisticsRecorder::ForgetHistogramForTesting(base::StringPiece name) { 419 void StatisticsRecorder::ForgetHistogramForTesting(base::StringPiece name) {
419 if (histograms_) 420 if (histograms_)
420 histograms_->erase(name); 421 histograms_->erase(name);
421 } 422 }
422 423
423 // static 424 // static
425 std::unique_ptr<StatisticsRecorder>
426 StatisticsRecorder::CreateTemporaryForTesting() {
427 return WrapUnique(new StatisticsRecorder());
428 }
429
430 // static
424 void StatisticsRecorder::UninitializeForTesting() { 431 void StatisticsRecorder::UninitializeForTesting() {
425 // Stop now if it's never been initialized. 432 // Stop now if it's never been initialized.
426 if (lock_ == NULL || histograms_ == NULL) 433 if (lock_ == NULL || histograms_ == NULL)
427 return; 434 return;
428 435
429 // Get the global instance and destruct it. It's held in static memory so 436 // Get the global instance and destruct it. It's held in static memory so
430 // can't "delete" it; call the destructor explicitly. 437 // can't "delete" it; call the destructor explicitly.
431 DCHECK(g_statistics_recorder_.private_instance_); 438 DCHECK(g_statistics_recorder_.private_instance_);
432 g_statistics_recorder_.Get().~StatisticsRecorder(); 439 g_statistics_recorder_.Get().~StatisticsRecorder();
433 440
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 // static 520 // static
514 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL; 521 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL;
515 // static 522 // static
516 StatisticsRecorder::CallbackMap* StatisticsRecorder::callbacks_ = NULL; 523 StatisticsRecorder::CallbackMap* StatisticsRecorder::callbacks_ = NULL;
517 // static 524 // static
518 StatisticsRecorder::RangesMap* StatisticsRecorder::ranges_ = NULL; 525 StatisticsRecorder::RangesMap* StatisticsRecorder::ranges_ = NULL;
519 // static 526 // static
520 base::Lock* StatisticsRecorder::lock_ = NULL; 527 base::Lock* StatisticsRecorder::lock_ = NULL;
521 528
522 } // namespace base 529 } // namespace base
OLDNEW
« no previous file with comments | « base/metrics/statistics_recorder.h ('k') | base/metrics/statistics_recorder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698