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/predictor.h" | 5 #include "chrome/browser/net/predictor.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
60 const base::ListValue* referral_list) { | 60 const base::ListValue* referral_list) { |
61 CHECK_LT(0u, referral_list->GetSize()); // Room for version. | 61 CHECK_LT(0u, referral_list->GetSize()); // Room for version. |
62 int format_version = -1; | 62 int format_version = -1; |
63 CHECK(referral_list->GetInteger(0, &format_version)); | 63 CHECK(referral_list->GetInteger(0, &format_version)); |
64 CHECK_EQ(Predictor::kPredictorReferrerVersion, format_version); | 64 CHECK_EQ(Predictor::kPredictorReferrerVersion, format_version); |
65 const base::ListValue* motivation_list(NULL); | 65 const base::ListValue* motivation_list(NULL); |
66 for (size_t i = 1; i < referral_list->GetSize(); ++i) { | 66 for (size_t i = 1; i < referral_list->GetSize(); ++i) { |
67 referral_list->GetList(i, &motivation_list); | 67 referral_list->GetList(i, &motivation_list); |
68 std::string existing_spec; | 68 std::string existing_spec; |
69 EXPECT_TRUE(motivation_list->GetString(0, &existing_spec)); | 69 EXPECT_TRUE(motivation_list->GetString(0, &existing_spec)); |
70 if (motivation == GURL(existing_spec)) | 70 if (motivation == existing_spec) |
Charlie Harrison
2016/11/09 21:12:58
Let's keep the GURL() here, or at least DCHECK tha
cfredric
2016/11/09 22:12:46
Done.
| |
71 return motivation_list; | 71 return motivation_list; |
72 } | 72 } |
73 return NULL; | 73 return NULL; |
74 } | 74 } |
75 | 75 |
76 static base::ListValue* FindSerializationMotivation( | 76 static base::ListValue* FindSerializationMotivation( |
77 const GURL& motivation, | 77 const GURL& motivation, |
78 base::ListValue* referral_list) { | 78 base::ListValue* referral_list) { |
79 return const_cast<base::ListValue*>(FindSerializationMotivation( | 79 return const_cast<base::ListValue*>(FindSerializationMotivation( |
80 motivation, static_cast<const base::ListValue*>(referral_list))); | 80 motivation, static_cast<const base::ListValue*>(referral_list))); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
131 const base::ListValue* motivation_list = | 131 const base::ListValue* motivation_list = |
132 FindSerializationMotivation(motivation, &referral_list); | 132 FindSerializationMotivation(motivation, &referral_list); |
133 if (!motivation_list) | 133 if (!motivation_list) |
134 return false; | 134 return false; |
135 const base::ListValue* subresource_list; | 135 const base::ListValue* subresource_list; |
136 EXPECT_TRUE(motivation_list->GetList(1, &subresource_list)); | 136 EXPECT_TRUE(motivation_list->GetList(1, &subresource_list)); |
137 for (size_t i = 0; i < subresource_list->GetSize();) { | 137 for (size_t i = 0; i < subresource_list->GetSize();) { |
138 std::string url_spec; | 138 std::string url_spec; |
139 EXPECT_TRUE(subresource_list->GetString(i++, &url_spec)); | 139 EXPECT_TRUE(subresource_list->GetString(i++, &url_spec)); |
140 EXPECT_TRUE(subresource_list->GetDouble(i++, use_rate)); | 140 EXPECT_TRUE(subresource_list->GetDouble(i++, use_rate)); |
141 if (subresource == GURL(url_spec)) { | 141 if (subresource == url_spec) { |
Charlie Harrison
2016/11/09 21:12:58
same here. I'm generally nervous about using this
cfredric
2016/11/09 22:12:46
Done.
| |
142 return true; | 142 return true; |
143 } | 143 } |
144 } | 144 } |
145 return false; | 145 return false; |
146 } | 146 } |
147 | 147 |
148 TEST_F(PredictorTest, StartupShutdownTest) { | 148 TEST_F(PredictorTest, StartupShutdownTest) { |
149 Predictor testing_master(true); | 149 Predictor testing_master(true); |
150 testing_master.Shutdown(); | 150 testing_master.Shutdown(); |
151 } | 151 } |
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
560 testing_master.Resolve(goog, UrlInfo::OMNIBOX_MOTIVATED); | 560 testing_master.Resolve(goog, UrlInfo::OMNIBOX_MOTIVATED); |
561 | 561 |
562 // Proxy may not be in use (the PAC script has not yet been evaluated), so the | 562 // Proxy may not be in use (the PAC script has not yet been evaluated), so the |
563 // name has been registered for pre-resolve. | 563 // name has been registered for pre-resolve. |
564 EXPECT_FALSE(testing_master.work_queue_.IsEmpty()); | 564 EXPECT_FALSE(testing_master.work_queue_.IsEmpty()); |
565 | 565 |
566 testing_master.Shutdown(); | 566 testing_master.Shutdown(); |
567 } | 567 } |
568 | 568 |
569 } // namespace chrome_browser_net | 569 } // namespace chrome_browser_net |
OLD | NEW |