| 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/ui/webui/help/version_updater_win.h" | 5 #include "chrome/browser/ui/webui/help/version_updater_win.h" |
| 6 | 6 |
| 7 #include "base/memory/weak_ptr.h" | 7 #include "base/memory/weak_ptr.h" |
| 8 #include "base/task_runner_util.h" | 8 #include "base/task_scheduler/post_task.h" |
| 9 #include "base/threading/sequenced_worker_pool.h" | |
| 10 #include "base/win/win_util.h" | 9 #include "base/win/win_util.h" |
| 11 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/first_run/upgrade_util.h" | 11 #include "chrome/browser/first_run/upgrade_util.h" |
| 13 #include "chrome/grit/generated_resources.h" | 12 #include "chrome/grit/generated_resources.h" |
| 14 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
| 15 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
| 16 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
| 17 #include "ui/aura/window_tree_host.h" | 16 #include "ui/aura/window_tree_host.h" |
| 18 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
| 19 #include "ui/gfx/native_widget_types.h" | 18 #include "ui/gfx/native_widget_types.h" |
| 20 | 19 |
| 21 VersionUpdaterWin::VersionUpdaterWin(gfx::AcceleratedWidget owner_widget) | 20 VersionUpdaterWin::VersionUpdaterWin(gfx::AcceleratedWidget owner_widget) |
| 22 : owner_widget_(owner_widget), weak_factory_(this) { | 21 : owner_widget_(owner_widget), weak_factory_(this) { |
| 23 } | 22 } |
| 24 | 23 |
| 25 VersionUpdaterWin::~VersionUpdaterWin() { | 24 VersionUpdaterWin::~VersionUpdaterWin() { |
| 26 } | 25 } |
| 27 | 26 |
| 28 void VersionUpdaterWin::CheckForUpdate(const StatusCallback& callback, | 27 void VersionUpdaterWin::CheckForUpdate(const StatusCallback& callback, |
| 29 const PromoteCallback&) { | 28 const PromoteCallback&) { |
| 30 // There is no supported integration with Google Update for Chromium. | 29 // There is no supported integration with Google Update for Chromium. |
| 31 callback_ = callback; | 30 callback_ = callback; |
| 32 | 31 |
| 33 callback_.Run(CHECKING, 0, std::string(), 0, base::string16()); | 32 callback_.Run(CHECKING, 0, std::string(), 0, base::string16()); |
| 34 BeginUpdateCheckOnFileThread(false /* !install_update_if_possible */); | 33 DoBeginUpdateCheck(false /* !install_update_if_possible */); |
| 35 } | 34 } |
| 36 | 35 |
| 37 void VersionUpdaterWin::OnUpdateCheckComplete( | 36 void VersionUpdaterWin::OnUpdateCheckComplete( |
| 38 const base::string16& new_version) { | 37 const base::string16& new_version) { |
| 39 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 38 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 40 Status status = CHECKING; | |
| 41 if (new_version.empty()) { | 39 if (new_version.empty()) { |
| 42 // Google Update says that no new version is available. Check to see if a | 40 // Google Update says that no new version is available. Check to see if a |
| 43 // restart is needed for a previously-applied update to take effect. | 41 // restart is needed for a previously-applied update to take effect. |
| 44 if (base::PostTaskAndReplyWithResult( | 42 base::PostTaskWithTraitsAndReplyWithResult( |
| 45 content::BrowserThread::GetBlockingPool(), | 43 FROM_HERE, {base::MayBlock(), base::TaskPriority::USER_VISIBLE}, |
| 46 FROM_HERE, | 44 base::Bind(&upgrade_util::IsUpdatePendingRestart), |
| 47 base::Bind(&upgrade_util::IsUpdatePendingRestart), | 45 base::Bind(&VersionUpdaterWin::OnPendingRestartCheck, |
| 48 base::Bind(&VersionUpdaterWin::OnPendingRestartCheck, | 46 weak_factory_.GetWeakPtr())); |
| 49 weak_factory_.GetWeakPtr()))) { | 47 // Early exit since callback_ will be Run in OnPendingRestartCheck. |
| 50 // Early exit since callback_ will be Run in OnPendingRestartCheck. | 48 return; |
| 51 return; | |
| 52 } | |
| 53 // Failure to post the task means that Chrome is shutting down. A pending | |
| 54 // update (if there is one) will be applied as Chrome exits, so tell the | |
| 55 // caller that it is up to date in either case. | |
| 56 status = UPDATED; | |
| 57 } else { | |
| 58 // Notify the caller that the update is now beginning and initiate it. | |
| 59 status = UPDATING; | |
| 60 BeginUpdateCheckOnFileThread(true /* install_update_if_possible */); | |
| 61 } | 49 } |
| 62 callback_.Run(status, 0, std::string(), 0, base::string16()); | 50 |
| 51 // Notify the caller that the update is now beginning and initiate it. |
| 52 DoBeginUpdateCheck(true /* install_update_if_possible */); |
| 53 callback_.Run(UPDATING, 0, std::string(), 0, base::string16()); |
| 63 } | 54 } |
| 64 | 55 |
| 65 void VersionUpdaterWin::OnUpgradeProgress(int progress, | 56 void VersionUpdaterWin::OnUpgradeProgress(int progress, |
| 66 const base::string16& new_version) { | 57 const base::string16& new_version) { |
| 67 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 58 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 68 callback_.Run(UPDATING, progress, std::string(), 0, base::string16()); | 59 callback_.Run(UPDATING, progress, std::string(), 0, base::string16()); |
| 69 } | 60 } |
| 70 | 61 |
| 71 void VersionUpdaterWin::OnUpgradeComplete(const base::string16& new_version) { | 62 void VersionUpdaterWin::OnUpgradeComplete(const base::string16& new_version) { |
| 72 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 63 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 97 message = l10n_util::GetStringFUTF16Int(IDS_UPGRADE_ERROR, error_code); | 88 message = l10n_util::GetStringFUTF16Int(IDS_UPGRADE_ERROR, error_code); |
| 98 } else { | 89 } else { |
| 99 message = l10n_util::GetStringFUTF16( | 90 message = l10n_util::GetStringFUTF16( |
| 100 IDS_ABOUT_BOX_ERROR_DURING_UPDATE_CHECK, html_error_message); | 91 IDS_ABOUT_BOX_ERROR_DURING_UPDATE_CHECK, html_error_message); |
| 101 } | 92 } |
| 102 break; | 93 break; |
| 103 } | 94 } |
| 104 callback_.Run(status, 0, std::string(), 0, message); | 95 callback_.Run(status, 0, std::string(), 0, message); |
| 105 } | 96 } |
| 106 | 97 |
| 107 void VersionUpdaterWin::BeginUpdateCheckOnFileThread( | 98 void VersionUpdaterWin::DoBeginUpdateCheck(bool install_update_if_possible) { |
| 108 bool install_update_if_possible) { | |
| 109 // Disconnect from any previous attempts to avoid redundant callbacks. | 99 // Disconnect from any previous attempts to avoid redundant callbacks. |
| 110 weak_factory_.InvalidateWeakPtrs(); | 100 weak_factory_.InvalidateWeakPtrs(); |
| 111 BeginUpdateCheck(content::BrowserThread::GetTaskRunnerForThread( | 101 BeginUpdateCheck(g_browser_process->GetApplicationLocale(), |
| 112 content::BrowserThread::FILE), | |
| 113 g_browser_process->GetApplicationLocale(), | |
| 114 install_update_if_possible, owner_widget_, | 102 install_update_if_possible, owner_widget_, |
| 115 weak_factory_.GetWeakPtr()); | 103 weak_factory_.GetWeakPtr()); |
| 116 } | 104 } |
| 117 | 105 |
| 118 void VersionUpdaterWin::OnPendingRestartCheck(bool is_update_pending_restart) { | 106 void VersionUpdaterWin::OnPendingRestartCheck(bool is_update_pending_restart) { |
| 119 callback_.Run(is_update_pending_restart ? NEARLY_UPDATED : UPDATED, 0, | 107 callback_.Run(is_update_pending_restart ? NEARLY_UPDATED : UPDATED, 0, |
| 120 std::string(), 0, base::string16()); | 108 std::string(), 0, base::string16()); |
| 121 } | 109 } |
| 122 | 110 |
| 123 VersionUpdater* VersionUpdater::Create(content::WebContents* web_contents) { | 111 VersionUpdater* VersionUpdater::Create(content::WebContents* web_contents) { |
| 124 // Retrieve the HWND for the browser window that is hosting the update check. | 112 // Retrieve the HWND for the browser window that is hosting the update check. |
| 125 // This will be used as the parent for a UAC prompt, if needed. It's possible | 113 // This will be used as the parent for a UAC prompt, if needed. It's possible |
| 126 // this this window will no longer have focus by the time UAC is needed. In | 114 // this this window will no longer have focus by the time UAC is needed. In |
| 127 // that case, the UAC prompt will appear in the taskbar and will require a | 115 // that case, the UAC prompt will appear in the taskbar and will require a |
| 128 // user click. This is the least surprising thing we can do for the user, and | 116 // user click. This is the least surprising thing we can do for the user, and |
| 129 // is the intended behavior for Windows applications. | 117 // is the intended behavior for Windows applications. |
| 130 // It's also possible that the browser window hosting the update check will | 118 // It's also possible that the browser window hosting the update check will |
| 131 // have been closed by the time the UAC prompt is needed. In this case, the | 119 // have been closed by the time the UAC prompt is needed. In this case, the |
| 132 // web contents may no longer be hosted in a window, leading either | 120 // web contents may no longer be hosted in a window, leading either |
| 133 // GetTopLevelNativeWindow or GetHost to return null. Passing nullptr to | 121 // GetTopLevelNativeWindow or GetHost to return null. Passing nullptr to |
| 134 // VersionUpdaterWin will then also cause the UAC prompt to appear in the task | 122 // VersionUpdaterWin will then also cause the UAC prompt to appear in the task |
| 135 // bar. | 123 // bar. |
| 136 gfx::NativeWindow window = web_contents->GetTopLevelNativeWindow(); | 124 gfx::NativeWindow window = web_contents->GetTopLevelNativeWindow(); |
| 137 aura::WindowTreeHost* window_tree_host = window ? window->GetHost() : nullptr; | 125 aura::WindowTreeHost* window_tree_host = window ? window->GetHost() : nullptr; |
| 138 return new VersionUpdaterWin( | 126 return new VersionUpdaterWin( |
| 139 window_tree_host ? window_tree_host->GetAcceleratedWidget() : nullptr); | 127 window_tree_host ? window_tree_host->GetAcceleratedWidget() : nullptr); |
| 140 } | 128 } |
| OLD | NEW |