Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(204)

Side by Side Diff: components/bubble/bubble_manager.cc

Issue 2640223004: Remove ScopedVector in //components/bubble. (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/bubble/bubble_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 CloseAllMatchingBubbles(nullptr, nullptr, reason); 60 CloseAllMatchingBubbles(nullptr, nullptr, reason);
61 } 61 }
62 62
63 void BubbleManager::UpdateAllBubbleAnchors() { 63 void BubbleManager::UpdateAllBubbleAnchors() {
64 DCHECK(thread_checker_.CalledOnValidThread()); 64 DCHECK(thread_checker_.CalledOnValidThread());
65 DCHECK_NE(manager_state_, ITERATING_BUBBLES); 65 DCHECK_NE(manager_state_, ITERATING_BUBBLES);
66 66
67 // Guard against bubbles being added or removed while iterating the bubbles. 67 // Guard against bubbles being added or removed while iterating the bubbles.
68 ManagerState original_state = manager_state_; 68 ManagerState original_state = manager_state_;
69 manager_state_ = ITERATING_BUBBLES; 69 manager_state_ = ITERATING_BUBBLES;
70 for (auto* controller : controllers_) 70 for (auto& controller : controllers_)
71 controller->UpdateAnchorPosition(); 71 controller->UpdateAnchorPosition();
72 manager_state_ = original_state; 72 manager_state_ = original_state;
73 } 73 }
74 74
75 void BubbleManager::AddBubbleManagerObserver(BubbleManagerObserver* observer) { 75 void BubbleManager::AddBubbleManagerObserver(BubbleManagerObserver* observer) {
76 observers_.AddObserver(observer); 76 observers_.AddObserver(observer);
77 } 77 }
78 78
79 void BubbleManager::RemoveBubbleManagerObserver( 79 void BubbleManager::RemoveBubbleManagerObserver(
80 BubbleManagerObserver* observer) { 80 BubbleManagerObserver* observer) {
(...skipping 18 matching lines...) Expand all
99 const content::RenderFrameHost* owner, 99 const content::RenderFrameHost* owner,
100 BubbleCloseReason reason) { 100 BubbleCloseReason reason) {
101 // Specifying both an owning frame and a particular bubble to close doesn't 101 // Specifying both an owning frame and a particular bubble to close doesn't
102 // make sense. If we have a frame, all bubbles owned by that frame need to 102 // make sense. If we have a frame, all bubbles owned by that frame need to
103 // have the opportunity to close. If we want to close a specific bubble, then 103 // have the opportunity to close. If we want to close a specific bubble, then
104 // it should get the close event regardless of which frame owns it. On the 104 // it should get the close event regardless of which frame owns it. On the
105 // other hand, OR'ing the conditions needs a special case in order to be able 105 // other hand, OR'ing the conditions needs a special case in order to be able
106 // to close all bubbles, so we disallow passing both until a need appears. 106 // to close all bubbles, so we disallow passing both until a need appears.
107 DCHECK(!bubble || !owner); 107 DCHECK(!bubble || !owner);
108 108
109 ScopedVector<BubbleController> close_queue; 109 std::vector<std::unique_ptr<BubbleController>> close_queue;
110 110
111 // Guard against bubbles being added or removed while iterating the bubbles. 111 // Guard against bubbles being added or removed while iterating the bubbles.
112 ManagerState original_state = manager_state_; 112 ManagerState original_state = manager_state_;
113 manager_state_ = ITERATING_BUBBLES; 113 manager_state_ = ITERATING_BUBBLES;
114 for (auto i = controllers_.begin(); i != controllers_.end();) { 114 for (auto i = controllers_.begin(); i != controllers_.end();) {
115 if ((!bubble || bubble == *i) && (!owner || (*i)->OwningFrameIs(owner)) && 115 if ((!bubble || bubble == (*i).get()) &&
116 (*i)->ShouldClose(reason)) { 116 (!owner || (*i)->OwningFrameIs(owner)) && (*i)->ShouldClose(reason)) {
117 close_queue.push_back(*i); 117 close_queue.push_back(std::move(*i));
118 i = controllers_.weak_erase(i); 118 i = controllers_.erase(i);
119 } else { 119 } else {
120 ++i; 120 ++i;
121 } 121 }
122 } 122 }
123 manager_state_ = original_state; 123 manager_state_ = original_state;
124 124
125 for (auto* controller : close_queue) { 125 for (auto& controller : close_queue) {
126 controller->DoClose(reason); 126 controller->DoClose(reason);
127 127
128 for (auto& observer : observers_) 128 for (auto& observer : observers_)
129 observer.OnBubbleClosed(controller->AsWeakPtr(), reason); 129 observer.OnBubbleClosed(controller->AsWeakPtr(), reason);
130 } 130 }
131 131
132 return !close_queue.empty(); 132 return !close_queue.empty();
133 } 133 }
OLDNEW
« no previous file with comments | « components/bubble/bubble_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698