summaryrefslogtreecommitdiffstats
path: root/chrome/browser/status_icons
diff options
context:
space:
mode:
authoratwilson@chromium.org <atwilson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-18 20:55:45 +0000
committeratwilson@chromium.org <atwilson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-18 20:55:45 +0000
commit4c793f0298cbafa6826ef1bc2d85d92bf64320ba (patch)
tree5e6e6a34051417ee4c6847f397713c5d56e99d0d /chrome/browser/status_icons
parent0906270c4485c74cf35fed76aee21458702ce68c (diff)
downloadchromium_src-4c793f0298cbafa6826ef1bc2d85d92bf64320ba.zip
chromium_src-4c793f0298cbafa6826ef1bc2d85d92bf64320ba.tar.gz
chromium_src-4c793f0298cbafa6826ef1bc2d85d92bf64320ba.tar.bz2
Added BackgroundModeManager which tracks when background apps are loaded/unloaded
and puts Chrome into BackgroundMode appropriately. Added EXTENSION_UNINSTALLING notification which is sent out when a notification is about to be uninstalled. Refactored StatusTray code to move StatusTray under the profile rather than attaching it to the browser process, and removed StatusTrayManager which is no longer needed now that BackgroundModeManager handles creating status icons. BUG=43382 TEST=background_mode_manager_unittests.cc Review URL: http://codereview.chromium.org/3134011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@56596 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/status_icons')
-rw-r--r--chrome/browser/status_icons/status_tray.cc26
-rw-r--r--chrome/browser/status_icons/status_tray.h35
-rw-r--r--chrome/browser/status_icons/status_tray_manager.cc57
-rw-r--r--chrome/browser/status_icons/status_tray_manager.h31
-rw-r--r--chrome/browser/status_icons/status_tray_unittest.cc37
5 files changed, 43 insertions, 143 deletions
diff --git a/chrome/browser/status_icons/status_tray.cc b/chrome/browser/status_icons/status_tray.cc
index b7ae49c..8648351 100644
--- a/chrome/browser/status_icons/status_tray.cc
+++ b/chrome/browser/status_icons/status_tray.cc
@@ -4,6 +4,8 @@
#include "chrome/browser/status_icons/status_tray.h"
+#include <algorithm>
+
#include "base/stl_util-inl.h"
#include "chrome/browser/status_icons/status_icon.h"
@@ -16,29 +18,23 @@ StatusTray::~StatusTray() {
void StatusTray::RemoveAllIcons() {
// Walk any active status icons and delete them.
- STLDeleteContainerPairSecondPointers(status_icons_.begin(),
- status_icons_.end());
+ STLDeleteContainerPointers(status_icons_.begin(), status_icons_.end());
status_icons_.clear();
}
-StatusIcon* StatusTray::GetStatusIcon(const string16& identifier) {
- StatusIconMap::const_iterator iter = status_icons_.find(identifier);
- if (iter != status_icons_.end())
- return iter->second;
-
- // No existing StatusIcon, create a new one.
- StatusIcon* icon = CreateStatusIcon();
+StatusIcon* StatusTray::CreateStatusIcon() {
+ StatusIcon* icon = CreatePlatformStatusIcon();
if (icon)
- status_icons_[identifier] = icon;
+ status_icons_.push_back(icon);
return icon;
}
-void StatusTray::RemoveStatusIcon(const string16& identifier) {
- StatusIconMap::iterator iter = status_icons_.find(identifier);
+void StatusTray::RemoveStatusIcon(StatusIcon* icon) {
+ StatusIconList::iterator iter = std::find(
+ status_icons_.begin(), status_icons_.end(), icon);
if (iter != status_icons_.end()) {
- // Free the StatusIcon from the map (can't put scoped_ptr in a map, so we
- // have to do it manually).
- delete iter->second;
+ // Free the StatusIcon from the list.
+ delete *iter;
status_icons_.erase(iter);
}
}
diff --git a/chrome/browser/status_icons/status_tray.h b/chrome/browser/status_icons/status_tray.h
index 6052582..a0da771 100644
--- a/chrome/browser/status_icons/status_tray.h
+++ b/chrome/browser/status_icons/status_tray.h
@@ -6,8 +6,10 @@
#define CHROME_BROWSER_STATUS_ICONS_STATUS_TRAY_H_
#pragma once
-#include "base/hash_tables.h"
-#include "base/scoped_ptr.h"
+#include <vector>
+
+#include "base/basictypes.h"
+#include "base/gtest_prod_util.h"
class StatusIcon;
@@ -16,38 +18,37 @@ class StatusIcon;
class StatusTray {
public:
// Static factory method that is implemented separately for each platform to
- // produce the appropriate platform-specific instance.
+ // produce the appropriate platform-specific instance. Returns NULL if this
+ // platform does not support status icons.
static StatusTray* Create();
virtual ~StatusTray();
- // Gets the current status icon associated with this identifier, or creates
- // a new one if none exists. The StatusTray retains ownership of the
- // StatusIcon. Returns NULL if the status tray icon could not be created.
- StatusIcon* GetStatusIcon(const string16& identifier);
+ // Creates a new StatusIcon. The StatusTray retains ownership of the
+ // StatusIcon. Returns NULL if the StatusIcon could not be created.
+ StatusIcon* CreateStatusIcon();
// Removes the current status icon associated with this identifier, if any.
- void RemoveStatusIcon(const string16& identifier);
+ void RemoveStatusIcon(StatusIcon* icon);
protected:
StatusTray();
- // Factory method for creating a status icon.
- virtual StatusIcon* CreateStatusIcon() = 0;
+ // Factory method for creating a status icon for this platform.
+ virtual StatusIcon* CreatePlatformStatusIcon() = 0;
// Removes all StatusIcons (used by derived classes to clean up in case they
// track external state used by the StatusIcons).
void RemoveAllIcons();
- typedef base::hash_map<string16, StatusIcon*> StatusIconMap;
+ typedef std::vector<StatusIcon*> StatusIconList;
// Returns the list of active status icons so subclasses can operate on them.
- const StatusIconMap& status_icons() { return status_icons_; }
+ const StatusIconList& status_icons() { return status_icons_; }
private:
- // Map containing all active StatusIcons.
- // Key: String identifiers (passed in to GetStatusIcon)
- // Value: The StatusIcon associated with that identifier (strong pointer -
- // StatusIcons are freed when the StatusTray destructor is called).
- StatusIconMap status_icons_;
+ FRIEND_TEST_ALL_PREFIXES(StatusTrayTest, CreateRemove);
+
+ // List containing all active StatusIcons.
+ StatusIconList status_icons_;
DISALLOW_COPY_AND_ASSIGN(StatusTray);
};
diff --git a/chrome/browser/status_icons/status_tray_manager.cc b/chrome/browser/status_icons/status_tray_manager.cc
deleted file mode 100644
index 57b6ed9..0000000
--- a/chrome/browser/status_icons/status_tray_manager.cc
+++ /dev/null
@@ -1,57 +0,0 @@
-// Copyright (c) 2010 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 "chrome/browser/status_icons/status_tray_manager.h"
-
-#include "app/l10n_util.h"
-#include "app/resource_bundle.h"
-#include "base/logging.h"
-#include "base/string_util.h"
-#include "base/utf_string_conversions.h"
-#include "chrome/browser/browser.h"
-#include "chrome/browser/browser_list.h"
-#include "chrome/browser/browser_window.h"
-#include "chrome/browser/status_icons/status_tray.h"
-#include "grit/browser_resources.h"
-#include "grit/chromium_strings.h"
-#include "grit/theme_resources.h"
-
-StatusTrayManager::StatusTrayManager() : profile_(NULL) {
-}
-
-StatusTrayManager::~StatusTrayManager() {
-}
-
-void StatusTrayManager::Init(Profile* profile) {
-#if !(defined(OS_LINUX) && defined(TOOLKIT_VIEWS))
- DCHECK(profile);
- profile_ = profile;
- status_tray_.reset(StatusTray::Create());
- StatusIcon* icon = status_tray_->GetStatusIcon(ASCIIToUTF16("chrome_main"));
- if (icon) {
- // Create an icon and add ourselves as a click observer on it
- SkBitmap* bitmap = ResourceBundle::GetSharedInstance().GetBitmapNamed(
- IDR_STATUS_TRAY_ICON);
- SkBitmap* pressed = ResourceBundle::GetSharedInstance().GetBitmapNamed(
- IDR_STATUS_TRAY_ICON_PRESSED);
- icon->SetImage(*bitmap);
- icon->SetPressedImage(*pressed);
- icon->SetToolTip(l10n_util::GetStringUTF16(IDS_PRODUCT_NAME));
- icon->AddObserver(this);
- }
-#endif
-}
-
-void StatusTrayManager::OnClicked() {
- // When the tray icon is clicked, bring up the extensions page for now.
- Browser* browser = BrowserList::GetLastActiveWithProfile(profile_);
- if (browser) {
- // Bring up the existing browser window and show the extensions tab.
- browser->window()->Activate();
- browser->ShowExtensionsTab();
- } else {
- // No windows are currently open, so open a new one.
- Browser::OpenExtensionsWindow(profile_);
- }
-}
diff --git a/chrome/browser/status_icons/status_tray_manager.h b/chrome/browser/status_icons/status_tray_manager.h
deleted file mode 100644
index 6829f94..0000000
--- a/chrome/browser/status_icons/status_tray_manager.h
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright (c) 2010 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.
-
-#ifndef CHROME_BROWSER_STATUS_ICONS_STATUS_TRAY_MANAGER_H_
-#define CHROME_BROWSER_STATUS_ICONS_STATUS_TRAY_MANAGER_H_
-#pragma once
-
-#include "base/scoped_ptr.h"
-#include "chrome/browser/status_icons/status_icon.h"
-
-class Profile;
-class StatusTray;
-
-// Manages the set of status tray icons and associated UI.
-class StatusTrayManager : private StatusIcon::Observer {
- public:
- StatusTrayManager();
- virtual ~StatusTrayManager();
-
- void Init(Profile* profile);
-
- private:
- // Overriden from StatusIcon::Observer:
- virtual void OnClicked();
-
- scoped_ptr<StatusTray> status_tray_;
- Profile* profile_;
-};
-
-#endif // CHROME_BROWSER_STATUS_ICONS_STATUS_TRAY_MANAGER_H_
diff --git a/chrome/browser/status_icons/status_tray_unittest.cc b/chrome/browser/status_icons/status_tray_unittest.cc
index 957faa7..26219bd 100644
--- a/chrome/browser/status_icons/status_tray_unittest.cc
+++ b/chrome/browser/status_icons/status_tray_unittest.cc
@@ -21,35 +21,26 @@ class MockStatusIcon : public StatusIcon {
class TestStatusTray : public StatusTray {
public:
- MOCK_METHOD0(CreateStatusIcon, StatusIcon*());
+ MOCK_METHOD0(CreatePlatformStatusIcon, StatusIcon*());
};
TEST(StatusTrayTest, Create) {
// Check for creation and leaks.
TestStatusTray tray;
- EXPECT_CALL(tray, CreateStatusIcon()).WillOnce(Return(new MockStatusIcon()));
- tray.GetStatusIcon(ASCIIToUTF16("test"));
+ EXPECT_CALL(tray,
+ CreatePlatformStatusIcon()).WillOnce(Return(new MockStatusIcon()));
+ tray.CreateStatusIcon();
}
-TEST(StatusTrayTest, GetIconTwice) {
+// Make sure that removing an icon removes it from the list.
+TEST(StatusTrayTest, CreateRemove) {
TestStatusTray tray;
- string16 id = ASCIIToUTF16("test");
- // We should not try to create a new icon if we get the same ID twice.
- EXPECT_CALL(tray, CreateStatusIcon()).WillOnce(Return(new MockStatusIcon()));
- StatusIcon* icon = tray.GetStatusIcon(id);
- EXPECT_EQ(icon, tray.GetStatusIcon(id));
-}
-
-TEST(StatusTrayTest, GetIconAfterRemove) {
- TestStatusTray tray;
- string16 id = ASCIIToUTF16("test");
- EXPECT_CALL(tray, CreateStatusIcon()).Times(2)
- .WillOnce(Return(new MockStatusIcon()))
- .WillOnce(Return(new MockStatusIcon()));
- StatusIcon* icon = tray.GetStatusIcon(id);
- EXPECT_EQ(icon, tray.GetStatusIcon(id));
-
- // If we remove the icon, then we should create a new one the next time in.
- tray.RemoveStatusIcon(id);
- tray.GetStatusIcon(id);
+ EXPECT_CALL(tray,
+ CreatePlatformStatusIcon()).WillOnce(Return(new MockStatusIcon()));
+ StatusIcon* icon = tray.CreateStatusIcon();
+ EXPECT_EQ(1U, tray.status_icons_.size());
+ tray.RemoveStatusIcon(icon);
+ EXPECT_EQ(0U, tray.status_icons_.size());
+ // Calling again should do nothing.
+ tray.RemoveStatusIcon(icon);
}