| 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 "chrome/browser/net/referrer.h" | 5 #include "chrome/browser/net/referrer.h" |
| 6 | 6 |
| 7 #include <limits.h> | 7 #include <limits.h> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 erase(discarded_urls[i]); | 113 erase(discarded_urls[i]); |
| 114 return size() > 0; | 114 return size() > 0; |
| 115 } | 115 } |
| 116 | 116 |
| 117 bool ReferrerValue::Trim(double reduce_rate, double threshold) { | 117 bool ReferrerValue::Trim(double reduce_rate, double threshold) { |
| 118 subresource_use_rate_ *= reduce_rate; | 118 subresource_use_rate_ *= reduce_rate; |
| 119 return subresource_use_rate_ > threshold; | 119 return subresource_use_rate_ > threshold; |
| 120 } | 120 } |
| 121 | 121 |
| 122 | 122 |
| 123 void Referrer::Deserialize(const Value& value) { | 123 void Referrer::Deserialize(const base::Value& value) { |
| 124 if (value.GetType() != Value::TYPE_LIST) | 124 if (value.GetType() != base::Value::TYPE_LIST) |
| 125 return; | 125 return; |
| 126 const ListValue* subresource_list(static_cast<const ListValue*>(&value)); | 126 const base::ListValue* subresource_list( |
| 127 static_cast<const base::ListValue*>(&value)); |
| 127 size_t index = 0; // Bounds checking is done by subresource_list->Get*(). | 128 size_t index = 0; // Bounds checking is done by subresource_list->Get*(). |
| 128 while (true) { | 129 while (true) { |
| 129 std::string url_spec; | 130 std::string url_spec; |
| 130 if (!subresource_list->GetString(index++, &url_spec)) | 131 if (!subresource_list->GetString(index++, &url_spec)) |
| 131 return; | 132 return; |
| 132 double rate; | 133 double rate; |
| 133 if (!subresource_list->GetDouble(index++, &rate)) | 134 if (!subresource_list->GetDouble(index++, &rate)) |
| 134 return; | 135 return; |
| 135 | 136 |
| 136 GURL url(url_spec); | 137 GURL url(url_spec); |
| 137 // TODO(jar): We could be more direct, and change birth date or similar to | 138 // TODO(jar): We could be more direct, and change birth date or similar to |
| 138 // show that this is a resurrected value we're adding in. I'm not yet sure | 139 // show that this is a resurrected value we're adding in. I'm not yet sure |
| 139 // of how best to optimize the learning and pruning (Trim) algorithm at this | 140 // of how best to optimize the learning and pruning (Trim) algorithm at this |
| 140 // level, so for now, we just suggest subresources, which leaves them all | 141 // level, so for now, we just suggest subresources, which leaves them all |
| 141 // with the same birth date (typically start of process). | 142 // with the same birth date (typically start of process). |
| 142 SuggestHost(url); | 143 SuggestHost(url); |
| 143 (*this)[url].SetSubresourceUseRate(rate); | 144 (*this)[url].SetSubresourceUseRate(rate); |
| 144 } | 145 } |
| 145 } | 146 } |
| 146 | 147 |
| 147 Value* Referrer::Serialize() const { | 148 base::Value* Referrer::Serialize() const { |
| 148 base::ListValue* subresource_list(new base::ListValue); | 149 base::ListValue* subresource_list(new base::ListValue); |
| 149 for (const_iterator it = begin(); it != end(); ++it) { | 150 for (const_iterator it = begin(); it != end(); ++it) { |
| 150 base::StringValue* url_spec(new base::StringValue(it->first.spec())); | 151 base::StringValue* url_spec(new base::StringValue(it->first.spec())); |
| 151 base::FundamentalValue* rate(new base::FundamentalValue( | 152 base::FundamentalValue* rate(new base::FundamentalValue( |
| 152 it->second.subresource_use_rate())); | 153 it->second.subresource_use_rate())); |
| 153 | 154 |
| 154 subresource_list->Append(url_spec); | 155 subresource_list->Append(url_spec); |
| 155 subresource_list->Append(rate); | 156 subresource_list->Append(rate); |
| 156 } | 157 } |
| 157 return subresource_list; | 158 return subresource_list; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 176 | 177 |
| 177 void ReferrerValue::ReferrerWasObserved() { | 178 void ReferrerValue::ReferrerWasObserved() { |
| 178 subresource_use_rate_ *= kWeightingForOldConnectsExpectedValue; | 179 subresource_use_rate_ *= kWeightingForOldConnectsExpectedValue; |
| 179 // Note: the use rate is temporarilly possibly incorect, as we need to find | 180 // Note: the use rate is temporarilly possibly incorect, as we need to find |
| 180 // out if we really end up connecting. This will happen in a few hundred | 181 // out if we really end up connecting. This will happen in a few hundred |
| 181 // milliseconds (when content arrives, etc.). | 182 // milliseconds (when content arrives, etc.). |
| 182 // Value of subresource_use_rate_ should be sampled before this call. | 183 // Value of subresource_use_rate_ should be sampled before this call. |
| 183 } | 184 } |
| 184 | 185 |
| 185 } // namespace chrome_browser_net | 186 } // namespace chrome_browser_net |
| OLD | NEW |