| 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/google/google_update_win.h" | 5 #include "chrome/browser/google/google_update_win.h" |
| 6 | 6 |
| 7 #include <atlbase.h> | 7 #include <atlbase.h> |
| 8 #include <atlcom.h> | 8 #include <atlcom.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| 11 | 11 |
| 12 #include <utility> | 12 #include <utility> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "base/bind.h" | 15 #include "base/bind.h" |
| 16 #include "base/callback.h" | 16 #include "base/callback.h" |
| 17 #include "base/files/file_path.h" | 17 #include "base/files/file_path.h" |
| 18 #include "base/location.h" | 18 #include "base/location.h" |
| 19 #include "base/macros.h" | 19 #include "base/macros.h" |
| 20 #include "base/metrics/histogram.h" | 20 #include "base/metrics/histogram.h" |
| 21 #include "base/metrics/sparse_histogram.h" | 21 #include "base/metrics/sparse_histogram.h" |
| 22 #include "base/path_service.h" | 22 #include "base/path_service.h" |
| 23 #include "base/sequenced_task_runner.h" |
| 23 #include "base/sequenced_task_runner_helpers.h" | 24 #include "base/sequenced_task_runner_helpers.h" |
| 24 #include "base/single_thread_task_runner.h" | |
| 25 #include "base/strings/string_util.h" | 25 #include "base/strings/string_util.h" |
| 26 #include "base/strings/stringprintf.h" | 26 #include "base/strings/stringprintf.h" |
| 27 #include "base/strings/utf_string_conversions.h" | 27 #include "base/strings/utf_string_conversions.h" |
| 28 #include "base/threading/thread_task_runner_handle.h" | 28 #include "base/threading/sequenced_task_runner_handle.h" |
| 29 #include "base/time/time.h" | 29 #include "base/time/time.h" |
| 30 #include "base/version.h" | 30 #include "base/version.h" |
| 31 #include "base/win/scoped_bstr.h" | 31 #include "base/win/scoped_bstr.h" |
| 32 #include "base/win/windows_version.h" | 32 #include "base/win/windows_version.h" |
| 33 #include "chrome/common/url_constants.h" | 33 #include "chrome/common/url_constants.h" |
| 34 #include "chrome/grit/generated_resources.h" | 34 #include "chrome/grit/generated_resources.h" |
| 35 #include "chrome/installer/util/browser_distribution.h" | 35 #include "chrome/installer/util/browser_distribution.h" |
| 36 #include "chrome/installer/util/google_update_settings.h" | 36 #include "chrome/installer/util/google_update_settings.h" |
| 37 #include "chrome/installer/util/helper.h" | 37 #include "chrome/installer/util/helper.h" |
| 38 #include "chrome/installer/util/install_util.h" | 38 #include "chrome/installer/util/install_util.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 53 UPGRADE_IS_AVAILABLE = 2, | 53 UPGRADE_IS_AVAILABLE = 2, |
| 54 // The upgrade happened successfully. | 54 // The upgrade happened successfully. |
| 55 UPGRADE_SUCCESSFUL = 3, | 55 UPGRADE_SUCCESSFUL = 3, |
| 56 // No need to upgrade, Chrome is up to date. | 56 // No need to upgrade, Chrome is up to date. |
| 57 UPGRADE_ALREADY_UP_TO_DATE = 4, | 57 UPGRADE_ALREADY_UP_TO_DATE = 4, |
| 58 // An error occurred. | 58 // An error occurred. |
| 59 UPGRADE_ERROR = 5, | 59 UPGRADE_ERROR = 5, |
| 60 NUM_UPGRADE_STATUS | 60 NUM_UPGRADE_STATUS |
| 61 }; | 61 }; |
| 62 | 62 |
| 63 GlobalInterfaceTableClassFactory* g_global_interface_table_factory = nullptr; |
| 63 GoogleUpdate3ClassFactory* g_google_update_factory = nullptr; | 64 GoogleUpdate3ClassFactory* g_google_update_factory = nullptr; |
| 64 | 65 |
| 65 // The time interval, in milliseconds, between polls to Google Update. This | 66 // The time interval, in milliseconds, between polls to Google Update. This |
| 66 // value was chosen unscientificaly during an informal discussion. | 67 // value was chosen unscientificaly during an informal discussion. |
| 67 const int64_t kGoogleUpdatePollIntervalMs = 250; | 68 const int64_t kGoogleUpdatePollIntervalMs = 250; |
| 68 | 69 |
| 69 const int kGoogleAllowedRetries = 1; | 70 const int kGoogleAllowedRetries = 1; |
| 70 const int kGoogleRetryIntervalSeconds = 5; | 71 const int kGoogleRetryIntervalSeconds = 5; |
| 71 | 72 |
| 72 // Constants from Google Update. | 73 // Constants from Google Update. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 ::CoSetProxyBlanket(interface_pointer, | 116 ::CoSetProxyBlanket(interface_pointer, |
| 116 RPC_C_AUTHN_DEFAULT, | 117 RPC_C_AUTHN_DEFAULT, |
| 117 RPC_C_AUTHZ_DEFAULT, | 118 RPC_C_AUTHZ_DEFAULT, |
| 118 COLE_DEFAULT_PRINCIPAL, | 119 COLE_DEFAULT_PRINCIPAL, |
| 119 RPC_C_AUTHN_LEVEL_PKT_PRIVACY, | 120 RPC_C_AUTHN_LEVEL_PKT_PRIVACY, |
| 120 RPC_C_IMP_LEVEL_IMPERSONATE, | 121 RPC_C_IMP_LEVEL_IMPERSONATE, |
| 121 nullptr, | 122 nullptr, |
| 122 EOAC_DYNAMIC_CLOAKING); | 123 EOAC_DYNAMIC_CLOAKING); |
| 123 } | 124 } |
| 124 | 125 |
| 126 HRESULT CreateGlobalInterfaceTable( |
| 127 base::win::ScopedComPtr<IGlobalInterfaceTable>* global_interface_table) { |
| 128 if (g_global_interface_table_factory) |
| 129 return g_global_interface_table_factory->Run(global_interface_table); |
| 130 |
| 131 return global_interface_table->CreateInstance(CLSID_StdGlobalInterfaceTable, |
| 132 nullptr, CLSCTX_INPROC_SERVER); |
| 133 } |
| 134 |
| 125 // Creates a class factory for a COM Local Server class using either plain | 135 // Creates a class factory for a COM Local Server class using either plain |
| 126 // vanilla CoGetClassObject, or using the Elevation moniker if running on | 136 // vanilla CoGetClassObject, or using the Elevation moniker if running on |
| 127 // Vista+. |hwnd| must refer to a foregound window in order to get the UAC | 137 // Vista+. |hwnd| must refer to a foregound window in order to get the UAC |
| 128 // prompt to appear in the foreground if running on Vista+. It can also be NULL | 138 // prompt to appear in the foreground if running on Vista+. It can also be NULL |
| 129 // if background UAC prompts are desired. | 139 // if background UAC prompts are desired. |
| 130 HRESULT CoGetClassObjectAsAdmin(REFCLSID class_id, | 140 HRESULT CoGetClassObjectAsAdmin(REFCLSID class_id, |
| 131 REFIID interface_id, | 141 REFIID interface_id, |
| 132 gfx::AcceleratedWidget hwnd, | 142 gfx::AcceleratedWidget hwnd, |
| 133 void** interface_ptr) { | 143 void** interface_ptr) { |
| 134 if (!interface_ptr) | 144 if (!interface_ptr) |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 return hresult; | 206 return hresult; |
| 197 | 207 |
| 198 ConfigureProxyBlanket(class_factory.get()); | 208 ConfigureProxyBlanket(class_factory.get()); |
| 199 | 209 |
| 200 return class_factory->CreateInstance( | 210 return class_factory->CreateInstance( |
| 201 nullptr, | 211 nullptr, |
| 202 base::win::ScopedComPtr<IGoogleUpdate3Web>::iid(), | 212 base::win::ScopedComPtr<IGoogleUpdate3Web>::iid(), |
| 203 google_update->ReceiveVoid()); | 213 google_update->ReceiveVoid()); |
| 204 } | 214 } |
| 205 | 215 |
| 216 // InterfaceCookie ------------------------------------------------------------- |
| 217 |
| 218 // Manages the lifetime of an interface's cookie in the COM Global Interface |
| 219 // Table. |
| 220 template <class T> |
| 221 class InterfaceCookie { |
| 222 public: |
| 223 InterfaceCookie() = default; |
| 224 ~InterfaceCookie(); |
| 225 |
| 226 void Initialize( |
| 227 base::win::ScopedComPtr<IGlobalInterfaceTable> global_interface_table); |
| 228 |
| 229 // Registers |interface_pointer| in the process's Global Interface Table. |
| 230 HRESULT Register(const base::win::ScopedComPtr<T>& interface_pointer); |
| 231 |
| 232 // Populates |interface_pointer| with the cookie's interface in the process's |
| 233 // Global Interface Table. |
| 234 HRESULT Get(base::win::ScopedComPtr<T>* interface_pointer) const; |
| 235 |
| 236 // Revokes the cookie from the Global Interface Table. This function is safe |
| 237 // to call when the cookie is empty. |
| 238 HRESULT Revoke(); |
| 239 |
| 240 explicit operator bool() const { return cookie_ != 0; } |
| 241 |
| 242 private: |
| 243 base::win::ScopedComPtr<IGlobalInterfaceTable> global_interface_table_; |
| 244 DWORD cookie_ = 0; |
| 245 |
| 246 DISALLOW_COPY_AND_ASSIGN(InterfaceCookie); |
| 247 }; |
| 248 |
| 249 template <class T> |
| 250 InterfaceCookie<T>::~InterfaceCookie() { |
| 251 Revoke(); |
| 252 } |
| 253 |
| 254 template <class T> |
| 255 void InterfaceCookie<T>::Initialize( |
| 256 base::win::ScopedComPtr<IGlobalInterfaceTable> global_interface_table) { |
| 257 DCHECK(!global_interface_table_); |
| 258 global_interface_table_ = std::move(global_interface_table); |
| 259 } |
| 260 |
| 261 template <class T> |
| 262 HRESULT InterfaceCookie<T>::Register( |
| 263 const base::win::ScopedComPtr<T>& interface_pointer) { |
| 264 DCHECK(global_interface_table_); |
| 265 DCHECK_EQ(0U, cookie_); |
| 266 return global_interface_table_->RegisterInterfaceInGlobal( |
| 267 interface_pointer.get(), base::win::ScopedComPtr<T>::iid(), &cookie_); |
| 268 } |
| 269 |
| 270 template <class T> |
| 271 HRESULT InterfaceCookie<T>::Get( |
| 272 base::win::ScopedComPtr<T>* interface_pointer) const { |
| 273 DCHECK(global_interface_table_); |
| 274 DCHECK(interface_pointer); |
| 275 DCHECK_NE(0U, cookie_); |
| 276 return global_interface_table_->GetInterfaceFromGlobal( |
| 277 cookie_, base::win::ScopedComPtr<T>::iid(), |
| 278 interface_pointer->ReceiveVoid()); |
| 279 } |
| 280 |
| 281 template <class T> |
| 282 HRESULT InterfaceCookie<T>::Revoke() { |
| 283 if (!cookie_) |
| 284 return S_OK; |
| 285 |
| 286 DCHECK(global_interface_table_); |
| 287 HRESULT hresult = global_interface_table_->RevokeInterfaceFromGlobal(cookie_); |
| 288 if (SUCCEEDED(hresult)) |
| 289 cookie_ = 0; |
| 290 return hresult; |
| 291 } |
| 292 |
| 206 // UpdateCheckDriver ----------------------------------------------------------- | 293 // UpdateCheckDriver ----------------------------------------------------------- |
| 207 | 294 |
| 208 // A driver that is created and destroyed on the caller's thread and drives | 295 // A driver that is created and destroyed on the caller's task runner and drives |
| 209 // Google Update on another. | 296 // Google Update on another. |
| 210 class UpdateCheckDriver { | 297 class UpdateCheckDriver { |
| 211 public: | 298 public: |
| 212 // Runs an update check on |task_runner|, invoking methods of |delegate| on | 299 // Runs an update check on |task_runner|, invoking methods of |delegate| on |
| 213 // the caller's thread to report progress and final results. | 300 // the caller's task runner to report progress and final results. |
| 214 static void RunUpdateCheck( | 301 static void RunUpdateCheck( |
| 215 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 302 scoped_refptr<base::SequencedTaskRunner> task_runner, |
| 216 const std::string& locale, | 303 const std::string& locale, |
| 217 bool install_update_if_possible, | 304 bool install_update_if_possible, |
| 218 gfx::AcceleratedWidget elevation_window, | 305 gfx::AcceleratedWidget elevation_window, |
| 219 const base::WeakPtr<UpdateCheckDelegate>& delegate); | 306 const base::WeakPtr<UpdateCheckDelegate>& delegate); |
| 220 | 307 |
| 221 private: | 308 private: |
| 222 friend class base::DeleteHelper<UpdateCheckDriver>; | 309 friend class base::DeleteHelper<UpdateCheckDriver>; |
| 223 | 310 |
| 224 UpdateCheckDriver( | 311 UpdateCheckDriver(scoped_refptr<base::SequencedTaskRunner> task_runner, |
| 225 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 312 const std::string& locale, |
| 226 const std::string& locale, | 313 bool install_update_if_possible, |
| 227 bool install_update_if_possible, | 314 gfx::AcceleratedWidget elevation_window, |
| 228 gfx::AcceleratedWidget elevation_window, | 315 const base::WeakPtr<UpdateCheckDelegate>& delegate); |
| 229 const base::WeakPtr<UpdateCheckDelegate>& delegate); | |
| 230 | 316 |
| 231 // Invokes a completion or error method on all delegates, as appropriate. | 317 // Invokes a completion or error method on all delegates, as appropriate. |
| 232 ~UpdateCheckDriver(); | 318 ~UpdateCheckDriver(); |
| 233 | 319 |
| 234 // If an UpdateCheckDriver is already running, the delegate is added to the | 320 // If an UpdateCheckDriver is already running, the delegate is added to the |
| 235 // existing one instead of creating a new one. | 321 // existing one instead of creating a new one. |
| 236 void AddDelegate(const base::WeakPtr<UpdateCheckDelegate>& delegate); | 322 void AddDelegate(const base::WeakPtr<UpdateCheckDelegate>& delegate); |
| 237 | 323 |
| 238 // Notifies delegates of an update's progress. |progress|, a number between 0 | 324 // Notifies delegates of an update's progress. |progress|, a number between 0 |
| 239 // and 100 (inclusive), is an estimation as to what percentage of the upgrade | 325 // and 100 (inclusive), is an estimation as to what percentage of the upgrade |
| (...skipping 16 matching lines...) Expand all Loading... |
| 256 // to the user. This call should be followed by deletion of the driver, | 342 // to the user. This call should be followed by deletion of the driver, |
| 257 // which will result in callers being notified via their delegates. | 343 // which will result in callers being notified via their delegates. |
| 258 void OnUpgradeError(GoogleUpdateErrorCode error_code, | 344 void OnUpgradeError(GoogleUpdateErrorCode error_code, |
| 259 HRESULT hresult, | 345 HRESULT hresult, |
| 260 int installer_exit_code, | 346 int installer_exit_code, |
| 261 const base::string16& error_string); | 347 const base::string16& error_string); |
| 262 | 348 |
| 263 // Returns true if |current_state| and |state_value| can be obtained from the | 349 // Returns true if |current_state| and |state_value| can be obtained from the |
| 264 // ongoing update check. Otherwise, populates |hresult| with the reason they | 350 // ongoing update check. Otherwise, populates |hresult| with the reason they |
| 265 // could not be obtained. | 351 // could not be obtained. |
| 266 bool GetCurrentState(base::win::ScopedComPtr<ICurrentState>* current_state, | 352 bool GetCurrentState(base::win::ScopedComPtr<IAppBundleWeb>* app_bundle, |
| 353 base::win::ScopedComPtr<ICurrentState>* current_state, |
| 267 CurrentState* state_value, | 354 CurrentState* state_value, |
| 268 HRESULT* hresult) const; | 355 HRESULT* hresult) const; |
| 269 | 356 |
| 270 // Returns true if |current_state| and |state_value| constitute an error state | 357 // Returns true if |current_state| and |state_value| constitute an error state |
| 271 // for the ongoing update check, in which case |error_code| is populated with | 358 // for the ongoing update check, in which case |error_code| is populated with |
| 272 // one of GOOGLE_UPDATE_ERROR_UPDATING, GOOGLE_UPDATE_DISABLED_BY_POLICY, or | 359 // one of GOOGLE_UPDATE_ERROR_UPDATING, GOOGLE_UPDATE_DISABLED_BY_POLICY, or |
| 273 // GOOGLE_UPDATE_ONDEMAND_CLASS_REPORTED_ERROR. |hresult| is populated with | 360 // GOOGLE_UPDATE_ONDEMAND_CLASS_REPORTED_ERROR. |hresult| is populated with |
| 274 // the most relevant HRESULT (which may be a value from Google Update; see | 361 // the most relevant HRESULT (which may be a value from Google Update; see |
| 275 // https://code.google.com/p/omaha/source/browse/trunk/base/error.h). In case | 362 // https://code.google.com/p/omaha/source/browse/trunk/base/error.h). In case |
| 276 // Chrome's installer failed during execution, |installer_exit_code| may be | 363 // Chrome's installer failed during execution, |installer_exit_code| may be |
| 277 // populated with its process exit code (see enum installer::InstallStatus in | 364 // populated with its process exit code (see enum installer::InstallStatus in |
| 278 // chrome/installer/util/util_constants.h); otherwise, it will be -1. | 365 // chrome/installer/util/util_constants.h); otherwise, it will be -1. |
| 279 // |error_string| will be populated with a completion message if one is | 366 // |error_string| will be populated with a completion message if one is |
| 280 // provided by Google Update. | 367 // provided by Google Update. |
| 281 bool IsErrorState(const base::win::ScopedComPtr<ICurrentState>& current_state, | 368 bool IsErrorState(const base::win::ScopedComPtr<IAppBundleWeb>& app_bundle, |
| 369 const base::win::ScopedComPtr<ICurrentState>& current_state, |
| 282 CurrentState state_value, | 370 CurrentState state_value, |
| 283 GoogleUpdateErrorCode* error_code, | 371 GoogleUpdateErrorCode* error_code, |
| 284 HRESULT* hresult, | 372 HRESULT* hresult, |
| 285 int* installer_exit_code, | 373 int* installer_exit_code, |
| 286 base::string16* error_string) const; | 374 base::string16* error_string) const; |
| 287 | 375 |
| 288 // Returns true if |current_state| and |state_value| constitute a final state | 376 // Returns true if |current_state| and |state_value| constitute a final state |
| 289 // for the ongoing update check, in which case |upgrade_status| is populated | 377 // for the ongoing update check, in which case |upgrade_status| is populated |
| 290 // with one of UPGRADE_ALREADY_UP_TO_DATE or UPGRADE_IS_AVAILABLE (in case a | 378 // with one of UPGRADE_ALREADY_UP_TO_DATE or UPGRADE_IS_AVAILABLE (in case a |
| 291 // pure check is being performed rather than an update) or UPGRADE_SUCCESSFUL | 379 // pure check is being performed rather than an update) or UPGRADE_SUCCESSFUL |
| (...skipping 17 matching lines...) Expand all Loading... |
| 309 base::string16* new_version, | 397 base::string16* new_version, |
| 310 int* progress) const; | 398 int* progress) const; |
| 311 | 399 |
| 312 // Polls Google Update to determine the state of the ongoing check or | 400 // Polls Google Update to determine the state of the ongoing check or |
| 313 // update. If the process has reached a terminal state, this instance will be | 401 // update. If the process has reached a terminal state, this instance will be |
| 314 // deleted and the caller will be notified of the final status. Otherwise, the | 402 // deleted and the caller will be notified of the final status. Otherwise, the |
| 315 // caller will be notified of the intermediate state (iff it differs from a | 403 // caller will be notified of the intermediate state (iff it differs from a |
| 316 // previous notification) and another future poll will be scheduled. | 404 // previous notification) and another future poll will be scheduled. |
| 317 void PollGoogleUpdate(); | 405 void PollGoogleUpdate(); |
| 318 | 406 |
| 319 // The global driver instance. Accessed only on the caller's thread. | 407 // The global driver instance. Accessed only on the caller's task runner. |
| 320 static UpdateCheckDriver* driver_; | 408 static UpdateCheckDriver* driver_; |
| 321 | 409 |
| 322 // The task runner on which the update checks runs. | 410 // The task runner on which the update checks runs. |
| 323 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 411 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
| 324 | 412 |
| 325 // The caller's task runner, on which methods of the |delegates_| will be | 413 // The caller's task runner, on which methods of the |delegates_| will be |
| 326 // invoked. | 414 // invoked. |
| 327 scoped_refptr<base::SingleThreadTaskRunner> result_runner_; | 415 scoped_refptr<base::SequencedTaskRunner> result_runner_; |
| 328 | 416 |
| 329 // The UI locale. | 417 // The UI locale. |
| 330 std::string locale_; | 418 std::string locale_; |
| 331 | 419 |
| 332 // False to only check for an update; true to also install one if available. | 420 // False to only check for an update; true to also install one if available. |
| 333 bool install_update_if_possible_; | 421 bool install_update_if_possible_; |
| 334 | 422 |
| 335 // A parent window in case any UX is required (e.g., an elevation prompt). | 423 // A parent window in case any UX is required (e.g., an elevation prompt). |
| 336 gfx::AcceleratedWidget elevation_window_; | 424 gfx::AcceleratedWidget elevation_window_; |
| 337 | 425 |
| 338 // Contains all delegates by which feedback is conveyed. Accessed only on the | 426 // Contains all delegates by which feedback is conveyed. Accessed only on the |
| 339 // caller's thread. | 427 // caller's task runner. |
| 340 std::vector<base::WeakPtr<UpdateCheckDelegate>> delegates_; | 428 std::vector<base::WeakPtr<UpdateCheckDelegate>> delegates_; |
| 341 | 429 |
| 342 // Number of remaining retries allowed when errors occur. | 430 // Number of remaining retries allowed when errors occur. |
| 343 int allowed_retries_; | 431 int allowed_retries_; |
| 344 | 432 |
| 345 // True if operating on a per-machine installation rather than a per-user one. | 433 // True if operating on a per-machine installation rather than a per-user one. |
| 346 bool system_level_install_; | 434 bool system_level_install_; |
| 347 | 435 |
| 348 // The on-demand updater that is doing the work. | 436 // The COM Global Interface Table for the process. |
| 349 base::win::ScopedComPtr<IGoogleUpdate3Web> google_update_; | 437 base::win::ScopedComPtr<IGlobalInterfaceTable> global_interface_table_; |
| 350 | 438 |
| 351 // An app bundle containing the application being updated. | 439 // A cookie in the Global Interface Table for the on-demand updater that is |
| 352 base::win::ScopedComPtr<IAppBundleWeb> app_bundle_; | 440 // doing the work. |
| 441 InterfaceCookie<IGoogleUpdate3Web> google_update_cookie_; |
| 353 | 442 |
| 354 // The application being updated (Chrome, Chrome Binaries, or Chrome SxS). | 443 // A cookie in the Global Interface Table for the app bundle containing the |
| 355 base::win::ScopedComPtr<IAppWeb> app_; | 444 // application being updated. |
| 445 InterfaceCookie<IAppBundleWeb> app_bundle_cookie_; |
| 356 | 446 |
| 357 // The progress value reported most recently to the caller. | 447 // The progress value reported most recently to the caller. |
| 358 int last_reported_progress_; | 448 int last_reported_progress_; |
| 359 | 449 |
| 360 // The results of the update check to be logged via UMA and/or reported to the | 450 // The results of the update check to be logged via UMA and/or reported to the |
| 361 // caller. | 451 // caller. |
| 362 GoogleUpdateUpgradeStatus status_; | 452 GoogleUpdateUpgradeStatus status_; |
| 363 GoogleUpdateErrorCode error_code_; | 453 GoogleUpdateErrorCode error_code_; |
| 364 base::string16 html_error_message_; | 454 base::string16 html_error_message_; |
| 365 base::string16 new_version_; | 455 base::string16 new_version_; |
| 366 HRESULT hresult_; | 456 HRESULT hresult_; |
| 367 int installer_exit_code_; | 457 int installer_exit_code_; |
| 368 | 458 |
| 369 DISALLOW_COPY_AND_ASSIGN(UpdateCheckDriver); | 459 DISALLOW_COPY_AND_ASSIGN(UpdateCheckDriver); |
| 370 }; | 460 }; |
| 371 | 461 |
| 372 UpdateCheckDriver* UpdateCheckDriver::driver_ = nullptr; | 462 UpdateCheckDriver* UpdateCheckDriver::driver_ = nullptr; |
| 373 | 463 |
| 374 // static | 464 // static |
| 375 void UpdateCheckDriver::RunUpdateCheck( | 465 void UpdateCheckDriver::RunUpdateCheck( |
| 376 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 466 scoped_refptr<base::SequencedTaskRunner> task_runner, |
| 377 const std::string& locale, | 467 const std::string& locale, |
| 378 bool install_update_if_possible, | 468 bool install_update_if_possible, |
| 379 gfx::AcceleratedWidget elevation_window, | 469 gfx::AcceleratedWidget elevation_window, |
| 380 const base::WeakPtr<UpdateCheckDelegate>& delegate) { | 470 const base::WeakPtr<UpdateCheckDelegate>& delegate) { |
| 381 // Create the driver if it doesn't exist, or add the delegate to the existing | 471 // Create the driver if it doesn't exist, or add the delegate to the existing |
| 382 // one. | 472 // one. |
| 383 if (!driver_) { | 473 if (!driver_) { |
| 384 // The driver is owned by itself, and will self-destruct when its work is | 474 // The driver is owned by itself, and will self-destruct when its work is |
| 385 // done. | 475 // done. |
| 386 driver_ = | 476 driver_ = |
| 387 new UpdateCheckDriver(task_runner, locale, install_update_if_possible, | 477 new UpdateCheckDriver(task_runner, locale, install_update_if_possible, |
| 388 elevation_window, delegate); | 478 elevation_window, delegate); |
| 389 task_runner->PostTask(FROM_HERE, | 479 task_runner->PostTask(FROM_HERE, |
| 390 base::Bind(&UpdateCheckDriver::BeginUpdateCheck, | 480 base::Bind(&UpdateCheckDriver::BeginUpdateCheck, |
| 391 base::Unretained(driver_))); | 481 base::Unretained(driver_))); |
| 392 } else { | 482 } else { |
| 393 DCHECK_EQ(driver_->task_runner_, task_runner); | 483 DCHECK_EQ(driver_->task_runner_, task_runner); |
| 394 driver_->AddDelegate(delegate); | 484 driver_->AddDelegate(delegate); |
| 395 } | 485 } |
| 396 } | 486 } |
| 397 | 487 |
| 398 // Runs on the caller's thread. | 488 // Runs on the caller's task runner. |
| 399 UpdateCheckDriver::UpdateCheckDriver( | 489 UpdateCheckDriver::UpdateCheckDriver( |
| 400 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 490 scoped_refptr<base::SequencedTaskRunner> task_runner, |
| 401 const std::string& locale, | 491 const std::string& locale, |
| 402 bool install_update_if_possible, | 492 bool install_update_if_possible, |
| 403 gfx::AcceleratedWidget elevation_window, | 493 gfx::AcceleratedWidget elevation_window, |
| 404 const base::WeakPtr<UpdateCheckDelegate>& delegate) | 494 const base::WeakPtr<UpdateCheckDelegate>& delegate) |
| 405 : task_runner_(std::move(task_runner)), | 495 : task_runner_(std::move(task_runner)), |
| 406 result_runner_(base::ThreadTaskRunnerHandle::Get()), | 496 result_runner_(base::SequencedTaskRunnerHandle::Get()), |
| 407 locale_(locale), | 497 locale_(locale), |
| 408 install_update_if_possible_(install_update_if_possible), | 498 install_update_if_possible_(install_update_if_possible), |
| 409 elevation_window_(elevation_window), | 499 elevation_window_(elevation_window), |
| 410 delegates_(1, delegate), | 500 delegates_(1, delegate), |
| 411 allowed_retries_(kGoogleAllowedRetries), | 501 allowed_retries_(kGoogleAllowedRetries), |
| 412 system_level_install_(false), | 502 system_level_install_(false), |
| 413 last_reported_progress_(0), | 503 last_reported_progress_(0), |
| 414 status_(UPGRADE_ERROR), | 504 status_(UPGRADE_ERROR), |
| 415 error_code_(GOOGLE_UPDATE_NO_ERROR), | 505 error_code_(GOOGLE_UPDATE_NO_ERROR), |
| 416 hresult_(S_OK), | 506 hresult_(S_OK), |
| 417 installer_exit_code_(-1) {} | 507 installer_exit_code_(-1) {} |
| 418 | 508 |
| 419 UpdateCheckDriver::~UpdateCheckDriver() { | 509 UpdateCheckDriver::~UpdateCheckDriver() { |
| 420 DCHECK(result_runner_->BelongsToCurrentThread()); | 510 DCHECK(result_runner_->RunsTasksOnCurrentThread()); |
| 511 DCHECK(!google_update_cookie_); |
| 512 DCHECK(!app_bundle_cookie_); |
| 513 |
| 421 // If there is an error, then error_code must not be blank, and vice versa. | 514 // If there is an error, then error_code must not be blank, and vice versa. |
| 422 DCHECK_NE(status_ == UPGRADE_ERROR, error_code_ == GOOGLE_UPDATE_NO_ERROR); | 515 DCHECK_NE(status_ == UPGRADE_ERROR, error_code_ == GOOGLE_UPDATE_NO_ERROR); |
| 423 UMA_HISTOGRAM_ENUMERATION("GoogleUpdate.UpgradeResult", status_, | 516 UMA_HISTOGRAM_ENUMERATION("GoogleUpdate.UpgradeResult", status_, |
| 424 NUM_UPGRADE_STATUS); | 517 NUM_UPGRADE_STATUS); |
| 425 if (status_ == UPGRADE_ERROR) { | 518 if (status_ == UPGRADE_ERROR) { |
| 426 UMA_HISTOGRAM_ENUMERATION("GoogleUpdate.UpdateErrorCode", error_code_, | 519 UMA_HISTOGRAM_ENUMERATION("GoogleUpdate.UpdateErrorCode", error_code_, |
| 427 NUM_ERROR_CODES); | 520 NUM_ERROR_CODES); |
| 428 if (FAILED(hresult_)) | 521 if (FAILED(hresult_)) |
| 429 UMA_HISTOGRAM_SPARSE_SLOWLY("GoogleUpdate.ErrorHresult", hresult_); | 522 UMA_HISTOGRAM_SPARSE_SLOWLY("GoogleUpdate.ErrorHresult", hresult_); |
| 430 if (installer_exit_code_ != -1) { | 523 if (installer_exit_code_ != -1) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 445 else if (install_update_if_possible_) | 538 else if (install_update_if_possible_) |
| 446 delegate->OnUpgradeComplete(new_version_); | 539 delegate->OnUpgradeComplete(new_version_); |
| 447 else | 540 else |
| 448 delegate->OnUpdateCheckComplete(new_version_); | 541 delegate->OnUpdateCheckComplete(new_version_); |
| 449 } | 542 } |
| 450 } | 543 } |
| 451 } | 544 } |
| 452 | 545 |
| 453 void UpdateCheckDriver::AddDelegate( | 546 void UpdateCheckDriver::AddDelegate( |
| 454 const base::WeakPtr<UpdateCheckDelegate>& delegate) { | 547 const base::WeakPtr<UpdateCheckDelegate>& delegate) { |
| 455 DCHECK(result_runner_->BelongsToCurrentThread()); | 548 DCHECK(result_runner_->RunsTasksOnCurrentThread()); |
| 456 delegates_.push_back(delegate); | 549 delegates_.push_back(delegate); |
| 457 } | 550 } |
| 458 | 551 |
| 459 void UpdateCheckDriver::NotifyUpgradeProgress( | 552 void UpdateCheckDriver::NotifyUpgradeProgress( |
| 460 int progress, | 553 int progress, |
| 461 const base::string16& new_version) { | 554 const base::string16& new_version) { |
| 462 DCHECK(result_runner_->BelongsToCurrentThread()); | 555 DCHECK(result_runner_->RunsTasksOnCurrentThread()); |
| 463 | 556 |
| 464 for (const auto& delegate : delegates_) { | 557 for (const auto& delegate : delegates_) { |
| 465 if (delegate) | 558 if (delegate) |
| 466 delegate->OnUpgradeProgress(progress, new_version); | 559 delegate->OnUpgradeProgress(progress, new_version); |
| 467 } | 560 } |
| 468 } | 561 } |
| 469 | 562 |
| 470 void UpdateCheckDriver::BeginUpdateCheck() { | 563 void UpdateCheckDriver::BeginUpdateCheck() { |
| 471 GoogleUpdateErrorCode error_code = GOOGLE_UPDATE_NO_ERROR; | 564 GoogleUpdateErrorCode error_code = GOOGLE_UPDATE_NO_ERROR; |
| 472 HRESULT hresult = BeginUpdateCheckInternal(&error_code); | 565 HRESULT hresult = BeginUpdateCheckInternal(&error_code); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 490 } | 583 } |
| 491 | 584 |
| 492 DCHECK(FAILED(hresult)); | 585 DCHECK(FAILED(hresult)); |
| 493 // Return results immediately since the driver is not polling Google Update. | 586 // Return results immediately since the driver is not polling Google Update. |
| 494 OnUpgradeError(error_code, hresult, -1, base::string16()); | 587 OnUpgradeError(error_code, hresult, -1, base::string16()); |
| 495 result_runner_->DeleteSoon(FROM_HERE, this); | 588 result_runner_->DeleteSoon(FROM_HERE, this); |
| 496 } | 589 } |
| 497 | 590 |
| 498 HRESULT UpdateCheckDriver::BeginUpdateCheckInternal( | 591 HRESULT UpdateCheckDriver::BeginUpdateCheckInternal( |
| 499 GoogleUpdateErrorCode* error_code) { | 592 GoogleUpdateErrorCode* error_code) { |
| 593 // All errors prior to creation of the main update class are reported as: |
| 594 *error_code = GOOGLE_UPDATE_ONDEMAND_CLASS_NOT_FOUND; |
| 500 HRESULT hresult = S_OK; | 595 HRESULT hresult = S_OK; |
| 501 // Instantiate GoogleUpdate3Web{Machine,User}Class. | 596 |
| 502 if (!google_update_) { | 597 // Create/get the process's Global Interface Table. |
| 598 if (!global_interface_table_) { |
| 599 // Make sure ATL is initialized in this module. |
| 600 ui::win::CreateATLModuleIfNeeded(); |
| 601 |
| 602 hresult = CreateGlobalInterfaceTable(&global_interface_table_); |
| 603 if (FAILED(hresult)) |
| 604 return hresult; |
| 605 |
| 606 google_update_cookie_.Initialize(global_interface_table_); |
| 607 app_bundle_cookie_.Initialize(global_interface_table_); |
| 608 } |
| 609 |
| 610 // Create or get the GoogleUpdate3Web class. |
| 611 base::win::ScopedComPtr<IGoogleUpdate3Web> google_update; |
| 612 if (!google_update_cookie_) { |
| 613 // Instantiate GoogleUpdate3Web{Machine,User}Class. |
| 503 base::FilePath chrome_exe; | 614 base::FilePath chrome_exe; |
| 504 if (!PathService::Get(base::DIR_EXE, &chrome_exe)) | 615 if (!PathService::Get(base::DIR_EXE, &chrome_exe)) |
| 505 NOTREACHED(); | 616 NOTREACHED(); |
| 506 | 617 |
| 507 system_level_install_ = !InstallUtil::IsPerUserInstall(chrome_exe); | 618 system_level_install_ = !InstallUtil::IsPerUserInstall(chrome_exe); |
| 508 | 619 |
| 509 // Make sure ATL is initialized in this module. | |
| 510 ui::win::CreateATLModuleIfNeeded(); | |
| 511 | |
| 512 *error_code = CanUpdateCurrentChrome(chrome_exe, system_level_install_); | 620 *error_code = CanUpdateCurrentChrome(chrome_exe, system_level_install_); |
| 513 if (*error_code != GOOGLE_UPDATE_NO_ERROR) | 621 if (*error_code != GOOGLE_UPDATE_NO_ERROR) |
| 514 return E_FAIL; | 622 return E_FAIL; |
| 515 | 623 |
| 624 *error_code = GOOGLE_UPDATE_ONDEMAND_CLASS_NOT_FOUND; |
| 516 hresult = CreateGoogleUpdate3WebClass(system_level_install_, | 625 hresult = CreateGoogleUpdate3WebClass(system_level_install_, |
| 517 install_update_if_possible_, | 626 install_update_if_possible_, |
| 518 elevation_window_, &google_update_); | 627 elevation_window_, &google_update); |
| 519 if (FAILED(hresult)) { | 628 if (SUCCEEDED(hresult)) { |
| 520 *error_code = GOOGLE_UPDATE_ONDEMAND_CLASS_NOT_FOUND; | 629 ConfigureProxyBlanket(google_update.get()); |
| 521 return hresult; | 630 |
| 631 hresult = google_update_cookie_.Register(google_update); |
| 522 } | 632 } |
| 523 | 633 |
| 524 ConfigureProxyBlanket(google_update_.get()); | 634 if (FAILED(hresult)) |
| 635 return hresult; |
| 636 } else { |
| 637 hresult = google_update_cookie_.Get(&google_update); |
| 638 if (FAILED(hresult)) |
| 639 return hresult; |
| 525 } | 640 } |
| 526 | 641 |
| 527 // The class was created, so all subsequent errors are reported as: | 642 // The class was created, so all subsequent errors are reported as: |
| 528 *error_code = GOOGLE_UPDATE_ONDEMAND_CLASS_REPORTED_ERROR; | 643 *error_code = GOOGLE_UPDATE_ONDEMAND_CLASS_REPORTED_ERROR; |
| 529 | 644 |
| 530 // Create an app bundle. | 645 // Create or get the AppBundleWeb used to update Chrome. |
| 531 if (!app_bundle_) { | 646 if (!app_bundle_cookie_) { |
| 532 base::win::ScopedComPtr<IAppBundleWeb> app_bundle; | 647 base::win::ScopedComPtr<IAppBundleWeb> app_bundle; |
| 533 base::win::ScopedComPtr<IDispatch> dispatch; | 648 base::win::ScopedComPtr<IDispatch> dispatch; |
| 534 hresult = google_update_->createAppBundleWeb(dispatch.Receive()); | 649 hresult = google_update->createAppBundleWeb(dispatch.Receive()); |
| 535 if (FAILED(hresult)) | 650 if (FAILED(hresult)) |
| 536 return hresult; | 651 return hresult; |
| 537 hresult = dispatch.QueryInterface(app_bundle.Receive()); | 652 hresult = dispatch.QueryInterface(app_bundle.Receive()); |
| 538 if (FAILED(hresult)) | 653 if (FAILED(hresult)) |
| 539 return hresult; | 654 return hresult; |
| 540 dispatch.Release(); | 655 dispatch.Release(); |
| 541 | 656 |
| 542 ConfigureProxyBlanket(app_bundle.get()); | 657 ConfigureProxyBlanket(app_bundle.get()); |
| 543 | 658 |
| 544 if (!locale_.empty()) { | 659 if (!locale_.empty()) { |
| 545 // Ignore the result of this since, while setting the display language is | 660 // Ignore the result of this since, while setting the display language is |
| 546 // nice to have, a failure to do so does not affect the likelihood that | 661 // nice to have, a failure to do so does not affect the likelihood that |
| 547 // the update check and/or install will succeed. | 662 // the update check and/or install will succeed. |
| 548 app_bundle->put_displayLanguage( | 663 app_bundle->put_displayLanguage( |
| 549 base::win::ScopedBstr(base::UTF8ToUTF16(locale_).c_str())); | 664 base::win::ScopedBstr(base::UTF8ToUTF16(locale_).c_str())); |
| 550 } | 665 } |
| 551 | 666 |
| 552 hresult = app_bundle->initialize(); | 667 hresult = app_bundle->initialize(); |
| 553 if (FAILED(hresult)) | 668 if (FAILED(hresult)) |
| 554 return hresult; | 669 return hresult; |
| 555 if (elevation_window_) { | 670 if (elevation_window_) { |
| 556 // Likewise, a failure to set the parent window need not block an update | 671 // Likewise, a failure to set the parent window need not block an update |
| 557 // check. | 672 // check. |
| 558 app_bundle->put_parentHWND( | 673 app_bundle->put_parentHWND( |
| 559 reinterpret_cast<ULONG_PTR>(elevation_window_)); | 674 reinterpret_cast<ULONG_PTR>(elevation_window_)); |
| 560 } | 675 } |
| 561 app_bundle_.swap(app_bundle); | |
| 562 } | |
| 563 | |
| 564 // Get a reference to the Chrome app in the bundle. | |
| 565 if (!app_) { | |
| 566 base::string16 app_guid = | 676 base::string16 app_guid = |
| 567 installer::GetAppGuidForUpdates(system_level_install_); | 677 installer::GetAppGuidForUpdates(system_level_install_); |
| 568 DCHECK(!app_guid.empty()); | 678 DCHECK(!app_guid.empty()); |
| 569 | 679 |
| 570 base::win::ScopedComPtr<IDispatch> dispatch; | |
| 571 // It is common for this call to fail with APP_USING_EXTERNAL_UPDATER if | 680 // It is common for this call to fail with APP_USING_EXTERNAL_UPDATER if |
| 572 // an auto update is in progress. | 681 // an auto update is in progress. |
| 573 hresult = app_bundle_->createInstalledApp( | 682 hresult = |
| 574 base::win::ScopedBstr(app_guid.c_str())); | 683 app_bundle->createInstalledApp(base::win::ScopedBstr(app_guid.c_str())); |
| 575 if (FAILED(hresult)) | 684 if (FAILED(hresult)) |
| 576 return hresult; | 685 return hresult; |
| 577 // Move the IAppBundleWeb reference into a local now so that failures from | |
| 578 // this point onward result in it being released. | |
| 579 base::win::ScopedComPtr<IAppBundleWeb> app_bundle; | |
| 580 app_bundle.swap(app_bundle_); | |
| 581 hresult = app_bundle->get_appWeb(0, dispatch.Receive()); | |
| 582 if (FAILED(hresult)) | |
| 583 return hresult; | |
| 584 base::win::ScopedComPtr<IAppWeb> app; | |
| 585 hresult = dispatch.QueryInterface(app.Receive()); | |
| 586 if (FAILED(hresult)) | |
| 587 return hresult; | |
| 588 ConfigureProxyBlanket(app.get()); | |
| 589 hresult = app_bundle->checkForUpdate(); | 686 hresult = app_bundle->checkForUpdate(); |
| 590 if (FAILED(hresult)) | 687 if (FAILED(hresult)) |
| 591 return hresult; | 688 return hresult; |
| 592 app_bundle_.swap(app_bundle); | 689 |
| 593 app_.swap(app); | 690 hresult = app_bundle_cookie_.Register(app_bundle); |
| 691 if (FAILED(hresult)) |
| 692 return hresult; |
| 594 } | 693 } |
| 595 | 694 |
| 596 return hresult; | 695 return hresult; |
| 597 } | 696 } |
| 598 | 697 |
| 599 bool UpdateCheckDriver::GetCurrentState( | 698 bool UpdateCheckDriver::GetCurrentState( |
| 699 base::win::ScopedComPtr<IAppBundleWeb>* app_bundle, |
| 600 base::win::ScopedComPtr<ICurrentState>* current_state, | 700 base::win::ScopedComPtr<ICurrentState>* current_state, |
| 601 CurrentState* state_value, | 701 CurrentState* state_value, |
| 602 HRESULT* hresult) const { | 702 HRESULT* hresult) const { |
| 703 // Get the bundle being checked or updated. |
| 704 *hresult = app_bundle_cookie_.Get(app_bundle); |
| 705 if (FAILED(*hresult)) |
| 706 return false; |
| 707 |
| 708 // Get Chrome's app from the bundle. |
| 603 base::win::ScopedComPtr<IDispatch> dispatch; | 709 base::win::ScopedComPtr<IDispatch> dispatch; |
| 604 *hresult = app_->get_currentState(dispatch.Receive()); | 710 *hresult = (*app_bundle)->get_appWeb(0, dispatch.Receive()); |
| 711 if (FAILED(*hresult)) |
| 712 return false; |
| 713 base::win::ScopedComPtr<IAppWeb> app; |
| 714 *hresult = dispatch.QueryInterface(app.Receive()); |
| 715 if (FAILED(*hresult)) |
| 716 return false; |
| 717 dispatch.Release(); |
| 718 ConfigureProxyBlanket(app.get()); |
| 719 |
| 720 // Get the status of Chrome's update check or update. |
| 721 *hresult = app->get_currentState(dispatch.Receive()); |
| 605 if (FAILED(*hresult)) | 722 if (FAILED(*hresult)) |
| 606 return false; | 723 return false; |
| 607 *hresult = dispatch.QueryInterface(current_state->Receive()); | 724 *hresult = dispatch.QueryInterface(current_state->Receive()); |
| 608 if (FAILED(*hresult)) | 725 if (FAILED(*hresult)) |
| 609 return false; | 726 return false; |
| 727 dispatch.Release(); |
| 610 ConfigureProxyBlanket(current_state->get()); | 728 ConfigureProxyBlanket(current_state->get()); |
| 611 LONG value = 0; | 729 LONG value = 0; |
| 612 *hresult = (*current_state)->get_stateValue(&value); | 730 *hresult = (*current_state)->get_stateValue(&value); |
| 613 if (FAILED(*hresult)) | 731 if (FAILED(*hresult)) |
| 614 return false; | 732 return false; |
| 615 *state_value = static_cast<CurrentState>(value); | 733 *state_value = static_cast<CurrentState>(value); |
| 616 return true; | 734 return true; |
| 617 } | 735 } |
| 618 | 736 |
| 619 bool UpdateCheckDriver::IsErrorState( | 737 bool UpdateCheckDriver::IsErrorState( |
| 738 const base::win::ScopedComPtr<IAppBundleWeb>& app_bundle, |
| 620 const base::win::ScopedComPtr<ICurrentState>& current_state, | 739 const base::win::ScopedComPtr<ICurrentState>& current_state, |
| 621 CurrentState state_value, | 740 CurrentState state_value, |
| 622 GoogleUpdateErrorCode* error_code, | 741 GoogleUpdateErrorCode* error_code, |
| 623 HRESULT* hresult, | 742 HRESULT* hresult, |
| 624 int* installer_exit_code, | 743 int* installer_exit_code, |
| 625 base::string16* error_string) const { | 744 base::string16* error_string) const { |
| 626 if (state_value == STATE_ERROR) { | 745 if (state_value == STATE_ERROR) { |
| 627 // In general, errors reported by Google Update fall under this category | 746 // In general, errors reported by Google Update fall under this category |
| 628 // (see special case below). | 747 // (see special case below). |
| 629 *error_code = GOOGLE_UPDATE_ERROR_UPDATING; | 748 *error_code = GOOGLE_UPDATE_ERROR_UPDATING; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 654 *installer_exit_code = code; | 773 *installer_exit_code = code; |
| 655 } | 774 } |
| 656 | 775 |
| 657 base::win::ScopedBstr message; | 776 base::win::ScopedBstr message; |
| 658 if (SUCCEEDED(current_state->get_completionMessage(message.Receive()))) | 777 if (SUCCEEDED(current_state->get_completionMessage(message.Receive()))) |
| 659 error_string->assign(message, message.Length()); | 778 error_string->assign(message, message.Length()); |
| 660 | 779 |
| 661 return true; | 780 return true; |
| 662 } | 781 } |
| 663 if (state_value == STATE_UPDATE_AVAILABLE && install_update_if_possible_) { | 782 if (state_value == STATE_UPDATE_AVAILABLE && install_update_if_possible_) { |
| 664 *hresult = app_bundle_->install(); | 783 *hresult = app_bundle->install(); |
| 665 if (FAILED(*hresult)) { | 784 if (FAILED(*hresult)) { |
| 666 // Report a failure to start the install as a general error while trying | 785 // Report a failure to start the install as a general error while trying |
| 667 // to interact with Google Update. | 786 // to interact with Google Update. |
| 668 *error_code = GOOGLE_UPDATE_ONDEMAND_CLASS_REPORTED_ERROR; | 787 *error_code = GOOGLE_UPDATE_ONDEMAND_CLASS_REPORTED_ERROR; |
| 669 *installer_exit_code = -1; | 788 *installer_exit_code = -1; |
| 670 return true; | 789 return true; |
| 671 } | 790 } |
| 672 // Return false for handling in IsIntermediateState. | 791 // Return false for handling in IsIntermediateState. |
| 673 } | 792 } |
| 674 return false; | 793 return false; |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 767 case STATE_ERROR: | 886 case STATE_ERROR: |
| 768 default: | 887 default: |
| 769 NOTREACHED(); | 888 NOTREACHED(); |
| 770 UMA_HISTOGRAM_SPARSE_SLOWLY("GoogleUpdate.UnexpectedState", state_value); | 889 UMA_HISTOGRAM_SPARSE_SLOWLY("GoogleUpdate.UnexpectedState", state_value); |
| 771 return false; | 890 return false; |
| 772 } | 891 } |
| 773 return true; | 892 return true; |
| 774 } | 893 } |
| 775 | 894 |
| 776 void UpdateCheckDriver::PollGoogleUpdate() { | 895 void UpdateCheckDriver::PollGoogleUpdate() { |
| 896 base::win::ScopedComPtr<IAppBundleWeb> app_bundle; |
| 777 base::win::ScopedComPtr<ICurrentState> state; | 897 base::win::ScopedComPtr<ICurrentState> state; |
| 778 CurrentState state_value = STATE_INIT; | 898 CurrentState state_value = STATE_INIT; |
| 779 HRESULT hresult = S_OK; | 899 HRESULT hresult = S_OK; |
| 780 GoogleUpdateErrorCode error_code = GOOGLE_UPDATE_NO_ERROR; | 900 GoogleUpdateErrorCode error_code = GOOGLE_UPDATE_NO_ERROR; |
| 781 int installer_exit_code = -1; | 901 int installer_exit_code = -1; |
| 782 base::string16 error_string; | 902 base::string16 error_string; |
| 783 GoogleUpdateUpgradeStatus upgrade_status = UPGRADE_ERROR; | 903 GoogleUpdateUpgradeStatus upgrade_status = UPGRADE_ERROR; |
| 784 base::string16 new_version; | 904 base::string16 new_version; |
| 785 int progress = 0; | 905 int progress = 0; |
| 786 | 906 |
| 787 if (!GetCurrentState(&state, &state_value, &hresult)) { | 907 if (!GetCurrentState(&app_bundle, &state, &state_value, &hresult)) { |
| 788 OnUpgradeError(GOOGLE_UPDATE_ONDEMAND_CLASS_REPORTED_ERROR, hresult, -1, | 908 OnUpgradeError(GOOGLE_UPDATE_ONDEMAND_CLASS_REPORTED_ERROR, hresult, -1, |
| 789 base::string16()); | 909 base::string16()); |
| 790 } else if (IsErrorState(state, state_value, &error_code, &hresult, | 910 } else if (IsErrorState(app_bundle, state, state_value, &error_code, &hresult, |
| 791 &installer_exit_code, &error_string)) { | 911 &installer_exit_code, &error_string)) { |
| 792 OnUpgradeError(error_code, hresult, installer_exit_code, error_string); | 912 OnUpgradeError(error_code, hresult, installer_exit_code, error_string); |
| 793 } else if (IsFinalState(state, state_value, &upgrade_status, &new_version)) { | 913 } else if (IsFinalState(state, state_value, &upgrade_status, &new_version)) { |
| 794 status_ = upgrade_status; | 914 status_ = upgrade_status; |
| 795 error_code_ = GOOGLE_UPDATE_NO_ERROR; | 915 error_code_ = GOOGLE_UPDATE_NO_ERROR; |
| 796 html_error_message_.clear(); | 916 html_error_message_.clear(); |
| 797 if (!new_version.empty()) | 917 if (!new_version.empty()) |
| 798 new_version_ = new_version; | 918 new_version_ = new_version; |
| 799 hresult_ = S_OK; | 919 hresult_ = S_OK; |
| 800 installer_exit_code_ = -1; | 920 installer_exit_code_ = -1; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 817 // Schedule the next check. | 937 // Schedule the next check. |
| 818 task_runner_->PostDelayedTask( | 938 task_runner_->PostDelayedTask( |
| 819 FROM_HERE, base::Bind(&UpdateCheckDriver::PollGoogleUpdate, | 939 FROM_HERE, base::Bind(&UpdateCheckDriver::PollGoogleUpdate, |
| 820 base::Unretained(this)), | 940 base::Unretained(this)), |
| 821 base::TimeDelta::FromMilliseconds(kGoogleUpdatePollIntervalMs)); | 941 base::TimeDelta::FromMilliseconds(kGoogleUpdatePollIntervalMs)); |
| 822 // Early return for this non-terminal state. | 942 // Early return for this non-terminal state. |
| 823 return; | 943 return; |
| 824 } | 944 } |
| 825 | 945 |
| 826 // Release the reference on the COM objects before bouncing back to the | 946 // Release the reference on the COM objects before bouncing back to the |
| 827 // caller's thread. | 947 // caller's task runner. |
| 828 state.Release(); | 948 state.Release(); |
| 829 app_.Release(); | 949 app_bundle.Release(); |
| 830 app_bundle_.Release(); | 950 app_bundle_cookie_.Revoke(); |
| 831 google_update_.Release(); | 951 google_update_cookie_.Revoke(); |
| 832 | 952 |
| 833 result_runner_->DeleteSoon(FROM_HERE, this); | 953 result_runner_->DeleteSoon(FROM_HERE, this); |
| 834 } | 954 } |
| 835 | 955 |
| 836 void UpdateCheckDriver::OnUpgradeError(GoogleUpdateErrorCode error_code, | 956 void UpdateCheckDriver::OnUpgradeError(GoogleUpdateErrorCode error_code, |
| 837 HRESULT hresult, | 957 HRESULT hresult, |
| 838 int installer_exit_code, | 958 int installer_exit_code, |
| 839 const base::string16& error_string) { | 959 const base::string16& error_string) { |
| 840 status_ = UPGRADE_ERROR; | 960 status_ = UPGRADE_ERROR; |
| 841 error_code_ = error_code; | 961 error_code_ = error_code; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 858 html_error_msg += base::StringPrintf(L": %d", installer_exit_code_); | 978 html_error_msg += base::StringPrintf(L": %d", installer_exit_code_); |
| 859 if (system_level_install_) | 979 if (system_level_install_) |
| 860 html_error_msg += L" -- system level"; | 980 html_error_msg += L" -- system level"; |
| 861 if (error_string.empty()) { | 981 if (error_string.empty()) { |
| 862 html_error_message_ = l10n_util::GetStringFUTF16( | 982 html_error_message_ = l10n_util::GetStringFUTF16( |
| 863 IDS_ABOUT_BOX_ERROR_UPDATE_CHECK_FAILED, html_error_msg); | 983 IDS_ABOUT_BOX_ERROR_UPDATE_CHECK_FAILED, html_error_msg); |
| 864 } else { | 984 } else { |
| 865 html_error_message_ = l10n_util::GetStringFUTF16( | 985 html_error_message_ = l10n_util::GetStringFUTF16( |
| 866 IDS_ABOUT_BOX_GOOGLE_UPDATE_ERROR, error_string, html_error_msg); | 986 IDS_ABOUT_BOX_GOOGLE_UPDATE_ERROR, error_string, html_error_msg); |
| 867 } | 987 } |
| 988 |
| 989 app_bundle_cookie_.Revoke(); |
| 990 google_update_cookie_.Revoke(); |
| 868 } | 991 } |
| 869 | 992 |
| 870 } // namespace | 993 } // namespace |
| 871 | 994 |
| 872 | 995 |
| 873 // Globals --------------------------------------------------------------------- | 996 // Globals --------------------------------------------------------------------- |
| 874 | 997 |
| 875 void BeginUpdateCheck( | 998 void BeginUpdateCheck(scoped_refptr<base::SequencedTaskRunner> task_runner, |
| 876 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 999 const std::string& locale, |
| 877 const std::string& locale, | 1000 bool install_update_if_possible, |
| 878 bool install_update_if_possible, | 1001 gfx::AcceleratedWidget elevation_window, |
| 879 gfx::AcceleratedWidget elevation_window, | 1002 const base::WeakPtr<UpdateCheckDelegate>& delegate) { |
| 880 const base::WeakPtr<UpdateCheckDelegate>& delegate) { | |
| 881 UpdateCheckDriver::RunUpdateCheck(std::move(task_runner), locale, | 1003 UpdateCheckDriver::RunUpdateCheck(std::move(task_runner), locale, |
| 882 install_update_if_possible, | 1004 install_update_if_possible, |
| 883 elevation_window, delegate); | 1005 elevation_window, delegate); |
| 884 } | 1006 } |
| 885 | 1007 |
| 886 | 1008 |
| 887 // Private API exposed for testing. -------------------------------------------- | 1009 // Private API exposed for testing. -------------------------------------------- |
| 888 | 1010 |
| 889 void SetGoogleUpdateFactoryForTesting( | 1011 void SetUpdateCheckFactoriesForTesting( |
| 1012 const GlobalInterfaceTableClassFactory& global_interface_table_factory, |
| 890 const GoogleUpdate3ClassFactory& google_update_factory) { | 1013 const GoogleUpdate3ClassFactory& google_update_factory) { |
| 1014 if (g_global_interface_table_factory) { |
| 1015 delete g_global_interface_table_factory; |
| 1016 g_global_interface_table_factory = nullptr; |
| 1017 } |
| 1018 if (!global_interface_table_factory.is_null()) |
| 1019 g_global_interface_table_factory = |
| 1020 new GlobalInterfaceTableClassFactory(global_interface_table_factory); |
| 1021 |
| 891 if (g_google_update_factory) { | 1022 if (g_google_update_factory) { |
| 892 delete g_google_update_factory; | 1023 delete g_google_update_factory; |
| 893 g_google_update_factory = nullptr; | 1024 g_google_update_factory = nullptr; |
| 894 } | 1025 } |
| 895 if (!google_update_factory.is_null()) { | 1026 if (!google_update_factory.is_null()) { |
| 896 g_google_update_factory = | 1027 g_google_update_factory = |
| 897 new GoogleUpdate3ClassFactory(google_update_factory); | 1028 new GoogleUpdate3ClassFactory(google_update_factory); |
| 898 } | 1029 } |
| 899 } | 1030 } |
| OLD | NEW |