Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(503)

Side by Side Diff: ash/system/tray_update.cc

Issue 10291004: ash: Show a nagging reminder for available updates. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ash/system/tray_update.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "ash/system/tray_update.h" 5 #include "ash/system/tray_update.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/system/tray/system_tray.h"
8 #include "ash/system/tray/system_tray_delegate.h" 9 #include "ash/system/tray/system_tray_delegate.h"
9 #include "ash/system/tray/tray_constants.h" 10 #include "ash/system/tray/tray_constants.h"
10 #include "ash/system/tray/tray_views.h" 11 #include "ash/system/tray/tray_views.h"
12 #include "ash/wm/shelf_layout_manager.h"
13 #include "base/time.h"
14 #include "base/timer.h"
11 #include "grit/ash_strings.h" 15 #include "grit/ash_strings.h"
12 #include "grit/ui_resources.h" 16 #include "grit/ui_resources.h"
17 #include "ui/aura/window.h"
13 #include "ui/base/resource/resource_bundle.h" 18 #include "ui/base/resource/resource_bundle.h"
19 #include "ui/gfx/compositor/layer.h"
20 #include "ui/gfx/compositor/layer_animation_sequence.h"
21 #include "ui/gfx/compositor/layer_animation_observer.h"
14 #include "ui/gfx/image/image.h" 22 #include "ui/gfx/image/image.h"
15 #include "ui/views/controls/image_view.h" 23 #include "ui/views/controls/image_view.h"
16 #include "ui/views/controls/label.h" 24 #include "ui/views/controls/label.h"
17 #include "ui/views/layout/box_layout.h" 25 #include "ui/views/layout/box_layout.h"
18 #include "ui/views/widget/widget.h" 26 #include "ui/views/widget/widget.h"
19 27
20 namespace { 28 namespace {
21 29
30 // How many seconds should we wait before showing the nag reminder?
31 const int kUpdateNaggingTimeSeconds = 24 * 60 * 60;
32
33 // How long should the nag reminder be displayed?
34 const int kShowUpdateNaggerForSeconds = 15;
35
22 class UpdateView : public ash::internal::ActionableView { 36 class UpdateView : public ash::internal::ActionableView {
23 public: 37 public:
24 UpdateView() { 38 UpdateView() {
25 SetLayoutManager(new 39 SetLayoutManager(new
26 views::BoxLayout(views::BoxLayout::kHorizontal, 40 views::BoxLayout(views::BoxLayout::kHorizontal,
27 ash::kTrayPopupPaddingHorizontal, 0, 41 ash::kTrayPopupPaddingHorizontal, 0,
28 ash::kTrayPopupPaddingBetweenItems)); 42 ash::kTrayPopupPaddingBetweenItems));
29 43
30 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); 44 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
31 views::ImageView* image = 45 views::ImageView* image =
(...skipping 17 matching lines...) Expand all
49 } 63 }
50 64
51 DISALLOW_COPY_AND_ASSIGN(UpdateView); 65 DISALLOW_COPY_AND_ASSIGN(UpdateView);
52 }; 66 };
53 67
54 } 68 }
55 69
56 namespace ash { 70 namespace ash {
57 namespace internal { 71 namespace internal {
58 72
73 namespace tray {
74
75 class UpdateNagger : public ui::LayerAnimationObserver {
76 public:
77 explicit UpdateNagger(SystemTrayItem* owner)
78 : owner_(owner) {
79 RestartTimer();
80 Shell::GetInstance()->tray()->widget()->GetNativeView()->layer()->
81 GetAnimator()->AddObserver(this);
82 }
83
84 virtual ~UpdateNagger() {
85 Shell::GetInstance()->tray()->widget()->GetNativeView()->layer()->
86 GetAnimator()->RemoveObserver(this);
87 }
88
89 void RestartTimer() {
90 timer_.Stop();
91 timer_.Start(FROM_HERE,
92 base::TimeDelta::FromSeconds(kUpdateNaggingTimeSeconds),
93 this,
94 &UpdateNagger::Nag);
95 }
96
97 private:
98 void Nag() {
99 owner_->PopupDetailedView(kShowUpdateNaggerForSeconds, false);
100 }
101
102 // Overridden from ui::LayerAnimationObserver.
103 virtual void OnLayerAnimationEnded(
104 ui::LayerAnimationSequence* sequence) OVERRIDE {
105 if (Shell::GetInstance()->shelf()->IsVisible())
106 timer_.Stop();
107 else if (!timer_.IsRunning())
108 RestartTimer();
109 }
110
111 virtual void OnLayerAnimationAborted(
112 ui::LayerAnimationSequence* sequence) OVERRIDE {}
113
114 virtual void OnLayerAnimationScheduled(
115 ui::LayerAnimationSequence* sequence) OVERRIDE {}
116
117 SystemTrayItem* owner_;
118 base::OneShotTimer<UpdateNagger> timer_;
119
120 DISALLOW_COPY_AND_ASSIGN(UpdateNagger);
121 };
122
123 } // namespace tray
124
59 TrayUpdate::TrayUpdate() 125 TrayUpdate::TrayUpdate()
60 : TrayImageItem(IDR_AURA_UBER_TRAY_UPDATE) { 126 : TrayImageItem(IDR_AURA_UBER_TRAY_UPDATE) {
61 } 127 }
62 128
63 TrayUpdate::~TrayUpdate() {} 129 TrayUpdate::~TrayUpdate() {}
64 130
65 bool TrayUpdate::GetInitialVisibility() { 131 bool TrayUpdate::GetInitialVisibility() {
66 return Shell::GetInstance()->tray_delegate()->SystemShouldUpgrade(); 132 return Shell::GetInstance()->tray_delegate()->SystemShouldUpgrade();
67 } 133 }
68 134
69 views::View* TrayUpdate::CreateDefaultView(user::LoginStatus status) { 135 views::View* TrayUpdate::CreateDefaultView(user::LoginStatus status) {
70 if (!Shell::GetInstance()->tray_delegate()->SystemShouldUpgrade()) 136 if (!Shell::GetInstance()->tray_delegate()->SystemShouldUpgrade())
71 return NULL; 137 return NULL;
72 return new UpdateView; 138 return new UpdateView;
73 } 139 }
74 140
75 void TrayUpdate::DestroyDefaultView() { 141 views::View* TrayUpdate::CreateDetailedView(user::LoginStatus status) {
142 return CreateDefaultView(status);
143 }
144
145 void TrayUpdate::DestroyDetailedView() {
146 if (nagger_.get()) {
147 // The nagger was being displayed. Now that the detailed view is being
148 // closed, that means either the user clicks on it to restart, or the user
149 // didn't click on it to restart. In either case, start the timer to show
150 // the nag reminder again after the specified time.
151 nagger_->RestartTimer();
152 }
76 } 153 }
77 154
78 void TrayUpdate::OnUpdateRecommended() { 155 void TrayUpdate::OnUpdateRecommended() {
79 tray_view()->SetVisible(true); 156 tray_view()->SetVisible(true);
157 if (!Shell::GetInstance()->shelf()->IsVisible() && !nagger_.get()) {
158 // The shelf is not visible, and there is no nagger scheduled.
159 nagger_.reset(new tray::UpdateNagger(this));
160 }
80 } 161 }
81 162
82 } // namespace internal 163 } // namespace internal
83 } // namespace ash 164 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/tray_update.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698