OLD | NEW |
---|---|
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 "base/memory/ref_counted.h" | 5 #include "base/memory/ref_counted.h" |
6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "base/memory/weak_ptr.h" | 7 #include "base/memory/weak_ptr.h" |
8 #include "base/strings/string16.h" | 8 #include "base/strings/string16.h" |
9 #include "base/version.h" | 9 #include "base/version.h" |
10 #include "base/win/win_util.h" | 10 #include "base/win/win_util.h" |
(...skipping 10 matching lines...) Expand all Loading... | |
21 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
22 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
23 #include "ui/views/widget/widget.h" | 23 #include "ui/views/widget/widget.h" |
24 | 24 |
25 using content::BrowserThread; | 25 using content::BrowserThread; |
26 | 26 |
27 namespace { | 27 namespace { |
28 | 28 |
29 // Windows implementation of version update functionality, used by the WebUI | 29 // Windows implementation of version update functionality, used by the WebUI |
30 // About/Help page. | 30 // About/Help page. |
31 class VersionUpdaterWin : public VersionUpdater, | 31 class VersionUpdaterWin : public VersionUpdater { |
32 public GoogleUpdateStatusListener { | |
33 private: | 32 private: |
34 friend class VersionReader; | 33 friend class VersionReader; |
35 friend class VersionUpdater; | 34 friend class VersionUpdater; |
36 | 35 |
37 // Clients must use VersionUpdater::Create(). | 36 // Clients must use VersionUpdater::Create(). |
38 VersionUpdaterWin(); | 37 VersionUpdaterWin(); |
39 virtual ~VersionUpdaterWin(); | 38 virtual ~VersionUpdaterWin(); |
40 | 39 |
41 // VersionUpdater implementation. | 40 // VersionUpdater implementation. |
42 virtual void CheckForUpdate(const StatusCallback& callback) override; | 41 virtual void CheckForUpdate(const StatusCallback& callback) override; |
43 virtual void RelaunchBrowser() const override; | 42 virtual void RelaunchBrowser() const override; |
44 | 43 |
45 // GoogleUpdateStatusListener implementation. | 44 // chrome::UpdateCheckCallback. |
46 virtual void OnReportResults(GoogleUpdateUpgradeResult result, | 45 void OnUpdateCheckResults(GoogleUpdateUpgradeResult result, |
47 GoogleUpdateErrorCode error_code, | 46 GoogleUpdateErrorCode error_code, |
48 const base::string16& error_message, | 47 const base::string16& error_message, |
49 const base::string16& version) override; | 48 const base::string16& version); |
50 | 49 |
51 // Update the UI to show the status of the upgrade. | 50 // Update the UI to show the status of the upgrade. |
52 void UpdateStatus(GoogleUpdateUpgradeResult result, | 51 void UpdateStatus(GoogleUpdateUpgradeResult result, |
53 GoogleUpdateErrorCode error_code, | 52 GoogleUpdateErrorCode error_code, |
54 const base::string16& error_message); | 53 const base::string16& error_message); |
55 | 54 |
56 // Got the intalled version so the handling of the UPGRADE_ALREADY_UP_TO_DATE | 55 // Got the intalled version so the handling of the UPGRADE_ALREADY_UP_TO_DATE |
57 // result case can now be completeb on the UI thread. | 56 // result case can now be completeb on the UI thread. |
58 void GotInstalledVersion(const Version& version); | 57 void GotInstalledVersion(const Version& version); |
59 | 58 |
60 // Little helper function to create google_updater_. | |
61 void CreateGoogleUpdater(); | |
62 | |
63 // Helper function to clear google_updater_. | |
64 void ClearGoogleUpdater(); | |
65 | |
66 // Returns a window that can be used for elevation. | 59 // Returns a window that can be used for elevation. |
67 HWND GetElevationParent(); | 60 HWND GetElevationParent(); |
68 | 61 |
69 // The class that communicates with Google Update to find out if an update is | |
70 // available and asks it to start an upgrade. | |
71 scoped_refptr<GoogleUpdate> google_updater_; | |
72 | |
73 // Used for callbacks. | 62 // Used for callbacks. |
74 base::WeakPtrFactory<VersionUpdaterWin> weak_factory_; | 63 base::WeakPtrFactory<VersionUpdaterWin> weak_factory_; |
75 | 64 |
76 // Callback used to communicate update status to the client. | 65 // Callback used to communicate update status to the client. |
77 StatusCallback callback_; | 66 StatusCallback callback_; |
78 | 67 |
79 DISALLOW_COPY_AND_ASSIGN(VersionUpdaterWin); | 68 DISALLOW_COPY_AND_ASSIGN(VersionUpdaterWin); |
80 }; | 69 }; |
81 | 70 |
82 // This class is used to read the version on the FILE thread and then call back | 71 // This class is used to read the version on the FILE thread and then call back |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
115 // We use a weak pointer in case the updater gets destroyed while waiting. | 104 // We use a weak pointer in case the updater gets destroyed while waiting. |
116 base::WeakPtr<VersionUpdaterWin> version_updater_; | 105 base::WeakPtr<VersionUpdaterWin> version_updater_; |
117 | 106 |
118 // This is the version that gets read in the FILE thread and set on the | 107 // This is the version that gets read in the FILE thread and set on the |
119 // the updater in the UI thread. | 108 // the updater in the UI thread. |
120 Version installed_version_; | 109 Version installed_version_; |
121 }; | 110 }; |
122 | 111 |
123 VersionUpdaterWin::VersionUpdaterWin() | 112 VersionUpdaterWin::VersionUpdaterWin() |
124 : weak_factory_(this) { | 113 : weak_factory_(this) { |
125 CreateGoogleUpdater(); | |
126 } | 114 } |
127 | 115 |
128 VersionUpdaterWin::~VersionUpdaterWin() { | 116 VersionUpdaterWin::~VersionUpdaterWin() { |
129 // The Google Updater will hold a pointer to the listener until it reports | |
130 // status, so that pointer must be cleared when the listener is destoyed. | |
131 ClearGoogleUpdater(); | |
132 } | 117 } |
133 | 118 |
134 void VersionUpdaterWin::CheckForUpdate(const StatusCallback& callback) { | 119 void VersionUpdaterWin::CheckForUpdate(const StatusCallback& callback) { |
135 callback_ = callback; | 120 callback_ = callback; |
136 | 121 |
137 // On-demand updates for Chrome don't work in Vista RTM when UAC is turned | 122 // On-demand updates for Chrome don't work in Vista RTM when UAC is turned |
138 // off. So, in this case, the version updater must not mention | 123 // off. So, in this case, the version updater must not mention |
139 // on-demand updates. Silent updates (in the background) should still | 124 // on-demand updates. Silent updates (in the background) should still |
140 // work as before - enabling UAC or installing the latest service pack | 125 // work as before - enabling UAC or installing the latest service pack |
141 // for Vista is another option. | 126 // for Vista is another option. |
142 if (!(base::win::GetVersion() == base::win::VERSION_VISTA && | 127 if (!(base::win::GetVersion() == base::win::VERSION_VISTA && |
143 (base::win::OSInfo::GetInstance()->service_pack().major == 0) && | 128 (base::win::OSInfo::GetInstance()->service_pack().major == 0) && |
144 !base::win::UserAccountControlIsEnabled())) { | 129 !base::win::UserAccountControlIsEnabled())) { |
145 // This could happen if the page got refreshed after results were returned. | |
146 if (!google_updater_.get()) | |
147 CreateGoogleUpdater(); | |
148 UpdateStatus(UPGRADE_CHECK_STARTED, GOOGLE_UPDATE_NO_ERROR, | 130 UpdateStatus(UPGRADE_CHECK_STARTED, GOOGLE_UPDATE_NO_ERROR, |
149 base::string16()); | 131 base::string16()); |
150 // Specify false to not upgrade yet. | 132 // Specify false to not upgrade yet. |
151 google_updater_->CheckForUpdate(false, GetElevationParent()); | 133 ::CheckForUpdate(false, GetElevationParent(), |
Peter Kasting
2014/11/26 22:13:05
Nit: "::" shouldn't be necessary here, I wouldn't
grt (UTC plus 2)
2014/11/27 04:44:57
ADL wasn't enough to find it. I've renamed the fun
| |
134 base::Bind(&VersionUpdaterWin::OnUpdateCheckResults, | |
135 weak_factory_.GetWeakPtr())); | |
152 } | 136 } |
153 } | 137 } |
154 | 138 |
155 void VersionUpdaterWin::RelaunchBrowser() const { | 139 void VersionUpdaterWin::RelaunchBrowser() const { |
156 chrome::AttemptRestart(); | 140 chrome::AttemptRestart(); |
157 } | 141 } |
158 | 142 |
159 void VersionUpdaterWin::OnReportResults( | 143 void VersionUpdaterWin::OnUpdateCheckResults( |
160 GoogleUpdateUpgradeResult result, GoogleUpdateErrorCode error_code, | 144 GoogleUpdateUpgradeResult result, |
161 const base::string16& error_message, const base::string16& version) { | 145 GoogleUpdateErrorCode error_code, |
162 // Drop the last reference to the object so that it gets cleaned up here. | 146 const base::string16& error_message, |
163 ClearGoogleUpdater(); | 147 const base::string16& version) { |
164 UpdateStatus(result, error_code, error_message); | 148 UpdateStatus(result, error_code, error_message); |
165 } | 149 } |
166 | 150 |
167 void VersionUpdaterWin::UpdateStatus(GoogleUpdateUpgradeResult result, | 151 void VersionUpdaterWin::UpdateStatus(GoogleUpdateUpgradeResult result, |
168 GoogleUpdateErrorCode error_code, | 152 GoogleUpdateErrorCode error_code, |
169 const base::string16& error_message) { | 153 const base::string16& error_message) { |
170 // For Chromium builds it would show an error message. | 154 // For Chromium builds it would show an error message. |
171 // But it looks weird because in fact there is no error, | 155 // But it looks weird because in fact there is no error, |
172 // just the update server is not available for non-official builds. | 156 // just the update server is not available for non-official builds. |
173 #if defined(GOOGLE_CHROME_BUILD) | 157 #if defined(GOOGLE_CHROME_BUILD) |
174 Status status = UPDATED; | 158 Status status = UPDATED; |
175 base::string16 message; | 159 base::string16 message; |
176 | 160 |
177 switch (result) { | 161 switch (result) { |
178 case UPGRADE_CHECK_STARTED: { | 162 case UPGRADE_CHECK_STARTED: { |
179 status = CHECKING; | 163 status = CHECKING; |
180 break; | 164 break; |
181 } | 165 } |
182 case UPGRADE_STARTED: { | 166 case UPGRADE_STARTED: { |
183 status = UPDATING; | 167 status = UPDATING; |
184 break; | 168 break; |
185 } | 169 } |
186 case UPGRADE_IS_AVAILABLE: { | 170 case UPGRADE_IS_AVAILABLE: { |
187 DCHECK(!google_updater_.get()); // Should have been nulled out already. | |
188 CreateGoogleUpdater(); | |
189 UpdateStatus(UPGRADE_STARTED, GOOGLE_UPDATE_NO_ERROR, base::string16()); | 171 UpdateStatus(UPGRADE_STARTED, GOOGLE_UPDATE_NO_ERROR, base::string16()); |
190 // Specify true to upgrade now. | 172 // Specify true to upgrade now. |
191 google_updater_->CheckForUpdate(true, GetElevationParent()); | 173 ::CheckForUpdate(true, GetElevationParent(), |
174 base::Bind(&VersionUpdaterWin::OnUpdateCheckResults, | |
175 weak_factory_.GetWeakPtr())); | |
192 return; | 176 return; |
193 } | 177 } |
194 case UPGRADE_ALREADY_UP_TO_DATE: { | 178 case UPGRADE_ALREADY_UP_TO_DATE: { |
195 // Google Update reported that Chrome is up-to-date. | 179 // Google Update reported that Chrome is up-to-date. |
196 // To confirm the updated version is running, the reading | 180 // To confirm the updated version is running, the reading |
197 // must be done on the file thread. The rest of this case | 181 // must be done on the file thread. The rest of this case |
198 // will be handled within GotInstalledVersion. | 182 // will be handled within GotInstalledVersion. |
199 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, base::Bind( | 183 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, base::Bind( |
200 &VersionReader::GetVersionFromFileThread, | 184 &VersionReader::GetVersionFromFileThread, |
201 new VersionReader(weak_factory_.GetWeakPtr()))); | 185 new VersionReader(weak_factory_.GetWeakPtr()))); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
245 // out of date. | 229 // out of date. |
246 chrome::VersionInfo version_info; | 230 chrome::VersionInfo version_info; |
247 Version running_version(version_info.Version()); | 231 Version running_version(version_info.Version()); |
248 callback_.Run((version.IsValid() && version.CompareTo(running_version) > 0) | 232 callback_.Run((version.IsValid() && version.CompareTo(running_version) > 0) |
249 ? NEARLY_UPDATED | 233 ? NEARLY_UPDATED |
250 : UPDATED, | 234 : UPDATED, |
251 0, | 235 0, |
252 base::string16()); | 236 base::string16()); |
253 } | 237 } |
254 | 238 |
255 void VersionUpdaterWin::CreateGoogleUpdater() { | |
256 ClearGoogleUpdater(); | |
257 google_updater_ = new GoogleUpdate(); | |
258 google_updater_->set_status_listener(this); | |
259 } | |
260 | |
261 void VersionUpdaterWin::ClearGoogleUpdater() { | |
262 if (google_updater_.get()) { | |
263 google_updater_->set_status_listener(NULL); | |
264 google_updater_ = NULL; | |
265 } | |
266 } | |
267 | |
268 BOOL CALLBACK WindowEnumeration(HWND window, LPARAM param) { | 239 BOOL CALLBACK WindowEnumeration(HWND window, LPARAM param) { |
269 if (IsWindowVisible(window)) { | 240 if (IsWindowVisible(window)) { |
270 HWND* returned_window = reinterpret_cast<HWND*>(param); | 241 HWND* returned_window = reinterpret_cast<HWND*>(param); |
271 *returned_window = window; | 242 *returned_window = window; |
272 return FALSE; | 243 return FALSE; |
273 } | 244 } |
274 return TRUE; | 245 return TRUE; |
275 } | 246 } |
276 | 247 |
277 HWND VersionUpdaterWin::GetElevationParent() { | 248 HWND VersionUpdaterWin::GetElevationParent() { |
(...skipping 10 matching lines...) Expand all Loading... | |
288 << GetCurrentThreadId(); | 259 << GetCurrentThreadId(); |
289 #endif | 260 #endif |
290 return window; | 261 return window; |
291 } | 262 } |
292 | 263 |
293 } // namespace | 264 } // namespace |
294 | 265 |
295 VersionUpdater* VersionUpdater::Create(content::BrowserContext* /* context */) { | 266 VersionUpdater* VersionUpdater::Create(content::BrowserContext* /* context */) { |
296 return new VersionUpdaterWin; | 267 return new VersionUpdaterWin; |
297 } | 268 } |
OLD | NEW |