Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/upgrade_detector.h" | 5 #include "chrome/browser/upgrade_detector.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 | 28 |
| 29 #if defined(OS_WIN) | 29 #if defined(OS_WIN) |
| 30 #include "chrome/installer/util/install_util.h" | 30 #include "chrome/installer/util/install_util.h" |
| 31 #elif defined(OS_MACOSX) | 31 #elif defined(OS_MACOSX) |
| 32 #include "chrome/browser/cocoa/keystone_glue.h" | 32 #include "chrome/browser/cocoa/keystone_glue.h" |
| 33 #elif defined(OS_POSIX) | 33 #elif defined(OS_POSIX) |
| 34 #include "base/process_util.h" | 34 #include "base/process_util.h" |
| 35 #include "base/version.h" | 35 #include "base/version.h" |
| 36 #endif | 36 #endif |
| 37 | 37 |
| 38 #if defined(OS_CHROMEOS) | |
| 39 #include "chrome/browser/chromeos/cros/cros_library.h" | |
| 40 #include "chrome/browser/chromeos/cros/update_library.h" | |
| 41 #endif | |
| 42 | |
| 38 namespace { | 43 namespace { |
| 39 | 44 |
| 40 // How long (in milliseconds) to wait (each cycle) before checking whether | 45 // How long (in milliseconds) to wait (each cycle) before checking whether |
| 41 // Chrome's been upgraded behind our back. | 46 // Chrome's been upgraded behind our back. |
| 42 const int kCheckForUpgradeMs = 2 * 60 * 60 * 1000; // 2 hours. | 47 const int kCheckForUpgradeMs = 2 * 60 * 60 * 1000; // 2 hours. |
| 43 | 48 |
| 44 // How long to wait (each cycle) before checking which severity level we should | 49 // How long to wait (each cycle) before checking which severity level we should |
| 45 // be at. Once we reach the highest severity, the timer will stop. | 50 // be at. Once we reach the highest severity, the timer will stop. |
| 46 const int kNotifyCycleTimeMs = 20 * 60 * 1000; // 20 minutes. | 51 const int kNotifyCycleTimeMs = 20 * 60 * 1000; // 20 minutes. |
| 47 | 52 |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 198 | 203 |
| 199 UpgradeDetector::~UpgradeDetector() { | 204 UpgradeDetector::~UpgradeDetector() { |
| 200 } | 205 } |
| 201 | 206 |
| 202 // static | 207 // static |
| 203 UpgradeDetector* UpgradeDetector::GetInstance() { | 208 UpgradeDetector* UpgradeDetector::GetInstance() { |
| 204 return Singleton<UpgradeDetector>::get(); | 209 return Singleton<UpgradeDetector>::get(); |
| 205 } | 210 } |
| 206 | 211 |
| 207 void UpgradeDetector::CheckForUpgrade() { | 212 void UpgradeDetector::CheckForUpgrade() { |
| 213 #if defined(OS_CHROMEOS) | |
| 214 // For ChromeOS, check update library status to detect upgrade. | |
| 215 if (chromeos::CrosLibrary::Get()->GetUpdateLibrary()->status().status == | |
| 216 chromeos::UPDATE_STATUS_UPDATED_NEED_REBOOT) { | |
|
Finnur
2011/05/24 10:38:39
I take it this is appropriate to be called on the
| |
| 217 UpgradeDetected(); | |
| 218 } | |
| 219 #else | |
| 208 method_factory_.RevokeAll(); | 220 method_factory_.RevokeAll(); |
| 209 Task* callback_task = | 221 Task* callback_task = |
| 210 method_factory_.NewRunnableMethod(&UpgradeDetector::UpgradeDetected); | 222 method_factory_.NewRunnableMethod(&UpgradeDetector::UpgradeDetected); |
| 211 // We use FILE as the thread to run the upgrade detection code on all | 223 // We use FILE as the thread to run the upgrade detection code on all |
| 212 // platforms. For Linux, this is because we don't want to block the UI thread | 224 // platforms. For Linux, this is because we don't want to block the UI thread |
| 213 // while launching a background process and reading its output; on the Mac and | 225 // while launching a background process and reading its output; on the Mac and |
| 214 // on Windows checking for an upgrade requires reading a file. | 226 // on Windows checking for an upgrade requires reading a file. |
| 215 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 227 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 216 new DetectUpgradeTask(callback_task, | 228 new DetectUpgradeTask(callback_task, |
| 217 &is_unstable_channel_)); | 229 &is_unstable_channel_)); |
| 230 #endif | |
| 218 } | 231 } |
| 219 | 232 |
| 220 void UpgradeDetector::UpgradeDetected() { | 233 void UpgradeDetector::UpgradeDetected() { |
| 221 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 234 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 222 | 235 |
| 223 // Stop the recurring timer (that is checking for changes). | 236 // Stop the recurring timer (that is checking for changes). |
| 224 detect_upgrade_timer_.Stop(); | 237 detect_upgrade_timer_.Stop(); |
| 225 | 238 |
| 226 upgrade_detected_time_ = base::Time::Now(); | 239 upgrade_detected_time_ = base::Time::Now(); |
| 227 | 240 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 289 } | 302 } |
| 290 } | 303 } |
| 291 | 304 |
| 292 notify_upgrade_ = true; | 305 notify_upgrade_ = true; |
| 293 | 306 |
| 294 NotificationService::current()->Notify( | 307 NotificationService::current()->Notify( |
| 295 NotificationType::UPGRADE_RECOMMENDED, | 308 NotificationType::UPGRADE_RECOMMENDED, |
| 296 Source<UpgradeDetector>(this), | 309 Source<UpgradeDetector>(this), |
| 297 NotificationService::NoDetails()); | 310 NotificationService::NoDetails()); |
| 298 } | 311 } |
| OLD | NEW |