OLD | NEW |
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 "chrome/browser/net/http_pipelining_compatibility_client.h" | 5 #include "chrome/browser/net/http_pipelining_compatibility_client.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 } | 120 } |
121 | 121 |
122 MessageLoopForIO message_loop_; | 122 MessageLoopForIO message_loop_; |
123 net::TestServer test_server_; | 123 net::TestServer test_server_; |
124 TestURLRequestContextGetter* context_; | 124 TestURLRequestContextGetter* context_; |
125 content::TestBrowserThread io_thread_; | 125 content::TestBrowserThread io_thread_; |
126 | 126 |
127 private: | 127 private: |
128 base::Histogram::SampleSet GetHistogram(const char* name) { | 128 base::Histogram::SampleSet GetHistogram(const char* name) { |
129 base::Histogram::SampleSet sample; | 129 base::Histogram::SampleSet sample; |
130 base::Histogram* histogram; | 130 base::Histogram* current_histogram = NULL; |
| 131 base::Histogram* cached_histogram = NULL; |
| 132 base::StatisticsRecorder::FindHistogram(name, ¤t_histogram); |
131 if (ContainsKey(histograms_, name)) { | 133 if (ContainsKey(histograms_, name)) { |
132 histogram = histograms_[name]; | 134 cached_histogram = histograms_[name]; |
133 histogram->SnapshotSample(&sample); | 135 } |
134 } else if (base::StatisticsRecorder::FindHistogram(name, &histogram)) { | 136 |
135 histograms_[name] = histogram; | 137 // This is to work around the CACHE_HISTOGRAM_* macros caching the last used |
136 histogram->SnapshotSample(&sample); | 138 // histogram by name. So, even though we throw out the StatisticsRecorder |
| 139 // between tests, the CACHE_HISTOGRAM_* might still write into the old |
| 140 // Histogram if it has the same name as the last run. We keep a cache of the |
| 141 // last used Histogram and then update the cache if it's different than the |
| 142 // current Histogram. |
| 143 if (cached_histogram && current_histogram) { |
| 144 cached_histogram->SnapshotSample(&sample); |
| 145 if (cached_histogram != current_histogram) { |
| 146 base::Histogram::SampleSet current_sample; |
| 147 current_histogram->SnapshotSample(¤t_sample); |
| 148 sample.Add(current_sample); |
| 149 histograms_[name] = current_histogram; |
| 150 } |
| 151 } else if (current_histogram) { |
| 152 current_histogram->SnapshotSample(&sample); |
| 153 histograms_[name] = current_histogram; |
| 154 } else if (cached_histogram) { |
| 155 cached_histogram->SnapshotSample(&sample); |
137 } | 156 } |
138 return sample; | 157 return sample; |
139 } | 158 } |
140 | 159 |
141 static std::map<std::string, base::Histogram*> histograms_; | 160 static std::map<std::string, base::Histogram*> histograms_; |
142 std::map<std::string, base::Histogram::SampleSet> samples_; | 161 std::map<std::string, base::Histogram::SampleSet> samples_; |
143 std::map<std::string, base::Histogram::SampleSet> original_samples_; | 162 std::map<std::string, base::Histogram::SampleSet> original_samples_; |
144 base::StatisticsRecorder recorder_; | 163 base::StatisticsRecorder recorder_; |
145 }; | 164 }; |
146 | 165 |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 | 428 |
410 base::Histogram::SampleSet status_sample2 = | 429 base::Histogram::SampleSet status_sample2 = |
411 GetHistogramValue(1, FIELD_STATUS); | 430 GetHistogramValue(1, FIELD_STATUS); |
412 EXPECT_EQ(1, status_sample2.TotalCount()); | 431 EXPECT_EQ(1, status_sample2.TotalCount()); |
413 EXPECT_EQ(1, status_sample2.counts( | 432 EXPECT_EQ(1, status_sample2.counts( |
414 HttpPipeliningCompatibilityClient::NETWORK_ERROR)); | 433 HttpPipeliningCompatibilityClient::NETWORK_ERROR)); |
415 | 434 |
416 base::Histogram::SampleSet network_sample2 = | 435 base::Histogram::SampleSet network_sample2 = |
417 GetHistogramValue(1, FIELD_NETWORK_ERROR); | 436 GetHistogramValue(1, FIELD_NETWORK_ERROR); |
418 EXPECT_EQ(1, network_sample2.TotalCount()); | 437 EXPECT_EQ(1, network_sample2.TotalCount()); |
419 EXPECT_EQ(1, network_sample2.counts(-net::ERR_EMPTY_RESPONSE)); | 438 EXPECT_EQ(1, network_sample2.counts(-net::ERR_PIPELINE_EVICTION)); |
420 | 439 |
421 base::Histogram::SampleSet response_sample2 = | 440 base::Histogram::SampleSet response_sample2 = |
422 GetHistogramValue(1, FIELD_RESPONSE_CODE); | 441 GetHistogramValue(1, FIELD_RESPONSE_CODE); |
423 EXPECT_EQ(0, response_sample2.TotalCount()); | 442 EXPECT_EQ(0, response_sample2.TotalCount()); |
424 | 443 |
425 base::Histogram::SampleSet status_sample3 = | 444 base::Histogram::SampleSet status_sample3 = |
426 GetHistogramValue(2, FIELD_STATUS); | 445 GetHistogramValue(2, FIELD_STATUS); |
427 EXPECT_EQ(1, status_sample3.TotalCount()); | 446 EXPECT_EQ(1, status_sample3.TotalCount()); |
428 EXPECT_EQ(1, status_sample3.counts( | 447 EXPECT_EQ(1, status_sample3.counts( |
429 HttpPipeliningCompatibilityClient::BAD_RESPONSE_CODE)); | 448 HttpPipeliningCompatibilityClient::NETWORK_ERROR)); |
430 | 449 |
431 base::Histogram::SampleSet network_sample3 = | 450 base::Histogram::SampleSet network_sample3 = |
432 GetHistogramValue(2, FIELD_NETWORK_ERROR); | 451 GetHistogramValue(2, FIELD_NETWORK_ERROR); |
433 EXPECT_EQ(0, network_sample3.TotalCount()); | 452 EXPECT_EQ(1, network_sample3.TotalCount()); |
| 453 EXPECT_EQ(1, network_sample3.counts(-net::ERR_PIPELINE_EVICTION)); |
434 | 454 |
435 base::Histogram::SampleSet response_sample3 = | 455 base::Histogram::SampleSet response_sample3 = |
436 GetHistogramValue(2, FIELD_RESPONSE_CODE); | 456 GetHistogramValue(2, FIELD_RESPONSE_CODE); |
437 EXPECT_EQ(1, response_sample3.TotalCount()); | 457 EXPECT_EQ(0, response_sample3.TotalCount()); |
438 EXPECT_EQ(1, response_sample3.counts(401)); | |
439 } | 458 } |
440 | 459 |
441 } // anonymous namespace | 460 } // anonymous namespace |
442 | 461 |
443 } // namespace chrome_browser_net | 462 } // namespace chrome_browser_net |
OLD | NEW |