summaryrefslogtreecommitdiffstats
path: root/chrome/browser/status_icons
diff options
context:
space:
mode:
authorevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-31 16:08:56 +0000
committerevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-31 16:08:56 +0000
commit61ee6287a14aed0235a40488394fb700e9c5c43c (patch)
tree88131d2d5bfb1ce476758d4b314e1d29cbaac4f5 /chrome/browser/status_icons
parentee87b33efc3912d228461c871ee5957353944d59 (diff)
downloadchromium_src-61ee6287a14aed0235a40488394fb700e9c5c43c.zip
chromium_src-61ee6287a14aed0235a40488394fb700e9c5c43c.tar.gz
chromium_src-61ee6287a14aed0235a40488394fb700e9c5c43c.tar.bz2
Simplify the Observer Pattern used in status icons implementation.
BUG=None TEST=compiles and everything still works as before. Patch from Thiago Farina <thiago.farina@gmail.com> Review URL: http://codereview.chromium.org/1518002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43219 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/status_icons')
-rw-r--r--chrome/browser/status_icons/status_icon.cc20
-rw-r--r--chrome/browser/status_icons/status_icon.h13
-rw-r--r--chrome/browser/status_icons/status_icon_unittest.cc2
-rw-r--r--chrome/browser/status_icons/status_tray_manager.h4
-rw-r--r--chrome/browser/status_icons/status_tray_unittest.cc4
5 files changed, 17 insertions, 26 deletions
diff --git a/chrome/browser/status_icons/status_icon.cc b/chrome/browser/status_icons/status_icon.cc
index 85fd175..9eada2e 100644
--- a/chrome/browser/status_icons/status_icon.cc
+++ b/chrome/browser/status_icons/status_icon.cc
@@ -6,25 +6,15 @@
#include "chrome/browser/status_icons/status_icon.h"
-void StatusIcon::AddObserver(StatusIconObserver* observer) {
- observers_.push_back(observer);
+void StatusIcon::AddObserver(Observer* observer) {
+ observers_.AddObserver(observer);
}
-void StatusIcon::RemoveObserver(StatusIconObserver* observer) {
- std::vector<StatusIconObserver*>::iterator iter =
- std::find(observers_.begin(), observers_.end(), observer);
- if (iter != observers_.end())
- observers_.erase(iter);
+void StatusIcon::RemoveObserver(Observer* observer) {
+ observers_.RemoveObserver(observer);
}
void StatusIcon::DispatchClickEvent() {
- // Walk observers, call callback for each one.
- for (std::vector<StatusIconObserver*>::const_iterator iter =
- observers_.begin();
- iter != observers_.end();
- ++iter) {
- StatusIconObserver* observer = *iter;
- observer->OnClicked();
- }
+ FOR_EACH_OBSERVER(Observer, observers_, OnClicked());
}
diff --git a/chrome/browser/status_icons/status_icon.h b/chrome/browser/status_icons/status_icon.h
index 3050026..00fc48d 100644
--- a/chrome/browser/status_icons/status_icon.h
+++ b/chrome/browser/status_icons/status_icon.h
@@ -7,6 +7,7 @@
#include <vector>
+#include "base/observer_list.h"
#include "base/string16.h"
class SkBitmap;
@@ -28,23 +29,23 @@ class StatusIcon {
// Sets the hover text for this status icon.
virtual void SetToolTip(const string16& tool_tip) = 0;
- class StatusIconObserver {
+ class Observer {
public:
- virtual ~StatusIconObserver() {}
+ virtual ~Observer() {}
// Called when the user clicks on the system tray icon.
virtual void OnClicked() = 0;
};
- // Adds/removes an observer for status bar events.
- void AddObserver(StatusIconObserver* observer);
- void RemoveObserver(StatusIconObserver* observer);
+ // Adds/Removes an observer for status bar events.
+ void AddObserver(Observer* observer);
+ void RemoveObserver(Observer* observer);
// Dispatches a click event to the observers.
void DispatchClickEvent();
private:
- std::vector<StatusIconObserver*> observers_;
+ ObserverList<Observer> observers_;
DISALLOW_COPY_AND_ASSIGN(StatusIcon);
};
diff --git a/chrome/browser/status_icons/status_icon_unittest.cc b/chrome/browser/status_icons/status_icon_unittest.cc
index de791c9c0..db8c529 100644
--- a/chrome/browser/status_icons/status_icon_unittest.cc
+++ b/chrome/browser/status_icons/status_icon_unittest.cc
@@ -6,7 +6,7 @@
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
-class MockStatusIconObserver : public StatusIcon::StatusIconObserver {
+class MockStatusIconObserver : public StatusIcon::Observer {
public:
MOCK_METHOD0(OnClicked, void());
};
diff --git a/chrome/browser/status_icons/status_tray_manager.h b/chrome/browser/status_icons/status_tray_manager.h
index 9f9d2d7..2a880e4 100644
--- a/chrome/browser/status_icons/status_tray_manager.h
+++ b/chrome/browser/status_icons/status_tray_manager.h
@@ -12,7 +12,7 @@ class Profile;
class StatusTray;
// Manages the set of status tray icons and associated UI.
-class StatusTrayManager : private StatusIcon::StatusIconObserver {
+class StatusTrayManager : private StatusIcon::Observer {
public:
StatusTrayManager();
virtual ~StatusTrayManager();
@@ -20,7 +20,7 @@ class StatusTrayManager : private StatusIcon::StatusIconObserver {
void Init(Profile* profile);
private:
- // StatusIcon::StatusIconObserver callbacks
+ // Overriden from StatusIcon::Observer:
virtual void OnClicked();
scoped_ptr<StatusTray> status_tray_;
diff --git a/chrome/browser/status_icons/status_tray_unittest.cc b/chrome/browser/status_icons/status_tray_unittest.cc
index 538a132..9b60010 100644
--- a/chrome/browser/status_icons/status_tray_unittest.cc
+++ b/chrome/browser/status_icons/status_tray_unittest.cc
@@ -14,8 +14,8 @@ class MockStatusIcon : public StatusIcon {
virtual void SetImage(const SkBitmap& image) {}
virtual void SetPressedImage(const SkBitmap& image) {}
virtual void SetToolTip(const string16& tool_tip) {}
- virtual void AddObserver(StatusIcon::StatusIconObserver* observer) {}
- virtual void RemoveObserver(StatusIcon::StatusIconObserver* observer) {}
+ virtual void AddObserver(StatusIcon::Observer* observer) {}
+ virtual void RemoveObserver(StatusIcon::Observer* observer) {}
};
class TestStatusTray : public StatusTray {