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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 static base::ListValue* FindSerializationMotivation( | 74 static base::ListValue* FindSerializationMotivation( |
75 const GURL& motivation, | 75 const GURL& motivation, |
76 base::ListValue* referral_list) { | 76 base::ListValue* referral_list) { |
77 return const_cast<base::ListValue*>(FindSerializationMotivation( | 77 return const_cast<base::ListValue*>(FindSerializationMotivation( |
78 motivation, static_cast<const base::ListValue*>(referral_list))); | 78 motivation, static_cast<const base::ListValue*>(referral_list))); |
79 } | 79 } |
80 | 80 |
81 // Create a new empty serialization list. | 81 // Create a new empty serialization list. |
82 static base::ListValue* NewEmptySerializationList() { | 82 static base::ListValue* NewEmptySerializationList() { |
83 base::ListValue* list = new base::ListValue; | 83 base::ListValue* list = new base::ListValue; |
84 list->Append( | 84 list->AppendInteger(Predictor::kPredictorReferrerVersion); |
85 new base::FundamentalValue(Predictor::kPredictorReferrerVersion)); | |
86 return list; | 85 return list; |
87 } | 86 } |
88 | 87 |
89 // Add a motivating_url and a subresource_url to a serialized list, using | 88 // Add a motivating_url and a subresource_url to a serialized list, using |
90 // this given latency. This is a helper function for quickly building these | 89 // this given latency. This is a helper function for quickly building these |
91 // lists. | 90 // lists. |
92 static void AddToSerializedList(const GURL& motivation, | 91 static void AddToSerializedList(const GURL& motivation, |
93 const GURL& subresource, | 92 const GURL& subresource, |
94 double use_rate, | 93 double use_rate, |
95 base::ListValue* referral_list) { | 94 base::ListValue* referral_list) { |
96 // Find the motivation if it is already used. | 95 // Find the motivation if it is already used. |
97 base::ListValue* motivation_list = FindSerializationMotivation(motivation, | 96 base::ListValue* motivation_list = FindSerializationMotivation(motivation, |
98 referral_list); | 97 referral_list); |
99 if (!motivation_list) { | 98 if (!motivation_list) { |
100 // This is the first mention of this motivation, so build a list. | 99 // This is the first mention of this motivation, so build a list. |
101 motivation_list = new base::ListValue; | 100 motivation_list = new base::ListValue; |
102 motivation_list->Append(new base::StringValue(motivation.spec())); | 101 motivation_list->AppendString(motivation.spec()); |
103 // Provide empty subresource list. | 102 // Provide empty subresource list. |
104 motivation_list->Append(new base::ListValue()); | 103 motivation_list->Append(new base::ListValue()); |
105 | 104 |
106 // ...and make it part of the serialized referral_list. | 105 // ...and make it part of the serialized referral_list. |
107 referral_list->Append(motivation_list); | 106 referral_list->Append(motivation_list); |
108 } | 107 } |
109 | 108 |
110 base::ListValue* subresource_list(NULL); | 109 base::ListValue* subresource_list(NULL); |
111 // 0 == url; 1 == subresource_list. | 110 // 0 == url; 1 == subresource_list. |
112 EXPECT_TRUE(motivation_list->GetList(1, &subresource_list)); | 111 EXPECT_TRUE(motivation_list->GetList(1, &subresource_list)); |
113 | 112 |
114 // We won't bother to check for the subresource being there already. Worst | 113 // We won't bother to check for the subresource being there already. Worst |
115 // case, during deserialization, the latency value we supply plus the | 114 // case, during deserialization, the latency value we supply plus the |
116 // existing value(s) will be added to the referrer. | 115 // existing value(s) will be added to the referrer. |
117 | 116 |
118 subresource_list->Append(new base::StringValue(subresource.spec())); | 117 subresource_list->AppendString(subresource.spec()); |
119 subresource_list->Append(new base::FundamentalValue(use_rate)); | 118 subresource_list->AppendDouble(use_rate); |
120 } | 119 } |
121 | 120 |
122 // For a given motivation, and subresource, find what latency is currently | 121 // For a given motivation, and subresource, find what latency is currently |
123 // listed. This assume a well formed serialization, which has at most one such | 122 // listed. This assume a well formed serialization, which has at most one such |
124 // entry for any pair of names. If no such pair is found, then return false. | 123 // entry for any pair of names. If no such pair is found, then return false. |
125 // Data is written into use_rate arguments. | 124 // Data is written into use_rate arguments. |
126 static bool GetDataFromSerialization(const GURL& motivation, | 125 static bool GetDataFromSerialization(const GURL& motivation, |
127 const GURL& subresource, | 126 const GURL& subresource, |
128 const base::ListValue& referral_list, | 127 const base::ListValue& referral_list, |
129 double* use_rate) { | 128 double* use_rate) { |
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
646 testing_master.Resolve(goog, UrlInfo::OMNIBOX_MOTIVATED); | 645 testing_master.Resolve(goog, UrlInfo::OMNIBOX_MOTIVATED); |
647 | 646 |
648 // Proxy may not be in use (the PAC script has not yet been evaluated), so the | 647 // Proxy may not be in use (the PAC script has not yet been evaluated), so the |
649 // name has been registered for pre-resolve. | 648 // name has been registered for pre-resolve. |
650 EXPECT_FALSE(testing_master.work_queue_.IsEmpty()); | 649 EXPECT_FALSE(testing_master.work_queue_.IsEmpty()); |
651 | 650 |
652 testing_master.Shutdown(); | 651 testing_master.Shutdown(); |
653 } | 652 } |
654 | 653 |
655 } // namespace chrome_browser_net | 654 } // namespace chrome_browser_net |
OLD | NEW |