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/data_reduction_proxy/core/browser/data_reduction_proxy_comp
ression_stats.h" | 5 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_comp
ression_stats.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 compression_stats_->SetInt64( | 156 compression_stats_->SetInt64( |
157 prefs::kHttpReceivedContentLength, kReceivedLength); | 157 prefs::kHttpReceivedContentLength, kReceivedLength); |
158 | 158 |
159 base::ListValue* original_daily_content_length_list = | 159 base::ListValue* original_daily_content_length_list = |
160 compression_stats_->GetList(prefs::kDailyHttpOriginalContentLength); | 160 compression_stats_->GetList(prefs::kDailyHttpOriginalContentLength); |
161 base::ListValue* received_daily_content_length_list = | 161 base::ListValue* received_daily_content_length_list = |
162 compression_stats_->GetList(prefs::kDailyHttpReceivedContentLength); | 162 compression_stats_->GetList(prefs::kDailyHttpReceivedContentLength); |
163 | 163 |
164 for (size_t i = 0; i < kNumDaysInHistory; ++i) { | 164 for (size_t i = 0; i < kNumDaysInHistory; ++i) { |
165 original_daily_content_length_list->Set( | 165 original_daily_content_length_list->Set( |
166 i, new base::StringValue(base::SizeTToString(i))); | 166 i, new base::Value(base::SizeTToString(i))); |
167 } | 167 } |
168 | 168 |
169 received_daily_content_length_list->Clear(); | 169 received_daily_content_length_list->Clear(); |
170 for (size_t i = 0; i < kNumDaysInHistory / 2; ++i) { | 170 for (size_t i = 0; i < kNumDaysInHistory / 2; ++i) { |
171 received_daily_content_length_list->Set( | 171 received_daily_content_length_list->Set( |
172 i, new base::StringValue(base::SizeTToString(i))); | 172 i, new base::Value(base::SizeTToString(i))); |
173 } | 173 } |
174 } | 174 } |
175 | 175 |
176 // Create daily pref list of |kNumDaysInHistory| zero values. | 176 // Create daily pref list of |kNumDaysInHistory| zero values. |
177 void CreatePrefList(const char* pref) { | 177 void CreatePrefList(const char* pref) { |
178 base::ListValue* update = compression_stats_->GetList(pref); | 178 base::ListValue* update = compression_stats_->GetList(pref); |
179 update->Clear(); | 179 update->Clear(); |
180 for (size_t i = 0; i < kNumDaysInHistory; ++i) { | 180 for (size_t i = 0; i < kNumDaysInHistory; ++i) { |
181 update->Insert( | 181 update->Insert(0, base::MakeUnique<base::Value>(base::Int64ToString(0))); |
182 0, base::MakeUnique<base::StringValue>(base::Int64ToString(0))); | |
183 } | 182 } |
184 } | 183 } |
185 | 184 |
186 // Verify the pref list values in |pref_service_| are equal to those in | 185 // Verify the pref list values in |pref_service_| are equal to those in |
187 // |simple_pref_service| for |pref|. | 186 // |simple_pref_service| for |pref|. |
188 void VerifyPrefListWasWritten(const char* pref) { | 187 void VerifyPrefListWasWritten(const char* pref) { |
189 const base::ListValue* delayed_list = compression_stats_->GetList(pref); | 188 const base::ListValue* delayed_list = compression_stats_->GetList(pref); |
190 const base::ListValue* written_list = pref_service()->GetList(pref); | 189 const base::ListValue* written_list = pref_service()->GetList(pref); |
191 ASSERT_EQ(delayed_list->GetSize(), written_list->GetSize()); | 190 ASSERT_EQ(delayed_list->GetSize(), written_list->GetSize()); |
192 size_t count = delayed_list->GetSize(); | 191 size_t count = delayed_list->GetSize(); |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 SetInt64(prefs::kHttpOriginalContentLength, kOriginalLength); | 536 SetInt64(prefs::kHttpOriginalContentLength, kOriginalLength); |
538 SetInt64(prefs::kHttpReceivedContentLength, kReceivedLength); | 537 SetInt64(prefs::kHttpReceivedContentLength, kReceivedLength); |
539 | 538 |
540 stats_value = compression_stats()->HistoricNetworkStatsInfoToValue(); | 539 stats_value = compression_stats()->HistoricNetworkStatsInfoToValue(); |
541 EXPECT_TRUE(stats_value->GetAsDictionary(&dict)); | 540 EXPECT_TRUE(stats_value->GetAsDictionary(&dict)); |
542 VerifyPrefs(dict); | 541 VerifyPrefs(dict); |
543 } | 542 } |
544 | 543 |
545 TEST_F(DataReductionProxyCompressionStatsTest, StatsRestoredOnOnRestart) { | 544 TEST_F(DataReductionProxyCompressionStatsTest, StatsRestoredOnOnRestart) { |
546 base::ListValue list_value; | 545 base::ListValue list_value; |
547 list_value.Insert( | 546 list_value.Insert(0, |
548 0, base::MakeUnique<base::StringValue>(base::Int64ToString(1234))); | 547 base::MakeUnique<base::Value>(base::Int64ToString(1234))); |
549 pref_service()->Set(prefs::kDailyHttpOriginalContentLength, list_value); | 548 pref_service()->Set(prefs::kDailyHttpOriginalContentLength, list_value); |
550 | 549 |
551 ResetCompressionStatsWithDelay( | 550 ResetCompressionStatsWithDelay( |
552 base::TimeDelta::FromMinutes(kWriteDelayMinutes)); | 551 base::TimeDelta::FromMinutes(kWriteDelayMinutes)); |
553 | 552 |
554 const base::ListValue* value = pref_service()->GetList( | 553 const base::ListValue* value = pref_service()->GetList( |
555 prefs::kDailyHttpOriginalContentLength); | 554 prefs::kDailyHttpOriginalContentLength); |
556 std::string string_value; | 555 std::string string_value; |
557 value->GetString(0, &string_value); | 556 value->GetString(0, &string_value); |
558 EXPECT_EQ("1234", string_value); | 557 EXPECT_EQ("1234", string_value); |
(...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1335 expected_data_usage = | 1334 expected_data_usage = |
1336 base::MakeUnique<std::vector<data_reduction_proxy::DataUsageBucket>>( | 1335 base::MakeUnique<std::vector<data_reduction_proxy::DataUsageBucket>>( |
1337 kNumExpectedBuckets); | 1336 kNumExpectedBuckets); |
1338 DataUsageLoadVerifier verifier2(std::move(expected_data_usage)); | 1337 DataUsageLoadVerifier verifier2(std::move(expected_data_usage)); |
1339 LoadHistoricalDataUsage(base::Bind(&DataUsageLoadVerifier::OnLoadDataUsage, | 1338 LoadHistoricalDataUsage(base::Bind(&DataUsageLoadVerifier::OnLoadDataUsage, |
1340 base::Unretained(&verifier2))); | 1339 base::Unretained(&verifier2))); |
1341 base::RunLoop().RunUntilIdle(); | 1340 base::RunLoop().RunUntilIdle(); |
1342 } | 1341 } |
1343 | 1342 |
1344 } // namespace data_reduction_proxy | 1343 } // namespace data_reduction_proxy |
OLD | NEW |