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

Unified Diff: ash/system/chromeos/network/network_icon_animation.cc

Issue 12094072: Use ash NetworkIconAnimation in NetworkMenuIcon code (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: ash/system/chromeos/network/network_icon_animation.cc
diff --git a/ash/system/chromeos/network/network_icon_animation.cc b/ash/system/chromeos/network/network_icon_animation.cc
new file mode 100644
index 0000000000000000000000000000000000000000..55cc7f03c53346da50abedc5f7bac354dbb781cc
--- /dev/null
+++ b/ash/system/chromeos/network/network_icon_animation.cc
@@ -0,0 +1,59 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ash/system/chromeos/network/network_icon_animation.h"
+
+#include "ash/system/chromeos/network/network_icon_animation_observer.h"
+
+namespace {
+const int kThrobDurationMs = 750; // Animation cycle length.
+}
+
+namespace ash {
+namespace network_icon {
+
+NetworkIconAnimation::NetworkIconAnimation()
+ : ALLOW_THIS_IN_INITIALIZER_LIST(animation_(this)) {
+ // Set up the animation throbber.
+ animation_.SetThrobDuration(kThrobDurationMs);
+ animation_.SetTweenType(ui::Tween::LINEAR);
+}
+
+NetworkIconAnimation::~NetworkIconAnimation() {
+}
+
+void NetworkIconAnimation::AnimationProgressed(const ui::Animation* animation) {
+ if (animation != &animation_)
+ return;
+ FOR_EACH_OBSERVER(AnimationObserver, observers_, NetworkIconChanged());
+}
+
+double NetworkIconAnimation::GetAnimation() {
+ if (!animation_.is_animating()) {
+ animation_.Reset();
+ animation_.StartThrobbing(-1 /*throb indefinitely*/);
+ return 0;
+ }
+ return animation_.GetCurrentValue();
+}
+
+void NetworkIconAnimation::AddObserver(AnimationObserver* observer) {
+ observers_.AddObserver(observer);
+}
+
+void NetworkIconAnimation::RemoveObserver(AnimationObserver* observer) {
+ observers_.RemoveObserver(observer);
+ if (observers_.size() == 0)
+ animation_.Stop();
+}
+
+// static
+NetworkIconAnimation* NetworkIconAnimation::GetInstance() {
+ static NetworkIconAnimation* s_icon_animation =
+ new NetworkIconAnimation();
jennyz 2013/01/31 19:16:50 A little bit concern about using static for single
stevenjb 2013/01/31 19:37:42 We already use this same model in a number of plac
stevenjb 2013/01/31 19:41:03 Confirmed with oshima that this is OK.
+ return s_icon_animation;
+}
+
+} // namespace network_icon
+} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698