Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(631)

Side by Side Diff: chrome/browser/ui/webui/help/version_updater_win.cc

Issue 2952133002: Use task runner in version_updater_win.cc. (Closed)
Patch Set: address comments Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/webui/help/version_updater_win.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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; 39 Status status = CHECKING;
Peter Kasting 2017/07/20 05:28:53 Nit: This variable can now go away entirely, and w
calamity 2017/07/20 05:54:48 Done.
41 if (new_version.empty()) { 40 if (new_version.empty()) {
42 // Google Update says that no new version is available. Check to see if a 41 // 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. 42 // restart is needed for a previously-applied update to take effect.
44 if (base::PostTaskAndReplyWithResult( 43 base::PostTaskWithTraitsAndReplyWithResult(
45 content::BrowserThread::GetBlockingPool(), 44 FROM_HERE, {base::MayBlock(), base::TaskPriority::USER_VISIBLE},
46 FROM_HERE, 45 base::Bind(&upgrade_util::IsUpdatePendingRestart),
47 base::Bind(&upgrade_util::IsUpdatePendingRestart), 46 base::Bind(&VersionUpdaterWin::OnPendingRestartCheck,
48 base::Bind(&VersionUpdaterWin::OnPendingRestartCheck, 47 weak_factory_.GetWeakPtr()));
49 weak_factory_.GetWeakPtr()))) { 48 // Early exit since callback_ will be Run in OnPendingRestartCheck.
50 // Early exit since callback_ will be Run in OnPendingRestartCheck. 49 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 } 50 }
51
52 // Notify the caller that the update is now beginning and initiate it.
53 status = UPDATING;
54 DoBeginUpdateCheck(true /* install_update_if_possible */);
62 callback_.Run(status, 0, std::string(), 0, base::string16()); 55 callback_.Run(status, 0, std::string(), 0, base::string16());
63 } 56 }
64 57
65 void VersionUpdaterWin::OnUpgradeProgress(int progress, 58 void VersionUpdaterWin::OnUpgradeProgress(int progress,
66 const base::string16& new_version) { 59 const base::string16& new_version) {
67 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 60 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
68 callback_.Run(UPDATING, progress, std::string(), 0, base::string16()); 61 callback_.Run(UPDATING, progress, std::string(), 0, base::string16());
69 } 62 }
70 63
71 void VersionUpdaterWin::OnUpgradeComplete(const base::string16& new_version) { 64 void VersionUpdaterWin::OnUpgradeComplete(const base::string16& new_version) {
(...skipping 25 matching lines...) Expand all
97 message = l10n_util::GetStringFUTF16Int(IDS_UPGRADE_ERROR, error_code); 90 message = l10n_util::GetStringFUTF16Int(IDS_UPGRADE_ERROR, error_code);
98 } else { 91 } else {
99 message = l10n_util::GetStringFUTF16( 92 message = l10n_util::GetStringFUTF16(
100 IDS_ABOUT_BOX_ERROR_DURING_UPDATE_CHECK, html_error_message); 93 IDS_ABOUT_BOX_ERROR_DURING_UPDATE_CHECK, html_error_message);
101 } 94 }
102 break; 95 break;
103 } 96 }
104 callback_.Run(status, 0, std::string(), 0, message); 97 callback_.Run(status, 0, std::string(), 0, message);
105 } 98 }
106 99
107 void VersionUpdaterWin::BeginUpdateCheckOnFileThread( 100 void VersionUpdaterWin::DoBeginUpdateCheck(bool install_update_if_possible) {
108 bool install_update_if_possible) {
109 // Disconnect from any previous attempts to avoid redundant callbacks. 101 // Disconnect from any previous attempts to avoid redundant callbacks.
110 weak_factory_.InvalidateWeakPtrs(); 102 weak_factory_.InvalidateWeakPtrs();
111 BeginUpdateCheck(content::BrowserThread::GetTaskRunnerForThread( 103 BeginUpdateCheck(g_browser_process->GetApplicationLocale(),
112 content::BrowserThread::FILE),
113 g_browser_process->GetApplicationLocale(),
114 install_update_if_possible, owner_widget_, 104 install_update_if_possible, owner_widget_,
115 weak_factory_.GetWeakPtr()); 105 weak_factory_.GetWeakPtr());
116 } 106 }
117 107
118 void VersionUpdaterWin::OnPendingRestartCheck(bool is_update_pending_restart) { 108 void VersionUpdaterWin::OnPendingRestartCheck(bool is_update_pending_restart) {
119 callback_.Run(is_update_pending_restart ? NEARLY_UPDATED : UPDATED, 0, 109 callback_.Run(is_update_pending_restart ? NEARLY_UPDATED : UPDATED, 0,
120 std::string(), 0, base::string16()); 110 std::string(), 0, base::string16());
121 } 111 }
122 112
123 VersionUpdater* VersionUpdater::Create(content::WebContents* web_contents) { 113 VersionUpdater* VersionUpdater::Create(content::WebContents* web_contents) {
124 // Retrieve the HWND for the browser window that is hosting the update check. 114 // 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 115 // 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 116 // 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 117 // 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 118 // user click. This is the least surprising thing we can do for the user, and
129 // is the intended behavior for Windows applications. 119 // is the intended behavior for Windows applications.
130 // It's also possible that the browser window hosting the update check will 120 // 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 121 // 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 122 // web contents may no longer be hosted in a window, leading either
133 // GetTopLevelNativeWindow or GetHost to return null. Passing nullptr to 123 // GetTopLevelNativeWindow or GetHost to return null. Passing nullptr to
134 // VersionUpdaterWin will then also cause the UAC prompt to appear in the task 124 // VersionUpdaterWin will then also cause the UAC prompt to appear in the task
135 // bar. 125 // bar.
136 gfx::NativeWindow window = web_contents->GetTopLevelNativeWindow(); 126 gfx::NativeWindow window = web_contents->GetTopLevelNativeWindow();
137 aura::WindowTreeHost* window_tree_host = window ? window->GetHost() : nullptr; 127 aura::WindowTreeHost* window_tree_host = window ? window->GetHost() : nullptr;
138 return new VersionUpdaterWin( 128 return new VersionUpdaterWin(
139 window_tree_host ? window_tree_host->GetAcceleratedWidget() : nullptr); 129 window_tree_host ? window_tree_host->GetAcceleratedWidget() : nullptr);
140 } 130 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/help/version_updater_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698