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