Add ENABLE_MEDIA_ROUTER define to builds other than Android and iOS.
[chromium-blink-merge.git] / chrome / browser / sessions / session_restore_android.cc
blob424f7e280d6cfbef758030a0186f767cb069a99f
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
3 // found in the LICENSE file.
5 #include "chrome/browser/sessions/session_restore.h"
7 #include <vector>
9 #include "base/memory/scoped_vector.h"
10 #include "chrome/browser/android/tab_android.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/ui/android/tab_model/tab_model.h"
13 #include "chrome/browser/ui/android/tab_model/tab_model_list.h"
14 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/browser_finder.h"
16 #include "components/sessions/content/content_serialized_navigation_builder.h"
17 #include "components/sessions/session_types.h"
18 #include "content/public/browser/navigation_controller.h"
19 #include "content/public/browser/navigation_entry.h"
20 #include "content/public/browser/web_contents.h"
22 // The android implementation does not do anything "foreign session" specific.
23 // We use it to restore tabs from "recently closed" too.
24 // static
25 content::WebContents* SessionRestore::RestoreForeignSessionTab(
26 content::WebContents* web_contents,
27 const sessions::SessionTab& session_tab,
28 WindowOpenDisposition disposition) {
29 DCHECK(session_tab.navigations.size() > 0);
30 content::BrowserContext* context = web_contents->GetBrowserContext();
31 Profile* profile = Profile::FromBrowserContext(context);
32 TabModel* tab_model = TabModelList::GetTabModelForWebContents(web_contents);
33 DCHECK(tab_model);
34 ScopedVector<content::NavigationEntry> scoped_entries =
35 sessions::ContentSerializedNavigationBuilder::ToNavigationEntries(
36 session_tab.navigations, profile);
37 // NavigationController::Restore() expects to take ownership of the entries.
38 std::vector<content::NavigationEntry*> entries;
39 scoped_entries.release(&entries);
40 content::WebContents* new_web_contents = content::WebContents::Create(
41 content::WebContents::CreateParams(context));
42 int selected_index = session_tab.normalized_navigation_index();
43 new_web_contents->GetController().Restore(
44 selected_index,
45 content::NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY,
46 &entries);
48 TabAndroid* current_tab = TabAndroid::FromWebContents(web_contents);
49 DCHECK(current_tab);
50 if (disposition == CURRENT_TAB) {
51 current_tab->SwapTabContents(web_contents, new_web_contents, false, false);
52 delete web_contents;
53 } else {
54 DCHECK(disposition == NEW_FOREGROUND_TAB ||
55 disposition == NEW_BACKGROUND_TAB);
56 tab_model->CreateTab(new_web_contents, current_tab->GetAndroidId());
58 return new_web_contents;
61 // static
62 std::vector<Browser*> SessionRestore::RestoreForeignSessionWindows(
63 Profile* profile,
64 chrome::HostDesktopType host_desktop_type,
65 std::vector<const sessions::SessionWindow*>::const_iterator begin,
66 std::vector<const sessions::SessionWindow*>::const_iterator end) {
67 NOTREACHED();
68 return std::vector<Browser*>();