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/extensions/updater/manifest_fetch_data.h" | 5 #include "chrome/browser/extensions/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/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
13 #include "chrome/browser/google/google_util.h" | 13 #include "chrome/browser/google/google_util.h" |
14 #include "net/base/escape.h" | 14 #include "net/base/escape.h" |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
18 // Maximum length of an extension manifest update check url, since it is a GET | 18 // Maximum length of an extension manifest update check url, since it is a GET |
19 // request. We want to stay under 2K because of proxies, etc. | 19 // request. We want to stay under 2K because of proxies, etc. |
20 const int kExtensionsManifestMaxURLSize = 2000; | 20 const int kExtensionsManifestMaxURLSize = 2000; |
21 | 21 |
22 } // namespace | 22 } // namespace |
23 | 23 |
24 namespace extensions { | 24 namespace extensions { |
25 | 25 |
| 26 ManifestFetchExtensionInfo::ManifestFetchExtensionInfo( |
| 27 const std::string& id, const std::string& version, |
| 28 const std::string& update_url_data, const std::string& install_source, |
| 29 bool is_sync) |
| 30 : id(id), |
| 31 version(version), |
| 32 update_url_data(update_url_data), |
| 33 install_source(install_source), |
| 34 is_sync(is_sync) { |
| 35 } |
| 36 |
| 37 ManifestFetchExtensionInfo::ManifestFetchExtensionInfo() |
| 38 : id(""), |
| 39 version(""), |
| 40 update_url_data(""), |
| 41 install_source(""), |
| 42 is_sync(false) { |
| 43 } |
| 44 |
| 45 ManifestFetchExtensionInfo::~ManifestFetchExtensionInfo() { |
| 46 } |
| 47 |
| 48 |
26 ManifestFetchData::ManifestFetchData(const GURL& update_url) | 49 ManifestFetchData::ManifestFetchData(const GURL& update_url) |
27 : base_url_(update_url), | 50 : base_url_(update_url), |
28 full_url_(update_url) { | 51 full_url_(update_url) { |
29 } | 52 } |
30 | 53 |
31 ManifestFetchData::~ManifestFetchData() {} | 54 ManifestFetchData::~ManifestFetchData() {} |
32 | 55 |
33 // The format for request parameters in update checks is: | 56 // The format for request parameters in update checks is: |
34 // | 57 // |
35 // ?x=EXT1_INFO&x=EXT2_INFO | 58 // ?x=EXT1_INFO&x=EXT2_INFO |
(...skipping 12 matching lines...) Expand all Loading... |
48 // Extension 1- id:aaaa version:1.1 | 71 // Extension 1- id:aaaa version:1.1 |
49 // Extension 2- id:bbbb version:2.0 | 72 // Extension 2- id:bbbb version:2.0 |
50 // | 73 // |
51 // the full update url would be: | 74 // the full update url would be: |
52 // http://somehost/path?x=id%3Daaaa%26v%3D1.1%26uc&x=id%3Dbbbb%26v%3D2.0%26uc | 75 // http://somehost/path?x=id%3Daaaa%26v%3D1.1%26uc&x=id%3Dbbbb%26v%3D2.0%26uc |
53 // | 76 // |
54 // (Note that '=' is %3D and '&' is %26 when urlencoded.) | 77 // (Note that '=' is %3D and '&' is %26 when urlencoded.) |
55 bool ManifestFetchData::AddExtension(std::string id, std::string version, | 78 bool ManifestFetchData::AddExtension(std::string id, std::string version, |
56 const PingData* ping_data, | 79 const PingData* ping_data, |
57 const std::string& update_url_data, | 80 const std::string& update_url_data, |
58 const std::string& install_source) { | 81 const std::string& install_source, |
59 if (extension_ids_.find(id) != extension_ids_.end()) { | 82 const bool is_sync) { |
| 83 if (extension_infos_.find(id) != extension_infos_.end()) { |
60 NOTREACHED() << "Duplicate extension id " << id; | 84 NOTREACHED() << "Duplicate extension id " << id; |
61 return false; | 85 return false; |
62 } | 86 } |
63 | 87 |
64 // Compute the string we'd append onto the full_url_, and see if it fits. | 88 // Compute the string we'd append onto the full_url_, and see if it fits. |
65 std::vector<std::string> parts; | 89 std::vector<std::string> parts; |
66 parts.push_back("id=" + id); | 90 parts.push_back("id=" + id); |
67 parts.push_back("v=" + version); | 91 parts.push_back("v=" + version); |
68 if (!install_source.empty()) | 92 if (!install_source.empty()) |
69 parts.push_back("installsource=" + install_source); | 93 parts.push_back("installsource=" + install_source); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 } | 128 } |
105 if (!ping_value.empty()) | 129 if (!ping_value.empty()) |
106 parts.push_back("ping=" + net::EscapeQueryParamValue(ping_value, true)); | 130 parts.push_back("ping=" + net::EscapeQueryParamValue(ping_value, true)); |
107 } | 131 } |
108 | 132 |
109 std::string extra = full_url_.has_query() ? "&" : "?"; | 133 std::string extra = full_url_.has_query() ? "&" : "?"; |
110 extra += "x=" + net::EscapeQueryParamValue(JoinString(parts, '&'), true); | 134 extra += "x=" + net::EscapeQueryParamValue(JoinString(parts, '&'), true); |
111 | 135 |
112 // Check against our max url size, exempting the first extension added. | 136 // Check against our max url size, exempting the first extension added. |
113 int new_size = full_url_.possibly_invalid_spec().size() + extra.size(); | 137 int new_size = full_url_.possibly_invalid_spec().size() + extra.size(); |
114 if (!extension_ids_.empty() && new_size > kExtensionsManifestMaxURLSize) { | 138 if (!extension_infos_.empty() && new_size > kExtensionsManifestMaxURLSize) { |
115 UMA_HISTOGRAM_PERCENTAGE("Extensions.UpdateCheckHitUrlSizeLimit", 1); | 139 UMA_HISTOGRAM_PERCENTAGE("Extensions.UpdateCheckHitUrlSizeLimit", 1); |
116 return false; | 140 return false; |
117 } | 141 } |
118 UMA_HISTOGRAM_PERCENTAGE("Extensions.UpdateCheckHitUrlSizeLimit", 0); | 142 UMA_HISTOGRAM_PERCENTAGE("Extensions.UpdateCheckHitUrlSizeLimit", 0); |
119 | 143 |
120 // We have room so go ahead and add the extension. | 144 // We have room so go ahead and add the extension. |
121 extension_ids_.insert(id); | 145 extension_infos_[id] = ManifestFetchExtensionInfo(id, version, |
| 146 update_url_data, |
| 147 install_source, |
| 148 is_sync); |
122 full_url_ = GURL(full_url_.possibly_invalid_spec() + extra); | 149 full_url_ = GURL(full_url_.possibly_invalid_spec() + extra); |
123 return true; | 150 return true; |
124 } | 151 } |
125 | 152 |
126 bool ManifestFetchData::Includes(const std::string& extension_id) const { | 153 bool ManifestFetchData::Includes(const std::string& extension_id) const { |
127 return extension_ids_.find(extension_id) != extension_ids_.end(); | 154 return extension_infos_.find(extension_id) != extension_infos_.end(); |
128 } | 155 } |
129 | 156 |
130 bool ManifestFetchData::DidPing(std::string extension_id, PingType type) const { | 157 bool ManifestFetchData::DidPing(std::string extension_id, PingType type) const { |
131 std::map<std::string, PingData>::const_iterator i = pings_.find(extension_id); | 158 std::map<std::string, PingData>::const_iterator i = pings_.find(extension_id); |
132 if (i == pings_.end()) | 159 if (i == pings_.end()) |
133 return false; | 160 return false; |
134 int value = 0; | 161 int value = 0; |
135 if (type == ROLLCALL) | 162 if (type == ROLLCALL) |
136 value = i->second.rollcall_days; | 163 value = i->second.rollcall_days; |
137 else if (type == ACTIVE) | 164 else if (type == ACTIVE) |
138 value = i->second.active_days; | 165 value = i->second.active_days; |
139 else | 166 else |
140 NOTREACHED(); | 167 NOTREACHED(); |
141 return value == kNeverPinged || value > 0; | 168 return value == kNeverPinged || value > 0; |
142 } | 169 } |
143 | 170 |
144 } // namespace extensions | 171 } // namespace extensions |
OLD | NEW |