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

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

Issue 9700049: Help: Implement version updating on Win. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 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
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/ui/browser_list.h"
16 #include "chrome/common/chrome_version_info.h"
17 #include "chrome/installer/util/browser_distribution.h"
18 #include "chrome/installer/util/install_util.h"
19 #include "content/public/browser/user_metrics.h"
20 #include "grit/chromium_strings.h"
21 #include "grit/generated_resources.h"
22 #include "ui/base/l10n/l10n_util.h"
23
24 VersionUpdater* VersionUpdater::Create() {
25 return new VersionUpdaterWin;
26 }
27
28 VersionUpdaterWin::VersionUpdaterWin()
29 : google_updater_(new GoogleUpdate()) {
30 google_updater_->set_status_listener(this);
31 }
32
33 VersionUpdaterWin::~VersionUpdaterWin() {
34 // The Google Updater will hold a pointer to us until it reports status, so we
35 // need to let it know that we will no longer be listening.
36 if (google_updater_)
37 google_updater_->set_status_listener(NULL);
38 }
39
40 void VersionUpdaterCros::CheckForUpdate(const StatusCallback& callback) {
41 callback_ = callback;
42
43 // On-demand updates for Chrome don't work in Vista RTM when UAC is turned
44 // off. So, in this case we just want the About box to not mention
45 // on-demand updates. Silent updates (in the background) should still
46 // work as before - enabling UAC or installing the latest service pack
47 // for Vista is another option.
48 if (!(base::win::GetVersion() == base::win::VERSION_VISTA &&
49 (base::win::OSInfo::GetInstance()->service_pack().major == 0) &&
50 !base::win::UserAccountControlIsEnabled())) {
51 UpdateStatus(UPGRADE_CHECK_STARTED, GOOGLE_UPDATE_NO_ERROR, string16());
52 google_updater_->CheckForUpdate(false, // Don't upgrade yet.
53 NULL); // No window widget.
54 }
55 }
56
57 void VersionUpdaterCros::RelaunchBrowser() const {
58 BrowserList::AttemptRestart();
59 }
60
61 void VersionUpdaterWin::OnReportResults(
62 GoogleUpdateUpgradeResult result, GoogleUpdateErrorCode error_code,
63 const string16& error_message, const string16& version) {
64 // Drop the last reference to the object so that it gets cleaned up here.
65 google_updater_ = NULL;
66 UpdateStatus(result, error_code, error_message);
67 }
68
69 void AboutChromeView::UpdateStatus(GoogleUpdateUpgradeResult result,
70 GoogleUpdateErrorCode error_code,
71 const string16& error_message) {
72 Status status = UPDATED;
73 string16 message;
74
75 switch (result) {
76 case UPGRADE_CHECK_STARTED: {
77 content::RecordAction(UserMetricsAction("UpgradeCheck_Started"));
78 status = CHECKING;
79 break;
80 }
81 case UPGRADE_STARTED: {
82 content::RecordAction(UserMetricsAction("Upgrade_Started"));
83 status = UPDATING;
84 break;
85 }
86 case UPGRADE_IS_AVAILABLE: {
87 content::RecordAction(
88 UserMetricsAction("UpgradeCheck_UpgradeIsAvailable"));
89 DCHECK(!google_updater_); // Should have been nulled out already.
90 google_updater_ = new GoogleUpdate();
91 google_updater_->set_status_listener(this);
92 UpdateStatus(UPGRADE_STARTED, GOOGLE_UPDATE_NO_ERROR, string16());
93 google_updater_->CheckForUpdate(true, // Upgrade now.
94 NULL); // No window widget.
95 return;
96 }
97 case UPGRADE_ALREADY_UP_TO_DATE: {
98 // The extra version check is necessary on Windows because the application
99 // may be already up to date on disk though the running app is still
100 // out of date. Chrome OS doesn't quite have this issue since the
101 // OS/App are updated together. If a newer version of the OS has been
102 // staged then UPGRADE_SUCESSFUL will be returned.
103 // Google Update reported that Chrome is up-to-date. Now make sure that we
104 // are running the latest version and if not, notify the user by falling
105 // into the next case of UPGRADE_SUCCESSFUL.
106 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
107 base::ThreadRestrictions::ScopedAllowIO allow_io;
108 chrome::VersionInfo version_info;
109 scoped_ptr<Version> installed_version(
110 InstallUtil::GetChromeVersion(dist, false));
111 if (!installed_version.get()) {
112 // User-level Chrome is not installed, check system-level.
113 installed_version.reset(InstallUtil::GetChromeVersion(dist, true));
114 }
115 scoped_ptr<Version> running_version(
116 Version::GetVersionFromString(version_info.Version()));
117 if (!installed_version.get() ||
118 (installed_version->CompareTo(*running_version) <= 0)) {
119 content::RecordAction(
120 UserMetricsAction("UpgradeCheck_AlreadyUpToDate"));
121 status = UPDATED;
122 break;
123 }
124 // No break here as we want to notify user about upgrade if there is one.
125 }
126 case UPGRADE_SUCCESSFUL: {
127 if (result == UPGRADE_ALREADY_UP_TO_DATE)
128 content::RecordAction(
129 UserMetricsAction("UpgradeCheck_AlreadyUpgraded"));
130 else
131 content::RecordAction(UserMetricsAction("UpgradeCheck_Upgraded"));
132 status = NEARLY_UPDATED;
133 break;
134 }
135 case UPGRADE_ERROR: {
136 content::RecordAction(UserMetricsAction("UpgradeCheck_Error"));
137 status = FAILED;
138 if (!error_message.empty()) {
139 message =
140 l10n_util::GetStringFUTF16(IDS_ABOUT_BOX_ERROR_DURING_UPDATE_CHECK,
141 error_message);
142 }
143 if (error_code != GOOGLE_UPDATE_DISABLED_BY_POLICY) {
144 message =
145 l10n_util::GetStringFUTF16Int(IDS_UPGRADE_ERROR, error_code);
146 } else {
147 message =
148 l10n_util::GetStringUTF16(IDS_UPGRADE_DISABLED_BY_POLICY);
149 }
150 break;
151 }
152 }
153
154 callback_.Run(status, 0, message);
155 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698