| 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/component_updater/component_updater_service.h" | 5 #include "chrome/browser/component_updater/component_updater_service.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/at_exit.h" | 11 #include "base/at_exit.h" |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/file_util.h" | 14 #include "base/file_util.h" |
| 15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 18 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
| 19 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
| 20 #include "base/strings/string_piece.h" | 20 #include "base/strings/string_piece.h" |
| 21 #include "base/strings/string_util.h" | 21 #include "base/strings/string_util.h" |
| 22 #include "base/strings/stringprintf.h" | 22 #include "base/strings/stringprintf.h" |
| 23 #include "base/timer/timer.h" | 23 #include "base/timer/timer.h" |
| 24 #include "chrome/browser/browser_process.h" | 24 #include "chrome/browser/browser_process.h" |
| 25 #include "chrome/browser/chrome_notification_types.h" | 25 #include "chrome/browser/chrome_notification_types.h" |
| 26 #include "chrome/browser/component_updater/component_patcher.h" | 26 #include "chrome/browser/component_updater/component_patcher.h" |
| 27 #include "chrome/browser/component_updater/component_unpacker.h" | 27 #include "chrome/browser/component_updater/component_unpacker.h" |
| 28 #include "chrome/browser/component_updater/component_updater_ping_manager.h" |
| 29 #include "chrome/browser/component_updater/crx_update_item.h" |
| 28 #include "chrome/common/chrome_utility_messages.h" | 30 #include "chrome/common/chrome_utility_messages.h" |
| 29 #include "chrome/common/chrome_version_info.h" | 31 #include "chrome/common/chrome_version_info.h" |
| 30 #include "chrome/common/extensions/extension.h" | 32 #include "chrome/common/extensions/extension.h" |
| 31 #include "chrome/common/omaha_query_params/omaha_query_params.h" | 33 #include "chrome/common/omaha_query_params/omaha_query_params.h" |
| 32 #include "content/public/browser/browser_thread.h" | 34 #include "content/public/browser/browser_thread.h" |
| 33 #include "content/public/browser/notification_service.h" | 35 #include "content/public/browser/notification_service.h" |
| 34 #include "content/public/browser/utility_process_host.h" | 36 #include "content/public/browser/utility_process_host.h" |
| 35 #include "content/public/browser/utility_process_host_client.h" | 37 #include "content/public/browser/utility_process_host_client.h" |
| 36 #include "net/base/escape.h" | 38 #include "net/base/escape.h" |
| 37 #include "net/base/load_flags.h" | 39 #include "net/base/load_flags.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 &val)) { | 102 &val)) { |
| 101 id.append(1, val + 'a'); | 103 id.append(1, val + 'a'); |
| 102 } else { | 104 } else { |
| 103 id.append(1, 'a'); | 105 id.append(1, 'a'); |
| 104 } | 106 } |
| 105 } | 107 } |
| 106 DCHECK(Extension::IdIsValid(id)); | 108 DCHECK(Extension::IdIsValid(id)); |
| 107 return id; | 109 return id; |
| 108 } | 110 } |
| 109 | 111 |
| 110 // Returns given a crx id it returns a small number, less than 100, that has a | |
| 111 // decent chance of being unique among the registered components. It also has | |
| 112 // the nice property that can be trivially computed by hand. | |
| 113 static int CrxIdtoUMAId(const std::string& id) { | |
| 114 CHECK_GT(id.size(), 2U); | |
| 115 return id[0] + id[1] + id[2] - ('a' * 3); | |
| 116 } | |
| 117 | |
| 118 // Helper to do version check for components. | 112 // Helper to do version check for components. |
| 119 bool IsVersionNewer(const Version& current, const std::string& proposed) { | 113 bool IsVersionNewer(const Version& current, const std::string& proposed) { |
| 120 Version proposed_ver(proposed); | 114 Version proposed_ver(proposed); |
| 121 if (!proposed_ver.IsValid()) | 115 if (!proposed_ver.IsValid()) |
| 122 return false; | 116 return false; |
| 123 return (current.CompareTo(proposed_ver) < 0); | 117 return (current.CompareTo(proposed_ver) < 0); |
| 124 } | 118 } |
| 125 | 119 |
| 126 // Helper template class that allows our main class to have separate | 120 // Helper template class that allows our main class to have separate |
| 127 // OnURLFetchComplete() callbacks for different types of url requests | 121 // OnURLFetchComplete() callbacks for different types of url requests |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 } | 159 } |
| 166 fetcher->Start(); | 160 fetcher->Start(); |
| 167 } | 161 } |
| 168 | 162 |
| 169 // Returns true if the url request of |fetcher| was succesful. | 163 // Returns true if the url request of |fetcher| was succesful. |
| 170 bool FetchSuccess(const net::URLFetcher& fetcher) { | 164 bool FetchSuccess(const net::URLFetcher& fetcher) { |
| 171 return (fetcher.GetStatus().status() == net::URLRequestStatus::SUCCESS) && | 165 return (fetcher.GetStatus().status() == net::URLRequestStatus::SUCCESS) && |
| 172 (fetcher.GetResponseCode() == 200); | 166 (fetcher.GetResponseCode() == 200); |
| 173 } | 167 } |
| 174 | 168 |
| 175 // This is the one and only per-item state structure. Designed to be hosted | 169 // Returns the error code which occured during the fetch.The function returns 0 |
| 176 // in a std::vector or a std::list. The two main members are |component| | 170 // if the fetch was successful. If errors happen, the function could return a |
| 177 // which is supplied by the the component updater client and |status| which | 171 // network error, an http response code, or the status of the fetch, if the |
| 178 // is modified as the item is processed by the update pipeline. The expected | 172 // fetch is pending or canceled. |
| 179 // transition graph is: | 173 int GetFetchError(const net::URLFetcher& fetcher) { |
| 180 // | 174 if (FetchSuccess(fetcher)) |
| 181 // kNew | 175 return 0; |
| 182 // | | |
| 183 // V | |
| 184 // +----------------------> kChecking -<---------+-----<-------+ | |
| 185 // | | | | | |
| 186 // | error V no | | | |
| 187 // kNoUpdate <---------------- [update?] ->---- kUpToDate kUpdated | |
| 188 // ^ | ^ | |
| 189 // | yes | | | |
| 190 // | diff=false V | | |
| 191 // | +-----------> kCanUpdate | | |
| 192 // | | | | | |
| 193 // | | V no | | |
| 194 // | | [differential update?]->----+ | | |
| 195 // | | | | | | |
| 196 // | | yes | | | | |
| 197 // | | error V | | | |
| 198 // | +---------<- kDownloadingDiff | | | |
| 199 // | | | | | | |
| 200 // | | | | | | |
| 201 // | | error V | | | |
| 202 // | +---------<- kUpdatingDiff ->--------|-----------+ success | |
| 203 // | | | | |
| 204 // | error V | | |
| 205 // +----------------------------------------- kDownloading | | |
| 206 // | | | | |
| 207 // | error V | | |
| 208 // +------------------------------------------ kUpdating ->----+ success | |
| 209 // | |
| 210 struct CrxUpdateItem { | |
| 211 enum Status { | |
| 212 kNew, | |
| 213 kChecking, | |
| 214 kCanUpdate, | |
| 215 kDownloadingDiff, | |
| 216 kDownloading, | |
| 217 kUpdatingDiff, | |
| 218 kUpdating, | |
| 219 kUpdated, | |
| 220 kUpToDate, | |
| 221 kNoUpdate, | |
| 222 kLastStatus | |
| 223 }; | |
| 224 | 176 |
| 225 Status status; | 177 const net::URLRequestStatus::Status status(fetcher.GetStatus().status()); |
| 226 std::string id; | 178 if (status == net::URLRequestStatus::FAILED) |
| 227 CrxComponent component; | 179 return fetcher.GetStatus().error(); |
| 228 | 180 |
| 229 base::Time last_check; | 181 if (status == net::URLRequestStatus::IO_PENDING || |
| 182 status == net::URLRequestStatus::CANCELED) |
| 183 return status; |
| 230 | 184 |
| 231 // These members are initialized with their corresponding values from the | 185 const int response_code(fetcher.GetResponseCode()); |
| 232 // update server response. | 186 if (status == net::URLRequestStatus::SUCCESS && response_code != 200) |
| 233 GURL crx_url; | 187 return response_code; |
| 234 GURL diff_crx_url; | |
| 235 int size; | |
| 236 int diff_size; | |
| 237 | 188 |
| 238 // The from/to version and fingerprint values. | 189 return -1; |
| 239 Version previous_version; | |
| 240 Version next_version; | |
| 241 std::string previous_fp; | |
| 242 std::string next_fp; | |
| 243 | |
| 244 // True if the differential update failed for any reason. | |
| 245 bool diff_update_failed; | |
| 246 | |
| 247 CrxUpdateItem() | |
| 248 : status(kNew), | |
| 249 size(0), | |
| 250 diff_size(0), | |
| 251 diff_update_failed(false) { | |
| 252 } | 190 } |
| 253 | 191 |
| 254 // Function object used to find a specific component. | |
| 255 class FindById { | |
| 256 public: | |
| 257 explicit FindById(const std::string& id) : id_(id) {} | |
| 258 | |
| 259 bool operator() (CrxUpdateItem* item) const { | |
| 260 return (item->id == id_); | |
| 261 } | |
| 262 private: | |
| 263 const std::string& id_; | |
| 264 }; | |
| 265 }; | |
| 266 | |
| 267 // Returns true if a differential update is available for the update item. | 192 // Returns true if a differential update is available for the update item. |
| 268 bool IsDiffUpdateAvailable(const CrxUpdateItem* update_item) { | 193 bool IsDiffUpdateAvailable(const CrxUpdateItem* update_item) { |
| 269 return update_item->diff_crx_url.is_valid(); | 194 return update_item->diff_crx_url.is_valid(); |
| 270 } | 195 } |
| 271 | 196 |
| 272 // Returns true if a differential update is available, it has not failed yet, | 197 // Returns true if a differential update is available, it has not failed yet, |
| 273 // and the configuration allows it. | 198 // and the configuration allows it. |
| 274 bool CanTryDiffUpdate(const CrxUpdateItem* update_item, | 199 bool CanTryDiffUpdate(const CrxUpdateItem* update_item, |
| 275 const ComponentUpdateService::Configurator& config) { | 200 const ComponentUpdateService::Configurator& config) { |
| 276 return IsDiffUpdateAvailable(update_item) && | 201 return IsDiffUpdateAvailable(update_item) && |
| 277 !update_item->diff_update_failed && | 202 !update_item->diff_update_failed && |
| 278 config.DeltasEnabled(); | 203 config.DeltasEnabled(); |
| 279 } | 204 } |
| 280 | 205 |
| 281 } // namespace. | 206 } // namespace |
| 207 |
| 208 CrxUpdateItem::CrxUpdateItem() |
| 209 : status(kNew), |
| 210 diff_update_failed(false), |
| 211 error_category(0), |
| 212 error_code(0), |
| 213 extra_code1(0), |
| 214 diff_error_category(0), |
| 215 diff_error_code(0), |
| 216 diff_extra_code1(0) { |
| 217 } |
| 218 |
| 219 CrxUpdateItem::~CrxUpdateItem() { |
| 220 } |
| 282 | 221 |
| 283 CrxComponent::CrxComponent() | 222 CrxComponent::CrxComponent() |
| 284 : installer(NULL) { | 223 : installer(NULL) { |
| 285 } | 224 } |
| 286 | 225 |
| 287 CrxComponent::~CrxComponent() { | 226 CrxComponent::~CrxComponent() { |
| 288 } | 227 } |
| 289 | 228 |
| 290 ////////////////////////////////////////////////////////////////////////////// | 229 ////////////////////////////////////////////////////////////////////////////// |
| 291 // The one and only implementation of the ComponentUpdateService interface. In | 230 // The one and only implementation of the ComponentUpdateService interface. In |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 CRXContext() : installer(NULL) {} | 302 CRXContext() : installer(NULL) {} |
| 364 }; | 303 }; |
| 365 | 304 |
| 366 void OnURLFetchComplete(const net::URLFetcher* source, | 305 void OnURLFetchComplete(const net::URLFetcher* source, |
| 367 UpdateContext* context); | 306 UpdateContext* context); |
| 368 | 307 |
| 369 void OnURLFetchComplete(const net::URLFetcher* source, | 308 void OnURLFetchComplete(const net::URLFetcher* source, |
| 370 CRXContext* context); | 309 CRXContext* context); |
| 371 | 310 |
| 372 private: | 311 private: |
| 312 enum ErrorCategory { |
| 313 kErrorNone = 0, |
| 314 kNetworkError, |
| 315 kUnpackError, |
| 316 kInstallError, |
| 317 }; |
| 318 |
| 373 // See ManifestParserBridge. | 319 // See ManifestParserBridge. |
| 374 void OnParseUpdateManifestSucceeded( | 320 void OnParseUpdateManifestSucceeded(const UpdateManifest::Results& results); |
| 375 const UpdateManifest::Results& results); | |
| 376 | 321 |
| 377 // See ManifestParserBridge. | 322 // See ManifestParserBridge. |
| 378 void OnParseUpdateManifestFailed(const std::string& error_message); | 323 void OnParseUpdateManifestFailed(const std::string& error_message); |
| 379 | 324 |
| 380 bool AddItemToUpdateCheck(CrxUpdateItem* item, std::string* query); | 325 bool AddItemToUpdateCheck(CrxUpdateItem* item, std::string* query); |
| 381 | 326 |
| 382 void ProcessPendingItems(); | 327 void ProcessPendingItems(); |
| 383 | 328 |
| 384 void ScheduleNextRun(bool step_delay); | 329 void ScheduleNextRun(bool step_delay); |
| 385 | 330 |
| 386 void ParseManifest(const std::string& xml); | 331 void ParseManifest(const std::string& xml); |
| 387 | 332 |
| 388 void Install(const CRXContext* context, const base::FilePath& crx_path); | 333 void Install(const CRXContext* context, const base::FilePath& crx_path); |
| 389 | 334 |
| 390 void DoneInstalling(const std::string& component_id, | 335 void DoneInstalling(const std::string& component_id, |
| 391 ComponentUnpacker::Error error, | 336 ComponentUnpacker::Error error, |
| 392 int extended_error); | 337 int extended_error); |
| 393 | 338 |
| 394 size_t ChangeItemStatus(CrxUpdateItem::Status from, | 339 size_t ChangeItemStatus(CrxUpdateItem::Status from, |
| 395 CrxUpdateItem::Status to); | 340 CrxUpdateItem::Status to); |
| 396 | 341 |
| 397 CrxUpdateItem* FindUpdateItemById(const std::string& id); | 342 CrxUpdateItem* FindUpdateItemById(const std::string& id); |
| 398 | 343 |
| 399 scoped_ptr<ComponentUpdateService::Configurator> config_; | 344 scoped_ptr<ComponentUpdateService::Configurator> config_; |
| 400 | 345 |
| 401 scoped_ptr<ComponentPatcher> component_patcher_; | 346 scoped_ptr<ComponentPatcher> component_patcher_; |
| 402 | 347 |
| 403 scoped_ptr<net::URLFetcher> url_fetcher_; | 348 scoped_ptr<net::URLFetcher> url_fetcher_; |
| 404 | 349 |
| 350 scoped_ptr<component_updater::PingManager> ping_manager_; |
| 351 |
| 405 // A collection of every work item. | 352 // A collection of every work item. |
| 406 typedef std::vector<CrxUpdateItem*> UpdateItems; | 353 typedef std::vector<CrxUpdateItem*> UpdateItems; |
| 407 UpdateItems work_items_; | 354 UpdateItems work_items_; |
| 408 | 355 |
| 409 // A particular set of items from work_items_, which should be checked ASAP. | 356 // A particular set of items from work_items_, which should be checked ASAP. |
| 410 std::set<CrxUpdateItem*> requested_work_items_; | 357 std::set<CrxUpdateItem*> requested_work_items_; |
| 411 | 358 |
| 412 base::OneShotTimer<CrxUpdateService> timer_; | 359 base::OneShotTimer<CrxUpdateService> timer_; |
| 413 | 360 |
| 414 const Version chrome_version_; | 361 const Version chrome_version_; |
| 415 const std::string prod_id_; | 362 const std::string prod_id_; |
| 416 | 363 |
| 417 bool running_; | 364 bool running_; |
| 418 | 365 |
| 419 DISALLOW_COPY_AND_ASSIGN(CrxUpdateService); | 366 DISALLOW_COPY_AND_ASSIGN(CrxUpdateService); |
| 420 }; | 367 }; |
| 421 | 368 |
| 422 ////////////////////////////////////////////////////////////////////////////// | 369 ////////////////////////////////////////////////////////////////////////////// |
| 423 | 370 |
| 424 CrxUpdateService::CrxUpdateService(ComponentUpdateService::Configurator* config) | 371 CrxUpdateService::CrxUpdateService(ComponentUpdateService::Configurator* config) |
| 425 : config_(config), | 372 : config_(config), |
| 426 component_patcher_(config->CreateComponentPatcher()), | 373 component_patcher_(config->CreateComponentPatcher()), |
| 374 ping_manager_(new component_updater::PingManager( |
| 375 config->PingUrl(), |
| 376 config->RequestContext())), |
| 427 chrome_version_(chrome::VersionInfo().Version()), | 377 chrome_version_(chrome::VersionInfo().Version()), |
| 428 prod_id_(chrome::OmahaQueryParams::GetProdIdString( | 378 prod_id_(chrome::OmahaQueryParams::GetProdIdString( |
| 429 chrome::OmahaQueryParams::CHROME)), | 379 chrome::OmahaQueryParams::CHROME)), |
| 430 running_(false) { | 380 running_(false) { |
| 431 } | 381 } |
| 432 | 382 |
| 433 CrxUpdateService::~CrxUpdateService() { | 383 CrxUpdateService::~CrxUpdateService() { |
| 434 // Because we are a singleton, at this point only the UI thread should be | 384 // Because we are a singleton, at this point only the UI thread should be |
| 435 // alive, this simplifies the management of the work that could be in | 385 // alive, this simplifies the management of the work that could be in |
| 436 // flight in other threads. | 386 // flight in other threads. |
| 437 Stop(); | 387 Stop(); |
| 438 STLDeleteElements(&work_items_); | 388 STLDeleteElements(&work_items_); |
| 439 } | 389 } |
| 440 | 390 |
| 441 ComponentUpdateService::Status CrxUpdateService::Start() { | 391 ComponentUpdateService::Status CrxUpdateService::Start() { |
| 442 // Note that RegisterComponent will call Start() when the first | 392 // Note that RegisterComponent will call Start() when the first |
| 443 // component is registered, so it can be called twice. This way | 393 // component is registered, so it can be called twice. This way |
| 444 // we avoid scheduling the timer if there is no work to do. | 394 // we avoid scheduling the timer if there is no work to do. |
| 445 running_ = true; | 395 running_ = true; |
| 446 if (work_items_.empty()) | 396 if (work_items_.empty()) |
| 447 return kOk; | 397 return kOk; |
| 448 | 398 |
| 449 content::NotificationService::current()->Notify( | 399 content::NotificationService::current()->Notify( |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 query)) | 529 query)) |
| 580 return false; | 530 return false; |
| 581 | 531 |
| 582 item->status = CrxUpdateItem::kChecking; | 532 item->status = CrxUpdateItem::kChecking; |
| 583 item->last_check = base::Time::Now(); | 533 item->last_check = base::Time::Now(); |
| 584 item->previous_version = item->component.version; | 534 item->previous_version = item->component.version; |
| 585 item->next_version = Version(); | 535 item->next_version = Version(); |
| 586 item->previous_fp = item->component.fingerprint; | 536 item->previous_fp = item->component.fingerprint; |
| 587 item->next_fp.clear(); | 537 item->next_fp.clear(); |
| 588 item->diff_update_failed = false; | 538 item->diff_update_failed = false; |
| 539 item->error_category = 0; |
| 540 item->error_code = 0; |
| 541 item->extra_code1 = 0; |
| 542 item->diff_error_category = 0; |
| 543 item->diff_error_code = 0; |
| 544 item->diff_extra_code1 = 0; |
| 589 return true; | 545 return true; |
| 590 } | 546 } |
| 591 | 547 |
| 592 // Start the process of checking for an update, for a particular component | 548 // Start the process of checking for an update, for a particular component |
| 593 // that was previously registered. | 549 // that was previously registered. |
| 594 ComponentUpdateService::Status CrxUpdateService::CheckForUpdateSoon( | 550 ComponentUpdateService::Status CrxUpdateService::CheckForUpdateSoon( |
| 595 const CrxComponent& component) { | 551 const CrxComponent& component) { |
| 596 if (component.pk_hash.empty() || | 552 if (component.pk_hash.empty() || |
| 597 !component.version.IsValid() || | 553 !component.version.IsValid() || |
| 598 !component.installer) | 554 !component.installer) |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 794 size_t update_pending = 0; | 750 size_t update_pending = 0; |
| 795 std::vector<UpdateManifest::Result>::const_iterator it; | 751 std::vector<UpdateManifest::Result>::const_iterator it; |
| 796 for (it = results.list.begin(); it != results.list.end(); ++it) { | 752 for (it = results.list.begin(); it != results.list.end(); ++it) { |
| 797 CrxUpdateItem* crx = FindUpdateItemById(it->extension_id); | 753 CrxUpdateItem* crx = FindUpdateItemById(it->extension_id); |
| 798 if (!crx) | 754 if (!crx) |
| 799 continue; | 755 continue; |
| 800 | 756 |
| 801 if (crx->status != CrxUpdateItem::kChecking) | 757 if (crx->status != CrxUpdateItem::kChecking) |
| 802 continue; // Not updating this component now. | 758 continue; // Not updating this component now. |
| 803 | 759 |
| 804 config_->OnEvent(Configurator::kManifestCheck, CrxIdtoUMAId(crx->id)); | |
| 805 | |
| 806 if (it->version.empty()) { | 760 if (it->version.empty()) { |
| 807 // No version means no update available. | 761 // No version means no update available. |
| 808 crx->status = CrxUpdateItem::kNoUpdate; | 762 crx->status = CrxUpdateItem::kNoUpdate; |
| 809 continue; | 763 continue; |
| 810 } | 764 } |
| 811 if (!IsVersionNewer(crx->component.version, it->version)) { | 765 if (!IsVersionNewer(crx->component.version, it->version)) { |
| 812 // Our component is up to date. | 766 // Our component is up to date. |
| 813 crx->status = CrxUpdateItem::kUpToDate; | 767 crx->status = CrxUpdateItem::kUpToDate; |
| 814 continue; | 768 continue; |
| 815 } | 769 } |
| 816 if (!it->browser_min_version.empty()) { | 770 if (!it->browser_min_version.empty()) { |
| 817 if (IsVersionNewer(chrome_version_, it->browser_min_version)) { | 771 if (IsVersionNewer(chrome_version_, it->browser_min_version)) { |
| 818 // Does not apply for this chrome version. | 772 // Does not apply for this chrome version. |
| 819 crx->status = CrxUpdateItem::kNoUpdate; | 773 crx->status = CrxUpdateItem::kNoUpdate; |
| 820 continue; | 774 continue; |
| 821 } | 775 } |
| 822 } | 776 } |
| 823 // All test passed. Queue an upgrade for this component and fire the | 777 // All test passed. Queue an upgrade for this component and fire the |
| 824 // notifications. | 778 // notifications. |
| 825 crx->crx_url = it->crx_url; | 779 crx->crx_url = it->crx_url; |
| 826 crx->size = it->size; | |
| 827 crx->diff_crx_url = it->diff_crx_url; | 780 crx->diff_crx_url = it->diff_crx_url; |
| 828 crx->diff_size = it->diff_size; | |
| 829 crx->status = CrxUpdateItem::kCanUpdate; | 781 crx->status = CrxUpdateItem::kCanUpdate; |
| 830 crx->next_version = Version(it->version); | 782 crx->next_version = Version(it->version); |
| 831 crx->next_fp = it->package_fingerprint; | 783 crx->next_fp = it->package_fingerprint; |
| 832 ++update_pending; | 784 ++update_pending; |
| 833 | 785 |
| 834 content::NotificationService::current()->Notify( | 786 content::NotificationService::current()->Notify( |
| 835 chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, | 787 chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, |
| 836 content::Source<std::string>(&crx->id), | 788 content::Source<std::string>(&crx->id), |
| 837 content::NotificationService::NoDetails()); | 789 content::NotificationService::NoDetails()); |
| 838 } | 790 } |
| 839 | 791 |
| 840 // All the components that are not mentioned in the manifest we | 792 // All the components that are not mentioned in the manifest we |
| 841 // consider them up to date. | 793 // consider them up to date. |
| 842 ChangeItemStatus(CrxUpdateItem::kChecking, CrxUpdateItem::kUpToDate); | 794 ChangeItemStatus(CrxUpdateItem::kChecking, CrxUpdateItem::kUpToDate); |
| 843 | 795 |
| 844 // If there are updates pending we do a short wait. | 796 // If there are updates pending we do a short wait. |
| 845 ScheduleNextRun(update_pending > 0); | 797 ScheduleNextRun(update_pending > 0); |
| 846 } | 798 } |
| 847 | 799 |
| 848 void CrxUpdateService::OnParseUpdateManifestFailed( | 800 void CrxUpdateService::OnParseUpdateManifestFailed( |
| 849 const std::string& error_message) { | 801 const std::string& error_message) { |
| 850 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 802 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 851 size_t count = ChangeItemStatus(CrxUpdateItem::kChecking, | 803 size_t count = ChangeItemStatus(CrxUpdateItem::kChecking, |
| 852 CrxUpdateItem::kNoUpdate); | 804 CrxUpdateItem::kNoUpdate); |
| 853 config_->OnEvent(Configurator::kManifestError, static_cast<int>(count)); | |
| 854 DCHECK_GT(count, 0ul); | 805 DCHECK_GT(count, 0ul); |
| 855 ScheduleNextRun(false); | 806 ScheduleNextRun(false); |
| 856 } | 807 } |
| 857 | 808 |
| 858 // Called when the CRX package has been downloaded to a temporary location. | 809 // Called when the CRX package has been downloaded to a temporary location. |
| 859 // Here we fire the notifications and schedule the component-specific installer | 810 // Here we fire the notifications and schedule the component-specific installer |
| 860 // to be called in the file thread. | 811 // to be called in the file thread. |
| 861 void CrxUpdateService::OnURLFetchComplete(const net::URLFetcher* source, | 812 void CrxUpdateService::OnURLFetchComplete(const net::URLFetcher* source, |
| 862 CRXContext* context) { | 813 CRXContext* context) { |
| 863 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 814 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 864 int error_code = net::OK; | 815 int error_code = net::OK; |
| 865 | 816 |
| 866 CrxUpdateItem* crx = FindUpdateItemById(context->id); | 817 CrxUpdateItem* crx = FindUpdateItemById(context->id); |
| 867 DCHECK(crx->status == CrxUpdateItem::kDownloadingDiff || | 818 DCHECK(crx->status == CrxUpdateItem::kDownloadingDiff || |
| 868 crx->status == CrxUpdateItem::kDownloading); | 819 crx->status == CrxUpdateItem::kDownloading); |
| 869 | 820 |
| 870 if (source->FileErrorOccurred(&error_code) || !FetchSuccess(*source)) { | 821 if (source->FileErrorOccurred(&error_code) || !FetchSuccess(*source)) { |
| 871 if (crx->status == CrxUpdateItem::kDownloadingDiff) { | 822 if (crx->status == CrxUpdateItem::kDownloadingDiff) { |
| 823 crx->diff_error_category = kNetworkError; |
| 824 crx->diff_error_code = GetFetchError(*source); |
| 872 crx->diff_update_failed = true; | 825 crx->diff_update_failed = true; |
| 873 size_t count = ChangeItemStatus(CrxUpdateItem::kDownloadingDiff, | 826 size_t count = ChangeItemStatus(CrxUpdateItem::kDownloadingDiff, |
| 874 CrxUpdateItem::kCanUpdate); | 827 CrxUpdateItem::kCanUpdate); |
| 875 DCHECK_EQ(count, 1ul); | 828 DCHECK_EQ(count, 1ul); |
| 829 url_fetcher_.reset(); |
| 830 |
| 876 ScheduleNextRun(true); | 831 ScheduleNextRun(true); |
| 877 return; | 832 return; |
| 878 } | 833 } |
| 834 crx->error_category = kNetworkError; |
| 835 crx->error_code = GetFetchError(*source); |
| 879 size_t count = ChangeItemStatus(CrxUpdateItem::kDownloading, | 836 size_t count = ChangeItemStatus(CrxUpdateItem::kDownloading, |
| 880 CrxUpdateItem::kNoUpdate); | 837 CrxUpdateItem::kNoUpdate); |
| 881 DCHECK_EQ(count, 1ul); | 838 DCHECK_EQ(count, 1ul); |
| 882 config_->OnEvent(Configurator::kNetworkError, CrxIdtoUMAId(context->id)); | |
| 883 url_fetcher_.reset(); | 839 url_fetcher_.reset(); |
| 884 | 840 |
| 841 // At this point, since both the differential and the full downloads failed, |
| 842 // the update for this component has finished with an error. |
| 843 ping_manager_->OnUpdateComplete(crx); |
| 844 |
| 885 ScheduleNextRun(false); | 845 ScheduleNextRun(false); |
| 886 } else { | 846 } else { |
| 887 base::FilePath temp_crx_path; | 847 base::FilePath temp_crx_path; |
| 888 CHECK(source->GetResponseAsFilePath(true, &temp_crx_path)); | 848 CHECK(source->GetResponseAsFilePath(true, &temp_crx_path)); |
| 889 | 849 |
| 890 size_t count = 0; | 850 size_t count = 0; |
| 891 if (crx->status == CrxUpdateItem::kDownloadingDiff) { | 851 if (crx->status == CrxUpdateItem::kDownloadingDiff) { |
| 892 count = ChangeItemStatus(CrxUpdateItem::kDownloadingDiff, | 852 count = ChangeItemStatus(CrxUpdateItem::kDownloadingDiff, |
| 893 CrxUpdateItem::kUpdatingDiff); | 853 CrxUpdateItem::kUpdatingDiff); |
| 894 } else { | 854 } else { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 935 BrowserThread::PostDelayedTask( | 895 BrowserThread::PostDelayedTask( |
| 936 BrowserThread::UI, | 896 BrowserThread::UI, |
| 937 FROM_HERE, | 897 FROM_HERE, |
| 938 base::Bind(&CrxUpdateService::DoneInstalling, base::Unretained(this), | 898 base::Bind(&CrxUpdateService::DoneInstalling, base::Unretained(this), |
| 939 context->id, unpacker.error(), unpacker.extended_error()), | 899 context->id, unpacker.error(), unpacker.extended_error()), |
| 940 base::TimeDelta::FromMilliseconds(config_->StepDelay())); | 900 base::TimeDelta::FromMilliseconds(config_->StepDelay())); |
| 941 delete context; | 901 delete context; |
| 942 } | 902 } |
| 943 | 903 |
| 944 // Installation has been completed. Adjust the component status and | 904 // Installation has been completed. Adjust the component status and |
| 945 // schedule the next check. | 905 // schedule the next check. Schedule a short delay before trying the full |
| 906 // update when the differential update failed. |
| 946 void CrxUpdateService::DoneInstalling(const std::string& component_id, | 907 void CrxUpdateService::DoneInstalling(const std::string& component_id, |
| 947 ComponentUnpacker::Error error, | 908 ComponentUnpacker::Error error, |
| 948 int extra_code) { | 909 int extra_code) { |
| 949 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 910 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 950 | 911 |
| 912 ErrorCategory error_category = kErrorNone; |
| 913 switch (error) { |
| 914 case ComponentUnpacker::kNone: |
| 915 break; |
| 916 case ComponentUnpacker::kInstallerError: |
| 917 error_category = kInstallError; |
| 918 break; |
| 919 default: |
| 920 error_category = kUnpackError; |
| 921 break; |
| 922 } |
| 923 |
| 924 const bool is_success = error == ComponentUnpacker::kNone; |
| 925 |
| 951 CrxUpdateItem* item = FindUpdateItemById(component_id); | 926 CrxUpdateItem* item = FindUpdateItemById(component_id); |
| 952 if (item->status == CrxUpdateItem::kUpdatingDiff) { | 927 if (item->status == CrxUpdateItem::kUpdatingDiff && !is_success) { |
| 953 if (error != ComponentUnpacker::kNone) { | 928 item->diff_error_category = error_category; |
| 929 item->diff_error_code = error; |
| 930 item->diff_extra_code1 = extra_code; |
| 954 item->diff_update_failed = true; | 931 item->diff_update_failed = true; |
| 955 size_t count = ChangeItemStatus(CrxUpdateItem::kUpdatingDiff, | 932 size_t count = ChangeItemStatus(CrxUpdateItem::kUpdatingDiff, |
| 956 CrxUpdateItem::kCanUpdate); | 933 CrxUpdateItem::kCanUpdate); |
| 957 DCHECK_EQ(count, 1ul); | 934 DCHECK_EQ(count, 1ul); |
| 958 ScheduleNextRun(true); | 935 ScheduleNextRun(true); |
| 959 return; | 936 return; |
| 960 } | 937 } |
| 938 |
| 939 if (is_success) { |
| 940 item->status = CrxUpdateItem::kUpdated; |
| 941 item->component.version = item->next_version; |
| 942 item->component.fingerprint = item->next_fp; |
| 943 } else { |
| 944 item->status = CrxUpdateItem::kNoUpdate; |
| 945 item->error_category = error_category; |
| 946 item->error_code = error; |
| 947 item->extra_code1 = extra_code; |
| 961 } | 948 } |
| 962 | 949 |
| 963 item->status = (error == ComponentUnpacker::kNone) ? CrxUpdateItem::kUpdated : | 950 ping_manager_->OnUpdateComplete(item); |
| 964 CrxUpdateItem::kNoUpdate; | |
| 965 if (item->status == CrxUpdateItem::kUpdated) { | |
| 966 item->component.version = item->next_version; | |
| 967 item->component.fingerprint = item->next_fp; | |
| 968 } | |
| 969 | 951 |
| 970 Configurator::Events event; | |
| 971 switch (error) { | |
| 972 case ComponentUnpacker::kNone: | |
| 973 event = Configurator::kComponentUpdated; | |
| 974 break; | |
| 975 case ComponentUnpacker::kInstallerError: | |
| 976 event = Configurator::kInstallerError; | |
| 977 break; | |
| 978 default: | |
| 979 event = Configurator::kUnpackError; | |
| 980 break; | |
| 981 } | |
| 982 | |
| 983 config_->OnEvent(event, CrxIdtoUMAId(component_id)); | |
| 984 ScheduleNextRun(false); | 952 ScheduleNextRun(false); |
| 985 } | 953 } |
| 986 | 954 |
| 987 // The component update factory. Using the component updater as a singleton | 955 // The component update factory. Using the component updater as a singleton |
| 988 // is the job of the browser process. | 956 // is the job of the browser process. |
| 989 ComponentUpdateService* ComponentUpdateServiceFactory( | 957 ComponentUpdateService* ComponentUpdateServiceFactory( |
| 990 ComponentUpdateService::Configurator* config) { | 958 ComponentUpdateService::Configurator* config) { |
| 991 DCHECK(config); | 959 DCHECK(config); |
| 992 return new CrxUpdateService(config); | 960 return new CrxUpdateService(config); |
| 993 } | 961 } |
| OLD | NEW |