Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/bubble/bubble_manager.h" | 5 #include "components/bubble/bubble_manager.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "components/bubble/bubble_controller.h" | 10 #include "components/bubble/bubble_controller.h" |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 40 break; | 40 break; |
| 41 } | 41 } |
| 42 | 42 |
| 43 return bubble_ref; | 43 return bubble_ref; |
| 44 } | 44 } |
| 45 | 45 |
| 46 bool BubbleManager::CloseBubble(BubbleReference bubble, | 46 bool BubbleManager::CloseBubble(BubbleReference bubble, |
| 47 BubbleCloseReason reason) { | 47 BubbleCloseReason reason) { |
| 48 DCHECK(thread_checker_.CalledOnValidThread()); | 48 DCHECK(thread_checker_.CalledOnValidThread()); |
| 49 DCHECK_NE(manager_state_, ITERATING_BUBBLES); | 49 DCHECK_NE(manager_state_, ITERATING_BUBBLES); |
| 50 return CloseAllMatchingBubbles(bubble.get(), reason); | 50 return CloseAllMatchingBubbles(bubble.get(), nullptr, reason); |
| 51 } | 51 } |
| 52 | 52 |
| 53 void BubbleManager::CloseAllBubbles(BubbleCloseReason reason) { | 53 void BubbleManager::CloseAllBubbles(BubbleCloseReason reason) { |
| 54 // The following close reasons don't make sense for multiple bubbles: | 54 // The following close reasons don't make sense for multiple bubbles: |
| 55 DCHECK_NE(reason, BUBBLE_CLOSE_ACCEPTED); | 55 DCHECK_NE(reason, BUBBLE_CLOSE_ACCEPTED); |
| 56 DCHECK_NE(reason, BUBBLE_CLOSE_CANCELED); | 56 DCHECK_NE(reason, BUBBLE_CLOSE_CANCELED); |
| 57 DCHECK(thread_checker_.CalledOnValidThread()); | 57 DCHECK(thread_checker_.CalledOnValidThread()); |
| 58 DCHECK_NE(manager_state_, ITERATING_BUBBLES); | 58 DCHECK_NE(manager_state_, ITERATING_BUBBLES); |
| 59 CloseAllMatchingBubbles(nullptr, reason); | 59 CloseAllMatchingBubbles(nullptr, nullptr, reason); |
| 60 } | 60 } |
| 61 | 61 |
| 62 void BubbleManager::UpdateAllBubbleAnchors() { | 62 void BubbleManager::UpdateAllBubbleAnchors() { |
| 63 DCHECK(thread_checker_.CalledOnValidThread()); | 63 DCHECK(thread_checker_.CalledOnValidThread()); |
| 64 DCHECK_NE(manager_state_, ITERATING_BUBBLES); | 64 DCHECK_NE(manager_state_, ITERATING_BUBBLES); |
| 65 | 65 |
| 66 // Guard against bubbles being added or removed while iterating the bubbles. | 66 // Guard against bubbles being added or removed while iterating the bubbles. |
| 67 ManagerState original_state = manager_state_; | 67 ManagerState original_state = manager_state_; |
| 68 manager_state_ = ITERATING_BUBBLES; | 68 manager_state_ = ITERATING_BUBBLES; |
| 69 for (auto controller : controllers_) | 69 for (auto controller : controllers_) |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 82 | 82 |
| 83 void BubbleManager::FinalizePendingRequests() { | 83 void BubbleManager::FinalizePendingRequests() { |
| 84 // Return if already "Finalized". | 84 // Return if already "Finalized". |
| 85 if (manager_state_ == NO_MORE_BUBBLES) | 85 if (manager_state_ == NO_MORE_BUBBLES) |
| 86 return; | 86 return; |
| 87 | 87 |
| 88 manager_state_ = NO_MORE_BUBBLES; | 88 manager_state_ = NO_MORE_BUBBLES; |
| 89 CloseAllBubbles(BUBBLE_CLOSE_FORCED); | 89 CloseAllBubbles(BUBBLE_CLOSE_FORCED); |
| 90 } | 90 } |
| 91 | 91 |
| 92 bool BubbleManager::CloseAllMatchingBubbles(BubbleController* match, | 92 void BubbleManager::CloseBubblesOwnedBy(const content::RenderFrameHost* frame) { |
| 93 BubbleCloseReason reason) { | 93 CloseAllMatchingBubbles(nullptr, frame, BUBBLE_CLOSE_FRAME_DESTROYED); |
| 94 } | |
| 95 | |
| 96 bool BubbleManager::CloseAllMatchingBubbles( | |
| 97 BubbleController* bubble, | |
| 98 const content::RenderFrameHost* owner, | |
| 99 BubbleCloseReason reason) { | |
| 100 DCHECK(!bubble || !owner) << "It doesn't make sense to close a particular " | |
| 101 "bubble iff it's owned by a particular frame."; | |
|
Peter Kasting
2016/02/09 02:10:52
Nit: Rather than an output string here, I would le
Jeffrey Yasskin
2016/02/09 20:54:44
Done; how's this comment look?
| |
| 102 | |
| 94 ScopedVector<BubbleController> close_queue; | 103 ScopedVector<BubbleController> close_queue; |
| 95 | 104 |
| 96 // Guard against bubbles being added or removed while iterating the bubbles. | 105 // Guard against bubbles being added or removed while iterating the bubbles. |
| 97 ManagerState original_state = manager_state_; | 106 ManagerState original_state = manager_state_; |
| 98 manager_state_ = ITERATING_BUBBLES; | 107 manager_state_ = ITERATING_BUBBLES; |
| 99 for (auto iter = controllers_.begin(); iter != controllers_.end();) { | 108 for (auto i = controllers_.begin(); i != controllers_.end();) { |
| 100 if ((!match || match == *iter) && (*iter)->ShouldClose(reason)) { | 109 if ((!bubble || bubble == *i) && (!owner || (*i)->OwningFrameIs(owner)) && |
| 101 close_queue.push_back(*iter); | 110 (*i)->ShouldClose(reason)) { |
| 102 iter = controllers_.weak_erase(iter); | 111 close_queue.push_back(*i); |
| 112 i = controllers_.weak_erase(i); | |
| 103 } else { | 113 } else { |
| 104 ++iter; | 114 ++i; |
| 105 } | 115 } |
| 106 } | 116 } |
| 107 manager_state_ = original_state; | 117 manager_state_ = original_state; |
| 108 | 118 |
| 109 for (auto controller : close_queue) { | 119 for (auto controller : close_queue) { |
| 110 controller->DoClose(); | 120 controller->DoClose(); |
| 111 | 121 |
| 112 FOR_EACH_OBSERVER(BubbleManagerObserver, observers_, | 122 FOR_EACH_OBSERVER(BubbleManagerObserver, observers_, |
| 113 OnBubbleClosed(controller->AsWeakPtr(), reason)); | 123 OnBubbleClosed(controller->AsWeakPtr(), reason)); |
| 114 } | 124 } |
| 115 | 125 |
| 116 return !close_queue.empty(); | 126 return !close_queue.empty(); |
| 117 } | 127 } |
| OLD | NEW |