Commit f5da7dc9 authored by felipeg@chromium.org's avatar felipeg@chromium.org

Upstream session_backend_android.

BUG=138955


Review URL: https://chromiumcodereview.appspot.com/10832080

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@150342 0039d316-1c4b-4281-b951-d872f2087c98
parent 7480f642
...@@ -6,14 +6,36 @@ ...@@ -6,14 +6,36 @@
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sessions/session_types.h" #include "chrome/browser/sessions/session_types.h"
#include "webkit/glue/window_open_disposition.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/android/tab_model/tab_model.h"
#include "chrome/browser/ui/android/tab_model/tab_model_list.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/web_contents.h"
#include "ipc/ipc_message.h"
// static // static
// The android implementation does not do anything "foreign session" specific.
// We use it to restore tabs from "recently closed" too.
void SessionRestore::RestoreForeignSessionTab( void SessionRestore::RestoreForeignSessionTab(
content::WebContents* source_web_contents, content::WebContents* web_contents,
const SessionTab& session_tab, const SessionTab& session_tab,
WindowOpenDisposition disposition) { WindowOpenDisposition disposition) {
NOTIMPLEMENTED() << "TODO(yfriedman, dtrainor): Upstream this."; DCHECK(session_tab.navigations.size() > 0);
content::BrowserContext* context = web_contents->GetBrowserContext();
Profile* profile = Profile::FromBrowserContext(context);
TabModel* tab_model = TabModelList::GetTabModelWithProfile(profile);
DCHECK(tab_model);
std::vector<content::NavigationEntry*> entries;
TabNavigation::CreateNavigationEntriesFromTabNavigations(
profile, session_tab.navigations, &entries);
content::WebContents* new_web_contents = content::WebContents::Create(
context, NULL, MSG_ROUTING_NONE, 0, 0);
int selected_index = session_tab.normalized_navigation_index();
new_web_contents->GetController().Restore(selected_index,
true, /* from_last_session */
&entries);
tab_model->CreateTab(new_web_contents);
} }
// static // static
......
...@@ -9,15 +9,25 @@ ...@@ -9,15 +9,25 @@
// static // static
SessionService* SessionServiceFactory::GetForProfile(Profile* profile) { SessionService* SessionServiceFactory::GetForProfile(Profile* profile) {
#if defined(OS_ANDROID)
// For Android we do not store sessions in the SessionService.
return NULL;
#else
return static_cast<SessionService*>( return static_cast<SessionService*>(
GetInstance()->GetServiceForProfile(profile, true)); GetInstance()->GetServiceForProfile(profile, true));
#endif
} }
// static // static
SessionService* SessionServiceFactory::GetForProfileIfExisting( SessionService* SessionServiceFactory::GetForProfileIfExisting(
Profile* profile) { Profile* profile) {
#if defined(OS_ANDROID)
// For Android we do not store sessions in the SessionService.
return NULL;
#else
return static_cast<SessionService*>( return static_cast<SessionService*>(
GetInstance()->GetServiceForProfile(profile, false)); GetInstance()->GetServiceForProfile(profile, false));
#endif
} }
// static // static
......
...@@ -130,6 +130,15 @@ struct SessionTab { ...@@ -130,6 +130,15 @@ struct SessionTab {
SessionTab(); SessionTab();
virtual ~SessionTab(); virtual ~SessionTab();
// Since the current_navigation_index can be larger than the index for number
// of navigations in the current sessions (chrome://newtab is not stored), we
// must perform bounds checking.
// Returns a normalized bounds-checked navigation_index.
int normalized_navigation_index() const {
return std::max(0, std::min(current_navigation_index,
static_cast<int>(navigations.size() - 1)));
}
// Unique id of the window. // Unique id of the window.
SessionID window_id; SessionID window_id;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment