OLD | NEW |
(Empty) | |
| 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 |
| 10 StatusTray::StatusTray(StatusIconFactory* factory) |
| 11 : factory_(factory) { |
| 12 } |
| 13 |
| 14 StatusTray::~StatusTray() { |
| 15 // Walk any active status icons and delete them. |
| 16 STLDeleteContainerPairSecondPointers(status_icons_.begin(), |
| 17 status_icons_.end()); |
| 18 } |
| 19 |
| 20 StatusIcon* StatusTray::GetStatusIcon(const string16& identifier) { |
| 21 StatusIconMap::const_iterator iter = status_icons_.find(identifier); |
| 22 if (iter != status_icons_.end()) |
| 23 return iter->second; |
| 24 |
| 25 // No existing StatusIcon, create a new one. |
| 26 StatusIcon* icon = factory_->CreateIcon(); |
| 27 if (icon) |
| 28 status_icons_[identifier] = icon; |
| 29 return icon; |
| 30 } |
| 31 |
| 32 void StatusTray::RemoveStatusIcon(const string16& identifier) { |
| 33 StatusIconMap::iterator iter = status_icons_.find(identifier); |
| 34 if (iter != status_icons_.end()) { |
| 35 // Free the StatusIcon from the map (can't put scoped_ptr in a map, so we |
| 36 // have to do it manually). |
| 37 delete iter->second; |
| 38 status_icons_.erase(iter); |
| 39 } |
| 40 } |
OLD | NEW |