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

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

Issue 1427613002: [TabManager] Move remaining discard logic from TabStripModel to TabManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: chrisha@ comments. Created 5 years, 1 month 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 | « chrome/browser/ui/browser.cc ('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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ui/tabs/tab_strip_model.h" 5 #include "chrome/browser/ui/tabs/tab_strip_model.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
11 11
12 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
13 #include "base/stl_util.h" 13 #include "base/stl_util.h"
14 #include "chrome/app/chrome_command_ids.h" 14 #include "chrome/app/chrome_command_ids.h"
15 #include "chrome/browser/browser_shutdown.h" 15 #include "chrome/browser/browser_shutdown.h"
16 #include "chrome/browser/defaults.h" 16 #include "chrome/browser/defaults.h"
17 #include "chrome/browser/extensions/tab_helper.h" 17 #include "chrome/browser/extensions/tab_helper.h"
18 #include "chrome/browser/memory/tab_manager_web_contents_data.h"
19 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" 19 #include "chrome/browser/ui/tab_contents/core_tab_helper.h"
21 #include "chrome/browser/ui/tab_contents/core_tab_helper_delegate.h" 20 #include "chrome/browser/ui/tab_contents/core_tab_helper_delegate.h"
22 #include "chrome/browser/ui/tabs/tab_strip_model_delegate.h" 21 #include "chrome/browser/ui/tabs/tab_strip_model_delegate.h"
23 #include "chrome/browser/ui/tabs/tab_strip_model_order_controller.h" 22 #include "chrome/browser/ui/tabs/tab_strip_model_order_controller.h"
24 #include "chrome/browser/ui/tabs/tab_utils.h" 23 #include "chrome/browser/ui/tabs/tab_utils.h"
25 #include "chrome/browser/ui/web_contents_sizer.h" 24 #include "chrome/browser/ui/web_contents_sizer.h"
26 #include "chrome/common/url_constants.h" 25 #include "chrome/common/url_constants.h"
27 #include "components/web_modal/web_contents_modal_dialog_manager.h" 26 #include "components/web_modal/web_contents_modal_dialog_manager.h"
28 #include "content/public/browser/render_process_host.h" 27 #include "content/public/browser/render_process_host.h"
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 bool pinned() const { return pinned_; } 153 bool pinned() const { return pinned_; }
155 void set_pinned(bool value) { pinned_ = value; } 154 void set_pinned(bool value) { pinned_ = value; }
156 bool blocked() const { return blocked_; } 155 bool blocked() const { return blocked_; }
157 void set_blocked(bool value) { blocked_ = value; } 156 void set_blocked(bool value) { blocked_ = value; }
158 157
159 private: 158 private:
160 // Make sure that if someone deletes this WebContents out from under us, it 159 // Make sure that if someone deletes this WebContents out from under us, it
161 // is properly removed from the tab strip. 160 // is properly removed from the tab strip.
162 void WebContentsDestroyed() override; 161 void WebContentsDestroyed() override;
163 162
164 // Marks the tab as no longer discarded if it has been reloaded from another
165 // source (ie: context menu).
166 void DidStartLoading() override;
167
168 // The WebContents being tracked by this WebContentsData. The 163 // The WebContents being tracked by this WebContentsData. The
169 // WebContentsObserver does keep a reference, but when the WebContents is 164 // WebContentsObserver does keep a reference, but when the WebContents is
170 // deleted, the WebContentsObserver reference is NULLed and thus inaccessible. 165 // deleted, the WebContentsObserver reference is NULLed and thus inaccessible.
171 WebContents* contents_; 166 WebContents* contents_;
172 167
173 // The TabStripModel containing this WebContents. 168 // The TabStripModel containing this WebContents.
174 TabStripModel* tab_strip_model_; 169 TabStripModel* tab_strip_model_;
175 170
176 // The group is used to model a set of tabs spawned from a single parent 171 // The group is used to model a set of tabs spawned from a single parent
177 // tab. This value is preserved for a given tab as long as the tab remains 172 // tab. This value is preserved for a given tab as long as the tab remains
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 void TabStripModel::WebContentsData::WebContentsDestroyed() { 219 void TabStripModel::WebContentsData::WebContentsDestroyed() {
225 DCHECK_EQ(contents_, web_contents()); 220 DCHECK_EQ(contents_, web_contents());
226 221
227 // Note that we only detach the contents here, not close it - it's 222 // Note that we only detach the contents here, not close it - it's
228 // already been closed. We just want to undo our bookkeeping. 223 // already been closed. We just want to undo our bookkeeping.
229 int index = tab_strip_model_->GetIndexOfWebContents(web_contents()); 224 int index = tab_strip_model_->GetIndexOfWebContents(web_contents());
230 DCHECK_NE(TabStripModel::kNoTab, index); 225 DCHECK_NE(TabStripModel::kNoTab, index);
231 tab_strip_model_->DetachWebContentsAt(index); 226 tab_strip_model_->DetachWebContentsAt(index);
232 } 227 }
233 228
234 void TabStripModel::WebContentsData::DidStartLoading() {
235 // TODO(georgesak): move this into tab_manager.cc.
236 memory::TabManager::WebContentsData::SetDiscardState(contents_, false);
237 }
238
239 /////////////////////////////////////////////////////////////////////////////// 229 ///////////////////////////////////////////////////////////////////////////////
240 // TabStripModel, public: 230 // TabStripModel, public:
241 231
242 TabStripModel::TabStripModel(TabStripModelDelegate* delegate, Profile* profile) 232 TabStripModel::TabStripModel(TabStripModelDelegate* delegate, Profile* profile)
243 : delegate_(delegate), 233 : delegate_(delegate),
244 profile_(profile), 234 profile_(profile),
245 closing_all_(false), 235 closing_all_(false),
246 in_notify_(false), 236 in_notify_(false),
247 weak_factory_(this) { 237 weak_factory_(this) {
248 DCHECK(delegate_); 238 DCHECK(delegate_);
(...skipping 1011 matching lines...) Expand 10 before | Expand all | Expand 10 after
1260 ? TabStripModelObserver::CHANGE_REASON_USER_GESTURE 1250 ? TabStripModelObserver::CHANGE_REASON_USER_GESTURE
1261 : TabStripModelObserver::CHANGE_REASON_NONE; 1251 : TabStripModelObserver::CHANGE_REASON_NONE;
1262 CHECK(!in_notify_); 1252 CHECK(!in_notify_);
1263 in_notify_ = true; 1253 in_notify_ = true;
1264 FOR_EACH_OBSERVER(TabStripModelObserver, observers_, 1254 FOR_EACH_OBSERVER(TabStripModelObserver, observers_,
1265 ActiveTabChanged(old_contents, 1255 ActiveTabChanged(old_contents,
1266 new_contents, 1256 new_contents,
1267 active_index(), 1257 active_index(),
1268 reason)); 1258 reason));
1269 in_notify_ = false; 1259 in_notify_ = false;
1270 // TODO(georgesak): move this into tab_manager.cc.
1271 memory::TabManager::WebContentsData::SetDiscardState(new_contents, false);
1272 } 1260 }
1273 } 1261 }
1274 1262
1275 void TabStripModel::NotifyIfActiveOrSelectionChanged( 1263 void TabStripModel::NotifyIfActiveOrSelectionChanged(
1276 WebContents* old_contents, 1264 WebContents* old_contents,
1277 NotifyTypes notify_types, 1265 NotifyTypes notify_types,
1278 const ui::ListSelectionModel& old_model) { 1266 const ui::ListSelectionModel& old_model) {
1279 NotifyIfActiveTabChanged(old_contents, notify_types); 1267 NotifyIfActiveTabChanged(old_contents, notify_types);
1280 1268
1281 if (!selection_model().Equals(old_model)) { 1269 if (!selection_model().Equals(old_model)) {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1372 1360
1373 void TabStripModel::FixOpenersAndGroupsReferencing(int index) { 1361 void TabStripModel::FixOpenersAndGroupsReferencing(int index) {
1374 WebContents* old_contents = GetWebContentsAtImpl(index); 1362 WebContents* old_contents = GetWebContentsAtImpl(index);
1375 for (WebContentsData* data : contents_data_) { 1363 for (WebContentsData* data : contents_data_) {
1376 if (data->group() == old_contents) 1364 if (data->group() == old_contents)
1377 data->set_group(contents_data_[index]->group()); 1365 data->set_group(contents_data_[index]->group());
1378 if (data->opener() == old_contents) 1366 if (data->opener() == old_contents)
1379 data->set_opener(contents_data_[index]->opener()); 1367 data->set_opener(contents_data_[index]->opener());
1380 } 1368 }
1381 } 1369 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698