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 "components/metrics/metrics_service.h" | 5 #include "components/metrics/metrics_service.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/metrics/histogram_base.h" |
12 #include "base/metrics/metrics_hashes.h" | 13 #include "base/metrics/metrics_hashes.h" |
13 #include "base/metrics/statistics_recorder.h" | 14 #include "base/metrics/statistics_recorder.h" |
14 #include "base/prefs/testing_pref_service.h" | 15 #include "base/prefs/testing_pref_service.h" |
15 #include "base/threading/platform_thread.h" | 16 #include "base/threading/platform_thread.h" |
16 #include "components/compression/compression_utils.h" | 17 #include "components/compression/compression_utils.h" |
17 #include "components/metrics/client_info.h" | 18 #include "components/metrics/client_info.h" |
18 #include "components/metrics/metrics_log.h" | 19 #include "components/metrics/metrics_log.h" |
19 #include "components/metrics/metrics_pref_names.h" | 20 #include "components/metrics/metrics_pref_names.h" |
20 #include "components/metrics/metrics_state_manager.h" | 21 #include "components/metrics/metrics_state_manager.h" |
21 #include "components/metrics/test_metrics_provider.h" | 22 #include "components/metrics/test_metrics_provider.h" |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 | 384 |
384 TestMetricsProvider* test_provider = new TestMetricsProvider(); | 385 TestMetricsProvider* test_provider = new TestMetricsProvider(); |
385 service.RegisterMetricsProvider(scoped_ptr<MetricsProvider>(test_provider)); | 386 service.RegisterMetricsProvider(scoped_ptr<MetricsProvider>(test_provider)); |
386 | 387 |
387 service.InitializeMetricsRecordingState(); | 388 service.InitializeMetricsRecordingState(); |
388 service.Stop(); | 389 service.Stop(); |
389 | 390 |
390 EXPECT_TRUE(test_provider->on_recording_disabled_called()); | 391 EXPECT_TRUE(test_provider->on_recording_disabled_called()); |
391 } | 392 } |
392 | 393 |
| 394 TEST_F(MetricsServiceTest, MultiplePersistentAllocators) { |
| 395 base::HistogramBase::SetDefaultPersistentMemoryAllocator( |
| 396 new base::LocalPersistentMemoryAllocator(64 << 10, 0, std::string())); |
| 397 scoped_ptr<base::PersistentMemoryAllocator> pma1; |
| 398 LOCAL_HISTOGRAM_COUNTS("MetricsServiceTest.MPA1A", 30); |
| 399 LOCAL_HISTOGRAM_COUNTS("MetricsServiceTest.MPA1B", 30); |
| 400 pma1.reset(base::HistogramBase::ReleaseDefaultPersistentMemoryAllocator()); |
| 401 |
| 402 base::HistogramBase::SetDefaultPersistentMemoryAllocator( |
| 403 new base::LocalPersistentMemoryAllocator(64 << 10, 0, std::string())); |
| 404 scoped_ptr<base::PersistentMemoryAllocator> pma2; |
| 405 LOCAL_HISTOGRAM_COUNTS("MetricsServiceTest.MPA2A", 30); |
| 406 LOCAL_HISTOGRAM_COUNTS("MetricsServiceTest.MPA2B", 30); |
| 407 LOCAL_HISTOGRAM_COUNTS("MetricsServiceTest.MPA2C", 30); |
| 408 LOCAL_HISTOGRAM_COUNTS("MetricsServiceTest.MPA2D", 30); |
| 409 pma2.reset(base::HistogramBase::ReleaseDefaultPersistentMemoryAllocator()); |
| 410 |
| 411 base::HistogramBase::SetDefaultPersistentMemoryAllocator( |
| 412 new base::LocalPersistentMemoryAllocator(64 << 10, 0, std::string())); |
| 413 |
| 414 TestMetricsServiceClient client; |
| 415 TestMetricsService service( |
| 416 GetMetricsStateManager(), &client, GetLocalState()); |
| 417 |
| 418 { |
| 419 MetricsService::PersistentHistogramIterator i = service.persistent_begin(); |
| 420 EXPECT_EQ(service.persistent_end(), i); |
| 421 } |
| 422 |
| 423 LOCAL_HISTOGRAM_COUNTS("MetricsServiceTest.MPA3A", 30); |
| 424 { |
| 425 MetricsService::PersistentHistogramIterator i = service.persistent_begin(); |
| 426 EXPECT_EQ(service.persistent_end(), i); |
| 427 } |
| 428 |
| 429 service.AddPersistentMemorySegment(pma1.get()); |
| 430 { |
| 431 MetricsService::PersistentHistogramIterator i = service.persistent_begin(); |
| 432 EXPECT_NE(service.persistent_end(), i); |
| 433 EXPECT_TRUE(*i); |
| 434 EXPECT_NE(service.persistent_end(), ++i); |
| 435 EXPECT_TRUE(*i); |
| 436 EXPECT_EQ(service.persistent_end(), ++i); |
| 437 } |
| 438 |
| 439 service.AddPersistentMemorySegment(pma2.get()); |
| 440 { |
| 441 MetricsService::PersistentHistogramIterator i = service.persistent_begin(); |
| 442 EXPECT_NE(service.persistent_end(), i); |
| 443 EXPECT_NE(service.persistent_end(), ++i); |
| 444 EXPECT_NE(service.persistent_end(), ++i); |
| 445 EXPECT_NE(service.persistent_end(), ++i); |
| 446 EXPECT_NE(service.persistent_end(), ++i); |
| 447 EXPECT_NE(service.persistent_end(), ++i); |
| 448 EXPECT_EQ(service.persistent_end(), ++i); |
| 449 } |
| 450 } |
| 451 |
393 } // namespace metrics | 452 } // namespace metrics |
OLD | NEW |