status_tray.cc revision c407dc5cd9bdc5668497f21b26b09d988ab439de
1// Copyright (c) 2010 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "chrome/browser/status_icons/status_tray.h" 6 7#include "base/stl_util-inl.h" 8#include "chrome/browser/status_icons/status_icon.h" 9 10StatusTray::StatusTray() { 11} 12 13StatusTray::~StatusTray() { 14 RemoveAllIcons(); 15} 16 17void StatusTray::RemoveAllIcons() { 18 // Walk any active status icons and delete them. 19 STLDeleteContainerPairSecondPointers(status_icons_.begin(), 20 status_icons_.end()); 21 status_icons_.clear(); 22} 23 24StatusIcon* StatusTray::GetStatusIcon(const string16& identifier) { 25 StatusIconMap::const_iterator iter = status_icons_.find(identifier); 26 if (iter != status_icons_.end()) 27 return iter->second; 28 29 // No existing StatusIcon, create a new one. 30 StatusIcon* icon = CreateStatusIcon(); 31 if (icon) 32 status_icons_[identifier] = icon; 33 return icon; 34} 35 36void StatusTray::RemoveStatusIcon(const string16& identifier) { 37 StatusIconMap::iterator iter = status_icons_.find(identifier); 38 if (iter != status_icons_.end()) { 39 // Free the StatusIcon from the map (can't put scoped_ptr in a map, so we 40 // have to do it manually). 41 delete iter->second; 42 status_icons_.erase(iter); 43 } 44} 45