| 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/file_util.h" | 14 #include "base/file_util.h" |
| 14 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
| 16 #include "base/guid.h" |
| 15 #include "base/logging.h" | 17 #include "base/logging.h" |
| 16 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
| 17 #include "base/stl_util.h" | 19 #include "base/stl_util.h" |
| 18 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
| 19 #include "base/strings/string_piece.h" | 21 #include "base/strings/string_piece.h" |
| 20 #include "base/strings/string_util.h" | 22 #include "base/strings/string_util.h" |
| 21 #include "base/strings/stringprintf.h" | 23 #include "base/strings/stringprintf.h" |
| 24 #include "base/sys_info.h" |
| 22 #include "base/timer.h" | 25 #include "base/timer.h" |
| 23 #include "chrome/browser/browser_process.h" | 26 #include "chrome/browser/browser_process.h" |
| 27 #include "chrome/browser/component_updater/component_patcher.h" |
| 24 #include "chrome/browser/component_updater/component_unpacker.h" | 28 #include "chrome/browser/component_updater/component_unpacker.h" |
| 25 #include "chrome/common/chrome_notification_types.h" | 29 #include "chrome/common/chrome_notification_types.h" |
| 26 #include "chrome/common/chrome_utility_messages.h" | 30 #include "chrome/common/chrome_utility_messages.h" |
| 27 #include "chrome/common/chrome_version_info.h" | 31 #include "chrome/common/chrome_version_info.h" |
| 28 #include "chrome/common/extensions/extension.h" | 32 #include "chrome/common/extensions/extension.h" |
| 33 #include "chrome/common/omaha_query_params/omaha_query_params.h" |
| 29 #include "content/public/browser/browser_thread.h" | 34 #include "content/public/browser/browser_thread.h" |
| 30 #include "content/public/browser/notification_service.h" | 35 #include "content/public/browser/notification_service.h" |
| 31 #include "content/public/browser/utility_process_host.h" | 36 #include "content/public/browser/utility_process_host.h" |
| 32 #include "content/public/browser/utility_process_host_client.h" | 37 #include "content/public/browser/utility_process_host_client.h" |
| 33 #include "googleurl/src/gurl.h" | 38 #include "googleurl/src/gurl.h" |
| 34 #include "net/base/escape.h" | 39 #include "net/base/escape.h" |
| 35 #include "net/base/load_flags.h" | 40 #include "net/base/load_flags.h" |
| 36 #include "net/base/net_errors.h" | 41 #include "net/base/net_errors.h" |
| 37 #include "net/url_request/url_fetcher.h" | 42 #include "net/url_request/url_fetcher.h" |
| 38 #include "net/url_request/url_fetcher_delegate.h" | 43 #include "net/url_request/url_fetcher_delegate.h" |
| 39 #include "net/url_request/url_request_status.h" | 44 #include "net/url_request/url_request_status.h" |
| 40 | 45 |
| 41 using content::BrowserThread; | 46 using content::BrowserThread; |
| 42 using content::UtilityProcessHost; | 47 using content::UtilityProcessHost; |
| 43 using content::UtilityProcessHostClient; | 48 using content::UtilityProcessHostClient; |
| 44 using extensions::Extension; | 49 using extensions::Extension; |
| 45 | 50 |
| 46 // The component updater is designed to live until process shutdown, so | 51 // The component updater is designed to live until process shutdown, so |
| 47 // base::Bind() calls are not refcounted. | 52 // base::Bind() calls are not refcounted. |
| 48 | 53 |
| 49 namespace { | 54 namespace { |
| 55 |
| 56 typedef ComponentUpdateService::Configurator Config; |
| 57 |
| 50 // Manifest sources, from most important to least important. | 58 // Manifest sources, from most important to least important. |
| 51 const CrxComponent::UrlSource kManifestSources[] = { | 59 const CrxComponent::UrlSource kManifestSources[] = { |
| 52 CrxComponent::BANDAID, | 60 CrxComponent::BANDAID, |
| 53 CrxComponent::CWS_PUBLIC, | 61 CrxComponent::CWS_PUBLIC, |
| 54 CrxComponent::CWS_SANDBOX | 62 CrxComponent::CWS_SANDBOX, |
| 55 }; | 63 }; |
| 56 | 64 |
| 57 // Extends an omaha compatible update check url |query| string. Does | 65 // Extends an omaha compatible update check url |query| string. Does |
| 58 // not mutate the string if it would be longer than |limit| chars. | 66 // not mutate the string if it would be longer than |limit| chars. |
| 59 bool AddQueryString(const std::string& id, | 67 bool AddQueryString(const std::string& id, |
| 60 const std::string& version, | 68 const std::string& version, |
| 69 const std::string& fingerprint, |
| 61 size_t limit, | 70 size_t limit, |
| 62 std::string* query) { | 71 std::string* query) { |
| 63 std::string additional = | 72 std::string additional = |
| 64 base::StringPrintf("id=%s&v=%s&uc", id.c_str(), version.c_str()); | 73 base::StringPrintf("id=%s&v=%s&fp=%s&uc", |
| 74 id.c_str(), version.c_str(), fingerprint.c_str()); |
| 65 additional = "x=" + net::EscapeQueryParamValue(additional, true); | 75 additional = "x=" + net::EscapeQueryParamValue(additional, true); |
| 66 if ((additional.size() + query->size() + 1) > limit) | 76 if ((additional.size() + query->size() + 1) > limit) |
| 67 return false; | 77 return false; |
| 68 if (!query->empty()) | 78 if (!query->empty()) |
| 69 query->append(1, '&'); | 79 query->append(1, '&'); |
| 70 query->append(additional); | 80 query->append(additional); |
| 71 return true; | 81 return true; |
| 72 } | 82 } |
| 73 | 83 |
| 74 // Create the final omaha compatible query. The |extra| is optional and can | 84 // Create the final omaha compatible query. The |extra| is optional and can |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 net::LOAD_DISABLE_CACHE); | 166 net::LOAD_DISABLE_CACHE); |
| 157 // TODO(cpu): Define our retry and backoff policy. | 167 // TODO(cpu): Define our retry and backoff policy. |
| 158 fetcher->SetAutomaticallyRetryOn5xx(false); | 168 fetcher->SetAutomaticallyRetryOn5xx(false); |
| 159 if (save_to_file) { | 169 if (save_to_file) { |
| 160 fetcher->SaveResponseToTemporaryFile( | 170 fetcher->SaveResponseToTemporaryFile( |
| 161 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); | 171 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); |
| 162 } | 172 } |
| 163 fetcher->Start(); | 173 fetcher->Start(); |
| 164 } | 174 } |
| 165 | 175 |
| 166 // Returs true if the url request of |fetcher| was succesful. | 176 // Returns true if the url request of |fetcher| was succesful. |
| 167 bool FetchSuccess(const net::URLFetcher& fetcher) { | 177 bool FetchSuccess(const net::URLFetcher& fetcher) { |
| 168 return (fetcher.GetStatus().status() == net::URLRequestStatus::SUCCESS) && | 178 return (fetcher.GetStatus().status() == net::URLRequestStatus::SUCCESS) && |
| 169 (fetcher.GetResponseCode() == 200); | 179 (fetcher.GetResponseCode() == 200); |
| 170 } | 180 } |
| 171 | 181 |
| 182 // Returns the error code which occured during the fetch. This function |
| 183 // is intended to be called for logging purposes only, since it folds different |
| 184 // types of errors to fit them in the returned type. The function returns 0 if |
| 185 // the fetch was successful. If errors happen, the function could return a |
| 186 // network error, an http response code, or the status of the fetch, if the |
| 187 // fetch is pending or canceled. |
| 188 int GetFetchError(const net::URLFetcher& fetcher) { |
| 189 if (FetchSuccess(fetcher)) |
| 190 return 0; |
| 191 |
| 192 const net::URLRequestStatus::Status status(fetcher.GetStatus().status()); |
| 193 if (status == net::URLRequestStatus::FAILED) |
| 194 return fetcher.GetStatus().error(); |
| 195 |
| 196 if (status == net::URLRequestStatus::IO_PENDING || |
| 197 status == net::URLRequestStatus::CANCELED) |
| 198 return status; |
| 199 |
| 200 const int response_code(fetcher.GetResponseCode()); |
| 201 if (status == net::URLRequestStatus::SUCCESS && response_code != 200) |
| 202 return response_code; |
| 203 |
| 204 return -1; |
| 205 } |
| 206 |
| 207 |
| 172 // This is the one and only per-item state structure. Designed to be hosted | 208 // This is the one and only per-item state structure. Designed to be hosted |
| 173 // in a std::vector or a std::list. The two main members are |component| | 209 // in a std::vector or a std::list. The two main members are |component| |
| 174 // which is supplied by the the component updater client and |status| which | 210 // which is supplied by the the component updater client and |status| which |
| 175 // is modified as the item is processed by the update pipeline. The expected | 211 // is modified as the item is processed by the update pipeline. The expected |
| 176 // transition graph is: | 212 // transition graph is: |
| 177 // error error error | 213 // |
| 178 // +--kNoUpdate<------<-------+------<------+------<------+ | 214 // kNew |
| 179 // | | | | | 215 // | |
| 180 // V yes | | | | 216 // V |
| 181 // kNew --->kChecking-->[update?]----->kCanUpdate-->kDownloading-->kUpdating | 217 // +----------------------> kChecking -<---------+-----<-------+ |
| 182 // ^ | | | 218 // | | | | |
| 183 // | |no | | 219 // | V no | | |
| 184 // |--kUpToDate<---+ | | 220 // kNoUpdate [update?] ->---- kUpToDate kUpdated |
| 185 // | success | | 221 // ^ | ^ |
| 186 // +--kUpdated<-------------------------------------------+ | 222 // | yes | | |
| 223 // | diff=false V | |
| 224 // | +-----------> kCanUpdate | |
| 225 // | | | | |
| 226 // | | V no | |
| 227 // | | [differential update?]->----+ | |
| 228 // | | | | | |
| 229 // | | yes | | | |
| 230 // | | error V | | |
| 231 // | +---------<- kDownloadingDiff | | |
| 232 // | | | | | |
| 233 // | | | | | |
| 234 // | | error V | | |
| 235 // | +---------<- kUpdatingDiff ->--------|-----------+ success |
| 236 // | | | |
| 237 // | error V | |
| 238 // +----------------------------------------- kDownloading | |
| 239 // | | | |
| 240 // | error V | |
| 241 // +------------------------------------------ kUpdating ->----+ success |
| 187 // | 242 // |
| 188 struct CrxUpdateItem { | 243 struct CrxUpdateItem { |
| 189 enum Status { | 244 enum Status { |
| 190 kNew, | 245 kNew, |
| 191 kChecking, | 246 kChecking, |
| 192 kCanUpdate, | 247 kCanUpdate, |
| 248 kDownloadingDiff, |
| 193 kDownloading, | 249 kDownloading, |
| 250 kUpdatingDiff, |
| 194 kUpdating, | 251 kUpdating, |
| 195 kUpdated, | 252 kUpdated, |
| 196 kUpToDate, | 253 kUpToDate, |
| 197 kNoUpdate, | 254 kNoUpdate, |
| 198 kLastStatus | 255 kLastStatus |
| 199 }; | 256 }; |
| 200 | 257 |
| 201 Status status; | 258 Status status; |
| 259 std::string id; |
| 260 CrxComponent component; |
| 261 |
| 262 base::Time last_check; |
| 263 |
| 264 // True if the update response includes an update for this component. |
| 265 bool is_update_available; |
| 266 |
| 267 // True is a completion ping has been queued for this component. If an update |
| 268 // is available for this component, one completion ping must be sent |
| 269 // after the component has reached either the kNoUpdate or kUpdated states. |
| 270 bool ping_queued; |
| 271 |
| 272 // These members are initialized with their corresponding values from the |
| 273 // update server response. |
| 202 GURL crx_url; | 274 GURL crx_url; |
| 203 std::string id; | 275 GURL diff_crx_url; |
| 204 base::Time last_check; | 276 std::string package_hash; |
| 205 CrxComponent component; | 277 std::string diff_package_hash; |
| 278 int size; |
| 279 int diff_size; |
| 280 |
| 281 // The from/to version and fingerprint values. |
| 282 Version previous_version; |
| 206 Version next_version; | 283 Version next_version; |
| 284 std::string previous_fp; |
| 285 std::string next_fp; |
| 207 | 286 |
| 208 CrxUpdateItem() : status(kNew) {} | 287 // True if the differential update failed for any reason. |
| 288 bool diff_update_failed; |
| 289 |
| 290 // The error information for full and differential updates. |
| 291 int error_code; |
| 292 int extra_code1; |
| 293 int diff_error_code; |
| 294 int diff_extra_code1; |
| 295 |
| 296 CrxUpdateItem() |
| 297 : status(kNew), |
| 298 is_update_available(false), |
| 299 ping_queued(false), |
| 300 size(0), |
| 301 diff_size(0), |
| 302 diff_update_failed(false), |
| 303 error_code(0), |
| 304 extra_code1(0), |
| 305 diff_error_code(0), |
| 306 diff_extra_code1(0) { |
| 307 } |
| 209 | 308 |
| 210 // Function object used to find a specific component. | 309 // Function object used to find a specific component. |
| 211 class FindById { | 310 class FindById { |
| 212 public: | 311 public: |
| 213 explicit FindById(const std::string& id) : id_(id) {} | 312 explicit FindById(const std::string& id) : id_(id) {} |
| 214 | 313 |
| 215 bool operator() (CrxUpdateItem* item) const { | 314 bool operator() (CrxUpdateItem* item) const { |
| 216 return (item->id == id_); | 315 return (item->id == id_); |
| 217 } | 316 } |
| 218 private: | 317 private: |
| 219 const std::string& id_; | 318 const std::string& id_; |
| 220 }; | 319 }; |
| 221 }; | 320 }; |
| 222 | 321 |
| 322 // Returns true if a differential update is available for the update item. |
| 323 bool IsDiffUpdateAvailable(const CrxUpdateItem* update_item) { |
| 324 return update_item->diff_crx_url.is_valid(); |
| 325 } |
| 326 |
| 327 // Returns true if a differential update is available, it has not failed yet, |
| 328 // and the configuration allows it. |
| 329 bool CanTryDiffUpdate(const CrxUpdateItem* update_item, const Config& config) { |
| 330 return IsDiffUpdateAvailable(update_item) && |
| 331 !update_item->diff_update_failed && |
| 332 config.DeltasEnabled(); |
| 333 } |
| 334 |
| 223 } // namespace. | 335 } // namespace. |
| 224 | 336 |
| 225 typedef ComponentUpdateService::Configurator Config; | |
| 226 | |
| 227 CrxComponent::CrxComponent() | 337 CrxComponent::CrxComponent() |
| 228 : installer(NULL), | 338 : installer(NULL), |
| 229 source(BANDAID) { | 339 source(BANDAID) { |
| 230 } | 340 } |
| 231 | 341 |
| 232 CrxComponent::~CrxComponent() { | 342 CrxComponent::~CrxComponent() { |
| 233 } | 343 } |
| 234 | 344 |
| 235 ////////////////////////////////////////////////////////////////////////////// | 345 ////////////////////////////////////////////////////////////////////////////// |
| 236 // The one and only implementation of the ComponentUpdateService interface. In | 346 // The one and only implementation of the ComponentUpdateService interface. In |
| 237 // charge of running the show. The main method is ProcessPendingItems() which | 347 // charge of running the show. The main method is ProcessPendingItems() which |
| 238 // is called periodically to do the upgrades/installs or the update checks. | 348 // is called periodically to do the upgrades/installs or the update checks. |
| 239 // An important consideration here is to be as "low impact" as we can to the | 349 // An important consideration here is to be as "low impact" as we can to the |
| 240 // rest of the browser, so even if we have many components registered and | 350 // rest of the browser, so even if we have many components registered and |
| 241 // eligible for update, we only do one thing at a time with pauses in between | 351 // eligible for update, we only do one thing at a time with pauses in between |
| 242 // the tasks. Also when we do network requests there is only one |url_fetcher_| | 352 // the tasks. Also when we do network requests there is only one |url_fetcher_| |
| 243 // in flight at at a time. | 353 // in flight at a time. |
| 244 // There are no locks in this code, the main structure |work_items_| is mutated | 354 // There are no locks in this code, the main structure |work_items_| is mutated |
| 245 // only from the UI thread. The unpack and installation is done in the file | 355 // only from the UI thread. The unpack and installation is done in the file |
| 246 // thread and the network requests are done in the IO thread and in the file | 356 // thread and the network requests are done in the IO thread and in the file |
| 247 // thread. | 357 // thread. |
| 248 class CrxUpdateService : public ComponentUpdateService { | 358 class CrxUpdateService : public ComponentUpdateService { |
| 249 public: | 359 public: |
| 250 explicit CrxUpdateService(ComponentUpdateService::Configurator* config); | 360 explicit CrxUpdateService(ComponentUpdateService::Configurator* config); |
| 251 | 361 |
| 252 virtual ~CrxUpdateService(); | 362 virtual ~CrxUpdateService(); |
| 253 | 363 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 CrxUpdateService* service_; | 402 CrxUpdateService* service_; |
| 293 DISALLOW_COPY_AND_ASSIGN(ManifestParserBridge); | 403 DISALLOW_COPY_AND_ASSIGN(ManifestParserBridge); |
| 294 }; | 404 }; |
| 295 | 405 |
| 296 // Context for a update check url request. See DelegateWithContext above. | 406 // Context for a update check url request. See DelegateWithContext above. |
| 297 struct UpdateContext { | 407 struct UpdateContext { |
| 298 base::Time start; | 408 base::Time start; |
| 299 UpdateContext() : start(base::Time::Now()) {} | 409 UpdateContext() : start(base::Time::Now()) {} |
| 300 }; | 410 }; |
| 301 | 411 |
| 412 // Context for a completion ping. See DelegateWithContext above. The type |
| 413 // is needed for template type deduction and it could be used in the |
| 414 // future to pass arguments to the callback. |
| 415 struct PingContext { |
| 416 }; |
| 417 |
| 302 // Context for a crx download url request. See DelegateWithContext above. | 418 // Context for a crx download url request. See DelegateWithContext above. |
| 303 struct CRXContext { | 419 struct CRXContext { |
| 304 ComponentInstaller* installer; | 420 ComponentInstaller* installer; |
| 305 std::vector<uint8> pk_hash; | 421 std::vector<uint8> pk_hash; |
| 306 std::string id; | 422 std::string id; |
| 423 std::string fingerprint; |
| 307 CRXContext() : installer(NULL) {} | 424 CRXContext() : installer(NULL) {} |
| 308 }; | 425 }; |
| 309 | 426 |
| 310 void OnURLFetchComplete(const net::URLFetcher* source, | 427 void OnURLFetchComplete(const net::URLFetcher* source, |
| 311 UpdateContext* context); | 428 UpdateContext* context); |
| 312 | 429 |
| 313 void OnURLFetchComplete(const net::URLFetcher* source, | 430 void OnURLFetchComplete(const net::URLFetcher* source, |
| 314 CRXContext* context); | 431 CRXContext* context); |
| 315 | 432 |
| 433 void OnURLFetchComplete(const net::URLFetcher* source, |
| 434 PingContext* context); |
| 435 |
| 316 private: | 436 private: |
| 317 // See ManifestParserBridge. | 437 // See ManifestParserBridge. |
| 318 void OnParseUpdateManifestSucceeded( | 438 void OnParseUpdateManifestSucceeded( |
| 319 const UpdateManifest::Results& results); | 439 const UpdateManifest::Results& results); |
| 320 | 440 |
| 321 // See ManifestParserBridge. | 441 // See ManifestParserBridge. |
| 322 void OnParseUpdateManifestFailed( | 442 void OnParseUpdateManifestFailed(const std::string& error_message); |
| 323 const std::string& error_message); | |
| 324 | 443 |
| 325 bool AddItemToUpdateCheck(CrxUpdateItem* item, std::string* query); | 444 bool AddItemToUpdateCheck(CrxUpdateItem* item, std::string* query); |
| 326 | 445 |
| 327 void ProcessPendingItems(); | 446 void ProcessPendingItems(); |
| 328 | 447 |
| 329 void ScheduleNextRun(bool step_delay); | 448 void ScheduleNextRun(bool step_delay); |
| 330 | 449 |
| 331 void ParseManifest(const std::string& xml); | 450 void ParseManifest(const std::string& xml); |
| 332 | 451 |
| 333 void Install(const CRXContext* context, const base::FilePath& crx_path); | 452 void Install(const CRXContext* context, const base::FilePath& crx_path); |
| 334 | 453 |
| 335 void DoneInstalling(const std::string& component_id, | 454 void DoneInstalling(const std::string& component_id, |
| 336 ComponentUnpacker::Error error); | 455 ComponentUnpacker::Error error, |
| 456 int extended_error); |
| 337 | 457 |
| 338 size_t ChangeItemStatus(CrxUpdateItem::Status from, | 458 size_t ChangeItemStatus(CrxUpdateItem::Status from, |
| 339 CrxUpdateItem::Status to); | 459 CrxUpdateItem::Status to); |
| 340 | 460 |
| 341 CrxUpdateItem* FindUpdateItemById(const std::string& id); | 461 CrxUpdateItem* FindUpdateItemById(const std::string& id); |
| 342 | 462 |
| 463 void SendPing(const std::string& ping); |
| 464 |
| 465 // These functions build a ping request. Building the ping changes the state |
| 466 // of the update item to indicate that a completion ping has been collected |
| 467 // and queued for this item. |
| 468 std::string BuildPing() const; |
| 469 std::string BuildPingApps() const; |
| 470 static std::string BuildPingEvent(CrxUpdateItem* item); |
| 471 |
| 343 scoped_ptr<Config> config_; | 472 scoped_ptr<Config> config_; |
| 344 | 473 |
| 474 scoped_ptr<ComponentPatcher> component_patcher_; |
| 475 |
| 345 scoped_ptr<net::URLFetcher> url_fetcher_; | 476 scoped_ptr<net::URLFetcher> url_fetcher_; |
| 346 | 477 |
| 478 scoped_ptr<net::URLFetcher> ping_sender_; |
| 479 |
| 480 // A collection of every work item. |
| 347 typedef std::vector<CrxUpdateItem*> UpdateItems; | 481 typedef std::vector<CrxUpdateItem*> UpdateItems; |
| 348 // A collection of every work item. | |
| 349 UpdateItems work_items_; | 482 UpdateItems work_items_; |
| 350 | 483 |
| 351 // A particular set of items from work_items_, which should be checked ASAP. | 484 // A particular set of items from work_items_, which should be checked ASAP. |
| 352 std::set<CrxUpdateItem*> requested_work_items_; | 485 std::set<CrxUpdateItem*> requested_work_items_; |
| 353 | 486 |
| 354 base::OneShotTimer<CrxUpdateService> timer_; | 487 base::OneShotTimer<CrxUpdateService> timer_; |
| 355 | 488 |
| 356 Version chrome_version_; | 489 const Version chrome_version_; |
| 490 const std::string prod_id_; |
| 491 const std::string os_type_; |
| 492 const std::string os_version_; |
| 357 | 493 |
| 358 bool running_; | 494 bool running_; |
| 359 | 495 |
| 360 DISALLOW_COPY_AND_ASSIGN(CrxUpdateService); | 496 DISALLOW_COPY_AND_ASSIGN(CrxUpdateService); |
| 361 }; | 497 }; |
| 362 | 498 |
| 363 ////////////////////////////////////////////////////////////////////////////// | 499 ////////////////////////////////////////////////////////////////////////////// |
| 364 | 500 |
| 365 CrxUpdateService::CrxUpdateService( | 501 CrxUpdateService::CrxUpdateService(ComponentUpdateService::Configurator* config) |
| 366 ComponentUpdateService::Configurator* config) | |
| 367 : config_(config), | 502 : config_(config), |
| 503 component_patcher_(config->CreateComponentPatcher()), |
| 368 chrome_version_(chrome::VersionInfo().Version()), | 504 chrome_version_(chrome::VersionInfo().Version()), |
| 505 prod_id_(chrome::OmahaQueryParams::GetProdIdString( |
| 506 chrome::OmahaQueryParams::CHROME)), |
| 507 os_type_(chrome::VersionInfo().OSType()), |
| 508 os_version_(base::SysInfo().OperatingSystemVersion()), |
| 369 running_(false) { | 509 running_(false) { |
| 370 } | 510 } |
| 371 | 511 |
| 372 CrxUpdateService::~CrxUpdateService() { | 512 CrxUpdateService::~CrxUpdateService() { |
| 373 // Because we are a singleton, at this point only the UI thread should be | 513 // Because we are a singleton, at this point only the UI thread should be |
| 374 // alive, this simplifies the management of the work that could be in | 514 // alive, this simplifies the management of the work that could be in |
| 375 // flight in other threads. | 515 // flight in other threads. |
| 376 Stop(); | 516 Stop(); |
| 377 STLDeleteElements(&work_items_); | 517 STLDeleteElements(&work_items_); |
| 378 } | 518 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 void CrxUpdateService::ScheduleNextRun(bool step_delay) { | 551 void CrxUpdateService::ScheduleNextRun(bool step_delay) { |
| 412 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 552 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 413 DCHECK(url_fetcher_.get() == NULL); | 553 DCHECK(url_fetcher_.get() == NULL); |
| 414 CHECK(!timer_.IsRunning()); | 554 CHECK(!timer_.IsRunning()); |
| 415 // It could be the case that Stop() had been called while a url request | 555 // It could be the case that Stop() had been called while a url request |
| 416 // or unpacking was in flight, if so we arrive here but |running_| is | 556 // or unpacking was in flight, if so we arrive here but |running_| is |
| 417 // false. In that case do not loop again. | 557 // false. In that case do not loop again. |
| 418 if (!running_) | 558 if (!running_) |
| 419 return; | 559 return; |
| 420 | 560 |
| 561 if (!step_delay && config_->PingsEnabled()) { |
| 562 const std::string ping(BuildPing()); |
| 563 if (!ping.empty()) |
| 564 SendPing(ping); |
| 565 } |
| 566 |
| 421 // Keep the delay short if in the middle of an update (step_delay), | 567 // Keep the delay short if in the middle of an update (step_delay), |
| 422 // or there are new requested_work_items_ that have not been processed yet. | 568 // or there are new requested_work_items_ that have not been processed yet. |
| 423 int64 delay = (step_delay || requested_work_items_.size() > 0) | 569 int64 delay = (step_delay || requested_work_items_.size() > 0) |
| 424 ? config_->StepDelay() : config_->NextCheckDelay(); | 570 ? config_->StepDelay() : config_->NextCheckDelay(); |
| 425 | 571 |
| 426 if (!step_delay) { | 572 if (!step_delay) { |
| 427 content::NotificationService::current()->Notify( | 573 content::NotificationService::current()->Notify( |
| 428 chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, | 574 chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, |
| 429 content::Source<ComponentUpdateService>(this), | 575 content::Source<ComponentUpdateService>(this), |
| 430 content::NotificationService::NoDetails()); | 576 content::NotificationService::NoDetails()); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 CrxUpdateItem* uit; | 630 CrxUpdateItem* uit; |
| 485 uit = FindUpdateItemById(id); | 631 uit = FindUpdateItemById(id); |
| 486 if (uit) { | 632 if (uit) { |
| 487 uit->component = component; | 633 uit->component = component; |
| 488 return kReplaced; | 634 return kReplaced; |
| 489 } | 635 } |
| 490 | 636 |
| 491 uit = new CrxUpdateItem; | 637 uit = new CrxUpdateItem; |
| 492 uit->id.swap(id); | 638 uit->id.swap(id); |
| 493 uit->component = component; | 639 uit->component = component; |
| 640 |
| 494 work_items_.push_back(uit); | 641 work_items_.push_back(uit); |
| 495 // If this is the first component registered we call Start to | 642 // If this is the first component registered we call Start to |
| 496 // schedule the first timer. | 643 // schedule the first timer. |
| 497 if (running_ && (work_items_.size() == 1)) | 644 if (running_ && (work_items_.size() == 1)) |
| 498 Start(); | 645 Start(); |
| 499 | 646 |
| 500 return kOk; | 647 return kOk; |
| 501 } | 648 } |
| 502 | 649 |
| 503 // Sets a component to be checked for updates. | 650 // Sets a component to be checked for updates. |
| 504 // The componet to add is |crxit| and the |query| string is modified with the | 651 // The component to add is |crxit| and the |query| string is modified with the |
| 505 // required omaha compatible query. Returns false when the query strings | 652 // required omaha compatible query. Returns false when the query strings |
| 506 // is longer than specified by UrlSizeLimit(). | 653 // is longer than specified by UrlSizeLimit(). |
| 507 bool CrxUpdateService::AddItemToUpdateCheck(CrxUpdateItem* item, | 654 bool CrxUpdateService::AddItemToUpdateCheck(CrxUpdateItem* item, |
| 508 std::string* query) { | 655 std::string* query) { |
| 509 if (!AddQueryString(item->id, | 656 if (!AddQueryString(item->id, |
| 510 item->component.version.GetString(), | 657 item->component.version.GetString(), |
| 658 item->component.fingerprint, |
| 511 config_->UrlSizeLimit(), query)) | 659 config_->UrlSizeLimit(), query)) |
| 512 return false; | 660 return false; |
| 661 |
| 513 item->status = CrxUpdateItem::kChecking; | 662 item->status = CrxUpdateItem::kChecking; |
| 514 item->last_check = base::Time::Now(); | 663 item->last_check = base::Time::Now(); |
| 664 item->is_update_available = false; |
| 665 item->ping_queued = false; |
| 666 item->previous_version = item->component.version; |
| 667 item->next_version = Version(); |
| 668 item->previous_fp = item->component.fingerprint; |
| 669 item->next_fp = ""; |
| 670 item->diff_update_failed = false; |
| 671 item->error_code = 0; |
| 672 item->extra_code1 = 0; |
| 673 item->diff_error_code = 0; |
| 674 item->diff_extra_code1 = 0; |
| 515 return true; | 675 return true; |
| 516 } | 676 } |
| 517 | 677 |
| 518 // Start the process of checking for an update, for a particular component | 678 // Start the process of checking for an update, for a particular component |
| 519 // that was previously registered. | 679 // that was previously registered. |
| 520 ComponentUpdateService::Status CrxUpdateService::CheckForUpdateSoon( | 680 ComponentUpdateService::Status CrxUpdateService::CheckForUpdateSoon( |
| 521 const CrxComponent& component) { | 681 const CrxComponent& component) { |
| 522 if (component.pk_hash.empty() || | 682 if (component.pk_hash.empty() || |
| 523 !component.version.IsValid() || | 683 !component.version.IsValid() || |
| 524 !component.installer) | 684 !component.installer) |
| 525 return kError; | 685 return kError; |
| 526 | 686 |
| 527 std::string id = | 687 std::string id = |
| 528 HexStringToID(StringToLowerASCII(base::HexEncode(&component.pk_hash[0], | 688 HexStringToID(StringToLowerASCII(base::HexEncode(&component.pk_hash[0], |
| 529 component.pk_hash.size()/2))); | 689 component.pk_hash.size()/2))); |
| 530 | 690 |
| 531 CrxUpdateItem* uit; | 691 CrxUpdateItem* uit; |
| 532 uit = FindUpdateItemById(id); | 692 uit = FindUpdateItemById(id); |
| 533 if (!uit) | 693 if (!uit) |
| 534 return kError; | 694 return kError; |
| 535 | 695 |
| 536 // Check if the request is too soon. | 696 // Check if the request is too soon. |
| 537 base::TimeDelta delta = base::Time::Now() - uit->last_check; | 697 base::TimeDelta delta = base::Time::Now() - uit->last_check; |
| 538 if (delta < base::TimeDelta::FromSeconds(config_->OnDemandDelay())) { | 698 if (delta < base::TimeDelta::FromSeconds(config_->OnDemandDelay())) |
| 539 return kError; | 699 return kError; |
| 540 } | |
| 541 | 700 |
| 542 switch (uit->status) { | 701 switch (uit->status) { |
| 543 // If the item is already in the process of being updated, there is | 702 // If the item is already in the process of being updated, there is |
| 544 // no point in this call, so return kInProgress. | 703 // no point in this call, so return kInProgress. |
| 545 case CrxUpdateItem::kChecking: | 704 case CrxUpdateItem::kChecking: |
| 546 case CrxUpdateItem::kCanUpdate: | 705 case CrxUpdateItem::kCanUpdate: |
| 706 case CrxUpdateItem::kDownloadingDiff: |
| 547 case CrxUpdateItem::kDownloading: | 707 case CrxUpdateItem::kDownloading: |
| 708 case CrxUpdateItem::kUpdatingDiff: |
| 548 case CrxUpdateItem::kUpdating: | 709 case CrxUpdateItem::kUpdating: |
| 549 return kInProgress; | 710 return kInProgress; |
| 550 // Otherwise the item was already checked a while back (or it is new), | 711 // Otherwise the item was already checked a while back (or it is new), |
| 551 // set its status to kNew to give it a slightly higher priority. | 712 // set its status to kNew to give it a slightly higher priority. |
| 552 case CrxUpdateItem::kNew: | 713 case CrxUpdateItem::kNew: |
| 553 case CrxUpdateItem::kUpdated: | 714 case CrxUpdateItem::kUpdated: |
| 554 case CrxUpdateItem::kUpToDate: | 715 case CrxUpdateItem::kUpToDate: |
| 555 case CrxUpdateItem::kNoUpdate: | 716 case CrxUpdateItem::kNoUpdate: |
| 556 uit->status = CrxUpdateItem::kNew; | 717 uit->status = CrxUpdateItem::kNew; |
| 557 requested_work_items_.insert(uit); | 718 requested_work_items_.insert(uit); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 576 void CrxUpdateService::ProcessPendingItems() { | 737 void CrxUpdateService::ProcessPendingItems() { |
| 577 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 738 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 578 // First check for ready upgrades and do one. The first | 739 // First check for ready upgrades and do one. The first |
| 579 // step is to fetch the crx package. | 740 // step is to fetch the crx package. |
| 580 for (UpdateItems::const_iterator it = work_items_.begin(); | 741 for (UpdateItems::const_iterator it = work_items_.begin(); |
| 581 it != work_items_.end(); ++it) { | 742 it != work_items_.end(); ++it) { |
| 582 CrxUpdateItem* item = *it; | 743 CrxUpdateItem* item = *it; |
| 583 if (item->status != CrxUpdateItem::kCanUpdate) | 744 if (item->status != CrxUpdateItem::kCanUpdate) |
| 584 continue; | 745 continue; |
| 585 // Found component to update, start the process. | 746 // Found component to update, start the process. |
| 586 item->status = CrxUpdateItem::kDownloading; | |
| 587 CRXContext* context = new CRXContext; | 747 CRXContext* context = new CRXContext; |
| 588 context->pk_hash = item->component.pk_hash; | 748 context->pk_hash = item->component.pk_hash; |
| 589 context->id = item->id; | 749 context->id = item->id; |
| 590 context->installer = item->component.installer; | 750 context->installer = item->component.installer; |
| 751 context->fingerprint = item->next_fp; |
| 752 GURL package_url; |
| 753 if (CanTryDiffUpdate(item, *config_)) { |
| 754 package_url = item->diff_crx_url; |
| 755 item->status = CrxUpdateItem::kDownloadingDiff; |
| 756 } else { |
| 757 package_url = item->crx_url; |
| 758 item->status = CrxUpdateItem::kDownloading; |
| 759 } |
| 591 url_fetcher_.reset(net::URLFetcher::Create( | 760 url_fetcher_.reset(net::URLFetcher::Create( |
| 592 0, item->crx_url, net::URLFetcher::GET, | 761 0, package_url, net::URLFetcher::GET, |
| 593 MakeContextDelegate(this, context))); | 762 MakeContextDelegate(this, context))); |
| 594 StartFetch(url_fetcher_.get(), config_->RequestContext(), true); | 763 StartFetch(url_fetcher_.get(), config_->RequestContext(), true); |
| 595 return; | 764 return; |
| 596 } | 765 } |
| 597 | 766 |
| 598 for (size_t ix = 0; ix != arraysize(kManifestSources); ++ix) { | 767 for (size_t ix = 0; ix != arraysize(kManifestSources); ++ix) { |
| 599 const CrxComponent::UrlSource manifest_source = kManifestSources[ix]; | 768 const CrxComponent::UrlSource manifest_source = kManifestSources[ix]; |
| 600 | 769 |
| 601 std::string query; | 770 std::string query; |
| 602 // If no pending upgrades, we check if there are new components we have not | 771 // If no pending upgrades, we check if there are new components we have not |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 693 delete context; | 862 delete context; |
| 694 } | 863 } |
| 695 | 864 |
| 696 // Parsing the manifest is either done right now for tests or in a sandboxed | 865 // Parsing the manifest is either done right now for tests or in a sandboxed |
| 697 // process for the production environment. This mitigates the case where an | 866 // process for the production environment. This mitigates the case where an |
| 698 // attacker was able to feed us a malicious xml string. | 867 // attacker was able to feed us a malicious xml string. |
| 699 void CrxUpdateService::ParseManifest(const std::string& xml) { | 868 void CrxUpdateService::ParseManifest(const std::string& xml) { |
| 700 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 869 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 701 if (config_->InProcess()) { | 870 if (config_->InProcess()) { |
| 702 UpdateManifest manifest; | 871 UpdateManifest manifest; |
| 703 if (!manifest.Parse(xml)) { | 872 if (!manifest.Parse(xml)) |
| 704 CrxUpdateService::OnParseUpdateManifestFailed(manifest.errors()); | 873 CrxUpdateService::OnParseUpdateManifestFailed(manifest.errors()); |
| 705 } else { | 874 else |
| 706 CrxUpdateService::OnParseUpdateManifestSucceeded(manifest.results()); | 875 CrxUpdateService::OnParseUpdateManifestSucceeded(manifest.results()); |
| 707 } | |
| 708 } else { | 876 } else { |
| 709 UtilityProcessHost* host = | 877 UtilityProcessHost* host = |
| 710 UtilityProcessHost::Create(new ManifestParserBridge(this), | 878 UtilityProcessHost::Create(new ManifestParserBridge(this), |
| 711 base::MessageLoopProxy::current().get()); | 879 base::MessageLoopProxy::current().get()); |
| 712 host->EnableZygote(); | 880 host->EnableZygote(); |
| 713 host->Send(new ChromeUtilityMsg_ParseUpdateManifest(xml)); | 881 host->Send(new ChromeUtilityMsg_ParseUpdateManifest(xml)); |
| 714 } | 882 } |
| 715 } | 883 } |
| 716 | 884 |
| 717 // A valid Omaha update check has arrived, from only the list of components that | 885 // A valid Omaha update check has arrived, from only the list of components that |
| (...skipping 27 matching lines...) Expand all Loading... |
| 745 } | 913 } |
| 746 if (!it->browser_min_version.empty()) { | 914 if (!it->browser_min_version.empty()) { |
| 747 if (IsVersionNewer(chrome_version_, it->browser_min_version)) { | 915 if (IsVersionNewer(chrome_version_, it->browser_min_version)) { |
| 748 // Does not apply for this chrome version. | 916 // Does not apply for this chrome version. |
| 749 crx->status = CrxUpdateItem::kNoUpdate; | 917 crx->status = CrxUpdateItem::kNoUpdate; |
| 750 continue; | 918 continue; |
| 751 } | 919 } |
| 752 } | 920 } |
| 753 // All test passed. Queue an upgrade for this component and fire the | 921 // All test passed. Queue an upgrade for this component and fire the |
| 754 // notifications. | 922 // notifications. |
| 923 crx->is_update_available = true; |
| 755 crx->crx_url = it->crx_url; | 924 crx->crx_url = it->crx_url; |
| 925 crx->package_hash = it->package_hash; |
| 926 crx->size = it->size; |
| 927 crx->diff_crx_url = it->diff_crx_url; |
| 928 crx->diff_package_hash = it->diff_package_hash; |
| 929 crx->diff_size = it->diff_size; |
| 756 crx->status = CrxUpdateItem::kCanUpdate; | 930 crx->status = CrxUpdateItem::kCanUpdate; |
| 757 crx->next_version = Version(it->version); | 931 crx->next_version = Version(it->version); |
| 932 crx->next_fp = it->package_fingerprint; |
| 758 ++update_pending; | 933 ++update_pending; |
| 759 | 934 |
| 760 content::NotificationService::current()->Notify( | 935 content::NotificationService::current()->Notify( |
| 761 chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, | 936 chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, |
| 762 content::Source<std::string>(&crx->id), | 937 content::Source<std::string>(&crx->id), |
| 763 content::NotificationService::NoDetails()); | 938 content::NotificationService::NoDetails()); |
| 764 } | 939 } |
| 765 | 940 |
| 766 // All the components that are not mentioned in the manifest we | 941 // All the components that are not mentioned in the manifest we |
| 767 // consider them up to date. | 942 // consider them up to date. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 782 } | 957 } |
| 783 | 958 |
| 784 // Called when the CRX package has been downloaded to a temporary location. | 959 // Called when the CRX package has been downloaded to a temporary location. |
| 785 // Here we fire the notifications and schedule the component-specific installer | 960 // Here we fire the notifications and schedule the component-specific installer |
| 786 // to be called in the file thread. | 961 // to be called in the file thread. |
| 787 void CrxUpdateService::OnURLFetchComplete(const net::URLFetcher* source, | 962 void CrxUpdateService::OnURLFetchComplete(const net::URLFetcher* source, |
| 788 CRXContext* context) { | 963 CRXContext* context) { |
| 789 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 964 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 790 int error_code = net::OK; | 965 int error_code = net::OK; |
| 791 | 966 |
| 967 CrxUpdateItem* crx = FindUpdateItemById(context->id); |
| 968 |
| 792 if (source->FileErrorOccurred(&error_code) || !FetchSuccess(*source)) { | 969 if (source->FileErrorOccurred(&error_code) || !FetchSuccess(*source)) { |
| 793 size_t count = ChangeItemStatus(CrxUpdateItem::kDownloading, | 970 if (crx->status == CrxUpdateItem::kDownloadingDiff) { |
| 794 CrxUpdateItem::kNoUpdate); | 971 crx->diff_error_code = GetFetchError(*source); |
| 795 DCHECK_EQ(count, 1ul); | 972 crx->diff_update_failed = true; |
| 973 crx->status = CrxUpdateItem::kCanUpdate; |
| 974 BrowserThread::PostTask( |
| 975 BrowserThread::UI, |
| 976 FROM_HERE, |
| 977 base::Bind(&CrxUpdateService::ProcessPendingItems, |
| 978 base::Unretained(this))); |
| 979 return; |
| 980 } |
| 981 crx->error_code = GetFetchError(*source); |
| 982 crx->status = CrxUpdateItem::kNoUpdate; |
| 796 config_->OnEvent(Configurator::kNetworkError, CrxIdtoUMAId(context->id)); | 983 config_->OnEvent(Configurator::kNetworkError, CrxIdtoUMAId(context->id)); |
| 797 url_fetcher_.reset(); | 984 url_fetcher_.reset(); |
| 798 ScheduleNextRun(false); | 985 ScheduleNextRun(false); |
| 799 } else { | 986 } else { |
| 800 base::FilePath temp_crx_path; | 987 base::FilePath temp_crx_path; |
| 801 CHECK(source->GetResponseAsFilePath(true, &temp_crx_path)); | 988 CHECK(source->GetResponseAsFilePath(true, &temp_crx_path)); |
| 802 size_t count = ChangeItemStatus(CrxUpdateItem::kDownloading, | 989 crx->status = (crx->status == CrxUpdateItem::kDownloadingDiff) ? |
| 803 CrxUpdateItem::kUpdating); | 990 CrxUpdateItem::kUpdatingDiff : CrxUpdateItem::kUpdating; |
| 804 DCHECK_EQ(count, 1ul); | 991 |
| 805 url_fetcher_.reset(); | 992 url_fetcher_.reset(); |
| 806 | 993 |
| 807 content::NotificationService::current()->Notify( | 994 content::NotificationService::current()->Notify( |
| 808 chrome::NOTIFICATION_COMPONENT_UPDATE_READY, | 995 chrome::NOTIFICATION_COMPONENT_UPDATE_READY, |
| 809 content::Source<std::string>(&context->id), | 996 content::Source<std::string>(&context->id), |
| 810 content::NotificationService::NoDetails()); | 997 content::NotificationService::NoDetails()); |
| 811 | 998 |
| 812 // Why unretained? See comment at top of file. | 999 // Why unretained? See comment at top of file. |
| 813 BrowserThread::PostDelayedTask( | 1000 BrowserThread::PostDelayedTask( |
| 814 BrowserThread::FILE, | 1001 BrowserThread::FILE, |
| 815 FROM_HERE, | 1002 FROM_HERE, |
| 816 base::Bind(&CrxUpdateService::Install, | 1003 base::Bind(&CrxUpdateService::Install, |
| 817 base::Unretained(this), | 1004 base::Unretained(this), |
| 818 context, | 1005 context, |
| 819 temp_crx_path), | 1006 temp_crx_path), |
| 820 base::TimeDelta::FromMilliseconds(config_->StepDelay())); | 1007 base::TimeDelta::FromMilliseconds(config_->StepDelay())); |
| 821 } | 1008 } |
| 822 } | 1009 } |
| 823 | 1010 |
| 824 // Install consists of digital signature verification, unpacking and then | 1011 // Install consists of digital signature verification, unpacking and then |
| 825 // calling the component specific installer. All that is handled by the | 1012 // calling the component specific installer. All that is handled by the |
| 826 // |unpacker|. If there is an error this function is in charge of deleting | 1013 // |unpacker|. If there is an error this function is in charge of deleting |
| 827 // the files created. | 1014 // the files created. |
| 828 void CrxUpdateService::Install(const CRXContext* context, | 1015 void CrxUpdateService::Install(const CRXContext* context, |
| 829 const base::FilePath& crx_path) { | 1016 const base::FilePath& crx_path) { |
| 830 // This function owns the |crx_path| and the |context| object. | 1017 // This function owns the |crx_path| and the |context| object. |
| 831 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 1018 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 832 ComponentUnpacker | 1019 ComponentUnpacker unpacker(context->pk_hash, |
| 833 unpacker(context->pk_hash, crx_path, context->installer); | 1020 crx_path, |
| 834 if (!file_util::Delete(crx_path, false)) { | 1021 context->fingerprint, |
| 1022 component_patcher_.get(), |
| 1023 context->installer); |
| 1024 if (!file_util::Delete(crx_path, false)) |
| 835 NOTREACHED() << crx_path.value(); | 1025 NOTREACHED() << crx_path.value(); |
| 836 } | |
| 837 // Why unretained? See comment at top of file. | 1026 // Why unretained? See comment at top of file. |
| 838 BrowserThread::PostDelayedTask( | 1027 BrowserThread::PostDelayedTask( |
| 839 BrowserThread::UI, | 1028 BrowserThread::UI, |
| 840 FROM_HERE, | 1029 FROM_HERE, |
| 841 base::Bind(&CrxUpdateService::DoneInstalling, base::Unretained(this), | 1030 base::Bind(&CrxUpdateService::DoneInstalling, base::Unretained(this), |
| 842 context->id, unpacker.error()), | 1031 context->id, unpacker.error(), unpacker.extended_error()), |
| 843 base::TimeDelta::FromMilliseconds(config_->StepDelay())); | 1032 base::TimeDelta::FromMilliseconds(config_->StepDelay())); |
| 844 delete context; | 1033 delete context; |
| 845 } | 1034 } |
| 846 | 1035 |
| 847 // Installation has been completed. Adjust the component status and | 1036 // Installation has been completed. Adjust the component status and |
| 848 // schedule the next check. | 1037 // schedule the next check. |
| 849 void CrxUpdateService::DoneInstalling(const std::string& component_id, | 1038 void CrxUpdateService::DoneInstalling(const std::string& component_id, |
| 850 ComponentUnpacker::Error error) { | 1039 ComponentUnpacker::Error error, |
| 1040 int extra_code) { |
| 851 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1041 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 852 | 1042 |
| 853 CrxUpdateItem* item = FindUpdateItemById(component_id); | 1043 CrxUpdateItem* item = FindUpdateItemById(component_id); |
| 1044 if (item->status == CrxUpdateItem::kUpdatingDiff) { |
| 1045 if (error != ComponentUnpacker::kNone) { |
| 1046 item->diff_error_code = error; |
| 1047 item->diff_extra_code1 = extra_code; |
| 1048 item->diff_update_failed = true; |
| 1049 item->status = CrxUpdateItem::kCanUpdate; |
| 1050 BrowserThread::PostTask( |
| 1051 BrowserThread::UI, |
| 1052 FROM_HERE, |
| 1053 base::Bind(&CrxUpdateService::ProcessPendingItems, |
| 1054 base::Unretained(this))); |
| 1055 return; |
| 1056 } |
| 1057 } |
| 1058 |
| 1059 if (error != ComponentUnpacker::kNone) { |
| 1060 item->error_code = error; |
| 1061 item->extra_code1 = extra_code; |
| 1062 } |
| 1063 |
| 854 item->status = (error == ComponentUnpacker::kNone) ? CrxUpdateItem::kUpdated : | 1064 item->status = (error == ComponentUnpacker::kNone) ? CrxUpdateItem::kUpdated : |
| 855 CrxUpdateItem::kNoUpdate; | 1065 CrxUpdateItem::kNoUpdate; |
| 856 if (item->status == CrxUpdateItem::kUpdated) | 1066 if (item->status == CrxUpdateItem::kUpdated) { |
| 857 item->component.version = item->next_version; | 1067 item->component.version = item->next_version; |
| 1068 item->component.fingerprint = item->next_fp; |
| 1069 } |
| 858 | 1070 |
| 859 Configurator::Events event; | 1071 Configurator::Events event; |
| 860 switch (error) { | 1072 switch (error) { |
| 861 case ComponentUnpacker::kNone: | 1073 case ComponentUnpacker::kNone: |
| 862 event = Configurator::kComponentUpdated; | 1074 event = Configurator::kComponentUpdated; |
| 863 break; | 1075 break; |
| 864 case ComponentUnpacker::kInstallerError: | 1076 case ComponentUnpacker::kInstallerError: |
| 865 event = Configurator::kInstallerError; | 1077 event = Configurator::kInstallerError; |
| 866 break; | 1078 break; |
| 867 default: | 1079 default: |
| 868 event = Configurator::kUnpackError; | 1080 event = Configurator::kUnpackError; |
| 869 break; | 1081 break; |
| 870 } | 1082 } |
| 871 | 1083 |
| 872 config_->OnEvent(event, CrxIdtoUMAId(component_id)); | 1084 config_->OnEvent(event, CrxIdtoUMAId(component_id)); |
| 873 ScheduleNextRun(false); | 1085 ScheduleNextRun(false); |
| 874 } | 1086 } |
| 875 | 1087 |
| 1088 void CrxUpdateService::SendPing(const std::string& ping) { |
| 1089 VLOG(3) << "Sending ping. " << ping; |
| 1090 const std::string ping_url(config_->PingUrl().spec()); |
| 1091 ping_sender_.reset(net::URLFetcher::Create( |
| 1092 0, GURL(ping_url), net::URLFetcher::POST, |
| 1093 MakeContextDelegate(this, new PingContext()))); |
| 1094 ping_sender_->SetUploadData(std::string("application/xml"), ping); |
| 1095 StartFetch(ping_sender_.get(), config_->RequestContext(), false); |
| 1096 } |
| 1097 |
| 1098 void CrxUpdateService::OnURLFetchComplete(const net::URLFetcher* source, |
| 1099 PingContext* context) { |
| 1100 VLOG(3) << "Sending component update ping returned " |
| 1101 << FetchSuccess(*source); |
| 1102 ping_sender_.reset(); |
| 1103 } |
| 1104 |
| 1105 // Builds a ping message for the update items that have completed. Returns |
| 1106 // an empty string if there are no completed items. |
| 1107 std::string CrxUpdateService::BuildPing() const { |
| 1108 const std::string apps(BuildPingApps()); |
| 1109 if (apps.empty()) |
| 1110 return std::string(); |
| 1111 |
| 1112 const char response_format[] = |
| 1113 "<o:gupdate xmlns:o=\"http://www.google.com/update2/request\" " |
| 1114 "protocol=\"2.0\" version=\"%s-%s\" requestid=\"{%s}\"> " |
| 1115 "<o:os platform=\"%s\" version=\"%s\"/> " |
| 1116 "%s" |
| 1117 "</o:gupdate>"; |
| 1118 const std::string response_envelope( |
| 1119 base::StringPrintf(response_format, |
| 1120 prod_id_.c_str(), |
| 1121 chrome_version_.GetString().c_str(), |
| 1122 base::GenerateGUID().c_str(), |
| 1123 os_type_.c_str(), |
| 1124 os_version_.c_str(), |
| 1125 apps.c_str())); |
| 1126 return response_envelope; |
| 1127 } |
| 1128 |
| 1129 // Returns a string containing the sequence of app elements inside the |
| 1130 // ping message. |
| 1131 std::string CrxUpdateService::BuildPingApps() const { |
| 1132 const char app_format[] = "<o:app appid=\"%s\" version=\"%s\">%s</o:app>"; |
| 1133 |
| 1134 std::string ping_apps; |
| 1135 for (UpdateItems::const_iterator it = work_items_.begin(); |
| 1136 it != work_items_.end(); ++it) { |
| 1137 CrxUpdateItem* item = *it; |
| 1138 // Only ping once if an update was available and the item is completed. |
| 1139 if (item->is_update_available && !item->ping_queued && |
| 1140 (item->status == CrxUpdateItem::kNoUpdate || |
| 1141 item->status == CrxUpdateItem::kUpdated)) { |
| 1142 const std::string version = item->component.version.GetString().c_str(); |
| 1143 ping_apps += base::StringPrintf(app_format, |
| 1144 item->id.c_str(), |
| 1145 version.c_str(), |
| 1146 BuildPingEvent(item).c_str()); |
| 1147 } |
| 1148 } |
| 1149 return ping_apps; |
| 1150 } |
| 1151 |
| 1152 // Returns a string representing one ping event for an update item. |
| 1153 std::string CrxUpdateService::BuildPingEvent(CrxUpdateItem* item) { |
| 1154 DCHECK(item->status == CrxUpdateItem::kNoUpdate || |
| 1155 item->status == CrxUpdateItem::kUpdated); |
| 1156 DCHECK(item->is_update_available); |
| 1157 |
| 1158 using base::StringAppendF; |
| 1159 |
| 1160 std::string ping_event("<o:event eventtype=\"3\""); |
| 1161 const int event_result = item->status == CrxUpdateItem::kUpdated; |
| 1162 StringAppendF(&ping_event, " eventresult=\"%d\"", event_result); |
| 1163 StringAppendF(&ping_event, " previousversion=\"%s\"", |
| 1164 item->previous_version.GetString().c_str()); |
| 1165 StringAppendF(&ping_event, " nextversion=\"%s\"", |
| 1166 item->next_version.GetString().c_str()); |
| 1167 if (item->error_code) |
| 1168 StringAppendF(&ping_event, " errorcode=\"%d\"", item->error_code); |
| 1169 if (item->extra_code1) |
| 1170 StringAppendF(&ping_event, " extracode1=\"%d\"", item->extra_code1); |
| 1171 if (IsDiffUpdateAvailable(item)) |
| 1172 StringAppendF(&ping_event, " diffresult=\"%d\"", !item->diff_update_failed); |
| 1173 if (item->diff_error_code) |
| 1174 StringAppendF(&ping_event, " differrorcode=\"%d\"", item->diff_error_code); |
| 1175 if (item->diff_extra_code1) { |
| 1176 StringAppendF(&ping_event, |
| 1177 " diffextracode1=\"%d\"", |
| 1178 item->diff_extra_code1); |
| 1179 } |
| 1180 if (!item->previous_fp.empty()) |
| 1181 StringAppendF(&ping_event, " previousfp=\"%s\"", item->previous_fp.c_str()); |
| 1182 if (!item->next_fp.empty()) |
| 1183 StringAppendF(&ping_event, " nextfp=\"%s\"", item->next_fp.c_str()); |
| 1184 StringAppendF(&ping_event, "/>"); |
| 1185 item->ping_queued = true; |
| 1186 return ping_event; |
| 1187 } |
| 1188 |
| 1189 |
| 876 // The component update factory. Using the component updater as a singleton | 1190 // The component update factory. Using the component updater as a singleton |
| 877 // is the job of the browser process. | 1191 // is the job of the browser process. |
| 878 ComponentUpdateService* ComponentUpdateServiceFactory( | 1192 ComponentUpdateService* ComponentUpdateServiceFactory( |
| 879 ComponentUpdateService::Configurator* config) { | 1193 ComponentUpdateService::Configurator* config) { |
| 880 DCHECK(config); | 1194 DCHECK(config); |
| 881 return new CrxUpdateService(config); | 1195 return new CrxUpdateService(config); |
| 882 } | 1196 } |
| OLD | NEW |