Skip to content

Commit

Permalink
Remove usage of browser::FindLastActiveWithProfile in session_restore…
Browse files Browse the repository at this point in the history
… sync code by plumbing through the source WebContents.

BUG=129187
Review URL: https://chromiumcodereview.appspot.com/10658040

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@144290 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
jam@chromium.org committed Jun 26, 2012
1 parent d274638 commit a02e198
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 26 deletions.
14 changes: 5 additions & 9 deletions chrome/browser/sessions/session_restore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -576,12 +576,7 @@ class SessionRestoreImpl : public content::NotificationObserver {

bool use_new_window = disposition == NEW_WINDOW;

// The browser should not be specified; the browser to use is
// dictated by the WindowOpenDisposition.
DCHECK(browser_ == NULL);
Browser* browser = use_new_window ?
Browser::Create(profile_) :
browser::FindLastActiveWithProfile(profile_);
Browser* browser = use_new_window ? Browser::Create(profile_) : browser_;

RecordAppLaunchForTab(browser, tab, selected_index);

Expand Down Expand Up @@ -1077,12 +1072,13 @@ void SessionRestore::RestoreForeignSessionWindows(

// static
void SessionRestore::RestoreForeignSessionTab(
Profile* profile,
content::WebContents* source_web_contents,
const SessionTab& tab,
WindowOpenDisposition disposition) {
Browser* browser = browser::FindBrowserWithWebContents(source_web_contents);
Profile* profile = browser->profile();
std::vector<GURL> gurls;
SessionRestoreImpl restorer(profile,
static_cast<Browser*>(NULL), true, false, false, gurls);
SessionRestoreImpl restorer(profile, browser, true, false, false, gurls);
restorer.RestoreForeignTab(tab, disposition);
}

Expand Down
14 changes: 10 additions & 4 deletions chrome/browser/sessions/session_restore.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
class Browser;
class Profile;

namespace content {
class WebContents;
}

// SessionRestore handles restoring either the last or saved session. Session
// restore come in two variants, asynchronous or synchronous. The synchronous
// variety is meant for startup and blocks until restore is complete.
Expand Down Expand Up @@ -52,10 +56,12 @@ class SessionRestore {
std::vector<const SessionWindow*>::const_iterator end);

// Specifically used in the restoration of a foreign session. This method
// restores the given session tab to a browser.
static void RestoreForeignSessionTab(Profile* profile,
const SessionTab& tab,
WindowOpenDisposition disposition);
// restores the given session tab to the browser of |source_web_contents| if
// the disposition is not NEW_WINDOW.
static void RestoreForeignSessionTab(
content::WebContents* source_web_contents,
const SessionTab& tab,
WindowOpenDisposition disposition);

// Returns true if we're in the process of restoring |profile|.
static bool IsRestoring(const Profile* profile);
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/sessions/session_restore_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

// static
void SessionRestore::RestoreForeignSessionTab(
Profile* profile,
content::WebContents* source_web_contents,,
const SessionTab& session_tab,
WindowOpenDisposition disposition) {
NOTIMPLEMENTED() << "TODO(yfriedman): Upstream this.";
Expand Down
11 changes: 6 additions & 5 deletions chrome/browser/sessions/session_restore_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,6 @@ IN_PROC_BROWSER_TEST_F(SessionRestoreTest, IncognitotoNonIncognito) {
#endif // !OS_CHROMEOS

IN_PROC_BROWSER_TEST_F(SessionRestoreTest, RestoreForeignTab) {
Profile* profile = browser()->profile();

GURL url1("http://google.com");
GURL url2("http://google2.com");
TabNavigation nav1(0, url1, content::Referrer(), ASCIIToUTF16("one"),
Expand All @@ -396,7 +394,8 @@ IN_PROC_BROWSER_TEST_F(SessionRestoreTest, RestoreForeignTab) {
ui_test_utils::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
content::NotificationService::AllSources());
SessionRestore::RestoreForeignSessionTab(profile, tab, CURRENT_TAB);
SessionRestore::RestoreForeignSessionTab(
browser()->GetActiveWebContents(), tab, CURRENT_TAB);
observer.Wait();
}
ASSERT_EQ(1, browser()->tab_count());
Expand All @@ -408,7 +407,8 @@ IN_PROC_BROWSER_TEST_F(SessionRestoreTest, RestoreForeignTab) {
ui_test_utils::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
content::NotificationService::AllSources());
SessionRestore::RestoreForeignSessionTab(profile, tab, NEW_BACKGROUND_TAB);
SessionRestore::RestoreForeignSessionTab(
browser()->GetActiveWebContents(), tab, NEW_BACKGROUND_TAB);
observer.Wait();
}
ASSERT_EQ(2, browser()->tab_count());
Expand All @@ -418,7 +418,8 @@ IN_PROC_BROWSER_TEST_F(SessionRestoreTest, RestoreForeignTab) {

// Restore in a new window.
ui_test_utils::BrowserAddedObserver browser_observer;
SessionRestore::RestoreForeignSessionTab(profile, tab, NEW_WINDOW);
SessionRestore::RestoreForeignSessionTab(
browser()->GetActiveWebContents(), tab, NEW_WINDOW);
Browser* new_browser = browser_observer.WaitForSingleNewBrowser();

ASSERT_EQ(1, new_browser->tab_count());
Expand Down
9 changes: 5 additions & 4 deletions chrome/browser/ui/webui/ntp/foreign_session_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ void ForeignSessionHandler::HandleOpenForeignSession(const ListValue* args) {
if (!associator)
return;

Profile* profile = Profile::FromWebUI(web_ui());
if (tab_id != kInvalidId) {
// We don't actually care about |window_num|, this is just a sanity check.
DCHECK_LT(kInvalidId, window_num);
Expand All @@ -241,7 +240,8 @@ void ForeignSessionHandler::HandleOpenForeignSession(const ListValue* args) {
}
WindowOpenDisposition disposition =
web_ui_util::GetDispositionFromClick(args, 3);
SessionRestore::RestoreForeignSessionTab(profile, *tab, disposition);
SessionRestore::RestoreForeignSessionTab(
web_ui()->GetWebContents(), *tab, disposition);
} else {
std::vector<const SessionWindow*> windows;
// Note: we don't own the ForeignSessions themselves.
Expand All @@ -256,7 +256,8 @@ void ForeignSessionHandler::HandleOpenForeignSession(const ListValue* args) {
((window_num == kInvalidId) ?
std::vector<const SessionWindow*>::const_iterator(windows.end()) :
iter_begin + 1);
SessionRestore::RestoreForeignSessionWindows(profile, iter_begin, iter_end);
SessionRestore::RestoreForeignSessionWindows(
Profile::FromWebUI(web_ui()), iter_begin, iter_end);
}
}

Expand Down Expand Up @@ -330,7 +331,7 @@ bool ForeignSessionHandler::SessionWindowToValue(
modification_time = std::max(modification_time,
window.tabs[i]->timestamp);
tab_values->Append(tab_value.release());
}
}
}
if (tab_values->GetSize() == 0)
return false;
Expand Down
5 changes: 2 additions & 3 deletions chrome/browser/ui/webui/ntp/recently_closed_tabs_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,8 @@ void RecentlyClosedTabsHandler::HandleReopenTab(const ListValue* args) {
session_tab.current_navigation_index = tab_entry->current_navigation_index;
session_tab.navigations = tab_entry->navigations;

Profile* profile = Profile::FromWebUI(web_ui());
SessionRestore::RestoreForeignSessionTab(profile, session_tab,
NEW_FOREGROUND_TAB);
SessionRestore::RestoreForeignSessionTab(web_ui()->GetWebContents(),
session_tab, NEW_FOREGROUND_TAB);
#else
TabRestoreServiceDelegate* delegate =
TabRestoreServiceDelegate::FindDelegateForWebContents(
Expand Down

0 comments on commit a02e198

Please sign in to comment.