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