Chromium Code Reviews| 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/notifications/balloon_collection_base.h" | |
| 6 | |
| 7 #include "base/stl_util-inl.h" | |
| 8 #include "chrome/browser/notifications/notification.h" | |
| 9 #include "googleurl/src/gurl.h" | |
| 10 | |
| 11 BalloonCollectionBase::BalloonCollectionBase() { | |
| 12 } | |
| 13 | |
| 14 BalloonCollectionBase::~BalloonCollectionBase() { | |
| 15 STLDeleteElements(&balloons_); | |
| 16 } | |
| 17 | |
| 18 void BalloonCollectionBase::Add(Balloon* balloon) { | |
| 19 balloons_.push_back(balloon); | |
| 20 } | |
| 21 | |
| 22 void BalloonCollectionBase::Remove(Balloon* balloon) { | |
| 23 // Free after removing. | |
| 24 scoped_ptr<Balloon> to_delete(balloon); | |
| 25 Balloons::iterator iter; | |
| 26 for (iter = balloons_.begin(); iter != balloons_.end(); ++iter) { | |
| 27 if ((*iter) == balloon) { | |
| 28 balloons_.erase(iter); | |
| 29 return; | |
| 30 } | |
| 31 } | |
| 32 } | |
| 33 | |
| 34 bool BalloonCollectionBase::CloseById(const std::string& id) { | |
| 35 // Use a local list of balloons to close to avoid breaking | |
| 36 // iterator changes on each close. | |
| 37 Balloons to_close; | |
| 38 Balloons::iterator iter; | |
| 39 for (iter = balloons_.begin(); iter != balloons_.end(); ++iter) { | |
| 40 if ((*iter)->notification().notification_id() == id) | |
| 41 to_close.push_back(*iter); | |
| 42 } | |
| 43 for (iter = to_close.begin(); iter != to_close.end(); ++iter) | |
| 44 (*iter)->CloseByScript(); | |
| 45 | |
| 46 return !to_close.empty(); | |
| 47 } | |
| 48 | |
| 49 bool BalloonCollectionBase::CloseAllBySourceOrigin( | |
| 50 const GURL& source_origin) { | |
| 51 // Use a local list of balloons to close to avoid breaking | |
| 52 // iterator changes on each close. | |
| 53 Balloons to_close; | |
| 54 Balloons::iterator iter; | |
| 55 for (iter = balloons_.begin(); iter != balloons_.end(); ++iter) { | |
| 56 if ((*iter)->notification().origin_url() == source_origin) | |
| 57 to_close.push_back(*iter); | |
| 58 } | |
| 59 for (iter = to_close.begin(); iter != to_close.end(); ++iter) | |
| 60 (*iter)->CloseByScript(); | |
| 61 | |
| 62 return !to_close.empty(); | |
| 63 } | |
| 64 | |
| 65 Balloon* BalloonCollectionBase::FindBalloon( | |
| 66 const Notification& notification) { | |
| 67 Balloons::iterator iter; | |
| 68 for (iter = balloons_.begin(); iter != balloons_.end(); ++iter) { | |
| 69 if ((*iter)->notification().notification_id() == | |
| 70 notification.notification_id()) { | |
| 71 return *iter; | |
|
Andrew T Wilson (Slow)
2010/11/11 01:07:44
I'm not certain whether { should be omitted in thi
John Gregg
2010/11/11 18:13:51
Strangely the style guide doesn't actually spell o
| |
| 72 } | |
| 73 } | |
| 74 return NULL; | |
| 75 } | |
| OLD | NEW |