| 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 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 base::ListValue* list = new base::ListValue; | 285 base::ListValue* list = new base::ListValue; |
| 286 list->Append( | 286 list->Append(base::NumberValue::New(Predictor::PREDICTOR_REFERRER_VERSION)); |
| 287 new base::FundamentalValue(Predictor::PREDICTOR_REFERRER_VERSION)); | |
| 288 return list; | 287 return list; |
| 289 } | 288 } |
| 290 | 289 |
| 291 // Add a motivating_url and a subresource_url to a serialized list, using | 290 // Add a motivating_url and a subresource_url to a serialized list, using |
| 292 // this given latency. This is a helper function for quickly building these | 291 // this given latency. This is a helper function for quickly building these |
| 293 // lists. | 292 // lists. |
| 294 static void AddToSerializedList(const GURL& motivation, | 293 static void AddToSerializedList(const GURL& motivation, |
| 295 const GURL& subresource, | 294 const GURL& subresource, |
| 296 double use_rate, | 295 double use_rate, |
| 297 ListValue* referral_list ) { | 296 ListValue* referral_list ) { |
| 298 // Find the motivation if it is already used. | 297 // Find the motivation if it is already used. |
| 299 ListValue* motivation_list = FindSerializationMotivation(motivation, | 298 ListValue* motivation_list = FindSerializationMotivation(motivation, |
| 300 *referral_list); | 299 *referral_list); |
| 301 if (!motivation_list) { | 300 if (!motivation_list) { |
| 302 // This is the first mention of this motivation, so build a list. | 301 // This is the first mention of this motivation, so build a list. |
| 303 motivation_list = new ListValue; | 302 motivation_list = new ListValue; |
| 304 motivation_list->Append(new StringValue(motivation.spec())); | 303 motivation_list->Append(base::StringValue::New(motivation.spec())); |
| 305 // Provide empty subresource list. | 304 // Provide empty subresource list. |
| 306 motivation_list->Append(new ListValue()); | 305 motivation_list->Append(new ListValue()); |
| 307 | 306 |
| 308 // ...and make it part of the serialized referral_list. | 307 // ...and make it part of the serialized referral_list. |
| 309 referral_list->Append(motivation_list); | 308 referral_list->Append(motivation_list); |
| 310 } | 309 } |
| 311 | 310 |
| 312 ListValue* subresource_list(NULL); | 311 ListValue* subresource_list(NULL); |
| 313 // 0 == url; 1 == subresource_list. | 312 // 0 == url; 1 == subresource_list. |
| 314 EXPECT_TRUE(motivation_list->GetList(1, &subresource_list)); | 313 EXPECT_TRUE(motivation_list->GetList(1, &subresource_list)); |
| 315 | 314 |
| 316 // We won't bother to check for the subresource being there already. Worst | 315 // We won't bother to check for the subresource being there already. Worst |
| 317 // case, during deserialization, the latency value we supply plus the | 316 // case, during deserialization, the latency value we supply plus the |
| 318 // existing value(s) will be added to the referrer. | 317 // existing value(s) will be added to the referrer. |
| 319 | 318 |
| 320 subresource_list->Append(new base::StringValue(subresource.spec())); | 319 subresource_list->Append(new base::StringValue(subresource.spec())); |
| 321 subresource_list->Append(new base::FundamentalValue(use_rate)); | 320 subresource_list->Append(base::NumberValue::New(use_rate)); |
| 322 } | 321 } |
| 323 | 322 |
| 324 static const int kLatencyNotFound = -1; | 323 static const int kLatencyNotFound = -1; |
| 325 | 324 |
| 326 // For a given motivation, and subresource, find what latency is currently | 325 // For a given motivation, and subresource, find what latency is currently |
| 327 // listed. This assume a well formed serialization, which has at most one such | 326 // listed. This assume a well formed serialization, which has at most one such |
| 328 // entry for any pair of names. If no such pair is found, then return false. | 327 // entry for any pair of names. If no such pair is found, then return false. |
| 329 // Data is written into use_rate arguments. | 328 // Data is written into use_rate arguments. |
| 330 static bool GetDataFromSerialization(const GURL& motivation, | 329 static bool GetDataFromSerialization(const GURL& motivation, |
| 331 const GURL& subresource, | 330 const GURL& subresource, |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 618 EXPECT_EQ(2U, referral_list.GetSize()); | 617 EXPECT_EQ(2U, referral_list.GetSize()); |
| 619 | 618 |
| 620 predictor->DiscardAllResults(); | 619 predictor->DiscardAllResults(); |
| 621 predictor->SerializeReferrers(&referral_list); | 620 predictor->SerializeReferrers(&referral_list); |
| 622 EXPECT_EQ(1U, referral_list.GetSize()); | 621 EXPECT_EQ(1U, referral_list.GetSize()); |
| 623 | 622 |
| 624 predictor->Shutdown(); | 623 predictor->Shutdown(); |
| 625 } | 624 } |
| 626 | 625 |
| 627 } // namespace chrome_browser_net | 626 } // namespace chrome_browser_net |
| OLD | NEW |