| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <vector> | 10 #include <vector> |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 // SessionRestoreImpl is responsible for fetching the set of tabs to create | 399 // SessionRestoreImpl is responsible for fetching the set of tabs to create |
| 400 // from SessionService. SessionRestoreImpl deletes itself when done. | 400 // from SessionService. SessionRestoreImpl deletes itself when done. |
| 401 | 401 |
| 402 class SessionRestoreImpl : public content::NotificationObserver { | 402 class SessionRestoreImpl : public content::NotificationObserver { |
| 403 public: | 403 public: |
| 404 SessionRestoreImpl(Profile* profile, | 404 SessionRestoreImpl(Profile* profile, |
| 405 Browser* browser, | 405 Browser* browser, |
| 406 bool synchronous, | 406 bool synchronous, |
| 407 bool clobber_existing_tab, | 407 bool clobber_existing_tab, |
| 408 bool always_create_tabbed_browser, | 408 bool always_create_tabbed_browser, |
| 409 bool restore_session_state, |
| 409 const std::vector<GURL>& urls_to_open) | 410 const std::vector<GURL>& urls_to_open) |
| 410 : profile_(profile), | 411 : profile_(profile), |
| 411 browser_(browser), | 412 browser_(browser), |
| 412 synchronous_(synchronous), | 413 synchronous_(synchronous), |
| 413 clobber_existing_tab_(clobber_existing_tab), | 414 clobber_existing_tab_(clobber_existing_tab), |
| 414 always_create_tabbed_browser_(always_create_tabbed_browser), | 415 always_create_tabbed_browser_(always_create_tabbed_browser), |
| 416 restore_session_state_(restore_session_state), |
| 415 urls_to_open_(urls_to_open), | 417 urls_to_open_(urls_to_open), |
| 416 restore_started_(base::TimeTicks::Now()) { | 418 restore_started_(base::TimeTicks::Now()) { |
| 417 // When asynchronous its possible for there to be no windows. To make sure | 419 // When asynchronous its possible for there to be no windows. To make sure |
| 418 // Chrome doesn't prematurely exit AddRef the process. We'll release in the | 420 // Chrome doesn't prematurely exit AddRef the process. We'll release in the |
| 419 // destructor when restore is done. | 421 // destructor when restore is done. |
| 420 g_browser_process->AddRefModule(); | 422 g_browser_process->AddRefModule(); |
| 421 } | 423 } |
| 422 | 424 |
| 423 Browser* Restore() { | 425 Browser* Restore() { |
| 424 SessionService* session_service = | 426 SessionService* session_service = |
| 425 SessionServiceFactory::GetForProfile(profile_); | 427 SessionServiceFactory::GetForProfile(profile_); |
| 426 DCHECK(session_service); | 428 DCHECK(session_service); |
| 429 |
| 430 session_service->RestoreOrResetSessionState(restore_session_state_); |
| 431 |
| 427 SessionService::SessionCallback* callback = | 432 SessionService::SessionCallback* callback = |
| 428 NewCallback(this, &SessionRestoreImpl::OnGotSession); | 433 NewCallback(this, &SessionRestoreImpl::OnGotSession); |
| 429 session_service->GetLastSession(&request_consumer_, callback); | 434 session_service->GetLastSession(&request_consumer_, callback); |
| 430 | 435 |
| 431 if (synchronous_) { | 436 if (synchronous_) { |
| 432 bool old_state = MessageLoop::current()->NestableTasksAllowed(); | 437 bool old_state = MessageLoop::current()->NestableTasksAllowed(); |
| 433 MessageLoop::current()->SetNestableTasksAllowed(true); | 438 MessageLoop::current()->SetNestableTasksAllowed(true); |
| 434 MessageLoop::current()->Run(); | 439 MessageLoop::current()->Run(); |
| 435 MessageLoop::current()->SetNestableTasksAllowed(old_state); | 440 MessageLoop::current()->SetNestableTasksAllowed(old_state); |
| 436 Browser* browser = ProcessSessionWindows(&windows_); | 441 Browser* browser = ProcessSessionWindows(&windows_); |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 781 const bool synchronous_; | 786 const bool synchronous_; |
| 782 | 787 |
| 783 // See description of CLOBBER_CURRENT_TAB. | 788 // See description of CLOBBER_CURRENT_TAB. |
| 784 const bool clobber_existing_tab_; | 789 const bool clobber_existing_tab_; |
| 785 | 790 |
| 786 // If true and there is an error or there are no windows to restore, we | 791 // If true and there is an error or there are no windows to restore, we |
| 787 // create a tabbed browser anyway. This is used on startup to make sure at | 792 // create a tabbed browser anyway. This is used on startup to make sure at |
| 788 // at least one window is created. | 793 // at least one window is created. |
| 789 const bool always_create_tabbed_browser_; | 794 const bool always_create_tabbed_browser_; |
| 790 | 795 |
| 796 // See description of RESTORE_SESSION_STATE. |
| 797 const bool restore_session_state_; |
| 798 |
| 791 // Set of URLs to open in addition to those restored from the session. | 799 // Set of URLs to open in addition to those restored from the session. |
| 792 std::vector<GURL> urls_to_open_; | 800 std::vector<GURL> urls_to_open_; |
| 793 | 801 |
| 794 // Used to get the session. | 802 // Used to get the session. |
| 795 CancelableRequestConsumer request_consumer_; | 803 CancelableRequestConsumer request_consumer_; |
| 796 | 804 |
| 797 // Responsible for loading the tabs. | 805 // Responsible for loading the tabs. |
| 798 scoped_ptr<TabLoader> tab_loader_; | 806 scoped_ptr<TabLoader> tab_loader_; |
| 799 | 807 |
| 800 // When synchronous we run a nested message loop. To avoid creating windows | 808 // When synchronous we run a nested message loop. To avoid creating windows |
| (...skipping 29 matching lines...) Expand all Loading... |
| 830 NOTREACHED(); | 838 NOTREACHED(); |
| 831 return NULL; | 839 return NULL; |
| 832 } | 840 } |
| 833 restoring = true; | 841 restoring = true; |
| 834 profile->set_restored_last_session(true); | 842 profile->set_restored_last_session(true); |
| 835 // SessionRestoreImpl takes care of deleting itself when done. | 843 // SessionRestoreImpl takes care of deleting itself when done. |
| 836 SessionRestoreImpl* restorer = new SessionRestoreImpl( | 844 SessionRestoreImpl* restorer = new SessionRestoreImpl( |
| 837 profile, browser, (behavior & SYNCHRONOUS) != 0, | 845 profile, browser, (behavior & SYNCHRONOUS) != 0, |
| 838 (behavior & CLOBBER_CURRENT_TAB) != 0, | 846 (behavior & CLOBBER_CURRENT_TAB) != 0, |
| 839 (behavior & ALWAYS_CREATE_TABBED_BROWSER) != 0, | 847 (behavior & ALWAYS_CREATE_TABBED_BROWSER) != 0, |
| 848 (behavior & RESTORE_SESSION_STATE) != 0, |
| 840 urls_to_open); | 849 urls_to_open); |
| 841 return restorer->Restore(); | 850 return restorer->Restore(); |
| 842 } | 851 } |
| 843 | 852 |
| 844 // static | 853 // static |
| 845 void SessionRestore::RestoreForeignSessionWindows( | 854 void SessionRestore::RestoreForeignSessionWindows( |
| 846 Profile* profile, | 855 Profile* profile, |
| 847 std::vector<const SessionWindow*>::const_iterator begin, | 856 std::vector<const SessionWindow*>::const_iterator begin, |
| 848 std::vector<const SessionWindow*>::const_iterator end) { | 857 std::vector<const SessionWindow*>::const_iterator end) { |
| 849 // Create a SessionRestore object to eventually restore the tabs. | 858 // Create a SessionRestore object to eventually restore the tabs. |
| 850 std::vector<GURL> gurls; | 859 std::vector<GURL> gurls; |
| 851 SessionRestoreImpl restorer(profile, | 860 SessionRestoreImpl restorer(profile, |
| 852 static_cast<Browser*>(NULL), true, false, true, gurls); | 861 static_cast<Browser*>(NULL), true, false, true, false, gurls); |
| 853 restorer.RestoreForeignSession(begin, end); | 862 restorer.RestoreForeignSession(begin, end); |
| 854 } | 863 } |
| 855 | 864 |
| 856 // static | 865 // static |
| 857 void SessionRestore::RestoreForeignSessionTab(Profile* profile, | 866 void SessionRestore::RestoreForeignSessionTab(Profile* profile, |
| 858 const SessionTab& tab) { | 867 const SessionTab& tab) { |
| 859 // Create a SessionRestore object to eventually restore the tabs. | 868 // Create a SessionRestore object to eventually restore the tabs. |
| 860 std::vector<GURL> gurls; | 869 std::vector<GURL> gurls; |
| 861 SessionRestoreImpl restorer(profile, | 870 SessionRestoreImpl restorer(profile, |
| 862 static_cast<Browser*>(NULL), true, false, true, gurls); | 871 static_cast<Browser*>(NULL), true, false, true, false, gurls); |
| 863 restorer.RestoreForeignTab(tab); | 872 restorer.RestoreForeignTab(tab); |
| 864 } | 873 } |
| 865 | 874 |
| 866 // static | 875 // static |
| 867 bool SessionRestore::IsRestoring() { | 876 bool SessionRestore::IsRestoring() { |
| 868 return restoring; | 877 return restoring; |
| 869 } | 878 } |
| OLD | NEW |