| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <time.h> | 5 #include <time.h> |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <sstream> | 8 #include <sstream> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 std::string existing_spec; | 275 std::string existing_spec; |
| 276 EXPECT_TRUE(motivation_list->GetString(0, &existing_spec)); | 276 EXPECT_TRUE(motivation_list->GetString(0, &existing_spec)); |
| 277 if (motivation == GURL(existing_spec)) | 277 if (motivation == GURL(existing_spec)) |
| 278 return motivation_list; | 278 return motivation_list; |
| 279 } | 279 } |
| 280 return NULL; | 280 return NULL; |
| 281 } | 281 } |
| 282 | 282 |
| 283 // Create a new empty serialization list. | 283 // Create a new empty serialization list. |
| 284 static ListValue* NewEmptySerializationList() { | 284 static ListValue* NewEmptySerializationList() { |
| 285 ListValue* list = new ListValue; | 285 base::ListValue* list = new base::ListValue; |
| 286 list->Append(new FundamentalValue(Predictor::PREDICTOR_REFERRER_VERSION)); | 286 list->Append( |
| 287 new base::FundamentalValue(Predictor::PREDICTOR_REFERRER_VERSION)); |
| 287 return list; | 288 return list; |
| 288 } | 289 } |
| 289 | 290 |
| 290 // Add a motivating_url and a subresource_url to a serialized list, using | 291 // Add a motivating_url and a subresource_url to a serialized list, using |
| 291 // this given latency. This is a helper function for quickly building these | 292 // this given latency. This is a helper function for quickly building these |
| 292 // lists. | 293 // lists. |
| 293 static void AddToSerializedList(const GURL& motivation, | 294 static void AddToSerializedList(const GURL& motivation, |
| 294 const GURL& subresource, | 295 const GURL& subresource, |
| 295 double use_rate, | 296 double use_rate, |
| 296 ListValue* referral_list ) { | 297 ListValue* referral_list ) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 309 } | 310 } |
| 310 | 311 |
| 311 ListValue* subresource_list(NULL); | 312 ListValue* subresource_list(NULL); |
| 312 // 0 == url; 1 == subresource_list. | 313 // 0 == url; 1 == subresource_list. |
| 313 EXPECT_TRUE(motivation_list->GetList(1, &subresource_list)); | 314 EXPECT_TRUE(motivation_list->GetList(1, &subresource_list)); |
| 314 | 315 |
| 315 // We won't bother to check for the subresource being there already. Worst | 316 // We won't bother to check for the subresource being there already. Worst |
| 316 // case, during deserialization, the latency value we supply plus the | 317 // case, during deserialization, the latency value we supply plus the |
| 317 // existing value(s) will be added to the referrer. | 318 // existing value(s) will be added to the referrer. |
| 318 | 319 |
| 319 subresource_list->Append(new StringValue(subresource.spec())); | 320 subresource_list->Append(new base::StringValue(subresource.spec())); |
| 320 subresource_list->Append(new FundamentalValue(use_rate)); | 321 subresource_list->Append(new base::FundamentalValue(use_rate)); |
| 321 } | 322 } |
| 322 | 323 |
| 323 static const int kLatencyNotFound = -1; | 324 static const int kLatencyNotFound = -1; |
| 324 | 325 |
| 325 // For a given motivation, and subresource, find what latency is currently | 326 // For a given motivation, and subresource, find what latency is currently |
| 326 // listed. This assume a well formed serialization, which has at most one such | 327 // listed. This assume a well formed serialization, which has at most one such |
| 327 // entry for any pair of names. If no such pair is found, then return false. | 328 // entry for any pair of names. If no such pair is found, then return false. |
| 328 // Data is written into use_rate arguments. | 329 // Data is written into use_rate arguments. |
| 329 static bool GetDataFromSerialization(const GURL& motivation, | 330 static bool GetDataFromSerialization(const GURL& motivation, |
| 330 const GURL& subresource, | 331 const GURL& subresource, |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 617 EXPECT_EQ(2U, referral_list.GetSize()); | 618 EXPECT_EQ(2U, referral_list.GetSize()); |
| 618 | 619 |
| 619 predictor->DiscardAllResults(); | 620 predictor->DiscardAllResults(); |
| 620 predictor->SerializeReferrers(&referral_list); | 621 predictor->SerializeReferrers(&referral_list); |
| 621 EXPECT_EQ(1U, referral_list.GetSize()); | 622 EXPECT_EQ(1U, referral_list.GetSize()); |
| 622 | 623 |
| 623 predictor->Shutdown(); | 624 predictor->Shutdown(); |
| 624 } | 625 } |
| 625 | 626 |
| 626 } // namespace chrome_browser_net | 627 } // namespace chrome_browser_net |
| OLD | NEW |