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

Side by Side Diff: components/sessions/core/tab_restore_service_helper.cc

Issue 2248873002: Convert WindowOpenDisposition to an enum class. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 3 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
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 "components/sessions/core/tab_restore_service_helper.h" 5 #include "components/sessions/core/tab_restore_service_helper.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <iterator> 10 #include <iterator>
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 } 122 }
123 123
124 const TabRestoreService::Entries& TabRestoreServiceHelper::entries() const { 124 const TabRestoreService::Entries& TabRestoreServiceHelper::entries() const {
125 return entries_; 125 return entries_;
126 } 126 }
127 127
128 std::vector<LiveTab*> TabRestoreServiceHelper::RestoreMostRecentEntry( 128 std::vector<LiveTab*> TabRestoreServiceHelper::RestoreMostRecentEntry(
129 LiveTabContext* context) { 129 LiveTabContext* context) {
130 if (entries_.empty()) 130 if (entries_.empty())
131 return std::vector<LiveTab*>(); 131 return std::vector<LiveTab*>();
132 return RestoreEntryById(context, entries_.front()->id, UNKNOWN); 132 return RestoreEntryById(context, entries_.front()->id,
133 WindowOpenDisposition::UNKNOWN);
133 } 134 }
134 135
135 std::unique_ptr<TabRestoreService::Tab> 136 std::unique_ptr<TabRestoreService::Tab>
136 TabRestoreServiceHelper::RemoveTabEntryById(SessionID::id_type id) { 137 TabRestoreServiceHelper::RemoveTabEntryById(SessionID::id_type id) {
137 auto it = GetEntryIteratorById(id); 138 auto it = GetEntryIteratorById(id);
138 if (it == entries_.end()) 139 if (it == entries_.end())
139 return nullptr; 140 return nullptr;
140 141
141 if ((*it)->type != TabRestoreService::TAB) 142 if ((*it)->type != TabRestoreService::TAB)
142 return nullptr; 143 return nullptr;
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 UpdateTabBrowserIDs(restored_tab_browser_id, 236 UpdateTabBrowserIDs(restored_tab_browser_id,
236 context->GetSessionID().id()); 237 context->GetSessionID().id());
237 for (auto& tab_j : window.tabs) 238 for (auto& tab_j : window.tabs)
238 tab_j->browser_id = context->GetSessionID().id(); 239 tab_j->browser_id = context->GetSessionID().id();
239 } 240 }
240 break; 241 break;
241 } 242 }
242 } 243 }
243 context->ShowBrowserWindow(); 244 context->ShowBrowserWindow();
244 245
245 if (disposition == CURRENT_TAB && current_context && 246 if (disposition == WindowOpenDisposition::CURRENT_TAB &&
246 current_context->GetActiveLiveTab()) { 247 current_context && current_context->GetActiveLiveTab()) {
247 current_context->CloseTab(); 248 current_context->CloseTab();
248 } 249 }
249 break; 250 break;
250 } 251 }
251 } 252 }
252 253
253 if (!restoring_tab_in_window) { 254 if (!restoring_tab_in_window) {
254 entries_.erase(entry_iterator); 255 entries_.erase(entry_iterator);
255 } 256 }
256 257
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 tab->pinned = context->IsTabPinned(tab->tabstrip_index); 367 tab->pinned = context->IsTabPinned(tab->tabstrip_index);
367 } 368 }
368 } 369 }
369 370
370 LiveTabContext* TabRestoreServiceHelper::RestoreTab( 371 LiveTabContext* TabRestoreServiceHelper::RestoreTab(
371 const Tab& tab, 372 const Tab& tab,
372 LiveTabContext* context, 373 LiveTabContext* context,
373 WindowOpenDisposition disposition, 374 WindowOpenDisposition disposition,
374 LiveTab** live_tab) { 375 LiveTab** live_tab) {
375 LiveTab* restored_tab; 376 LiveTab* restored_tab;
376 if (disposition == CURRENT_TAB && context) { 377 if (disposition == WindowOpenDisposition::CURRENT_TAB && context) {
377 restored_tab = context->ReplaceRestoredTab( 378 restored_tab = context->ReplaceRestoredTab(
378 tab.navigations, tab.current_navigation_index, tab.from_last_session, 379 tab.navigations, tab.current_navigation_index, tab.from_last_session,
379 tab.extension_app_id, tab.platform_data.get(), tab.user_agent_override); 380 tab.extension_app_id, tab.platform_data.get(), tab.user_agent_override);
380 } else { 381 } else {
381 // We only respsect the tab's original browser if there's no disposition. 382 // We only respsect the tab's original browser if there's no disposition.
382 if (disposition == UNKNOWN && tab.browser_id) { 383 if (disposition == WindowOpenDisposition::UNKNOWN && tab.browser_id) {
383 context = client_->FindLiveTabContextWithID(tab.browser_id); 384 context = client_->FindLiveTabContextWithID(tab.browser_id);
384 } 385 }
385 386
386 int tab_index = -1; 387 int tab_index = -1;
387 388
388 // |context| will be NULL in cases where one isn't already available (eg, 389 // |context| will be NULL in cases where one isn't already available (eg,
389 // when invoked on Mac OS X with no windows open). In this case, create a 390 // when invoked on Mac OS X with no windows open). In this case, create a
390 // new browser into which we restore the tabs. 391 // new browser into which we restore the tabs.
391 if (context && disposition != NEW_WINDOW) { 392 if (context && disposition != WindowOpenDisposition::NEW_WINDOW) {
392 tab_index = tab.tabstrip_index; 393 tab_index = tab.tabstrip_index;
393 } else { 394 } else {
394 context = client_->CreateLiveTabContext(std::string()); 395 context = client_->CreateLiveTabContext(std::string());
395 if (tab.browser_id) 396 if (tab.browser_id)
396 UpdateTabBrowserIDs(tab.browser_id, context->GetSessionID().id()); 397 UpdateTabBrowserIDs(tab.browser_id, context->GetSessionID().id());
397 } 398 }
398 399
399 // Place the tab at the end if the tab index is no longer valid or 400 // Place the tab at the end if the tab index is no longer valid or
400 // we were passed a specific disposition. 401 // we were passed a specific disposition.
401 if (tab_index < 0 || tab_index > context->GetTabCount() || 402 if (tab_index < 0 || tab_index > context->GetTabCount() ||
402 disposition != UNKNOWN) { 403 disposition != WindowOpenDisposition::UNKNOWN) {
403 tab_index = context->GetTabCount(); 404 tab_index = context->GetTabCount();
404 } 405 }
405 406
406 restored_tab = context->AddRestoredTab( 407 restored_tab = context->AddRestoredTab(
407 tab.navigations, tab_index, tab.current_navigation_index, 408 tab.navigations, tab_index, tab.current_navigation_index,
408 tab.extension_app_id, disposition != NEW_BACKGROUND_TAB, tab.pinned, 409 tab.extension_app_id,
410 disposition != WindowOpenDisposition::NEW_BACKGROUND_TAB, tab.pinned,
409 tab.from_last_session, tab.platform_data.get(), 411 tab.from_last_session, tab.platform_data.get(),
410 tab.user_agent_override); 412 tab.user_agent_override);
411 restored_tab->LoadIfNecessary(); 413 restored_tab->LoadIfNecessary();
412 } 414 }
413 client_->OnTabRestored( 415 client_->OnTabRestored(
414 tab.navigations.at(tab.current_navigation_index).virtual_url()); 416 tab.navigations.at(tab.current_navigation_index).virtual_url());
415 if (live_tab) 417 if (live_tab)
416 *live_tab = restored_tab; 418 *live_tab = restored_tab;
417 419
418 return context; 420 return context;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 tab.browser_id = new_id; 484 tab.browser_id = new_id;
483 } 485 }
484 } 486 }
485 } 487 }
486 488
487 base::Time TabRestoreServiceHelper::TimeNow() const { 489 base::Time TabRestoreServiceHelper::TimeNow() const {
488 return time_factory_ ? time_factory_->TimeNow() : base::Time::Now(); 490 return time_factory_ ? time_factory_->TimeNow() : base::Time::Now();
489 } 491 }
490 492
491 } // namespace sessions 493 } // namespace sessions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698