Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(515)

Side by Side Diff: chrome/browser/sessions/session_restore.cc

Issue 6901031: Profile shouldn't own Session/TabRestore services. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase again and hope upload works this time Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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>
11 11
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/metrics/histogram.h" 15 #include "base/metrics/histogram.h"
16 #include "base/stl_util-inl.h" 16 #include "base/stl_util-inl.h"
17 #include "base/string_util.h" 17 #include "base/string_util.h"
18 #include "chrome/browser/extensions/extension_service.h" 18 #include "chrome/browser/extensions/extension_service.h"
19 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/sessions/session_service.h" 20 #include "chrome/browser/sessions/session_service.h"
21 #include "chrome/browser/sessions/session_service_factory.h"
21 #include "chrome/browser/sessions/session_types.h" 22 #include "chrome/browser/sessions/session_types.h"
22 #include "chrome/browser/tabs/tab_strip_model.h" 23 #include "chrome/browser/tabs/tab_strip_model.h"
23 #include "chrome/browser/ui/browser.h" 24 #include "chrome/browser/ui/browser.h"
24 #include "chrome/browser/ui/browser_list.h" 25 #include "chrome/browser/ui/browser_list.h"
25 #include "chrome/browser/ui/browser_navigator.h" 26 #include "chrome/browser/ui/browser_navigator.h"
26 #include "chrome/browser/ui/browser_window.h" 27 #include "chrome/browser/ui/browser_window.h"
27 #include "content/browser/renderer_host/render_widget_host.h" 28 #include "content/browser/renderer_host/render_widget_host.h"
28 #include "content/browser/renderer_host/render_widget_host_view.h" 29 #include "content/browser/renderer_host/render_widget_host_view.h"
29 #include "content/browser/tab_contents/navigation_controller.h" 30 #include "content/browser/tab_contents/navigation_controller.h"
30 #include "content/browser/tab_contents/tab_contents.h" 31 #include "content/browser/tab_contents/tab_contents.h"
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 : profile_(profile), 416 : profile_(profile),
416 browser_(browser), 417 browser_(browser),
417 synchronous_(synchronous), 418 synchronous_(synchronous),
418 clobber_existing_window_(clobber_existing_window), 419 clobber_existing_window_(clobber_existing_window),
419 always_create_tabbed_browser_(always_create_tabbed_browser), 420 always_create_tabbed_browser_(always_create_tabbed_browser),
420 urls_to_open_(urls_to_open), 421 urls_to_open_(urls_to_open),
421 restore_started_(base::TimeTicks::Now()) { 422 restore_started_(base::TimeTicks::Now()) {
422 } 423 }
423 424
424 Browser* Restore() { 425 Browser* Restore() {
425 SessionService* session_service = profile_->GetSessionService(); 426 SessionService* session_service =
427 SessionServiceFactory::GetForProfile(profile_);
426 DCHECK(session_service); 428 DCHECK(session_service);
427 SessionService::SessionCallback* callback = 429 SessionService::SessionCallback* callback =
428 NewCallback(this, &SessionRestoreImpl::OnGotSession); 430 NewCallback(this, &SessionRestoreImpl::OnGotSession);
429 session_service->GetLastSession(&request_consumer_, callback); 431 session_service->GetLastSession(&request_consumer_, callback);
430 432
431 if (synchronous_) { 433 if (synchronous_) {
432 bool old_state = MessageLoop::current()->NestableTasksAllowed(); 434 bool old_state = MessageLoop::current()->NestableTasksAllowed();
433 MessageLoop::current()->SetNestableTasksAllowed(true); 435 MessageLoop::current()->SetNestableTasksAllowed(true);
434 MessageLoop::current()->Run(); 436 MessageLoop::current()->Run();
435 MessageLoop::current()->SetNestableTasksAllowed(old_state); 437 MessageLoop::current()->SetNestableTasksAllowed(old_state);
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 params.disposition = i == 0 ? NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB; 722 params.disposition = i == 0 ? NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB;
721 params.tabstrip_index = index; 723 params.tabstrip_index = index;
722 params.tabstrip_add_types = add_types; 724 params.tabstrip_add_types = add_types;
723 browser::Navigate(&params); 725 browser::Navigate(&params);
724 } 726 }
725 } 727 }
726 728
727 // Invokes TabRestored on the SessionService for all tabs in browser after 729 // Invokes TabRestored on the SessionService for all tabs in browser after
728 // initial_count. 730 // initial_count.
729 void NotifySessionServiceOfRestoredTabs(Browser* browser, int initial_count) { 731 void NotifySessionServiceOfRestoredTabs(Browser* browser, int initial_count) {
730 SessionService* session_service = profile_->GetSessionService(); 732 SessionService* session_service =
733 SessionServiceFactory::GetForProfile(profile_);
731 for (int i = initial_count; i < browser->tab_count(); ++i) 734 for (int i = initial_count; i < browser->tab_count(); ++i)
732 session_service->TabRestored(&browser->GetTabContentsAt(i)->controller(), 735 session_service->TabRestored(&browser->GetTabContentsAt(i)->controller(),
733 browser->tabstrip_model()->IsTabPinned(i)); 736 browser->tabstrip_model()->IsTabPinned(i));
734 } 737 }
735 738
736 // The profile to create the sessions for. 739 // The profile to create the sessions for.
737 Profile* profile_; 740 Profile* profile_;
738 741
739 // The first browser to restore to, may be null. 742 // The first browser to restore to, may be null.
740 Browser* browser_; 743 Browser* browser_;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 bool always_create_tabbed_browser, 785 bool always_create_tabbed_browser,
783 const std::vector<GURL>& urls_to_open) { 786 const std::vector<GURL>& urls_to_open) {
784 #if defined(OS_CHROMEOS) 787 #if defined(OS_CHROMEOS)
785 chromeos::BootTimesLoader::Get()->AddLoginTimeMarker( 788 chromeos::BootTimesLoader::Get()->AddLoginTimeMarker(
786 "SessionRestoreStarted", false); 789 "SessionRestoreStarted", false);
787 #endif 790 #endif
788 DCHECK(profile); 791 DCHECK(profile);
789 // Always restore from the original profile (incognito profiles have no 792 // Always restore from the original profile (incognito profiles have no
790 // session service). 793 // session service).
791 profile = profile->GetOriginalProfile(); 794 profile = profile->GetOriginalProfile();
792 if (!profile->GetSessionService()) { 795 if (!SessionServiceFactory::GetForProfile(profile)) {
793 NOTREACHED(); 796 NOTREACHED();
794 return NULL; 797 return NULL;
795 } 798 }
796 restoring = true; 799 restoring = true;
797 profile->set_restored_last_session(true); 800 profile->set_restored_last_session(true);
798 // SessionRestoreImpl takes care of deleting itself when done. 801 // SessionRestoreImpl takes care of deleting itself when done.
799 SessionRestoreImpl* restorer = 802 SessionRestoreImpl* restorer =
800 new SessionRestoreImpl(profile, browser, synchronous, 803 new SessionRestoreImpl(profile, browser, synchronous,
801 clobber_existing_window, 804 clobber_existing_window,
802 always_create_tabbed_browser, urls_to_open); 805 always_create_tabbed_browser, urls_to_open);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
839 Browser* SessionRestore::RestoreSessionSynchronously( 842 Browser* SessionRestore::RestoreSessionSynchronously(
840 Profile* profile, 843 Profile* profile,
841 const std::vector<GURL>& urls_to_open) { 844 const std::vector<GURL>& urls_to_open) {
842 return Restore(profile, NULL, true, false, true, urls_to_open); 845 return Restore(profile, NULL, true, false, true, urls_to_open);
843 } 846 }
844 847
845 // static 848 // static
846 bool SessionRestore::IsRestoring() { 849 bool SessionRestore::IsRestoring() {
847 return restoring; 850 return restoring;
848 } 851 }
OLDNEW
« no previous file with comments | « chrome/browser/sessions/base_session_service.h ('k') | chrome/browser/sessions/session_restore_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698