Commit 95997039 authored by sadrul@chromium.org's avatar sadrul@chromium.org

ash: Show a nagging reminder for available updates.

BUG=122641
TEST=none

Review URL: https://chromiumcodereview.appspot.com/10291004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@134812 0039d316-1c4b-4281-b951-d872f2087c98
parent becfbf5b
...@@ -5,12 +5,20 @@ ...@@ -5,12 +5,20 @@
#include "ash/system/tray_update.h" #include "ash/system/tray_update.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/system/tray/system_tray.h"
#include "ash/system/tray/system_tray_delegate.h" #include "ash/system/tray/system_tray_delegate.h"
#include "ash/system/tray/tray_constants.h" #include "ash/system/tray/tray_constants.h"
#include "ash/system/tray/tray_views.h" #include "ash/system/tray/tray_views.h"
#include "ash/wm/shelf_layout_manager.h"
#include "base/time.h"
#include "base/timer.h"
#include "grit/ash_strings.h" #include "grit/ash_strings.h"
#include "grit/ui_resources.h" #include "grit/ui_resources.h"
#include "ui/aura/window.h"
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/compositor/layer.h"
#include "ui/gfx/compositor/layer_animation_sequence.h"
#include "ui/gfx/compositor/layer_animation_observer.h"
#include "ui/gfx/image/image.h" #include "ui/gfx/image/image.h"
#include "ui/views/controls/image_view.h" #include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h" #include "ui/views/controls/label.h"
...@@ -19,6 +27,12 @@ ...@@ -19,6 +27,12 @@
namespace { namespace {
// How many seconds should we wait before showing the nag reminder?
const int kUpdateNaggingTimeSeconds = 24 * 60 * 60;
// How long should the nag reminder be displayed?
const int kShowUpdateNaggerForSeconds = 15;
class UpdateView : public ash::internal::ActionableView { class UpdateView : public ash::internal::ActionableView {
public: public:
UpdateView() { UpdateView() {
...@@ -56,6 +70,58 @@ class UpdateView : public ash::internal::ActionableView { ...@@ -56,6 +70,58 @@ class UpdateView : public ash::internal::ActionableView {
namespace ash { namespace ash {
namespace internal { namespace internal {
namespace tray {
class UpdateNagger : public ui::LayerAnimationObserver {
public:
explicit UpdateNagger(SystemTrayItem* owner)
: owner_(owner) {
RestartTimer();
Shell::GetInstance()->tray()->widget()->GetNativeView()->layer()->
GetAnimator()->AddObserver(this);
}
virtual ~UpdateNagger() {
Shell::GetInstance()->tray()->widget()->GetNativeView()->layer()->
GetAnimator()->RemoveObserver(this);
}
void RestartTimer() {
timer_.Stop();
timer_.Start(FROM_HERE,
base::TimeDelta::FromSeconds(kUpdateNaggingTimeSeconds),
this,
&UpdateNagger::Nag);
}
private:
void Nag() {
owner_->PopupDetailedView(kShowUpdateNaggerForSeconds, false);
}
// Overridden from ui::LayerAnimationObserver.
virtual void OnLayerAnimationEnded(
ui::LayerAnimationSequence* sequence) OVERRIDE {
if (Shell::GetInstance()->shelf()->IsVisible())
timer_.Stop();
else if (!timer_.IsRunning())
RestartTimer();
}
virtual void OnLayerAnimationAborted(
ui::LayerAnimationSequence* sequence) OVERRIDE {}
virtual void OnLayerAnimationScheduled(
ui::LayerAnimationSequence* sequence) OVERRIDE {}
SystemTrayItem* owner_;
base::OneShotTimer<UpdateNagger> timer_;
DISALLOW_COPY_AND_ASSIGN(UpdateNagger);
};
} // namespace tray
TrayUpdate::TrayUpdate() TrayUpdate::TrayUpdate()
: TrayImageItem(IDR_AURA_UBER_TRAY_UPDATE) { : TrayImageItem(IDR_AURA_UBER_TRAY_UPDATE) {
} }
...@@ -72,11 +138,26 @@ views::View* TrayUpdate::CreateDefaultView(user::LoginStatus status) { ...@@ -72,11 +138,26 @@ views::View* TrayUpdate::CreateDefaultView(user::LoginStatus status) {
return new UpdateView; return new UpdateView;
} }
void TrayUpdate::DestroyDefaultView() { views::View* TrayUpdate::CreateDetailedView(user::LoginStatus status) {
return CreateDefaultView(status);
}
void TrayUpdate::DestroyDetailedView() {
if (nagger_.get()) {
// The nagger was being displayed. Now that the detailed view is being
// closed, that means either the user clicks on it to restart, or the user
// didn't click on it to restart. In either case, start the timer to show
// the nag reminder again after the specified time.
nagger_->RestartTimer();
}
} }
void TrayUpdate::OnUpdateRecommended() { void TrayUpdate::OnUpdateRecommended() {
tray_view()->SetVisible(true); tray_view()->SetVisible(true);
if (!Shell::GetInstance()->shelf()->IsVisible() && !nagger_.get()) {
// The shelf is not visible, and there is no nagger scheduled.
nagger_.reset(new tray::UpdateNagger(this));
}
} }
} // namespace internal } // namespace internal
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#pragma once #pragma once
#include "ash/system/tray/tray_image_item.h" #include "ash/system/tray/tray_image_item.h"
#include "base/memory/scoped_ptr.h"
namespace views { namespace views {
class View; class View;
...@@ -23,6 +24,10 @@ class ASH_EXPORT UpdateObserver { ...@@ -23,6 +24,10 @@ class ASH_EXPORT UpdateObserver {
namespace internal { namespace internal {
namespace tray {
class UpdateNagger;
}
class TrayUpdate : public TrayImageItem, class TrayUpdate : public TrayImageItem,
public UpdateObserver { public UpdateObserver {
public: public:
...@@ -33,11 +38,16 @@ class TrayUpdate : public TrayImageItem, ...@@ -33,11 +38,16 @@ class TrayUpdate : public TrayImageItem,
// Overridden from TrayImageItem. // Overridden from TrayImageItem.
virtual bool GetInitialVisibility() OVERRIDE; virtual bool GetInitialVisibility() OVERRIDE;
virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE; virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE;
virtual void DestroyDefaultView() OVERRIDE; virtual views::View* CreateDetailedView(user::LoginStatus status) OVERRIDE;
virtual void DestroyDetailedView() OVERRIDE;
// Overridden from UpdateObserver. // Overridden from UpdateObserver.
virtual void OnUpdateRecommended() OVERRIDE; virtual void OnUpdateRecommended() OVERRIDE;
// Used to nag the user in case the tray has been hidden too long with an
// unseen update notification.
scoped_ptr<tray::UpdateNagger> nagger_;
DISALLOW_COPY_AND_ASSIGN(TrayUpdate); DISALLOW_COPY_AND_ASSIGN(TrayUpdate);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment