| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/session_restore.h" | 5 #include "chrome/browser/sessions/session_restore.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <list> | 8 #include <list> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
| 14 #include "base/callback.h" | 14 #include "base/callback.h" |
| 15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
| 16 #include "base/debug/alias.h" | 16 #include "base/debug/alias.h" |
| 17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 18 #include "base/memory/scoped_vector.h" | 18 #include "base/memory/scoped_vector.h" |
| 19 #include "base/metrics/histogram.h" | 19 #include "base/metrics/histogram.h" |
| 20 #include "base/run_loop.h" | 20 #include "base/run_loop.h" |
| 21 #include "base/stl_util.h" | 21 #include "base/stl_util.h" |
| 22 #include "base/strings/stringprintf.h" | 22 #include "base/strings/stringprintf.h" |
| 23 #include "base/task/cancelable_task_tracker.h" | 23 #include "base/task/cancelable_task_tracker.h" |
| 24 #include "chrome/browser/browser_process.h" | 24 #include "chrome/browser/browser_process.h" |
| 25 #include "chrome/browser/chrome_notification_types.h" | 25 #include "chrome/browser/chrome_notification_types.h" |
| 26 #include "chrome/browser/profiles/profile.h" | 26 #include "chrome/browser/profiles/profile.h" |
| 27 #include "chrome/browser/search/search.h" | 27 #include "chrome/browser/search/search.h" |
| 28 #include "chrome/browser/sessions/session_service.h" | 28 #include "chrome/browser/sessions/session_service.h" |
| 29 #include "chrome/browser/sessions/session_service_factory.h" | 29 #include "chrome/browser/sessions/session_service_factory.h" |
| 30 #include "chrome/browser/sessions/session_service_utils.h" |
| 30 #include "chrome/browser/sessions/session_types.h" | 31 #include "chrome/browser/sessions/session_types.h" |
| 31 #include "chrome/browser/ui/browser.h" | 32 #include "chrome/browser/ui/browser.h" |
| 32 #include "chrome/browser/ui/browser_finder.h" | 33 #include "chrome/browser/ui/browser_finder.h" |
| 33 #include "chrome/browser/ui/browser_navigator.h" | 34 #include "chrome/browser/ui/browser_navigator.h" |
| 34 #include "chrome/browser/ui/browser_tabrestore.h" | 35 #include "chrome/browser/ui/browser_tabrestore.h" |
| 35 #include "chrome/browser/ui/browser_tabstrip.h" | 36 #include "chrome/browser/ui/browser_tabstrip.h" |
| 36 #include "chrome/browser/ui/browser_window.h" | 37 #include "chrome/browser/ui/browser_window.h" |
| 37 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 38 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 38 #include "chrome/browser/ui/webui/ntp/core_app_launcher_handler.h" | 39 #include "chrome/browser/ui/webui/ntp/core_app_launcher_handler.h" |
| 39 #include "chrome/common/url_constants.h" | 40 #include "chrome/common/url_constants.h" |
| (...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 // Restore window(s) from a foreign session. Returns newly created Browsers. | 596 // Restore window(s) from a foreign session. Returns newly created Browsers. |
| 596 std::vector<Browser*> RestoreForeignSession( | 597 std::vector<Browser*> RestoreForeignSession( |
| 597 std::vector<const SessionWindow*>::const_iterator begin, | 598 std::vector<const SessionWindow*>::const_iterator begin, |
| 598 std::vector<const SessionWindow*>::const_iterator end) { | 599 std::vector<const SessionWindow*>::const_iterator end) { |
| 599 StartTabCreation(); | 600 StartTabCreation(); |
| 600 std::vector<Browser*> browsers; | 601 std::vector<Browser*> browsers; |
| 601 // Create a browser instance to put the restored tabs in. | 602 // Create a browser instance to put the restored tabs in. |
| 602 for (std::vector<const SessionWindow*>::const_iterator i = begin; | 603 for (std::vector<const SessionWindow*>::const_iterator i = begin; |
| 603 i != end; ++i) { | 604 i != end; ++i) { |
| 604 Browser* browser = CreateRestoredBrowser( | 605 Browser* browser = CreateRestoredBrowser( |
| 605 static_cast<Browser::Type>((*i)->type), | 606 BrowserTypeForWindowType((*i)->type), |
| 606 (*i)->bounds, | 607 (*i)->bounds, |
| 607 (*i)->show_state, | 608 (*i)->show_state, |
| 608 (*i)->app_name); | 609 (*i)->app_name); |
| 609 browsers.push_back(browser); | 610 browsers.push_back(browser); |
| 610 | 611 |
| 611 // Restore and show the browser. | 612 // Restore and show the browser. |
| 612 const int initial_tab_count = 0; | 613 const int initial_tab_count = 0; |
| 613 int selected_tab_index = std::max( | 614 int selected_tab_index = std::max( |
| 614 0, | 615 0, |
| 615 std::min((*i)->selected_tab_index, | 616 std::min((*i)->selected_tab_index, |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 839 bool has_visible_browser = false; | 840 bool has_visible_browser = false; |
| 840 for (std::vector<SessionWindow*>::iterator i = windows->begin(); | 841 for (std::vector<SessionWindow*>::iterator i = windows->begin(); |
| 841 i != windows->end(); ++i) { | 842 i != windows->end(); ++i) { |
| 842 if ((*i)->show_state != ui::SHOW_STATE_MINIMIZED) | 843 if ((*i)->show_state != ui::SHOW_STATE_MINIMIZED) |
| 843 has_visible_browser = true; | 844 has_visible_browser = true; |
| 844 } | 845 } |
| 845 | 846 |
| 846 for (std::vector<SessionWindow*>::iterator i = windows->begin(); | 847 for (std::vector<SessionWindow*>::iterator i = windows->begin(); |
| 847 i != windows->end(); ++i) { | 848 i != windows->end(); ++i) { |
| 848 Browser* browser = NULL; | 849 Browser* browser = NULL; |
| 849 if (!has_tabbed_browser && (*i)->type == Browser::TYPE_TABBED) | 850 if (!has_tabbed_browser && (*i)->type == SessionWindow::TYPE_TABBED) |
| 850 has_tabbed_browser = true; | 851 has_tabbed_browser = true; |
| 851 if (i == windows->begin() && (*i)->type == Browser::TYPE_TABBED && | 852 if (i == windows->begin() && (*i)->type == SessionWindow::TYPE_TABBED && |
| 852 browser_ && browser_->is_type_tabbed() && | 853 browser_ && browser_->is_type_tabbed() && |
| 853 !browser_->profile()->IsOffTheRecord()) { | 854 !browser_->profile()->IsOffTheRecord()) { |
| 854 // The first set of tabs is added to the existing browser. | 855 // The first set of tabs is added to the existing browser. |
| 855 browser = browser_; | 856 browser = browser_; |
| 856 } else { | 857 } else { |
| 857 #if defined(OS_CHROMEOS) | 858 #if defined(OS_CHROMEOS) |
| 858 chromeos::BootTimesLoader::Get()->AddLoginTimeMarker( | 859 chromeos::BootTimesLoader::Get()->AddLoginTimeMarker( |
| 859 "SessionRestore-CreateRestoredBrowser-Start", false); | 860 "SessionRestore-CreateRestoredBrowser-Start", false); |
| 860 #endif | 861 #endif |
| 861 // Show the first window if none are visible. | 862 // Show the first window if none are visible. |
| 862 ui::WindowShowState show_state = (*i)->show_state; | 863 ui::WindowShowState show_state = (*i)->show_state; |
| 863 if (!has_visible_browser) { | 864 if (!has_visible_browser) { |
| 864 show_state = ui::SHOW_STATE_NORMAL; | 865 show_state = ui::SHOW_STATE_NORMAL; |
| 865 has_visible_browser = true; | 866 has_visible_browser = true; |
| 866 } | 867 } |
| 867 browser = CreateRestoredBrowser( | 868 browser = CreateRestoredBrowser( |
| 868 static_cast<Browser::Type>((*i)->type), | 869 BrowserTypeForWindowType((*i)->type), |
| 869 (*i)->bounds, | 870 (*i)->bounds, |
| 870 show_state, | 871 show_state, |
| 871 (*i)->app_name); | 872 (*i)->app_name); |
| 872 #if defined(OS_CHROMEOS) | 873 #if defined(OS_CHROMEOS) |
| 873 chromeos::BootTimesLoader::Get()->AddLoginTimeMarker( | 874 chromeos::BootTimesLoader::Get()->AddLoginTimeMarker( |
| 874 "SessionRestore-CreateRestoredBrowser-End", false); | 875 "SessionRestore-CreateRestoredBrowser-End", false); |
| 875 #endif | 876 #endif |
| 876 } | 877 } |
| 877 if ((*i)->type == Browser::TYPE_TABBED) | 878 if ((*i)->type == SessionWindow::TYPE_TABBED) |
| 878 last_browser = browser; | 879 last_browser = browser; |
| 879 WebContents* active_tab = | 880 WebContents* active_tab = |
| 880 browser->tab_strip_model()->GetActiveWebContents(); | 881 browser->tab_strip_model()->GetActiveWebContents(); |
| 881 int initial_tab_count = browser->tab_strip_model()->count(); | 882 int initial_tab_count = browser->tab_strip_model()->count(); |
| 882 bool close_active_tab = clobber_existing_tab_ && | 883 bool close_active_tab = clobber_existing_tab_ && |
| 883 i == windows->begin() && | 884 i == windows->begin() && |
| 884 (*i)->type == Browser::TYPE_TABBED && | 885 (*i)->type == SessionWindow::TYPE_TABBED && |
| 885 active_tab && browser == browser_ && | 886 active_tab && browser == browser_ && |
| 886 (*i)->tabs.size() > 0; | 887 (*i)->tabs.size() > 0; |
| 887 if (close_active_tab) | 888 if (close_active_tab) |
| 888 --initial_tab_count; | 889 --initial_tab_count; |
| 889 int selected_tab_index = | 890 int selected_tab_index = |
| 890 initial_tab_count > 0 ? browser->tab_strip_model()->active_index() | 891 initial_tab_count > 0 ? browser->tab_strip_model()->active_index() |
| 891 : std::max(0, | 892 : std::max(0, |
| 892 std::min((*i)->selected_tab_index, | 893 std::min((*i)->selected_tab_index, |
| 893 static_cast<int>((*i)->tabs.size()) - 1)); | 894 static_cast<int>((*i)->tabs.size()) - 1)); |
| 894 if ((*i)->window_id.id() == active_window_id) { | 895 if ((*i)->window_id.id() == active_window_id) { |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1291 if (!active_session_restorers) | 1292 if (!active_session_restorers) |
| 1292 return false; | 1293 return false; |
| 1293 for (std::set<SessionRestoreImpl*>::const_iterator it = | 1294 for (std::set<SessionRestoreImpl*>::const_iterator it = |
| 1294 active_session_restorers->begin(); | 1295 active_session_restorers->begin(); |
| 1295 it != active_session_restorers->end(); ++it) { | 1296 it != active_session_restorers->end(); ++it) { |
| 1296 if ((*it)->synchronous()) | 1297 if ((*it)->synchronous()) |
| 1297 return true; | 1298 return true; |
| 1298 } | 1299 } |
| 1299 return false; | 1300 return false; |
| 1300 } | 1301 } |
| OLD | NEW |