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

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: 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 | « no previous file | 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 "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"
16 #include "content/public/browser/web_contents.h" 14 #include "content/public/browser/web_contents.h"
17 #include "ui/aura/window.h" 15 #include "ui/aura/window.h"
18 #include "ui/aura/window_tree_host.h" 16 #include "ui/aura/window_tree_host.h"
19 #include "ui/base/l10n/l10n_util.h" 17 #include "ui/base/l10n/l10n_util.h"
20 #include "ui/gfx/native_widget_types.h" 18 #include "ui/gfx/native_widget_types.h"
21 19
22 VersionUpdaterWin::VersionUpdaterWin(gfx::AcceleratedWidget owner_widget) 20 VersionUpdaterWin::VersionUpdaterWin(gfx::AcceleratedWidget owner_widget)
23 : owner_widget_(owner_widget), weak_factory_(this) { 21 : owner_widget_(owner_widget), weak_factory_(this) {
24 } 22 }
25 23
(...skipping 13 matching lines...) Expand all
39 if (!(base::win::GetVersion() == base::win::VERSION_VISTA && 37 if (!(base::win::GetVersion() == base::win::VERSION_VISTA &&
40 (base::win::OSInfo::GetInstance()->service_pack().major == 0) && 38 (base::win::OSInfo::GetInstance()->service_pack().major == 0) &&
41 !base::win::UserAccountControlIsEnabled())) { 39 !base::win::UserAccountControlIsEnabled())) {
42 callback_.Run(CHECKING, 0, std::string(), 0, base::string16()); 40 callback_.Run(CHECKING, 0, std::string(), 0, base::string16());
43 BeginUpdateCheckOnFileThread(false /* !install_update_if_possible */); 41 BeginUpdateCheckOnFileThread(false /* !install_update_if_possible */);
44 } 42 }
45 } 43 }
46 44
47 void VersionUpdaterWin::OnUpdateCheckComplete( 45 void VersionUpdaterWin::OnUpdateCheckComplete(
48 const base::string16& new_version) { 46 const base::string16& new_version) {
49 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
50 Status status = CHECKING; 47 Status status = CHECKING;
51 if (new_version.empty()) { 48 if (new_version.empty()) {
52 // Google Update says that no new version is available. Check to see if a 49 // 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. 50 // restart is needed for a previously-applied update to take effect.
54 if (base::PostTaskAndReplyWithResult( 51 base::PostTaskWithTraitsAndReplyWithResult(
55 content::BrowserThread::GetBlockingPool(), 52 FROM_HERE, {base::MayBlock(), base::TaskPriority::USER_VISIBLE},
56 FROM_HERE, 53 base::Bind(&upgrade_util::IsUpdatePendingRestart),
57 base::Bind(&upgrade_util::IsUpdatePendingRestart), 54 base::Bind(&VersionUpdaterWin::OnPendingRestartCheck,
58 base::Bind(&VersionUpdaterWin::OnPendingRestartCheck, 55 weak_factory_.GetWeakPtr()));
59 weak_factory_.GetWeakPtr()))) { 56 // Early exit since callback_ will be Run in OnPendingRestartCheck.
60 // Early exit since callback_ will be Run in OnPendingRestartCheck. 57 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 } 58 }
59
60 // Notify the caller that the update is now beginning and initiate it.
61 status = UPDATING;
62 BeginUpdateCheckOnFileThread(true /* install_update_if_possible */);
72 callback_.Run(status, 0, std::string(), 0, base::string16()); 63 callback_.Run(status, 0, std::string(), 0, base::string16());
73 } 64 }
74 65
75 void VersionUpdaterWin::OnUpgradeProgress(int progress, 66 void VersionUpdaterWin::OnUpgradeProgress(int progress,
76 const base::string16& new_version) { 67 const base::string16& new_version) {
77 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
78 callback_.Run(UPDATING, progress, std::string(), 0, base::string16()); 68 callback_.Run(UPDATING, progress, std::string(), 0, base::string16());
79 } 69 }
80 70
81 void VersionUpdaterWin::OnUpgradeComplete(const base::string16& new_version) { 71 void VersionUpdaterWin::OnUpgradeComplete(const base::string16& new_version) {
82 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
83 callback_.Run(NEARLY_UPDATED, 0, std::string(), 0, base::string16()); 72 callback_.Run(NEARLY_UPDATED, 0, std::string(), 0, base::string16());
84 } 73 }
85 74
86 void VersionUpdaterWin::OnError(GoogleUpdateErrorCode error_code, 75 void VersionUpdaterWin::OnError(GoogleUpdateErrorCode error_code,
87 const base::string16& html_error_message, 76 const base::string16& html_error_message,
88 const base::string16& new_version) { 77 const base::string16& new_version) {
89 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
gab 2017/07/11 23:40:15 It's fine to keep these (the UI thread isn't going
calamity 2017/07/12 07:11:40 Done.
90 base::string16 message; 78 base::string16 message;
91 Status status = FAILED; 79 Status status = FAILED;
92 80
93 switch (error_code) { 81 switch (error_code) {
94 case GOOGLE_UPDATE_DISABLED_BY_POLICY: 82 case GOOGLE_UPDATE_DISABLED_BY_POLICY:
95 status = DISABLED_BY_ADMIN; 83 status = DISABLED_BY_ADMIN;
96 message = 84 message =
97 l10n_util::GetStringUTF16(IDS_UPGRADE_DISABLED_BY_POLICY); 85 l10n_util::GetStringUTF16(IDS_UPGRADE_DISABLED_BY_POLICY);
98 break; 86 break;
99 case GOOGLE_UPDATE_DISABLED_BY_POLICY_AUTO_ONLY: 87 case GOOGLE_UPDATE_DISABLED_BY_POLICY_AUTO_ONLY:
100 status = DISABLED_BY_ADMIN; 88 status = DISABLED_BY_ADMIN;
101 message = 89 message =
102 l10n_util::GetStringUTF16(IDS_UPGRADE_DISABLED_BY_POLICY_MANUAL); 90 l10n_util::GetStringUTF16(IDS_UPGRADE_DISABLED_BY_POLICY_MANUAL);
103 break; 91 break;
104 default: 92 default:
105 // html_error_message mentions error_code so don't combine messages. 93 // html_error_message mentions error_code so don't combine messages.
106 if (html_error_message.empty()) { 94 if (html_error_message.empty()) {
107 message = l10n_util::GetStringFUTF16Int(IDS_UPGRADE_ERROR, error_code); 95 message = l10n_util::GetStringFUTF16Int(IDS_UPGRADE_ERROR, error_code);
108 } else { 96 } else {
109 message = l10n_util::GetStringFUTF16( 97 message = l10n_util::GetStringFUTF16(
110 IDS_ABOUT_BOX_ERROR_DURING_UPDATE_CHECK, html_error_message); 98 IDS_ABOUT_BOX_ERROR_DURING_UPDATE_CHECK, html_error_message);
111 } 99 }
112 break; 100 break;
113 } 101 }
114 callback_.Run(status, 0, std::string(), 0, message); 102 callback_.Run(status, 0, std::string(), 0, message);
115 } 103 }
116 104
117 void VersionUpdaterWin::BeginUpdateCheckOnFileThread( 105 void VersionUpdaterWin::BeginUpdateCheckOnFileThread(
gab 2017/07/11 23:40:15 Rename method
calamity 2017/07/12 07:11:40 Done.
118 bool install_update_if_possible) { 106 bool install_update_if_possible) {
119 // Disconnect from any previous attempts to avoid redundant callbacks. 107 // Disconnect from any previous attempts to avoid redundant callbacks.
120 weak_factory_.InvalidateWeakPtrs(); 108 weak_factory_.InvalidateWeakPtrs();
121 BeginUpdateCheck(content::BrowserThread::GetTaskRunnerForThread( 109 BeginUpdateCheck(base::CreateSingleThreadTaskRunnerWithTraits(
gab 2017/07/11 23:40:15 Have the leaves of this call obtain the task runne
calamity 2017/07/12 07:11:40 I gave this a shot. The latest patchset shows my a
122 content::BrowserThread::FILE), 110 {base::MayBlock(), base::TaskPriority::USER_VISIBLE}),
123 g_browser_process->GetApplicationLocale(), 111 g_browser_process->GetApplicationLocale(),
124 install_update_if_possible, owner_widget_, 112 install_update_if_possible, owner_widget_,
125 weak_factory_.GetWeakPtr()); 113 weak_factory_.GetWeakPtr());
126 } 114 }
127 115
128 void VersionUpdaterWin::OnPendingRestartCheck(bool is_update_pending_restart) { 116 void VersionUpdaterWin::OnPendingRestartCheck(bool is_update_pending_restart) {
129 callback_.Run(is_update_pending_restart ? NEARLY_UPDATED : UPDATED, 0, 117 callback_.Run(is_update_pending_restart ? NEARLY_UPDATED : UPDATED, 0,
130 std::string(), 0, base::string16()); 118 std::string(), 0, base::string16());
131 } 119 }
132 120
133 VersionUpdater* VersionUpdater::Create(content::WebContents* web_contents) { 121 VersionUpdater* VersionUpdater::Create(content::WebContents* web_contents) {
134 // Retrieve the HWND for the browser window that is hosting the update check. 122 // 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 123 // 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 124 // 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 125 // 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 126 // user click. This is the least surprising thing we can do for the user, and
139 // is the intended behavior for Windows applications. 127 // is the intended behavior for Windows applications.
140 // It's also possible that the browser window hosting the update check will 128 // 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 129 // 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 130 // web contents may no longer be hosted in a window, leading either
143 // GetTopLevelNativeWindow or GetHost to return null. Passing nullptr to 131 // GetTopLevelNativeWindow or GetHost to return null. Passing nullptr to
144 // VersionUpdaterWin will then also cause the UAC prompt to appear in the task 132 // VersionUpdaterWin will then also cause the UAC prompt to appear in the task
145 // bar. 133 // bar.
146 gfx::NativeWindow window = web_contents->GetTopLevelNativeWindow(); 134 gfx::NativeWindow window = web_contents->GetTopLevelNativeWindow();
147 aura::WindowTreeHost* window_tree_host = window ? window->GetHost() : nullptr; 135 aura::WindowTreeHost* window_tree_host = window ? window->GetHost() : nullptr;
148 return new VersionUpdaterWin( 136 return new VersionUpdaterWin(
149 window_tree_host ? window_tree_host->GetAcceleratedWidget() : nullptr); 137 window_tree_host ? window_tree_host->GetAcceleratedWidget() : nullptr);
150 } 138 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698