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

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

Issue 2873193002: Make update over cellular an option for user (Closed)
Patch Set: Put code in CHROME_OS wrapper to fix trybot error Created 3 years, 7 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
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_runner_util.h"
9 #include "base/threading/sequenced_worker_pool.h" 9 #include "base/threading/sequenced_worker_pool.h"
10 #include "base/win/win_util.h" 10 #include "base/win/win_util.h"
(...skipping 21 matching lines...) Expand all
32 callback_ = callback; 32 callback_ = callback;
33 33
34 // On-demand updates for Chrome don't work in Vista RTM when UAC is turned 34 // 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 35 // off. So, in this case, the version updater must not mention
36 // on-demand updates. Silent updates (in the background) should still 36 // on-demand updates. Silent updates (in the background) should still
37 // work as before - enabling UAC or installing the latest service pack 37 // work as before - enabling UAC or installing the latest service pack
38 // for Vista is another option. 38 // for Vista is another option.
39 if (!(base::win::GetVersion() == base::win::VERSION_VISTA && 39 if (!(base::win::GetVersion() == base::win::VERSION_VISTA &&
40 (base::win::OSInfo::GetInstance()->service_pack().major == 0) && 40 (base::win::OSInfo::GetInstance()->service_pack().major == 0) &&
41 !base::win::UserAccountControlIsEnabled())) { 41 !base::win::UserAccountControlIsEnabled())) {
42 callback_.Run(CHECKING, 0, base::string16()); 42 callback_.Run(CHECKING, 0, std::string(), 0, base::string16());
43 BeginUpdateCheckOnFileThread(false /* !install_update_if_possible */); 43 BeginUpdateCheckOnFileThread(false /* !install_update_if_possible */);
44 } 44 }
45 } 45 }
46 46
47 void VersionUpdaterWin::OnUpdateCheckComplete( 47 void VersionUpdaterWin::OnUpdateCheckComplete(
48 const base::string16& new_version) { 48 const base::string16& new_version) {
49 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 49 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
50 Status status = CHECKING; 50 Status status = CHECKING;
51 if (new_version.empty()) { 51 if (new_version.empty()) {
52 // Google Update says that no new version is available. Check to see if a 52 // 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. 53 // restart is needed for a previously-applied update to take effect.
54 if (base::PostTaskAndReplyWithResult( 54 if (base::PostTaskAndReplyWithResult(
55 content::BrowserThread::GetBlockingPool(), 55 content::BrowserThread::GetBlockingPool(),
56 FROM_HERE, 56 FROM_HERE,
57 base::Bind(&upgrade_util::IsUpdatePendingRestart), 57 base::Bind(&upgrade_util::IsUpdatePendingRestart),
58 base::Bind(&VersionUpdaterWin::OnPendingRestartCheck, 58 base::Bind(&VersionUpdaterWin::OnPendingRestartCheck,
59 weak_factory_.GetWeakPtr()))) { 59 weak_factory_.GetWeakPtr()))) {
60 // Early exit since callback_ will be Run in OnPendingRestartCheck. 60 // Early exit since callback_ will be Run in OnPendingRestartCheck.
61 return; 61 return;
62 } 62 }
63 // Failure to post the task means that Chrome is shutting down. A pending 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 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. 65 // caller that it is up to date in either case.
66 status = UPDATED; 66 status = UPDATED;
67 } else { 67 } else {
68 // Notify the caller that the update is now beginning and initiate it. 68 // Notify the caller that the update is now beginning and initiate it.
69 status = UPDATING; 69 status = UPDATING;
70 BeginUpdateCheckOnFileThread(true /* install_update_if_possible */); 70 BeginUpdateCheckOnFileThread(true /* install_update_if_possible */);
71 } 71 }
72 callback_.Run(status, 0, base::string16()); 72 callback_.Run(status, 0, std::string(), 0, base::string16());
73 } 73 }
74 74
75 void VersionUpdaterWin::OnUpgradeProgress(int progress, 75 void VersionUpdaterWin::OnUpgradeProgress(int progress,
76 const base::string16& new_version) { 76 const base::string16& new_version) {
77 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 77 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
78 callback_.Run(UPDATING, progress, base::string16()); 78 callback_.Run(UPDATING, progress, std::string(), 0, base::string16());
79 } 79 }
80 80
81 void VersionUpdaterWin::OnUpgradeComplete(const base::string16& new_version) { 81 void VersionUpdaterWin::OnUpgradeComplete(const base::string16& new_version) {
82 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 82 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
83 callback_.Run(NEARLY_UPDATED, 0, base::string16()); 83 callback_.Run(NEARLY_UPDATED, 0, std::string(), 0, base::string16());
84 } 84 }
85 85
86 void VersionUpdaterWin::OnError(GoogleUpdateErrorCode error_code, 86 void VersionUpdaterWin::OnError(GoogleUpdateErrorCode error_code,
87 const base::string16& html_error_message, 87 const base::string16& html_error_message,
88 const base::string16& new_version) { 88 const base::string16& new_version) {
89 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 89 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
90 base::string16 message; 90 base::string16 message;
91 Status status = FAILED; 91 Status status = FAILED;
92 92
93 switch (error_code) { 93 switch (error_code) {
(...skipping 10 matching lines...) Expand all
104 default: 104 default:
105 // html_error_message mentions error_code so don't combine messages. 105 // html_error_message mentions error_code so don't combine messages.
106 if (html_error_message.empty()) { 106 if (html_error_message.empty()) {
107 message = l10n_util::GetStringFUTF16Int(IDS_UPGRADE_ERROR, error_code); 107 message = l10n_util::GetStringFUTF16Int(IDS_UPGRADE_ERROR, error_code);
108 } else { 108 } else {
109 message = l10n_util::GetStringFUTF16( 109 message = l10n_util::GetStringFUTF16(
110 IDS_ABOUT_BOX_ERROR_DURING_UPDATE_CHECK, html_error_message); 110 IDS_ABOUT_BOX_ERROR_DURING_UPDATE_CHECK, html_error_message);
111 } 111 }
112 break; 112 break;
113 } 113 }
114 callback_.Run(status, 0, message); 114 callback_.Run(status, 0, std::string(), 0, message);
115 } 115 }
116 116
117 void VersionUpdaterWin::BeginUpdateCheckOnFileThread( 117 void VersionUpdaterWin::BeginUpdateCheckOnFileThread(
118 bool install_update_if_possible) { 118 bool install_update_if_possible) {
119 // Disconnect from any previous attempts to avoid redundant callbacks. 119 // Disconnect from any previous attempts to avoid redundant callbacks.
120 weak_factory_.InvalidateWeakPtrs(); 120 weak_factory_.InvalidateWeakPtrs();
121 BeginUpdateCheck(content::BrowserThread::GetTaskRunnerForThread( 121 BeginUpdateCheck(content::BrowserThread::GetTaskRunnerForThread(
122 content::BrowserThread::FILE), 122 content::BrowserThread::FILE),
123 g_browser_process->GetApplicationLocale(), 123 g_browser_process->GetApplicationLocale(),
124 install_update_if_possible, owner_widget_, 124 install_update_if_possible, owner_widget_,
125 weak_factory_.GetWeakPtr()); 125 weak_factory_.GetWeakPtr());
126 } 126 }
127 127
128 void VersionUpdaterWin::OnPendingRestartCheck(bool is_update_pending_restart) { 128 void VersionUpdaterWin::OnPendingRestartCheck(bool is_update_pending_restart) {
129 callback_.Run(is_update_pending_restart ? NEARLY_UPDATED : UPDATED, 0, 129 callback_.Run(is_update_pending_restart ? NEARLY_UPDATED : UPDATED, 0,
130 base::string16()); 130 std::string(), 0, base::string16());
131 } 131 }
132 132
133 VersionUpdater* VersionUpdater::Create(content::WebContents* web_contents) { 133 VersionUpdater* VersionUpdater::Create(content::WebContents* web_contents) {
134 // Retrieve the HWND for the browser window that is hosting the update check. 134 // 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 135 // 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 136 // 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 137 // 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 138 // user click. This is the least surprising thing we can do for the user, and
139 // is the intended behavior for Windows applications. 139 // is the intended behavior for Windows applications.
140 // It's also possible that the browser window hosting the update check will 140 // 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 141 // 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 142 // web contents may no longer be hosted in a window, leading either
143 // GetTopLevelNativeWindow or GetHost to return null. Passing nullptr to 143 // GetTopLevelNativeWindow or GetHost to return null. Passing nullptr to
144 // VersionUpdaterWin will then also cause the UAC prompt to appear in the task 144 // VersionUpdaterWin will then also cause the UAC prompt to appear in the task
145 // bar. 145 // bar.
146 gfx::NativeWindow window = web_contents->GetTopLevelNativeWindow(); 146 gfx::NativeWindow window = web_contents->GetTopLevelNativeWindow();
147 aura::WindowTreeHost* window_tree_host = window ? window->GetHost() : nullptr; 147 aura::WindowTreeHost* window_tree_host = window ? window->GetHost() : nullptr;
148 return new VersionUpdaterWin( 148 return new VersionUpdaterWin(
149 window_tree_host ? window_tree_host->GetAcceleratedWidget() : nullptr); 149 window_tree_host ? window_tree_host->GetAcceleratedWidget() : nullptr);
150 } 150 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/help/version_updater_mac.mm ('k') | chrome/browser/ui/webui/settings/about_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698