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 // Handles the visible notification (or balloons). 6 7 #ifndef CHROME_BROWSER_NOTIFICATIONS_BALLOON_COLLECTION_BASE_H_ 8 #define CHROME_BROWSER_NOTIFICATIONS_BALLOON_COLLECTION_BASE_H_ 9 #pragma once 10 11 #include <deque> 12 #include <string> 13 14 #include "base/basictypes.h" 15 16 class Balloon; 17 class GURL; 18 class Notification; 19 20 // This class provides support for implementing a BalloonCollection 21 // including the parts common between Chrome UI and ChromeOS UI. 22 class BalloonCollectionBase { 23 public: 24 BalloonCollectionBase(); 25 virtual ~BalloonCollectionBase(); 26 27 typedef std::deque<Balloon*> Balloons; 28 29 // Adds a balloon to the collection. Takes ownership of pointer. 30 virtual void Add(Balloon* balloon); 31 32 // Removes a balloon from the collection (if present). Frees 33 // the pointer after removal. 34 virtual void Remove(Balloon* balloon); 35 36 // Finds any balloon matching the given notification id, and 37 // calls CloseByScript on it. Returns true if anything was 38 // found. 39 virtual bool CloseById(const std::string& id); 40 41 // Finds all balloons matching the given notification source, 42 // and calls CloseByScript on them. Returns true if anything 43 // was found. 44 virtual bool CloseAllBySourceOrigin(const GURL& source_origin); 45 46 // Calls CloseByScript on all balloons. 47 virtual void CloseAll(); 48 balloons()49 const Balloons& balloons() const { return balloons_; } 50 51 // Returns the balloon matching the given notification, or 52 // NULL if there is no matching balloon. 53 Balloon* FindBalloon(const Notification& notification); 54 55 // The number of balloons being displayed. count()56 int count() const { return static_cast<int>(balloons_.size()); } 57 58 private: 59 // Queue of active balloons. Pointers are owned by this class. 60 Balloons balloons_; 61 62 DISALLOW_COPY_AND_ASSIGN(BalloonCollectionBase); 63 }; 64 65 #endif // CHROME_BROWSER_NOTIFICATIONS_BALLOON_COLLECTION_BASE_H_ 66