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

Side by Side Diff: chrome/browser/tabs/tab_strip_model.cc

Issue 6346008: Attempt at fixing crash in tab code. It appears that we end up in a (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/tabs/tab_strip_model.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 (c) 2010 The Chromium Authors. All rights reserved. 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 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 "chrome/browser/tabs/tab_strip_model.h" 5 #include "chrome/browser/tabs/tab_strip_model.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 TabContentsData* data = new TabContentsData(contents); 134 TabContentsData* data = new TabContentsData(contents);
135 data->pinned = pin; 135 data->pinned = pin;
136 if ((add_types & ADD_INHERIT_GROUP) && selected_contents) { 136 if ((add_types & ADD_INHERIT_GROUP) && selected_contents) {
137 if (foreground) { 137 if (foreground) {
138 // Forget any existing relationships, we don't want to make things too 138 // Forget any existing relationships, we don't want to make things too
139 // confusing by having multiple groups active at the same time. 139 // confusing by having multiple groups active at the same time.
140 ForgetAllOpeners(); 140 ForgetAllOpeners();
141 } 141 }
142 // Anything opened by a link we deem to have an opener. 142 // Anything opened by a link we deem to have an opener.
143 data->SetGroup(&selected_contents->controller()); 143 data->SetGroup(&selected_contents->controller());
144 // TODO(sky): nuke when we figure out what is causing 34135.
145 CHECK(data->opener != &(contents->controller()));
144 } else if ((add_types & ADD_INHERIT_OPENER) && selected_contents) { 146 } else if ((add_types & ADD_INHERIT_OPENER) && selected_contents) {
145 if (foreground) { 147 if (foreground) {
146 // Forget any existing relationships, we don't want to make things too 148 // Forget any existing relationships, we don't want to make things too
147 // confusing by having multiple groups active at the same time. 149 // confusing by having multiple groups active at the same time.
148 ForgetAllOpeners(); 150 ForgetAllOpeners();
149 } 151 }
150 data->opener = &selected_contents->controller(); 152 data->opener = &selected_contents->controller();
153 // TODO(sky): nuke when we figure out what is causing 34135.
154 CHECK(data->opener != &(contents->controller()));
151 } 155 }
152 156
153 contents_data_.insert(contents_data_.begin() + index, data); 157 contents_data_.insert(contents_data_.begin() + index, data);
154 158
155 if (index <= selected_index_) { 159 if (index <= selected_index_) {
156 // If a tab is inserted before the current selected index, 160 // If a tab is inserted before the current selected index,
157 // then |selected_index| needs to be incremented. 161 // then |selected_index| needs to be incremented.
158 ++selected_index_; 162 ++selected_index_;
159 } 163 }
160 164
161 FOR_EACH_OBSERVER(TabStripModelObserver, observers_, 165 FOR_EACH_OBSERVER(TabStripModelObserver, observers_,
162 TabInsertedAt(contents, index, foreground)); 166 TabInsertedAt(contents, index, foreground));
163 167
164 if (foreground) 168 if (foreground)
165 ChangeSelectedContentsFrom(selected_contents, index, false); 169 ChangeSelectedContentsFrom(selected_contents, index, false);
166 } 170 }
167 171
168 TabContentsWrapper* TabStripModel::ReplaceTabContentsAt( 172 TabContentsWrapper* TabStripModel::ReplaceTabContentsAt(
169 int index, 173 int index,
170 TabContentsWrapper* new_contents) { 174 TabContentsWrapper* new_contents) {
171 // TODO: this should reset group/opener of any tabs that point at
172 // old_contents.
173 DCHECK(ContainsIndex(index)); 175 DCHECK(ContainsIndex(index));
174 TabContentsWrapper* old_contents = GetContentsAt(index); 176 TabContentsWrapper* old_contents = GetContentsAt(index);
175 177
178 ForgetOpenersAndGroupsReferencing(&(old_contents->controller()));
179
176 contents_data_[index]->contents = new_contents; 180 contents_data_[index]->contents = new_contents;
177 181
178 FOR_EACH_OBSERVER(TabStripModelObserver, observers_, 182 FOR_EACH_OBSERVER(TabStripModelObserver, observers_,
179 TabReplacedAt(this, old_contents, new_contents, index)); 183 TabReplacedAt(this, old_contents, new_contents, index));
180 184
181 // When the selected tab contents is replaced send out selected notification 185 // When the selected tab contents is replaced send out selected notification
182 // too. We do this as nearly all observers need to treat a replace of the 186 // too. We do this as nearly all observers need to treat a replace of the
183 // selected contents as selection changing. 187 // selected contents as selection changing.
184 if (selected_index_ == index) { 188 if (selected_index_ == index) {
185 FOR_EACH_OBSERVER(TabStripModelObserver, observers_, 189 FOR_EACH_OBSERVER(TabStripModelObserver, observers_,
(...skipping 24 matching lines...) Expand all
210 214
211 TabContentsWrapper* removed_contents = GetContentsAt(index); 215 TabContentsWrapper* removed_contents = GetContentsAt(index);
212 // TODO(sky): nuke reason and old_data when we figure out what is causing 216 // TODO(sky): nuke reason and old_data when we figure out what is causing
213 // 34135. 217 // 34135.
214 volatile int reason = 0; 218 volatile int reason = 0;
215 int next_selected_index = 219 int next_selected_index =
216 order_controller_->DetermineNewSelectedIndex(index, &reason); 220 order_controller_->DetermineNewSelectedIndex(index, &reason);
217 volatile TabContentsData old_data = *contents_data_.at(index); 221 volatile TabContentsData old_data = *contents_data_.at(index);
218 delete contents_data_.at(index); 222 delete contents_data_.at(index);
219 contents_data_.erase(contents_data_.begin() + index); 223 contents_data_.erase(contents_data_.begin() + index);
224 ForgetOpenersAndGroupsReferencing(&(removed_contents->controller()));
220 if (empty()) 225 if (empty())
221 closing_all_ = true; 226 closing_all_ = true;
222 FOR_EACH_OBSERVER(TabStripModelObserver, observers_, 227 FOR_EACH_OBSERVER(TabStripModelObserver, observers_,
223 TabDetachedAt(removed_contents, index)); 228 TabDetachedAt(removed_contents, index));
224 if (empty()) { 229 if (empty()) {
225 // TabDetachedAt() might unregister observers, so send |TabStripEmtpy()| in 230 // TabDetachedAt() might unregister observers, so send |TabStripEmtpy()| in
226 // a second pass. 231 // a second pass.
227 FOR_EACH_OBSERVER(TabStripModelObserver, observers_, TabStripEmpty()); 232 FOR_EACH_OBSERVER(TabStripModelObserver, observers_, TabStripEmpty());
228 } else { 233 } else {
229 if (index == selected_index_) { 234 if (index == selected_index_) {
(...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after
1009 FOR_EACH_OBSERVER(TabStripModelObserver, observers_, 1014 FOR_EACH_OBSERVER(TabStripModelObserver, observers_,
1010 TabMoved(moved_data->contents, index, to_position)); 1015 TabMoved(moved_data->contents, index, to_position));
1011 } 1016 }
1012 1017
1013 // static 1018 // static
1014 bool TabStripModel::OpenerMatches(const TabContentsData* data, 1019 bool TabStripModel::OpenerMatches(const TabContentsData* data,
1015 const NavigationController* opener, 1020 const NavigationController* opener,
1016 bool use_group) { 1021 bool use_group) {
1017 return data->opener == opener || (use_group && data->group == opener); 1022 return data->opener == opener || (use_group && data->group == opener);
1018 } 1023 }
1024
1025 void TabStripModel::ForgetOpenersAndGroupsReferencing(
1026 const NavigationController* tab) {
1027 for (TabContentsDataVector::const_iterator i = contents_data_.begin();
1028 i != contents_data_.end(); ++i) {
1029 if ((*i)->group == tab)
1030 (*i)->group = NULL;
1031 if ((*i)->opener == tab)
1032 (*i)->opener = NULL;
1033 }
1034 }
OLDNEW
« no previous file with comments | « chrome/browser/tabs/tab_strip_model.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698