| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/updater/manifest_fetch_data.h" | 5 #include "extensions/browser/updater/manifest_fetch_data.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| 11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 14 #include "extensions/common/extension.h" | 14 #include "extensions/common/extension.h" |
| 15 #include "net/base/escape.h" | 15 #include "net/base/escape.h" |
| 16 | 16 |
| 17 namespace extensions { | 17 namespace extensions { |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 // Maximum length of an extension manifest update check url, since it is a GET | 21 // Maximum length of an extension manifest update check url, since it is a GET |
| 22 // request. We want to stay under 2K because of proxies, etc. | 22 // request. We want to stay under 2K because of proxies, etc. |
| 23 const int kExtensionsManifestMaxURLSize = 2000; | 23 const size_t kExtensionsManifestMaxURLSize = 2000; |
| 24 | 24 |
| 25 void AddEnabledStateToPing(std::string* ping_value, | 25 void AddEnabledStateToPing(std::string* ping_value, |
| 26 const ManifestFetchData::PingData* ping_data) { | 26 const ManifestFetchData::PingData* ping_data) { |
| 27 *ping_value += "&e=" + std::string(ping_data->is_enabled ? "1" : "0"); | 27 *ping_value += "&e=" + std::string(ping_data->is_enabled ? "1" : "0"); |
| 28 if (!ping_data->is_enabled) { | 28 if (!ping_data->is_enabled) { |
| 29 // Add a dr=<number> param for each bit set in disable reasons. | 29 // Add a dr=<number> param for each bit set in disable reasons. |
| 30 for (int enum_value = 1; enum_value < Extension::DISABLE_REASON_LAST; | 30 for (int enum_value = 1; enum_value < Extension::DISABLE_REASON_LAST; |
| 31 enum_value <<= 1) { | 31 enum_value <<= 1) { |
| 32 if (ping_data->disable_reasons & enum_value) | 32 if (ping_data->disable_reasons & enum_value) |
| 33 *ping_value += "&dr=" + base::IntToString(enum_value); | 33 *ping_value += "&dr=" + base::IntToString(enum_value); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 } | 132 } |
| 133 if (!ping_value.empty()) | 133 if (!ping_value.empty()) |
| 134 parts.push_back("ping=" + net::EscapeQueryParamValue(ping_value, true)); | 134 parts.push_back("ping=" + net::EscapeQueryParamValue(ping_value, true)); |
| 135 } | 135 } |
| 136 | 136 |
| 137 std::string extra = full_url_.has_query() ? "&" : "?"; | 137 std::string extra = full_url_.has_query() ? "&" : "?"; |
| 138 extra += | 138 extra += |
| 139 "x=" + net::EscapeQueryParamValue(base::JoinString(parts, "&"), true); | 139 "x=" + net::EscapeQueryParamValue(base::JoinString(parts, "&"), true); |
| 140 | 140 |
| 141 // Check against our max url size, exempting the first extension added. | 141 // Check against our max url size, exempting the first extension added. |
| 142 int new_size = full_url_.possibly_invalid_spec().size() + extra.size(); | 142 size_t new_size = full_url_.possibly_invalid_spec().size() + extra.size(); |
| 143 if (!extension_ids_.empty() && new_size > kExtensionsManifestMaxURLSize) { | 143 if (!extension_ids_.empty() && new_size > kExtensionsManifestMaxURLSize) { |
| 144 UMA_HISTOGRAM_PERCENTAGE("Extensions.UpdateCheckHitUrlSizeLimit", 1); | 144 UMA_HISTOGRAM_PERCENTAGE("Extensions.UpdateCheckHitUrlSizeLimit", 1); |
| 145 return false; | 145 return false; |
| 146 } | 146 } |
| 147 UMA_HISTOGRAM_PERCENTAGE("Extensions.UpdateCheckHitUrlSizeLimit", 0); | 147 UMA_HISTOGRAM_PERCENTAGE("Extensions.UpdateCheckHitUrlSizeLimit", 0); |
| 148 | 148 |
| 149 // We have room so go ahead and add the extension. | 149 // We have room so go ahead and add the extension. |
| 150 extension_ids_.insert(id); | 150 extension_ids_.insert(id); |
| 151 full_url_ = GURL(full_url_.possibly_invalid_spec() + extra); | 151 full_url_ = GURL(full_url_.possibly_invalid_spec() + extra); |
| 152 return true; | 152 return true; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 170 NOTREACHED(); | 170 NOTREACHED(); |
| 171 return value == kNeverPinged || value > 0; | 171 return value == kNeverPinged || value > 0; |
| 172 } | 172 } |
| 173 | 173 |
| 174 void ManifestFetchData::Merge(const ManifestFetchData& other) { | 174 void ManifestFetchData::Merge(const ManifestFetchData& other) { |
| 175 DCHECK(full_url() == other.full_url()); | 175 DCHECK(full_url() == other.full_url()); |
| 176 request_ids_.insert(other.request_ids_.begin(), other.request_ids_.end()); | 176 request_ids_.insert(other.request_ids_.begin(), other.request_ids_.end()); |
| 177 } | 177 } |
| 178 | 178 |
| 179 } // namespace extensions | 179 } // namespace extensions |
| OLD | NEW |