Index: chrome/browser/upgrade_detector_impl.cc |
diff --git a/chrome/browser/upgrade_detector.cc b/chrome/browser/upgrade_detector_impl.cc |
similarity index 77% |
copy from chrome/browser/upgrade_detector.cc |
copy to chrome/browser/upgrade_detector_impl.cc |
index a0d8f0c809e81590d48cc1df8f7cbc8194f8b82a..23f747a4139b8858a37936d9ab9e318854cc83ab 100644 |
--- a/chrome/browser/upgrade_detector.cc |
+++ b/chrome/browser/upgrade_detector_impl.cc |
@@ -2,7 +2,7 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "chrome/browser/upgrade_detector.h" |
+#include "chrome/browser/upgrade_detector_impl.h" |
#include <string> |
@@ -15,15 +15,10 @@ |
#include "base/time.h" |
#include "base/utf_string_conversions.h" |
#include "chrome/browser/platform_util.h" |
-#include "chrome/browser/prefs/pref_service.h" |
#include "chrome/common/chrome_switches.h" |
#include "chrome/common/chrome_version_info.h" |
-#include "chrome/common/pref_names.h" |
#include "chrome/installer/util/browser_distribution.h" |
#include "content/browser/browser_thread.h" |
-#include "content/common/notification_service.h" |
-#include "content/common/notification_type.h" |
-#include "grit/theme_resources.h" |
#include "ui/base/resource/resource_bundle.h" |
#if defined(OS_WIN) |
@@ -35,11 +30,6 @@ |
#include "base/version.h" |
#endif |
-#if defined(OS_CHROMEOS) |
-#include "chrome/browser/chromeos/cros/cros_library.h" |
-#include "chrome/browser/chromeos/cros/update_library.h" |
-#endif |
- |
namespace { |
// How long (in milliseconds) to wait (each cycle) before checking whether |
@@ -157,32 +147,9 @@ class DetectUpgradeTask : public Task { |
} // namespace |
-// static |
-void UpgradeDetector::RegisterPrefs(PrefService* prefs) { |
- prefs->RegisterBooleanPref(prefs::kRestartLastSessionOnShutdown, false); |
-} |
- |
-int UpgradeDetector::GetIconResourceID(UpgradeNotificationIconType type) { |
- bool badge = type == UPGRADE_ICON_TYPE_BADGE; |
- switch (upgrade_notification_stage_) { |
- case UPGRADE_ANNOYANCE_SEVERE: |
- return badge ? IDR_UPDATE_BADGE4 : IDR_UPDATE_MENU4; |
- case UPGRADE_ANNOYANCE_HIGH: |
- return badge ? IDR_UPDATE_BADGE3 : IDR_UPDATE_MENU3; |
- case UPGRADE_ANNOYANCE_ELEVATED: |
- return badge ? IDR_UPDATE_BADGE2 : IDR_UPDATE_MENU2; |
- case UPGRADE_ANNOYANCE_LOW: |
- return badge ? IDR_UPDATE_BADGE : IDR_UPDATE_MENU; |
- default: |
- return 0; |
- } |
-} |
- |
-UpgradeDetector::UpgradeDetector() |
+UpgradeDetectorImpl::UpgradeDetectorImpl() |
: ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), |
- is_unstable_channel_(false), |
- upgrade_notification_stage_(UPGRADE_ANNOYANCE_NONE), |
- notify_upgrade_(false) { |
+ is_unstable_channel_(false) { |
CommandLine command_line(*CommandLine::ForCurrentProcess()); |
if (command_line.HasSwitch(switches::kDisableBackgroundNetworking)) |
return; |
@@ -196,30 +163,18 @@ UpgradeDetector::UpgradeDetector() |
{ |
detect_upgrade_timer_.Start( |
base::TimeDelta::FromMilliseconds(GetCheckForUpgradeEveryMs()), |
- this, &UpgradeDetector::CheckForUpgrade); |
+ this, &UpgradeDetectorImpl::CheckForUpgrade); |
} |
#endif |
} |
-UpgradeDetector::~UpgradeDetector() { |
+UpgradeDetectorImpl::~UpgradeDetectorImpl() { |
} |
-// static |
-UpgradeDetector* UpgradeDetector::GetInstance() { |
- return Singleton<UpgradeDetector>::get(); |
-} |
- |
-void UpgradeDetector::CheckForUpgrade() { |
-#if defined(OS_CHROMEOS) |
- // For ChromeOS, check update library status to detect upgrade. |
- if (chromeos::CrosLibrary::Get()->GetUpdateLibrary()->status().status == |
- chromeos::UPDATE_STATUS_UPDATED_NEED_REBOOT) { |
- UpgradeDetected(); |
- } |
-#else |
+void UpgradeDetectorImpl::CheckForUpgrade() { |
method_factory_.RevokeAll(); |
Task* callback_task = |
- method_factory_.NewRunnableMethod(&UpgradeDetector::UpgradeDetected); |
+ method_factory_.NewRunnableMethod(&UpgradeDetectorImpl::UpgradeDetected); |
// We use FILE as the thread to run the upgrade detection code on all |
// platforms. For Linux, this is because we don't want to block the UI thread |
// while launching a background process and reading its output; on the Mac and |
@@ -227,21 +182,15 @@ void UpgradeDetector::CheckForUpgrade() { |
BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
new DetectUpgradeTask(callback_task, |
&is_unstable_channel_)); |
-#endif |
} |
-void UpgradeDetector::UpgradeDetected() { |
+void UpgradeDetectorImpl::UpgradeDetected() { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
// Stop the recurring timer (that is checking for changes). |
detect_upgrade_timer_.Stop(); |
- upgrade_detected_time_ = base::Time::Now(); |
- |
- NotificationService::current()->Notify( |
- NotificationType::UPGRADE_DETECTED, |
- Source<UpgradeDetector>(this), |
- NotificationService::NoDetails()); |
+ NotifyUpgradeDetected(); |
// Start the repeating timer for notifying the user after a certain period. |
// The called function will eventually figure out that enough time has passed |
@@ -250,11 +199,11 @@ void UpgradeDetector::UpgradeDetected() { |
kNotifyCycleTimeForTestingMs; |
upgrade_notification_timer_.Start( |
base::TimeDelta::FromMilliseconds(cycle_time), |
- this, &UpgradeDetector::NotifyOnUpgrade); |
+ this, &UpgradeDetectorImpl::NotifyOnUpgrade); |
} |
-void UpgradeDetector::NotifyOnUpgrade() { |
- base::TimeDelta delta = base::Time::Now() - upgrade_detected_time_; |
+void UpgradeDetectorImpl::NotifyOnUpgrade() { |
+ base::TimeDelta delta = base::Time::Now() - upgrade_detected_time(); |
std::string interval = CmdLineInterval(); |
// A command line interval implies testing, which we'll make more convenient |
@@ -270,7 +219,7 @@ void UpgradeDetector::NotifyOnUpgrade() { |
const int kUnstableThreshold = 1; |
if (time_passed >= kUnstableThreshold) { |
- upgrade_notification_stage_ = UPGRADE_ANNOYANCE_LOW; |
+ set_upgrade_notification_stage(UPGRADE_ANNOYANCE_LOW); |
// That's as high as it goes. |
upgrade_notification_timer_.Stop(); |
@@ -287,25 +236,30 @@ void UpgradeDetector::NotifyOnUpgrade() { |
// These if statements must be sorted (highest interval first). |
if (time_passed >= kSevereThreshold) { |
- upgrade_notification_stage_ = UPGRADE_ANNOYANCE_SEVERE; |
+ set_upgrade_notification_stage(UPGRADE_ANNOYANCE_SEVERE); |
// We can't get any higher, baby. |
upgrade_notification_timer_.Stop(); |
} else if (time_passed >= kHighThreshold) { |
- upgrade_notification_stage_ = UPGRADE_ANNOYANCE_HIGH; |
+ set_upgrade_notification_stage(UPGRADE_ANNOYANCE_HIGH); |
} else if (time_passed >= kElevatedThreshold) { |
- upgrade_notification_stage_ = UPGRADE_ANNOYANCE_ELEVATED; |
+ set_upgrade_notification_stage(UPGRADE_ANNOYANCE_ELEVATED); |
} else if (time_passed >= kLowThreshold) { |
- upgrade_notification_stage_ = UPGRADE_ANNOYANCE_LOW; |
+ set_upgrade_notification_stage(UPGRADE_ANNOYANCE_LOW); |
} else { |
return; // Not ready to recommend upgrade. |
} |
} |
- notify_upgrade_ = true; |
+ NotifyUpgradeRecommended(); |
+} |
+ |
+// static |
+UpgradeDetectorImpl* UpgradeDetectorImpl::GetInstance() { |
+ return Singleton<UpgradeDetectorImpl>::get(); |
+} |
- NotificationService::current()->Notify( |
- NotificationType::UPGRADE_RECOMMENDED, |
- Source<UpgradeDetector>(this), |
- NotificationService::NoDetails()); |
+// static |
+UpgradeDetector* UpgradeDetector::GetInstance() { |
+ return UpgradeDetectorImpl::GetInstance(); |
} |