1// Copyright (c) 2011 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/ui/views/frame/browser_bubble_host.h" 6 7#include "base/logging.h" 8#include "chrome/browser/ui/views/browser_bubble.h" 9 10BrowserBubbleHost::BrowserBubbleHost() {} 11 12BrowserBubbleHost::~BrowserBubbleHost() {} 13 14void BrowserBubbleHost::WindowMoved() { 15 // Do safe iteration in case the bubble winds up closing as a result of this 16 // message. 17 for (BubbleSet::iterator i = browser_bubbles_.begin(); 18 i != browser_bubbles_.end();) { 19 BubbleSet::iterator bubble = i++; 20 (*bubble)->BrowserWindowMoved(); 21 } 22} 23 24void BrowserBubbleHost::AttachBrowserBubble(BrowserBubble* bubble) { 25 DCHECK(browser_bubbles_.find(bubble) == browser_bubbles_.end()) << 26 "Attempt to register the same BrowserBubble multiple times."; 27 browser_bubbles_.insert(bubble); 28} 29 30void BrowserBubbleHost::DetachBrowserBubble(BrowserBubble* bubble) { 31 BubbleSet::iterator it = browser_bubbles_.find(bubble); 32 DCHECK(it != browser_bubbles_.end()) << 33 "Attempt to detach an unrecognized BrowserBubble."; 34 if (it != browser_bubbles_.end()) 35 browser_bubbles_.erase(it); 36} 37 38void BrowserBubbleHost::Close() { 39 // BrowserWindowClosing will usually cause the bubble to remove itself from 40 // the set, so we need to iterate in a way that's safe against deletion. 41 for (BubbleSet::iterator i = browser_bubbles_.begin(); 42 i != browser_bubbles_.end();) { 43 BubbleSet::iterator bubble = i++; 44 (*bubble)->BrowserWindowClosing(); 45 } 46} 47 48