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

Side by Side Diff: chrome/browser/sessions/tab_restore_service_helper.cc

Issue 1343833002: Abstract content::SessionStorageNamespace from core TabRestore code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@extension_tab_helper
Patch Set: Hopefully fix Windows Created 5 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 "chrome/browser/sessions/tab_restore_service_helper.h" 5 #include "chrome/browser/sessions/tab_restore_service_helper.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
12 #include "base/stl_util.h" 12 #include "base/stl_util.h"
13 #include "chrome/browser/sessions/tab_restore_service_delegate.h" 13 #include "chrome/browser/sessions/tab_restore_service_delegate.h"
14 #include "chrome/browser/sessions/tab_restore_service_observer.h" 14 #include "chrome/browser/sessions/tab_restore_service_observer.h"
15 #include "components/sessions/content/content_serialized_navigation_builder.h" 15 #include "components/sessions/content/content_serialized_navigation_builder.h"
16 #include "components/sessions/core/tab_restore_service_client.h" 16 #include "components/sessions/core/tab_restore_service_client.h"
17 #include "components/sessions/session_types.h" 17 #include "components/sessions/session_types.h"
18 #include "content/public/browser/navigation_controller.h" 18 #include "content/public/browser/navigation_controller.h"
19 #include "content/public/browser/navigation_entry.h" 19 #include "content/public/browser/navigation_entry.h"
20 #include "content/public/browser/session_storage_namespace.h"
21 #include "content/public/browser/web_contents.h" 20 #include "content/public/browser/web_contents.h"
22 21
23 using content::NavigationController; 22 using content::NavigationController;
24 using content::NavigationEntry; 23 using content::NavigationEntry;
25 using content::WebContents; 24 using content::WebContents;
26 25
27 // TabRestoreServiceHelper::Observer ------------------------------------------- 26 // TabRestoreServiceHelper::Observer -------------------------------------------
28 27
29 TabRestoreServiceHelper::Observer::~Observer() {} 28 TabRestoreServiceHelper::Observer::~Observer() {}
30 29
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 Window* window = static_cast<Window*>(entry); 208 Window* window = static_cast<Window*>(entry);
210 209
211 // When restoring a window, either the entire window can be restored, or a 210 // When restoring a window, either the entire window can be restored, or a
212 // single tab within it. If the entry's ID matches the one to restore, then 211 // single tab within it. If the entry's ID matches the one to restore, then
213 // the entire window will be restored. 212 // the entire window will be restored.
214 if (!restoring_tab_in_window) { 213 if (!restoring_tab_in_window) {
215 delegate = client_->CreateTabRestoreServiceDelegate(host_desktop_type, 214 delegate = client_->CreateTabRestoreServiceDelegate(host_desktop_type,
216 window->app_name); 215 window->app_name);
217 for (size_t tab_i = 0; tab_i < window->tabs.size(); ++tab_i) { 216 for (size_t tab_i = 0; tab_i < window->tabs.size(); ++tab_i) {
218 const Tab& tab = window->tabs[tab_i]; 217 const Tab& tab = window->tabs[tab_i];
218 DCHECK(tab.from_last_session || tab.client_data);
219 WebContents* restored_tab = delegate->AddRestoredTab( 219 WebContents* restored_tab = delegate->AddRestoredTab(
220 tab.navigations, 220 tab.navigations, delegate->GetTabCount(),
221 delegate->GetTabCount(), 221 tab.current_navigation_index, tab.extension_app_id,
222 tab.current_navigation_index, 222 static_cast<int>(tab_i) == window->selected_tab_index, tab.pinned,
223 tab.extension_app_id, 223 tab.from_last_session, tab.client_data.get(),
224 static_cast<int>(tab_i) == window->selected_tab_index,
225 tab.pinned,
226 tab.from_last_session,
227 tab.session_storage_namespace.get(),
228 tab.user_agent_override); 224 tab.user_agent_override);
229 if (restored_tab) { 225 if (restored_tab) {
230 restored_tab->GetController().LoadIfNecessary(); 226 restored_tab->GetController().LoadIfNecessary();
231 client_->OnTabRestored( 227 client_->OnTabRestored(
232 tab.navigations.at(tab.current_navigation_index).virtual_url()); 228 tab.navigations.at(tab.current_navigation_index).virtual_url());
233 web_contents.push_back(restored_tab); 229 web_contents.push_back(restored_tab);
234 } 230 }
235 } 231 }
236 // All the window's tabs had the same former browser_id. 232 // All the window's tabs had the same former browser_id.
237 if (window->tabs[0].has_browser()) { 233 if (window->tabs[0].has_browser()) {
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 if (tab->current_navigation_index == -1 && entry_count > 0) 390 if (tab->current_navigation_index == -1 && entry_count > 0)
395 tab->current_navigation_index = 0; 391 tab->current_navigation_index = 0;
396 tab->tabstrip_index = index; 392 tab->tabstrip_index = index;
397 393
398 tab->extension_app_id = 394 tab->extension_app_id =
399 client_->GetExtensionAppIDForWebContents(controller->GetWebContents()); 395 client_->GetExtensionAppIDForWebContents(controller->GetWebContents());
400 396
401 tab->user_agent_override = 397 tab->user_agent_override =
402 controller->GetWebContents()->GetUserAgentOverride(); 398 controller->GetWebContents()->GetUserAgentOverride();
403 399
404 // TODO(ajwong): This does not correctly handle storage for isolated apps. 400 tab->client_data =
405 tab->session_storage_namespace = 401 client_->GetTabClientDataForWebContents(controller->GetWebContents());
406 controller->GetDefaultSessionStorageNamespace();
407 402
408 // Delegate may be NULL during unit tests. 403 // Delegate may be NULL during unit tests.
409 if (delegate) { 404 if (delegate) {
410 tab->browser_id = delegate->GetSessionID().id(); 405 tab->browser_id = delegate->GetSessionID().id();
411 tab->pinned = delegate->IsTabPinned(tab->tabstrip_index); 406 tab->pinned = delegate->IsTabPinned(tab->tabstrip_index);
412 } 407 }
413 } 408 }
414 409
415 TabRestoreServiceDelegate* TabRestoreServiceHelper::RestoreTab( 410 TabRestoreServiceDelegate* TabRestoreServiceHelper::RestoreTab(
416 const Tab& tab, 411 const Tab& tab,
417 TabRestoreServiceDelegate* delegate, 412 TabRestoreServiceDelegate* delegate,
418 int host_desktop_type, 413 int host_desktop_type,
419 WindowOpenDisposition disposition, 414 WindowOpenDisposition disposition,
420 WebContents** contents) { 415 WebContents** contents) {
416 DCHECK(tab.from_last_session || tab.client_data);
421 WebContents* web_contents; 417 WebContents* web_contents;
422 if (disposition == CURRENT_TAB && delegate) { 418 if (disposition == CURRENT_TAB && delegate) {
423 web_contents = delegate->ReplaceRestoredTab( 419 web_contents = delegate->ReplaceRestoredTab(
424 tab.navigations, 420 tab.navigations, tab.current_navigation_index, tab.from_last_session,
425 tab.current_navigation_index, 421 tab.extension_app_id, tab.client_data.get(), tab.user_agent_override);
426 tab.from_last_session,
427 tab.extension_app_id,
428 tab.session_storage_namespace.get(),
429 tab.user_agent_override);
430 } else { 422 } else {
431 // We only respsect the tab's original browser if there's no disposition. 423 // We only respsect the tab's original browser if there's no disposition.
432 if (disposition == UNKNOWN && tab.has_browser()) { 424 if (disposition == UNKNOWN && tab.has_browser()) {
433 delegate = client_->FindTabRestoreServiceDelegateWithID( 425 delegate = client_->FindTabRestoreServiceDelegateWithID(
434 tab.browser_id, host_desktop_type); 426 tab.browser_id, host_desktop_type);
435 } 427 }
436 428
437 int tab_index = -1; 429 int tab_index = -1;
438 430
439 // |delegate| will be NULL in cases where one isn't already available (eg, 431 // |delegate| will be NULL in cases where one isn't already available (eg,
440 // when invoked on Mac OS X with no windows open). In this case, create a 432 // when invoked on Mac OS X with no windows open). In this case, create a
441 // new browser into which we restore the tabs. 433 // new browser into which we restore the tabs.
442 if (delegate && disposition != NEW_WINDOW) { 434 if (delegate && disposition != NEW_WINDOW) {
443 tab_index = tab.tabstrip_index; 435 tab_index = tab.tabstrip_index;
444 } else { 436 } else {
445 delegate = client_->CreateTabRestoreServiceDelegate(host_desktop_type, 437 delegate = client_->CreateTabRestoreServiceDelegate(host_desktop_type,
446 std::string()); 438 std::string());
447 if (tab.has_browser()) 439 if (tab.has_browser())
448 UpdateTabBrowserIDs(tab.browser_id, delegate->GetSessionID().id()); 440 UpdateTabBrowserIDs(tab.browser_id, delegate->GetSessionID().id());
449 } 441 }
450 442
451 // Place the tab at the end if the tab index is no longer valid or 443 // Place the tab at the end if the tab index is no longer valid or
452 // we were passed a specific disposition. 444 // we were passed a specific disposition.
453 if (tab_index < 0 || tab_index > delegate->GetTabCount() || 445 if (tab_index < 0 || tab_index > delegate->GetTabCount() ||
454 disposition != UNKNOWN) { 446 disposition != UNKNOWN) {
455 tab_index = delegate->GetTabCount(); 447 tab_index = delegate->GetTabCount();
456 } 448 }
457 449
458 web_contents = delegate->AddRestoredTab(tab.navigations, 450 web_contents = delegate->AddRestoredTab(
459 tab_index, 451 tab.navigations, tab_index, tab.current_navigation_index,
460 tab.current_navigation_index, 452 tab.extension_app_id, disposition != NEW_BACKGROUND_TAB, tab.pinned,
461 tab.extension_app_id, 453 tab.from_last_session, tab.client_data.get(), tab.user_agent_override);
462 disposition != NEW_BACKGROUND_TAB,
463 tab.pinned,
464 tab.from_last_session,
465 tab.session_storage_namespace.get(),
466 tab.user_agent_override);
467 web_contents->GetController().LoadIfNecessary(); 454 web_contents->GetController().LoadIfNecessary();
468 } 455 }
469 client_->OnTabRestored( 456 client_->OnTabRestored(
470 tab.navigations.at(tab.current_navigation_index).virtual_url()); 457 tab.navigations.at(tab.current_navigation_index).virtual_url());
471 if (contents) 458 if (contents)
472 *contents = web_contents; 459 *contents = web_contents;
473 460
474 return delegate; 461 return delegate;
475 } 462 }
476 463
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 Tab* tab = static_cast<Tab*>(entry); 541 Tab* tab = static_cast<Tab*>(entry);
555 if (tab->browser_id == old_id) 542 if (tab->browser_id == old_id)
556 tab->browser_id = new_id; 543 tab->browser_id = new_id;
557 } 544 }
558 } 545 }
559 } 546 }
560 547
561 base::Time TabRestoreServiceHelper::TimeNow() const { 548 base::Time TabRestoreServiceHelper::TimeNow() const {
562 return time_factory_ ? time_factory_->TimeNow() : base::Time::Now(); 549 return time_factory_ ? time_factory_->TimeNow() : base::Time::Now();
563 } 550 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698