Chromium Code Reviews| Index: chrome/browser/chromeos/upgrade_detector_chromeos.cc |
| diff --git a/chrome/browser/chromeos/upgrade_detector_chromeos.cc b/chrome/browser/chromeos/upgrade_detector_chromeos.cc |
| index 7b22f9214053679f6c8176cec8a5f8b2da59ce6e..a96bf8d9874aec6b77006ffb6fb0fb15ac6ba4b3 100644 |
| --- a/chrome/browser/chromeos/upgrade_detector_chromeos.cc |
| +++ b/chrome/browser/chromeos/upgrade_detector_chromeos.cc |
| @@ -7,18 +7,74 @@ |
| #include "base/memory/singleton.h" |
| #include "chromeos/dbus/dbus_thread_manager.h" |
| +using chromeos::DBusThreadManager; |
| +using chromeos::UpdateEngineClient; |
| + |
| namespace { |
| // How long to wait (each cycle) before checking which severity level we should |
| // be at. Once we reach the highest severity, the timer will stop. |
| const int kNotifyCycleTimeMs = 20 * 60 * 1000; // 20 minutes. |
| +bool IsTargetChannelMoreStable(const std::string& current_channel, |
| + const std::string& target_channel) { |
|
stevenjb
2014/10/01 22:26:44
This should either be moved to UpdateEngineClient
ygorshenin1
2014/10/02 14:21:35
Done.
|
| + const auto& channels_list = UpdateEngineClient::kReleaseChannelsList; |
| + auto cix = |
| + std::find(channels_list.cbegin(), channels_list.cend(), current_channel); |
| + auto tix = |
| + std::find(channels_list.cbegin(), channels_list.cend(), target_channel); |
| + return tix > cix; |
| +} |
| + |
| } // namespace |
| -using chromeos::DBusThreadManager; |
| -using chromeos::UpdateEngineClient; |
| +class UpgradeDetectorChromeos::ChannelsRequester { |
| + public: |
| + ChannelsRequester() : weak_factory_(this) {} |
| + |
| + void RequestChannels(const base::Callback< |
| + void(const std::string&, const std::string&)>& callback) { |
|
stevenjb
2014/10/01 22:26:44
This callback should be typedfed somewhere
ygorshenin1
2014/10/02 14:21:35
Done.
|
| + UpdateEngineClient* client = |
| + DBusThreadManager::Get()->GetUpdateEngineClient(); |
| + callback_ = callback; |
| + client->GetChannel(true /* get_current_channel */, |
| + base::Bind(&ChannelsRequester::SetCurrentChannel, |
| + weak_factory_.GetWeakPtr())); |
| + client->GetChannel(false /* get_current_channel */, |
| + base::Bind(&ChannelsRequester::SetTargetChannel, |
| + weak_factory_.GetWeakPtr())); |
| + } |
| + |
| + private: |
| + void SetCurrentChannel(const std::string& current_channel) { |
|
stevenjb
2014/10/01 22:26:44
DCHECK(!current_channel.empty()), otherwise an emp
ygorshenin1
2014/10/02 14:21:35
Done.
|
| + current_channel_ = current_channel; |
| + TriggerCallbackIfReady(); |
| + } |
| + |
| + void SetTargetChannel(const std::string& target_channel) { |
|
stevenjb
2014/10/01 22:26:44
Ditto.
ygorshenin1
2014/10/02 14:21:35
Done.
|
| + target_channel_ = target_channel; |
| + TriggerCallbackIfReady(); |
| + } |
| + |
| + void TriggerCallbackIfReady() { |
| + if (current_channel_.empty() || target_channel_.empty()) |
| + return; |
| + if (!callback_.is_null()) |
| + callback_.Run(current_channel_, target_channel_); |
| + } |
| + |
| + std::string current_channel_; |
| + std::string target_channel_; |
| + |
| + base::Callback<void(const std::string&, const std::string&)> callback_; |
| -UpgradeDetectorChromeos::UpgradeDetectorChromeos() : initialized_(false) { |
| + base::WeakPtrFactory<ChannelsRequester> weak_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ChannelsRequester); |
| +}; |
| + |
| +UpgradeDetectorChromeos::UpgradeDetectorChromeos() |
| + : initialized_(false), weak_factory_(this) { |
| } |
| UpgradeDetectorChromeos::~UpgradeDetectorChromeos() { |
| @@ -43,13 +99,10 @@ void UpgradeDetectorChromeos::UpdateStatusChanged( |
| upgrade_detected_time_ = base::Time::Now(); |
| - // ChromeOS shows upgrade arrow once the upgrade becomes available. |
| - NotifyOnUpgrade(); |
| - |
| - // Setup timer to to move along the upgrade advisory system. |
| - upgrade_notification_timer_.Start( |
| - FROM_HERE, base::TimeDelta::FromMilliseconds(kNotifyCycleTimeMs), |
| - this, &UpgradeDetectorChromeos::NotifyOnUpgrade); |
| + channels_requester_.reset(new UpgradeDetectorChromeos::ChannelsRequester()); |
| + channels_requester_->RequestChannels( |
| + base::Bind(&UpgradeDetectorChromeos::OnChannelsReceived, |
| + weak_factory_.GetWeakPtr())); |
| } |
| void UpgradeDetectorChromeos::NotifyOnUpgrade() { |
| @@ -80,6 +133,23 @@ void UpgradeDetectorChromeos::NotifyOnUpgrade() { |
| NotifyUpgradeRecommended(); |
| } |
| +void UpgradeDetectorChromeos::OnChannelsReceived( |
| + const std::string& current_channel, |
| + const std::string& target_channel) { |
| + set_is_factory_reset_required( |
| + IsTargetChannelMoreStable(current_channel, target_channel)); |
|
stevenjb
2014/10/01 22:26:44
Could you add a comment explaining why IsTargetCha
ygorshenin1
2014/10/02 14:21:35
Done.
|
| + |
| + // ChromeOS shows upgrade arrow once the upgrade becomes available. |
| + NotifyOnUpgrade(); |
| + |
| + // Setup timer to to move along the upgrade advisory system. |
| + upgrade_notification_timer_.Start( |
| + FROM_HERE, |
| + base::TimeDelta::FromMilliseconds(kNotifyCycleTimeMs), |
| + this, |
| + &UpgradeDetectorChromeos::NotifyOnUpgrade); |
| +} |
| + |
| // static |
| UpgradeDetectorChromeos* UpgradeDetectorChromeos::GetInstance() { |
| return Singleton<UpgradeDetectorChromeos>::get(); |