OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/update_client/action_update_check.h" | 5 #include "components/update_client/action_update_check.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 if (!error) | 107 if (!error) |
108 OnUpdateCheckSucceeded(results); | 108 OnUpdateCheckSucceeded(results); |
109 else | 109 else |
110 OnUpdateCheckFailed(error); | 110 OnUpdateCheckFailed(error); |
111 } | 111 } |
112 | 112 |
113 void ActionUpdateCheck::OnUpdateCheckSucceeded( | 113 void ActionUpdateCheck::OnUpdateCheckSucceeded( |
114 const UpdateResponse::Results& results) { | 114 const UpdateResponse::Results& results) { |
115 DCHECK(thread_checker_.CalledOnValidThread()); | 115 DCHECK(thread_checker_.CalledOnValidThread()); |
116 VLOG(1) << "Update check succeeded."; | 116 VLOG(1) << "Update check succeeded."; |
117 std::vector<UpdateResponse::Result>::const_iterator it; | |
118 for (it = results.list.begin(); it != results.list.end(); ++it) { | |
119 CrxUpdateItem* crx = FindUpdateItemById(it->extension_id); | |
120 if (!crx) | |
121 continue; | |
122 | 117 |
123 if (crx->state != CrxUpdateItem::State::kChecking) { | 118 for (const auto& result : results.list) { |
124 NOTREACHED(); | 119 CrxUpdateItem* crx = FindUpdateItemById(result.extension_id); |
125 continue; // Not updating this CRX now. | 120 if (!crx) { |
126 } | 121 VLOG(1) << "Component not found " << result.extension_id; |
127 | |
128 if (it->manifest.version.empty()) { | |
129 // No version means no update available. | |
130 ChangeItemState(crx, CrxUpdateItem::State::kNoUpdate); | |
131 VLOG(1) << "No update available for CRX: " << crx->id; | |
132 continue; | 122 continue; |
133 } | 123 } |
134 | 124 |
135 if (!IsVersionNewer(crx->component.version, it->manifest.version)) { | 125 DCHECK_EQ(CrxUpdateItem::State::kChecking, crx->state); |
136 // The CRX is up to date. | |
137 ChangeItemState(crx, CrxUpdateItem::State::kUpToDate); | |
138 VLOG(1) << "Component already up to date: " << crx->id; | |
139 continue; | |
140 } | |
141 | 126 |
142 if (!it->manifest.browser_min_version.empty()) { | 127 if (result.status == "ok") |
143 if (IsVersionNewer(browser_version_, it->manifest.browser_min_version)) { | 128 HandleUpdateCheckOK(result, crx); |
144 // The CRX is not compatible with this Chrome version. | 129 else if (result.status == "noupdate") |
145 VLOG(1) << "Ignoring incompatible CRX: " << crx->id; | 130 HandleUpdateCheckNoupdate(result, crx); |
146 ChangeItemState(crx, CrxUpdateItem::State::kNoUpdate); | 131 else |
147 continue; | 132 HandleUpdateCheckError(result, crx); |
148 } | |
149 } | |
150 | |
151 if (it->manifest.packages.size() != 1) { | |
152 // Assume one and only one package per CRX. | |
153 VLOG(1) << "Ignoring multiple packages for CRX: " << crx->id; | |
154 ChangeItemState(crx, CrxUpdateItem::State::kNoUpdate); | |
155 continue; | |
156 } | |
157 | |
158 // Parse the members of the result and queue an upgrade for this CRX. | |
159 crx->next_version = base::Version(it->manifest.version); | |
160 | |
161 VLOG(1) << "Update found for CRX: " << crx->id; | |
162 | |
163 const auto& package(it->manifest.packages[0]); | |
164 crx->next_fp = package.fingerprint; | |
165 | |
166 // Resolve the urls by combining the base urls with the package names. | |
167 for (size_t i = 0; i != it->crx_urls.size(); ++i) { | |
168 const GURL url(it->crx_urls[i].Resolve(package.name)); | |
169 if (url.is_valid()) | |
170 crx->crx_urls.push_back(url); | |
171 } | |
172 for (size_t i = 0; i != it->crx_diffurls.size(); ++i) { | |
173 const GURL url(it->crx_diffurls[i].Resolve(package.namediff)); | |
174 if (url.is_valid()) | |
175 crx->crx_diffurls.push_back(url); | |
176 } | |
177 | |
178 crx->hash_sha256 = package.hash_sha256; | |
179 crx->hashdiff_sha256 = package.hashdiff_sha256; | |
180 | |
181 ChangeItemState(crx, CrxUpdateItem::State::kCanUpdate); | |
182 | |
183 update_context_->queue.push(crx->id); | |
184 } | 133 } |
185 | 134 |
186 // All components that are not included in the update response are | 135 // All components that are not included in the update response are |
187 // considered up to date. | 136 // considered up to date. |
188 ChangeAllItemsState(CrxUpdateItem::State::kChecking, | 137 ChangeAllItemsState(CrxUpdateItem::State::kChecking, |
189 CrxUpdateItem::State::kUpToDate); | 138 CrxUpdateItem::State::kUpToDate); |
190 | 139 |
191 if (update_context_->queue.empty()) { | 140 if (update_context_->queue.empty()) { |
192 VLOG(1) << "Update check completed but no update is needed."; | 141 VLOG(1) << "Update check completed but no action is needed."; |
193 UpdateComplete(Error::NONE); | 142 UpdateComplete(Error::NONE); |
194 return; | 143 return; |
195 } | 144 } |
196 | 145 |
197 // Starts the execution flow of updating the CRXs in this context. | 146 // Starts the execution flow of updating the CRXs in this context. |
198 UpdateCrx(); | 147 UpdateCrx(); |
199 } | 148 } |
200 | 149 |
| 150 void ActionUpdateCheck::HandleUpdateCheckOK( |
| 151 const UpdateResponse::Result& result, |
| 152 CrxUpdateItem* crx) { |
| 153 DCHECK(thread_checker_.CalledOnValidThread()); |
| 154 |
| 155 const auto& manifest = result.manifest; |
| 156 |
| 157 if (manifest.version.empty()) { |
| 158 // It can't update without a manifest version. |
| 159 VLOG(1) << "No manifest version available for CRX: " << crx->id; |
| 160 ChangeItemState(crx, CrxUpdateItem::State::kNoUpdate); |
| 161 return; |
| 162 } |
| 163 |
| 164 if (!IsVersionNewer(crx->component.version, manifest.version)) { |
| 165 // The CRX is up to date. |
| 166 VLOG(1) << "Component already up to date: " << crx->id; |
| 167 ChangeItemState(crx, CrxUpdateItem::State::kUpToDate); |
| 168 return; |
| 169 } |
| 170 |
| 171 if (!manifest.browser_min_version.empty()) { |
| 172 if (IsVersionNewer(browser_version_, manifest.browser_min_version)) { |
| 173 // The CRX is not compatible with this Chrome version. |
| 174 VLOG(1) << "Ignoring incompatible CRX: " << crx->id; |
| 175 ChangeItemState(crx, CrxUpdateItem::State::kNoUpdate); |
| 176 return; |
| 177 } |
| 178 } |
| 179 |
| 180 if (manifest.packages.size() != 1) { |
| 181 // Assume one and only one package per CRX. |
| 182 VLOG(1) << "Ignoring multiple packages for CRX: " << crx->id; |
| 183 ChangeItemState(crx, CrxUpdateItem::State::kNoUpdate); |
| 184 return; |
| 185 } |
| 186 |
| 187 // Parse the members of the result and queue an upgrade for this CRX. |
| 188 VLOG(1) << "Update found for CRX: " << crx->id; |
| 189 |
| 190 crx->next_version = base::Version(manifest.version); |
| 191 const auto& package = manifest.packages.front(); |
| 192 crx->next_fp = package.fingerprint; |
| 193 |
| 194 // Resolve the urls by combining the base urls with the package names. |
| 195 for (const auto& crx_url : result.crx_urls) { |
| 196 const GURL url = crx_url.Resolve(package.name); |
| 197 if (url.is_valid()) |
| 198 crx->crx_urls.push_back(url); |
| 199 } |
| 200 for (const auto& crx_diffurl : result.crx_diffurls) { |
| 201 const GURL url = crx_diffurl.Resolve(package.namediff); |
| 202 if (url.is_valid()) |
| 203 crx->crx_diffurls.push_back(url); |
| 204 } |
| 205 |
| 206 crx->hash_sha256 = package.hash_sha256; |
| 207 crx->hashdiff_sha256 = package.hashdiff_sha256; |
| 208 |
| 209 ChangeItemState(crx, CrxUpdateItem::State::kCanUpdate); |
| 210 |
| 211 update_context_->queue.push(crx->id); |
| 212 } |
| 213 |
| 214 void ActionUpdateCheck::HandleUpdateCheckNoupdate( |
| 215 const UpdateResponse::Result& result, |
| 216 CrxUpdateItem* crx) { |
| 217 DCHECK(thread_checker_.CalledOnValidThread()); |
| 218 VLOG(1) << "No update for CRX: " << crx->id; |
| 219 ChangeItemState(crx, CrxUpdateItem::State::kNoUpdate); |
| 220 } |
| 221 |
| 222 void ActionUpdateCheck::HandleUpdateCheckError( |
| 223 const UpdateResponse::Result& result, |
| 224 CrxUpdateItem* crx) { |
| 225 DCHECK(thread_checker_.CalledOnValidThread()); |
| 226 VLOG(1) << "Update error for CRX: " << crx->id << ", " << result.status; |
| 227 ChangeItemState(crx, CrxUpdateItem::State::kNoUpdate); |
| 228 } |
| 229 |
201 void ActionUpdateCheck::OnUpdateCheckFailed(int error) { | 230 void ActionUpdateCheck::OnUpdateCheckFailed(int error) { |
202 DCHECK(thread_checker_.CalledOnValidThread()); | 231 DCHECK(thread_checker_.CalledOnValidThread()); |
203 DCHECK(error); | 232 DCHECK(error); |
204 | 233 |
205 VLOG(1) << "Update check failed." << error; | 234 VLOG(1) << "Update check failed." << error; |
206 | 235 |
207 ChangeAllItemsState(CrxUpdateItem::State::kChecking, | 236 ChangeAllItemsState(CrxUpdateItem::State::kChecking, |
208 CrxUpdateItem::State::kNoUpdate); | 237 CrxUpdateItem::State::kNoUpdate); |
209 | 238 |
210 UpdateComplete(Error::UPDATE_CHECK_ERROR); | 239 UpdateComplete(Error::UPDATE_CHECK_ERROR); |
211 } | 240 } |
212 | 241 |
213 } // namespace update_client | 242 } // namespace update_client |
OLD | NEW |