| 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 "base/win/windows_version.h" | 10 #include "base/win/windows_version.h" |
| 12 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
| 13 #include "chrome/browser/first_run/upgrade_util.h" | 12 #include "chrome/browser/first_run/upgrade_util.h" |
| 14 #include "chrome/grit/generated_resources.h" | 13 #include "chrome/grit/generated_resources.h" |
| 15 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 16 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
| 17 #include "ui/aura/window.h" | 16 #include "ui/aura/window.h" |
| 18 #include "ui/aura/window_tree_host.h" | 17 #include "ui/aura/window_tree_host.h" |
| 19 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 33 | 32 |
| 34 // On-demand updates for Chrome don't work in Vista RTM when UAC is turned | 33 // On-demand updates for Chrome don't work in Vista RTM when UAC is turned |
| 35 // off. So, in this case, the version updater must not mention | 34 // off. So, in this case, the version updater must not mention |
| 36 // on-demand updates. Silent updates (in the background) should still | 35 // on-demand updates. Silent updates (in the background) should still |
| 37 // work as before - enabling UAC or installing the latest service pack | 36 // work as before - enabling UAC or installing the latest service pack |
| 38 // for Vista is another option. | 37 // for Vista is another option. |
| 39 if (!(base::win::GetVersion() == base::win::VERSION_VISTA && | 38 if (!(base::win::GetVersion() == base::win::VERSION_VISTA && |
| 40 (base::win::OSInfo::GetInstance()->service_pack().major == 0) && | 39 (base::win::OSInfo::GetInstance()->service_pack().major == 0) && |
| 41 !base::win::UserAccountControlIsEnabled())) { | 40 !base::win::UserAccountControlIsEnabled())) { |
| 42 callback_.Run(CHECKING, 0, std::string(), 0, base::string16()); | 41 callback_.Run(CHECKING, 0, std::string(), 0, base::string16()); |
| 43 BeginUpdateCheckOnFileThread(false /* !install_update_if_possible */); | 42 DoBeginUpdateCheck(false /* !install_update_if_possible */); |
| 44 } | 43 } |
| 45 } | 44 } |
| 46 | 45 |
| 47 void VersionUpdaterWin::OnUpdateCheckComplete( | 46 void VersionUpdaterWin::OnUpdateCheckComplete( |
| 48 const base::string16& new_version) { | 47 const base::string16& new_version) { |
| 49 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 48 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 50 Status status = CHECKING; | 49 Status status = CHECKING; |
| 51 if (new_version.empty()) { | 50 if (new_version.empty()) { |
| 52 // Google Update says that no new version is available. Check to see if a | 51 // Google Update says that no new version is available. Check to see if a |
| 53 // restart is needed for a previously-applied update to take effect. | 52 // restart is needed for a previously-applied update to take effect. |
| 54 if (base::PostTaskAndReplyWithResult( | 53 base::PostTaskWithTraitsAndReplyWithResult( |
| 55 content::BrowserThread::GetBlockingPool(), | 54 FROM_HERE, {base::MayBlock(), base::TaskPriority::USER_VISIBLE}, |
| 56 FROM_HERE, | 55 base::Bind(&upgrade_util::IsUpdatePendingRestart), |
| 57 base::Bind(&upgrade_util::IsUpdatePendingRestart), | 56 base::Bind(&VersionUpdaterWin::OnPendingRestartCheck, |
| 58 base::Bind(&VersionUpdaterWin::OnPendingRestartCheck, | 57 weak_factory_.GetWeakPtr())); |
| 59 weak_factory_.GetWeakPtr()))) { | 58 // Early exit since callback_ will be Run in OnPendingRestartCheck. |
| 60 // Early exit since callback_ will be Run in OnPendingRestartCheck. | 59 return; |
| 61 return; | |
| 62 } | |
| 63 // Failure to post the task means that Chrome is shutting down. A pending | |
| 64 // update (if there is one) will be applied as Chrome exits, so tell the | |
| 65 // caller that it is up to date in either case. | |
| 66 status = UPDATED; | |
| 67 } else { | |
| 68 // Notify the caller that the update is now beginning and initiate it. | |
| 69 status = UPDATING; | |
| 70 BeginUpdateCheckOnFileThread(true /* install_update_if_possible */); | |
| 71 } | 60 } |
| 61 |
| 62 // Notify the caller that the update is now beginning and initiate it. |
| 63 status = UPDATING; |
| 64 DoBeginUpdateCheck(true /* install_update_if_possible */); |
| 72 callback_.Run(status, 0, std::string(), 0, base::string16()); | 65 callback_.Run(status, 0, std::string(), 0, base::string16()); |
| 73 } | 66 } |
| 74 | 67 |
| 75 void VersionUpdaterWin::OnUpgradeProgress(int progress, | 68 void VersionUpdaterWin::OnUpgradeProgress(int progress, |
| 76 const base::string16& new_version) { | 69 const base::string16& new_version) { |
| 77 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 70 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 78 callback_.Run(UPDATING, progress, std::string(), 0, base::string16()); | 71 callback_.Run(UPDATING, progress, std::string(), 0, base::string16()); |
| 79 } | 72 } |
| 80 | 73 |
| 81 void VersionUpdaterWin::OnUpgradeComplete(const base::string16& new_version) { | 74 void VersionUpdaterWin::OnUpgradeComplete(const base::string16& new_version) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 107 message = l10n_util::GetStringFUTF16Int(IDS_UPGRADE_ERROR, error_code); | 100 message = l10n_util::GetStringFUTF16Int(IDS_UPGRADE_ERROR, error_code); |
| 108 } else { | 101 } else { |
| 109 message = l10n_util::GetStringFUTF16( | 102 message = l10n_util::GetStringFUTF16( |
| 110 IDS_ABOUT_BOX_ERROR_DURING_UPDATE_CHECK, html_error_message); | 103 IDS_ABOUT_BOX_ERROR_DURING_UPDATE_CHECK, html_error_message); |
| 111 } | 104 } |
| 112 break; | 105 break; |
| 113 } | 106 } |
| 114 callback_.Run(status, 0, std::string(), 0, message); | 107 callback_.Run(status, 0, std::string(), 0, message); |
| 115 } | 108 } |
| 116 | 109 |
| 117 void VersionUpdaterWin::BeginUpdateCheckOnFileThread( | 110 void VersionUpdaterWin::DoBeginUpdateCheck(bool install_update_if_possible) { |
| 118 bool install_update_if_possible) { | |
| 119 // Disconnect from any previous attempts to avoid redundant callbacks. | 111 // Disconnect from any previous attempts to avoid redundant callbacks. |
| 120 weak_factory_.InvalidateWeakPtrs(); | 112 weak_factory_.InvalidateWeakPtrs(); |
| 121 BeginUpdateCheck(content::BrowserThread::GetTaskRunnerForThread( | 113 BeginUpdateCheck(g_browser_process->GetApplicationLocale(), |
| 122 content::BrowserThread::FILE), | |
| 123 g_browser_process->GetApplicationLocale(), | |
| 124 install_update_if_possible, owner_widget_, | 114 install_update_if_possible, owner_widget_, |
| 125 weak_factory_.GetWeakPtr()); | 115 weak_factory_.GetWeakPtr()); |
| 126 } | 116 } |
| 127 | 117 |
| 128 void VersionUpdaterWin::OnPendingRestartCheck(bool is_update_pending_restart) { | 118 void VersionUpdaterWin::OnPendingRestartCheck(bool is_update_pending_restart) { |
| 129 callback_.Run(is_update_pending_restart ? NEARLY_UPDATED : UPDATED, 0, | 119 callback_.Run(is_update_pending_restart ? NEARLY_UPDATED : UPDATED, 0, |
| 130 std::string(), 0, base::string16()); | 120 std::string(), 0, base::string16()); |
| 131 } | 121 } |
| 132 | 122 |
| 133 VersionUpdater* VersionUpdater::Create(content::WebContents* web_contents) { | 123 VersionUpdater* VersionUpdater::Create(content::WebContents* web_contents) { |
| 134 // Retrieve the HWND for the browser window that is hosting the update check. | 124 // Retrieve the HWND for the browser window that is hosting the update check. |
| 135 // This will be used as the parent for a UAC prompt, if needed. It's possible | 125 // This will be used as the parent for a UAC prompt, if needed. It's possible |
| 136 // this this window will no longer have focus by the time UAC is needed. In | 126 // this this window will no longer have focus by the time UAC is needed. In |
| 137 // that case, the UAC prompt will appear in the taskbar and will require a | 127 // that case, the UAC prompt will appear in the taskbar and will require a |
| 138 // user click. This is the least surprising thing we can do for the user, and | 128 // user click. This is the least surprising thing we can do for the user, and |
| 139 // is the intended behavior for Windows applications. | 129 // is the intended behavior for Windows applications. |
| 140 // It's also possible that the browser window hosting the update check will | 130 // It's also possible that the browser window hosting the update check will |
| 141 // have been closed by the time the UAC prompt is needed. In this case, the | 131 // have been closed by the time the UAC prompt is needed. In this case, the |
| 142 // web contents may no longer be hosted in a window, leading either | 132 // web contents may no longer be hosted in a window, leading either |
| 143 // GetTopLevelNativeWindow or GetHost to return null. Passing nullptr to | 133 // GetTopLevelNativeWindow or GetHost to return null. Passing nullptr to |
| 144 // VersionUpdaterWin will then also cause the UAC prompt to appear in the task | 134 // VersionUpdaterWin will then also cause the UAC prompt to appear in the task |
| 145 // bar. | 135 // bar. |
| 146 gfx::NativeWindow window = web_contents->GetTopLevelNativeWindow(); | 136 gfx::NativeWindow window = web_contents->GetTopLevelNativeWindow(); |
| 147 aura::WindowTreeHost* window_tree_host = window ? window->GetHost() : nullptr; | 137 aura::WindowTreeHost* window_tree_host = window ? window->GetHost() : nullptr; |
| 148 return new VersionUpdaterWin( | 138 return new VersionUpdaterWin( |
| 149 window_tree_host ? window_tree_host->GetAcceleratedWidget() : nullptr); | 139 window_tree_host ? window_tree_host->GetAcceleratedWidget() : nullptr); |
| 150 } | 140 } |
| OLD | NEW |