Chromium Code Reviews| 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 <objbase.h> | 9 #include <objbase.h> |
| 10 #include <stdint.h> | 10 #include <stdint.h> |
| 11 #include <string.h> | 11 #include <string.h> |
| 12 | 12 |
| 13 #include <string> | 13 #include <string> |
| 14 #include <utility> | 14 #include <utility> |
| 15 #include <vector> | 15 #include <vector> |
| 16 | 16 |
| 17 #include "base/bind.h" | 17 #include "base/bind.h" |
| 18 #include "base/callback.h" | 18 #include "base/callback.h" |
| 19 #include "base/files/file_path.h" | 19 #include "base/files/file_path.h" |
| 20 #include "base/location.h" | 20 #include "base/location.h" |
| 21 #include "base/macros.h" | 21 #include "base/macros.h" |
| 22 #include "base/metrics/histogram_macros.h" | 22 #include "base/metrics/histogram_macros.h" |
| 23 #include "base/metrics/sparse_histogram.h" | 23 #include "base/metrics/sparse_histogram.h" |
| 24 #include "base/path_service.h" | 24 #include "base/path_service.h" |
| 25 #include "base/sequenced_task_runner_helpers.h" | 25 #include "base/sequenced_task_runner_helpers.h" |
| 26 #include "base/single_thread_task_runner.h" | 26 #include "base/single_thread_task_runner.h" |
| 27 #include "base/strings/string_util.h" | 27 #include "base/strings/string_util.h" |
| 28 #include "base/strings/stringprintf.h" | 28 #include "base/strings/stringprintf.h" |
| 29 #include "base/strings/utf_string_conversions.h" | 29 #include "base/strings/utf_string_conversions.h" |
| 30 #include "base/task_scheduler/post_task.h" | |
| 31 #include "base/task_scheduler/task_traits.h" | |
| 30 #include "base/threading/thread_task_runner_handle.h" | 32 #include "base/threading/thread_task_runner_handle.h" |
| 31 #include "base/time/time.h" | 33 #include "base/time/time.h" |
| 32 #include "base/version.h" | 34 #include "base/version.h" |
| 33 #include "base/win/scoped_bstr.h" | 35 #include "base/win/scoped_bstr.h" |
| 34 #include "base/win/windows_version.h" | 36 #include "base/win/windows_version.h" |
| 35 #include "chrome/common/url_constants.h" | 37 #include "chrome/common/url_constants.h" |
| 36 #include "chrome/grit/generated_resources.h" | 38 #include "chrome/grit/generated_resources.h" |
| 37 #include "chrome/install_static/install_util.h" | 39 #include "chrome/install_static/install_util.h" |
| 38 #include "chrome/installer/util/google_update_settings.h" | 40 #include "chrome/installer/util/google_update_settings.h" |
| 39 #include "chrome/installer/util/helper.h" | 41 #include "chrome/installer/util/helper.h" |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 198 return class_factory->CreateInstance( | 200 return class_factory->CreateInstance( |
| 199 nullptr, IID_PPV_ARGS(google_update->GetAddressOf())); | 201 nullptr, IID_PPV_ARGS(google_update->GetAddressOf())); |
| 200 } | 202 } |
| 201 | 203 |
| 202 // UpdateCheckDriver ----------------------------------------------------------- | 204 // UpdateCheckDriver ----------------------------------------------------------- |
| 203 | 205 |
| 204 // A driver that is created and destroyed on the caller's thread and drives | 206 // A driver that is created and destroyed on the caller's thread and drives |
| 205 // Google Update on another. | 207 // Google Update on another. |
| 206 class UpdateCheckDriver { | 208 class UpdateCheckDriver { |
| 207 public: | 209 public: |
| 208 // Runs an update check on |task_runner|, invoking methods of |delegate| on | 210 // Runs an update check, invoking methods of |delegate| on the caller's thread |
| 209 // the caller's thread to report progress and final results. | 211 // to report progress and final results. |
| 210 static void RunUpdateCheck( | 212 static void RunUpdateCheck( |
| 211 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | |
| 212 const std::string& locale, | 213 const std::string& locale, |
| 213 bool install_update_if_possible, | 214 bool install_update_if_possible, |
| 214 gfx::AcceleratedWidget elevation_window, | 215 gfx::AcceleratedWidget elevation_window, |
| 215 const base::WeakPtr<UpdateCheckDelegate>& delegate); | 216 const base::WeakPtr<UpdateCheckDelegate>& delegate); |
| 216 | 217 |
| 217 private: | 218 private: |
| 218 friend class base::DeleteHelper<UpdateCheckDriver>; | 219 friend class base::DeleteHelper<UpdateCheckDriver>; |
| 219 | 220 |
| 220 UpdateCheckDriver( | 221 UpdateCheckDriver( |
| 221 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | |
| 222 const std::string& locale, | 222 const std::string& locale, |
| 223 bool install_update_if_possible, | 223 bool install_update_if_possible, |
| 224 gfx::AcceleratedWidget elevation_window, | 224 gfx::AcceleratedWidget elevation_window, |
| 225 const base::WeakPtr<UpdateCheckDelegate>& delegate); | 225 const base::WeakPtr<UpdateCheckDelegate>& delegate); |
| 226 | 226 |
| 227 // Invokes a completion or error method on all delegates, as appropriate. | 227 // Invokes a completion or error method on all delegates, as appropriate. |
| 228 ~UpdateCheckDriver(); | 228 ~UpdateCheckDriver(); |
| 229 | 229 |
| 230 // If an UpdateCheckDriver is already running, the delegate is added to the | 230 // If an UpdateCheckDriver is already running, the delegate is added to the |
| 231 // existing one instead of creating a new one. | 231 // existing one instead of creating a new one. |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 362 HRESULT hresult_; | 362 HRESULT hresult_; |
| 363 int installer_exit_code_; | 363 int installer_exit_code_; |
| 364 | 364 |
| 365 DISALLOW_COPY_AND_ASSIGN(UpdateCheckDriver); | 365 DISALLOW_COPY_AND_ASSIGN(UpdateCheckDriver); |
| 366 }; | 366 }; |
| 367 | 367 |
| 368 UpdateCheckDriver* UpdateCheckDriver::driver_ = nullptr; | 368 UpdateCheckDriver* UpdateCheckDriver::driver_ = nullptr; |
| 369 | 369 |
| 370 // static | 370 // static |
| 371 void UpdateCheckDriver::RunUpdateCheck( | 371 void UpdateCheckDriver::RunUpdateCheck( |
| 372 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | |
| 373 const std::string& locale, | 372 const std::string& locale, |
| 374 bool install_update_if_possible, | 373 bool install_update_if_possible, |
| 375 gfx::AcceleratedWidget elevation_window, | 374 gfx::AcceleratedWidget elevation_window, |
| 376 const base::WeakPtr<UpdateCheckDelegate>& delegate) { | 375 const base::WeakPtr<UpdateCheckDelegate>& delegate) { |
| 377 // Create the driver if it doesn't exist, or add the delegate to the existing | 376 // Create the driver if it doesn't exist, or add the delegate to the existing |
| 378 // one. | 377 // one. |
| 379 if (!driver_) { | 378 if (!driver_) { |
| 380 // The driver is owned by itself, and will self-destruct when its work is | 379 // The driver is owned by itself, and will self-destruct when its work is |
| 381 // done. | 380 // done. |
| 382 driver_ = | 381 driver_ = new UpdateCheckDriver(locale, install_update_if_possible, |
| 383 new UpdateCheckDriver(task_runner, locale, install_update_if_possible, | 382 elevation_window, delegate); |
| 384 elevation_window, delegate); | 383 driver_->task_runner_->PostTask( |
| 385 task_runner->PostTask(FROM_HERE, | 384 FROM_HERE, base::Bind(&UpdateCheckDriver::BeginUpdateCheck, |
| 386 base::Bind(&UpdateCheckDriver::BeginUpdateCheck, | 385 base::Unretained(driver_))); |
| 387 base::Unretained(driver_))); | |
| 388 } else { | 386 } else { |
| 389 DCHECK_EQ(driver_->task_runner_, task_runner); | |
| 390 driver_->AddDelegate(delegate); | 387 driver_->AddDelegate(delegate); |
| 391 } | 388 } |
| 392 } | 389 } |
| 393 | 390 |
| 394 // Runs on the caller's thread. | 391 // Runs on the caller's thread. |
| 395 UpdateCheckDriver::UpdateCheckDriver( | 392 UpdateCheckDriver::UpdateCheckDriver( |
| 396 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | |
| 397 const std::string& locale, | 393 const std::string& locale, |
| 398 bool install_update_if_possible, | 394 bool install_update_if_possible, |
| 399 gfx::AcceleratedWidget elevation_window, | 395 gfx::AcceleratedWidget elevation_window, |
| 400 const base::WeakPtr<UpdateCheckDelegate>& delegate) | 396 const base::WeakPtr<UpdateCheckDelegate>& delegate) |
| 401 : task_runner_(std::move(task_runner)), | 397 : task_runner_(base::CreateSingleThreadTaskRunnerWithTraits( |
|
gab
2017/07/17 17:14:40
Does CreateSequencedTaskRunnerWithTraits() work?
calamity
2017/07/19 09:03:38
Seems to.
| |
| 398 {base::MayBlock(), base::TaskPriority::USER_VISIBLE})), | |
| 402 result_runner_(base::ThreadTaskRunnerHandle::Get()), | 399 result_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 403 locale_(locale), | 400 locale_(locale), |
| 404 install_update_if_possible_(install_update_if_possible), | 401 install_update_if_possible_(install_update_if_possible), |
| 405 elevation_window_(elevation_window), | 402 elevation_window_(elevation_window), |
| 406 delegates_(1, delegate), | 403 delegates_(1, delegate), |
| 407 allowed_retries_(kGoogleAllowedRetries), | 404 allowed_retries_(kGoogleAllowedRetries), |
| 408 system_level_install_(false), | 405 system_level_install_(false), |
| 409 last_reported_progress_(0), | 406 last_reported_progress_(0), |
| 410 status_(UPGRADE_ERROR), | 407 status_(UPGRADE_ERROR), |
| 411 error_code_(GOOGLE_UPDATE_NO_ERROR), | 408 error_code_(GOOGLE_UPDATE_NO_ERROR), |
| (...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 860 IDS_ABOUT_BOX_GOOGLE_UPDATE_ERROR, error_string, html_error_msg); | 857 IDS_ABOUT_BOX_GOOGLE_UPDATE_ERROR, error_string, html_error_msg); |
| 861 } | 858 } |
| 862 } | 859 } |
| 863 | 860 |
| 864 } // namespace | 861 } // namespace |
| 865 | 862 |
| 866 | 863 |
| 867 // Globals --------------------------------------------------------------------- | 864 // Globals --------------------------------------------------------------------- |
| 868 | 865 |
| 869 void BeginUpdateCheck( | 866 void BeginUpdateCheck( |
| 870 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | |
| 871 const std::string& locale, | 867 const std::string& locale, |
| 872 bool install_update_if_possible, | 868 bool install_update_if_possible, |
| 873 gfx::AcceleratedWidget elevation_window, | 869 gfx::AcceleratedWidget elevation_window, |
| 874 const base::WeakPtr<UpdateCheckDelegate>& delegate) { | 870 const base::WeakPtr<UpdateCheckDelegate>& delegate) { |
| 875 UpdateCheckDriver::RunUpdateCheck(std::move(task_runner), locale, | 871 UpdateCheckDriver::RunUpdateCheck(locale, install_update_if_possible, |
| 876 install_update_if_possible, | |
| 877 elevation_window, delegate); | 872 elevation_window, delegate); |
| 878 } | 873 } |
| 879 | 874 |
| 880 | 875 |
| 881 // Private API exposed for testing. -------------------------------------------- | 876 // Private API exposed for testing. -------------------------------------------- |
| 882 | 877 |
| 883 void SetGoogleUpdateFactoryForTesting( | 878 void SetGoogleUpdateFactoryForTesting( |
| 884 const GoogleUpdate3ClassFactory& google_update_factory) { | 879 const GoogleUpdate3ClassFactory& google_update_factory) { |
| 885 if (g_google_update_factory) { | 880 if (g_google_update_factory) { |
| 886 delete g_google_update_factory; | 881 delete g_google_update_factory; |
| 887 g_google_update_factory = nullptr; | 882 g_google_update_factory = nullptr; |
| 888 } | 883 } |
| 889 if (!google_update_factory.is_null()) { | 884 if (!google_update_factory.is_null()) { |
| 890 g_google_update_factory = | 885 g_google_update_factory = |
| 891 new GoogleUpdate3ClassFactory(google_update_factory); | 886 new GoogleUpdate3ClassFactory(google_update_factory); |
| 892 } | 887 } |
| 893 } | 888 } |
| OLD | NEW |