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

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

Issue 10699039: Switch to using the WebUI About screen on Windows. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/webui/help/version_updater_win.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Use of this source code is governed by a BSD-style license that can be
2 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/webui/help/version_updater_win.h"
6
7 #include "base/i18n/rtl.h"
8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/string16.h"
11 #include "base/threading/thread_restrictions.h"
12 #include "base/version.h"
13 #include "base/win/windows_version.h"
14 #include "base/win/win_util.h"
15 #include "chrome/browser/lifetime/application_lifetime.h"
16 #include "chrome/browser/ui/browser.h"
17 #include "chrome/browser/ui/browser_list.h"
18 #include "chrome/browser/ui/browser_window.h"
19 #include "chrome/common/chrome_version_info.h"
20 #include "chrome/installer/util/browser_distribution.h"
21 #include "chrome/installer/util/install_util.h"
22 #include "content/public/browser/user_metrics.h"
23 #include "grit/chromium_strings.h"
24 #include "grit/generated_resources.h"
25 #include "ui/base/l10n/l10n_util.h"
26 #include "ui/views/widget/widget.h"
27
28 using content::UserMetricsAction;
29
30 VersionUpdater* VersionUpdater::Create() {
31 return new VersionUpdaterWin;
32 }
33
34 VersionUpdaterWin::VersionUpdaterWin()
35 : google_updater_(new GoogleUpdate()) {
36 google_updater_->set_status_listener(this);
37 }
38
39 VersionUpdaterWin::~VersionUpdaterWin() {
40 // The Google Updater will hold a pointer to us until it reports status, so we
41 // need to let it know that we will no longer be listening.
42 if (google_updater_)
43 google_updater_->set_status_listener(NULL);
44 }
45
46 // static
47 views::Widget* VersionUpdaterWin::GetWidget() {
48 // Find an active browser.
49 Browser* browser = NULL;
50 for (BrowserList::const_iterator browser_iterator = BrowserList::begin();
51 browser_iterator != BrowserList::end(); browser_iterator++) {
52 if ((*browser_iterator)->window()) {
53 browser = *browser_iterator;
54 break;
55 }
56 }
57 if (!browser)
58 return NULL;
59 return views::Widget::GetWidgetForNativeWindow(
60 browser->window()->GetNativeHandle());
61 }
62
63 void VersionUpdaterWin::CheckForUpdate(const StatusCallback& callback) {
64 callback_ = callback;
65
66 // On-demand updates for Chrome don't work in Vista RTM when UAC is turned
67 // off. So, in this case we just want the About box to not mention
68 // on-demand updates. Silent updates (in the background) should still
69 // work as before - enabling UAC or installing the latest service pack
70 // for Vista is another option.
71 if (!(base::win::GetVersion() == base::win::VERSION_VISTA &&
72 (base::win::OSInfo::GetInstance()->service_pack().major == 0) &&
73 !base::win::UserAccountControlIsEnabled())) {
74 if (!google_updater_) {
75 google_updater_ = new GoogleUpdate();
76 google_updater_->set_status_listener(this);
77 }
78 UpdateStatus(UPGRADE_CHECK_STARTED, GOOGLE_UPDATE_NO_ERROR, string16());
79 google_updater_->CheckForUpdate(false, // Don't upgrade yet.
80 GetWidget());
81 }
82 }
83
84 void VersionUpdaterWin::RelaunchBrowser() const {
85 browser::AttemptRestart();
86 }
87
88 void VersionUpdaterWin::OnReportResults(
89 GoogleUpdateUpgradeResult result, GoogleUpdateErrorCode error_code,
90 const string16& error_message, const string16& version) {
91 // Drop the last reference to the object so that it gets cleaned up here.
92 google_updater_ = NULL;
93 UpdateStatus(result, error_code, error_message);
94 }
95
96 void VersionUpdaterWin::UpdateStatus(GoogleUpdateUpgradeResult result,
97 GoogleUpdateErrorCode error_code,
98 const string16& error_message) {
99 #if !defined(GOOGLE_CHROME_BUILD)
100 // For Chromium builds it would show an error message.
101 // But it looks weird because in fact there is no error,
102 // just the update server is not available for non-official builds.
103 return;
104 #endif
105
106 Status status = UPDATED;
107 string16 message;
108
109 switch (result) {
110 case UPGRADE_CHECK_STARTED: {
111 content::RecordAction(UserMetricsAction("UpgradeCheck_Started"));
112 status = CHECKING;
113 break;
114 }
115 case UPGRADE_STARTED: {
116 content::RecordAction(UserMetricsAction("Upgrade_Started"));
117 status = UPDATING;
118 break;
119 }
120 case UPGRADE_IS_AVAILABLE: {
121 content::RecordAction(
122 UserMetricsAction("UpgradeCheck_UpgradeIsAvailable"));
123 DCHECK(!google_updater_); // Should have been nulled out already.
124 google_updater_ = new GoogleUpdate();
125 google_updater_->set_status_listener(this);
126 UpdateStatus(UPGRADE_STARTED, GOOGLE_UPDATE_NO_ERROR, string16());
127 google_updater_->CheckForUpdate(true, // Upgrade now.
128 GetWidget());
129 return;
130 }
131 case UPGRADE_ALREADY_UP_TO_DATE: {
132 // Google Update reported that Chrome is up-to-date. Now make sure that we
133 // are running the latest version and if not, notify the user by falling
134 // into the next case of UPGRADE_SUCCESSFUL.
135 //
136 // The extra version check is necessary on Windows because the application
137 // may be already up to date on disk though the running app is still
138 // out of date. Chrome OS doesn't quite have this issue since the
139 // OS/App are updated together. If a newer version of the OS has been
140 // staged then UPGRADE_SUCESSFUL will be returned.
141 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
142 base::ThreadRestrictions::ScopedAllowIO allow_io;
143 chrome::VersionInfo version_info;
144 scoped_ptr<Version> installed_version(
145 InstallUtil::GetChromeVersion(dist, false));
146 if (!installed_version.get()) {
147 // User-level Chrome is not installed, check system-level.
148 installed_version.reset(InstallUtil::GetChromeVersion(dist, true));
149 }
150 scoped_ptr<Version> running_version(
151 Version::GetVersionFromString(version_info.Version()));
152 if (!installed_version.get() ||
153 (installed_version->CompareTo(*running_version) <= 0)) {
154 content::RecordAction(
155 UserMetricsAction("UpgradeCheck_AlreadyUpToDate"));
156 status = UPDATED;
157 break;
158 }
159
160 content::RecordAction(UserMetricsAction("UpgradeCheck_AlreadyUpgraded"));
161 status = NEARLY_UPDATED;
162 break;
163 }
164 case UPGRADE_SUCCESSFUL: {
165 content::RecordAction(UserMetricsAction("UpgradeCheck_Upgraded"));
166 status = NEARLY_UPDATED;
167 break;
168 }
169 case UPGRADE_ERROR: {
170 content::RecordAction(UserMetricsAction("UpgradeCheck_Error"));
171 status = FAILED;
172 if (!error_message.empty()) {
173 message =
174 l10n_util::GetStringFUTF16(IDS_ABOUT_BOX_ERROR_DURING_UPDATE_CHECK,
175 error_message);
176 }
177 if (error_code != GOOGLE_UPDATE_DISABLED_BY_POLICY) {
178 message =
179 l10n_util::GetStringFUTF16Int(IDS_UPGRADE_ERROR, error_code);
180 } else {
181 message =
182 l10n_util::GetStringUTF16(IDS_UPGRADE_DISABLED_BY_POLICY);
183 }
184 break;
185 }
186 }
187
188 // TODO(mad): Get proper progress value instead of passing 0.
189 callback_.Run(status, 0, message);
190 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/help/version_updater_win.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698