Chromium Code Reviews| 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/string16.h" | 8 #include "base/string16.h" |
| 9 #include "base/version.h" | 9 #include "base/version.h" |
| 10 #include "base/win/windows_version.h" | 10 #include "base/win/windows_version.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 GoogleUpdateErrorCode error_code, | 55 GoogleUpdateErrorCode error_code, |
| 56 const string16& error_message); | 56 const string16& error_message); |
| 57 | 57 |
| 58 // Got the intalled version so the handling of the UPGRADE_ALREADY_UP_TO_DATE | 58 // Got the intalled version so the handling of the UPGRADE_ALREADY_UP_TO_DATE |
| 59 // result case can now be completeb on the UI thread. | 59 // result case can now be completeb on the UI thread. |
| 60 void GotInstalledVersion(const Version& version); | 60 void GotInstalledVersion(const Version& version); |
| 61 | 61 |
| 62 // Little helper function to reset google_updater_. | 62 // Little helper function to reset google_updater_. |
| 63 void SetGoogleUpdater(); | 63 void SetGoogleUpdater(); |
| 64 | 64 |
| 65 // Helper function to clear google_updater_. | |
| 66 void ClearGoogleUpdater(); | |
| 67 | |
| 65 // Returns a window that can be used for elevation. | 68 // Returns a window that can be used for elevation. |
| 66 HWND GetElevationParent(); | 69 HWND GetElevationParent(); |
| 67 | 70 |
| 68 // The class that communicates with Google Update to find out if an update is | 71 // The class that communicates with Google Update to find out if an update is |
| 69 // available and asks it to start an upgrade. | 72 // available and asks it to start an upgrade. |
| 70 scoped_refptr<GoogleUpdate> google_updater_; | 73 scoped_refptr<GoogleUpdate> google_updater_; |
| 71 | 74 |
| 72 // Used for callbacks. | 75 // Used for callbacks. |
| 73 base::WeakPtrFactory<VersionUpdaterWin> weak_factory_; | 76 base::WeakPtrFactory<VersionUpdaterWin> weak_factory_; |
| 74 | 77 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 120 }; | 123 }; |
| 121 | 124 |
| 122 VersionUpdaterWin::VersionUpdaterWin() | 125 VersionUpdaterWin::VersionUpdaterWin() |
| 123 : weak_factory_(this) { | 126 : weak_factory_(this) { |
| 124 SetGoogleUpdater(); | 127 SetGoogleUpdater(); |
| 125 } | 128 } |
| 126 | 129 |
| 127 VersionUpdaterWin::~VersionUpdaterWin() { | 130 VersionUpdaterWin::~VersionUpdaterWin() { |
| 128 // The Google Updater will hold a pointer to the listener until it reports | 131 // The Google Updater will hold a pointer to the listener until it reports |
| 129 // status, so that pointer must be cleared when the listener is destoyed. | 132 // status, so that pointer must be cleared when the listener is destoyed. |
| 130 if (google_updater_) | 133 ClearGoogleUpdater(); |
| 131 google_updater_->set_status_listener(NULL); | |
| 132 } | 134 } |
| 133 | 135 |
| 134 void VersionUpdaterWin::CheckForUpdate(const StatusCallback& callback) { | 136 void VersionUpdaterWin::CheckForUpdate(const StatusCallback& callback) { |
| 135 callback_ = callback; | 137 callback_ = callback; |
| 136 | 138 |
| 137 // On-demand updates for Chrome don't work in Vista RTM when UAC is turned | 139 // 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 | 140 // off. So, in this case, the version updater must not mention |
| 139 // on-demand updates. Silent updates (in the background) should still | 141 // on-demand updates. Silent updates (in the background) should still |
| 140 // work as before - enabling UAC or installing the latest service pack | 142 // work as before - enabling UAC or installing the latest service pack |
| 141 // for Vista is another option. | 143 // for Vista is another option. |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 152 } | 154 } |
| 153 | 155 |
| 154 void VersionUpdaterWin::RelaunchBrowser() const { | 156 void VersionUpdaterWin::RelaunchBrowser() const { |
| 155 chrome::AttemptRestart(); | 157 chrome::AttemptRestart(); |
| 156 } | 158 } |
| 157 | 159 |
| 158 void VersionUpdaterWin::OnReportResults( | 160 void VersionUpdaterWin::OnReportResults( |
| 159 GoogleUpdateUpgradeResult result, GoogleUpdateErrorCode error_code, | 161 GoogleUpdateUpgradeResult result, GoogleUpdateErrorCode error_code, |
| 160 const string16& error_message, const string16& version) { | 162 const string16& error_message, const string16& version) { |
| 161 // Drop the last reference to the object so that it gets cleaned up here. | 163 // Drop the last reference to the object so that it gets cleaned up here. |
| 162 google_updater_ = NULL; | 164 ClearGoogleUpdater(); |
| 163 UpdateStatus(result, error_code, error_message); | 165 UpdateStatus(result, error_code, error_message); |
| 164 } | 166 } |
| 165 | 167 |
| 166 void VersionUpdaterWin::UpdateStatus(GoogleUpdateUpgradeResult result, | 168 void VersionUpdaterWin::UpdateStatus(GoogleUpdateUpgradeResult result, |
| 167 GoogleUpdateErrorCode error_code, | 169 GoogleUpdateErrorCode error_code, |
| 168 const string16& error_message) { | 170 const string16& error_message) { |
| 169 // For Chromium builds it would show an error message. | 171 // For Chromium builds it would show an error message. |
| 170 // But it looks weird because in fact there is no error, | 172 // But it looks weird because in fact there is no error, |
| 171 // just the update server is not available for non-official builds. | 173 // just the update server is not available for non-official builds. |
| 172 #if defined(GOOGLE_CHROME_BUILD) | 174 #if defined(GOOGLE_CHROME_BUILD) |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 249 if (!version.IsValid() || version.CompareTo(running_version) <= 0) { | 251 if (!version.IsValid() || version.CompareTo(running_version) <= 0) { |
| 250 content::RecordAction( | 252 content::RecordAction( |
| 251 UserMetricsAction("UpgradeCheck_AlreadyUpToDate")); | 253 UserMetricsAction("UpgradeCheck_AlreadyUpToDate")); |
| 252 callback_.Run(UPDATED, 0, string16()); | 254 callback_.Run(UPDATED, 0, string16()); |
| 253 } else { | 255 } else { |
| 254 content::RecordAction(UserMetricsAction("UpgradeCheck_AlreadyUpgraded")); | 256 content::RecordAction(UserMetricsAction("UpgradeCheck_AlreadyUpgraded")); |
| 255 callback_.Run(NEARLY_UPDATED, 0, string16()); | 257 callback_.Run(NEARLY_UPDATED, 0, string16()); |
| 256 } | 258 } |
| 257 } | 259 } |
| 258 | 260 |
| 259 void VersionUpdaterWin::SetGoogleUpdater() { | 261 void VersionUpdaterWin::SetGoogleUpdater() { |
|
MAD
2013/05/28 19:37:06
While you are there, maybe we should rename this t
grt (UTC plus 2)
2013/05/28 19:49:09
Nice idea. I went for "CreateGoogleUpdater". SGTY?
| |
| 262 ClearGoogleUpdater(); | |
| 260 google_updater_ = new GoogleUpdate(); | 263 google_updater_ = new GoogleUpdate(); |
| 261 google_updater_->set_status_listener(this); | 264 google_updater_->set_status_listener(this); |
| 262 } | 265 } |
| 263 | 266 |
| 267 void VersionUpdaterWin::ClearGoogleUpdater() { | |
| 268 if (google_updater_) { | |
| 269 google_updater_->set_status_listener(NULL); | |
| 270 google_updater_ = NULL; | |
| 271 } | |
| 272 } | |
| 273 | |
| 264 BOOL CALLBACK WindowEnumeration(HWND window, LPARAM param) { | 274 BOOL CALLBACK WindowEnumeration(HWND window, LPARAM param) { |
| 265 if (IsWindowVisible(window)) { | 275 if (IsWindowVisible(window)) { |
| 266 HWND* returned_window = reinterpret_cast<HWND*>(param); | 276 HWND* returned_window = reinterpret_cast<HWND*>(param); |
| 267 *returned_window = window; | 277 *returned_window = window; |
| 268 return FALSE; | 278 return FALSE; |
| 269 } | 279 } |
| 270 return TRUE; | 280 return TRUE; |
| 271 } | 281 } |
| 272 | 282 |
| 273 HWND VersionUpdaterWin::GetElevationParent() { | 283 HWND VersionUpdaterWin::GetElevationParent() { |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 284 << GetCurrentThreadId(); | 294 << GetCurrentThreadId(); |
| 285 #endif | 295 #endif |
| 286 return window; | 296 return window; |
| 287 } | 297 } |
| 288 | 298 |
| 289 } // namespace | 299 } // namespace |
| 290 | 300 |
| 291 VersionUpdater* VersionUpdater::Create() { | 301 VersionUpdater* VersionUpdater::Create() { |
| 292 return new VersionUpdaterWin; | 302 return new VersionUpdaterWin; |
| 293 } | 303 } |
| OLD | NEW |