OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <list> | 10 #include <list> |
11 #include <set> | 11 #include <set> |
12 #include <string> | 12 #include <string> |
13 | 13 |
14 #include "base/bind.h" | 14 #include "base/bind.h" |
15 #include "base/bind_helpers.h" | 15 #include "base/bind_helpers.h" |
16 #include "base/callback.h" | 16 #include "base/callback.h" |
17 #include "base/command_line.h" | 17 #include "base/command_line.h" |
18 #include "base/debug/alias.h" | 18 #include "base/debug/alias.h" |
19 #include "base/macros.h" | 19 #include "base/macros.h" |
20 #include "base/memory/scoped_ptr.h" | 20 #include "base/memory/scoped_ptr.h" |
21 #include "base/memory/scoped_vector.h" | 21 #include "base/memory/scoped_vector.h" |
22 #include "base/metrics/field_trial.h" | 22 #include "base/metrics/field_trial.h" |
23 #include "base/metrics/histogram.h" | 23 #include "base/metrics/histogram.h" |
24 #include "base/run_loop.h" | 24 #include "base/run_loop.h" |
25 #include "base/stl_util.h" | 25 #include "base/stl_util.h" |
26 #include "base/task/cancelable_task_tracker.h" | 26 #include "base/task/cancelable_task_tracker.h" |
27 #include "build/build_config.h" | 27 #include "build/build_config.h" |
28 #include "chrome/browser/browser_process.h" | 28 #include "chrome/browser/browser_process.h" |
29 #include "chrome/browser/chrome_notification_types.h" | 29 #include "chrome/browser/chrome_notification_types.h" |
| 30 #include "chrome/browser/lifetime/keep_alive_types.h" |
| 31 #include "chrome/browser/lifetime/scoped_keep_alive.h" |
30 #include "chrome/browser/profiles/profile.h" | 32 #include "chrome/browser/profiles/profile.h" |
31 #include "chrome/browser/search/search.h" | 33 #include "chrome/browser/search/search.h" |
32 #include "chrome/browser/sessions/session_restore_delegate.h" | 34 #include "chrome/browser/sessions/session_restore_delegate.h" |
33 #include "chrome/browser/sessions/session_service.h" | 35 #include "chrome/browser/sessions/session_service.h" |
34 #include "chrome/browser/sessions/session_service_factory.h" | 36 #include "chrome/browser/sessions/session_service_factory.h" |
35 #include "chrome/browser/sessions/session_service_utils.h" | 37 #include "chrome/browser/sessions/session_service_utils.h" |
36 #include "chrome/browser/sessions/tab_loader.h" | 38 #include "chrome/browser/sessions/tab_loader.h" |
37 #include "chrome/browser/ui/browser.h" | 39 #include "chrome/browser/ui/browser.h" |
38 #include "chrome/browser/ui/browser_finder.h" | 40 #include "chrome/browser/ui/browser_finder.h" |
39 #include "chrome/browser/ui/browser_navigator.h" | 41 #include "chrome/browser/ui/browser_navigator.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 std::set<SessionRestoreImpl*>::const_iterator it; | 109 std::set<SessionRestoreImpl*>::const_iterator it; |
108 for (it = active_session_restorers->begin(); | 110 for (it = active_session_restorers->begin(); |
109 it != active_session_restorers->end(); ++it) { | 111 it != active_session_restorers->end(); ++it) { |
110 if ((*it)->profile_ == profile) | 112 if ((*it)->profile_ == profile) |
111 break; | 113 break; |
112 } | 114 } |
113 DCHECK(it == active_session_restorers->end()); | 115 DCHECK(it == active_session_restorers->end()); |
114 | 116 |
115 active_session_restorers->insert(this); | 117 active_session_restorers->insert(this); |
116 | 118 |
117 // When asynchronous its possible for there to be no windows. To make sure | 119 keep_alive_.reset(new ScopedKeepAlive(KeepAliveOrigin::SESSION_RESTORE, |
118 // Chrome doesn't prematurely exit AddRef the process. We'll release in the | 120 KeepAliveRestartOption::DISABLED)); |
119 // destructor when restore is done. | |
120 g_browser_process->AddRefModule(); | |
121 } | 121 } |
122 | 122 |
123 bool synchronous() const { return synchronous_; } | 123 bool synchronous() const { return synchronous_; } |
124 | 124 |
125 Browser* Restore() { | 125 Browser* Restore() { |
126 SessionService* session_service = | 126 SessionService* session_service = |
127 SessionServiceFactory::GetForProfile(profile_); | 127 SessionServiceFactory::GetForProfile(profile_); |
128 DCHECK(session_service); | 128 DCHECK(session_service); |
129 session_service->GetLastSession( | 129 session_service->GetLastSession( |
130 base::Bind(&SessionRestoreImpl::OnGotSession, base::Unretained(this)), | 130 base::Bind(&SessionRestoreImpl::OnGotSession, base::Unretained(this)), |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 } | 242 } |
243 | 243 |
244 ~SessionRestoreImpl() override { | 244 ~SessionRestoreImpl() override { |
245 STLDeleteElements(&windows_); | 245 STLDeleteElements(&windows_); |
246 | 246 |
247 active_session_restorers->erase(this); | 247 active_session_restorers->erase(this); |
248 if (active_session_restorers->empty()) { | 248 if (active_session_restorers->empty()) { |
249 delete active_session_restorers; | 249 delete active_session_restorers; |
250 active_session_restorers = nullptr; | 250 active_session_restorers = nullptr; |
251 } | 251 } |
252 | |
253 g_browser_process->ReleaseModule(); | |
254 } | 252 } |
255 | 253 |
256 void Observe(int type, | 254 void Observe(int type, |
257 const content::NotificationSource& source, | 255 const content::NotificationSource& source, |
258 const content::NotificationDetails& details) override { | 256 const content::NotificationDetails& details) override { |
259 switch (type) { | 257 switch (type) { |
260 case chrome::NOTIFICATION_BROWSER_CLOSED: | 258 case chrome::NOTIFICATION_BROWSER_CLOSED: |
261 delete this; | 259 delete this; |
262 return; | 260 return; |
263 | 261 |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 | 709 |
712 // When synchronous we run a nested message loop. To avoid creating windows | 710 // When synchronous we run a nested message loop. To avoid creating windows |
713 // from the nested message loop (which can make exiting the nested message | 711 // from the nested message loop (which can make exiting the nested message |
714 // loop take a while) we cache the SessionWindows here and create the actual | 712 // loop take a while) we cache the SessionWindows here and create the actual |
715 // windows when the nested message loop exits. | 713 // windows when the nested message loop exits. |
716 std::vector<sessions::SessionWindow*> windows_; | 714 std::vector<sessions::SessionWindow*> windows_; |
717 SessionID::id_type active_window_id_; | 715 SessionID::id_type active_window_id_; |
718 | 716 |
719 content::NotificationRegistrar registrar_; | 717 content::NotificationRegistrar registrar_; |
720 | 718 |
| 719 // When asynchronous it's possible for there to be no windows. To make sure |
| 720 // Chrome doesn't prematurely exit we register a KeepAlive for the lifetime |
| 721 // of this object. |
| 722 scoped_ptr<ScopedKeepAlive> keep_alive_; |
| 723 |
721 // The time we started the restore. | 724 // The time we started the restore. |
722 base::TimeTicks restore_started_; | 725 base::TimeTicks restore_started_; |
723 | 726 |
724 // List of callbacks for session restore notification. | 727 // List of callbacks for session restore notification. |
725 SessionRestore::CallbackList* on_session_restored_callbacks_; | 728 SessionRestore::CallbackList* on_session_restored_callbacks_; |
726 | 729 |
727 DISALLOW_COPY_AND_ASSIGN(SessionRestoreImpl); | 730 DISALLOW_COPY_AND_ASSIGN(SessionRestoreImpl); |
728 }; | 731 }; |
729 | 732 |
730 } // namespace | 733 } // namespace |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
830 // static | 833 // static |
831 SessionRestore::CallbackSubscription | 834 SessionRestore::CallbackSubscription |
832 SessionRestore::RegisterOnSessionRestoredCallback( | 835 SessionRestore::RegisterOnSessionRestoredCallback( |
833 const base::Callback<void(int)>& callback) { | 836 const base::Callback<void(int)>& callback) { |
834 return on_session_restored_callbacks()->Add(callback); | 837 return on_session_restored_callbacks()->Add(callback); |
835 } | 838 } |
836 | 839 |
837 // static | 840 // static |
838 base::CallbackList<void(int)>* | 841 base::CallbackList<void(int)>* |
839 SessionRestore::on_session_restored_callbacks_ = nullptr; | 842 SessionRestore::on_session_restored_callbacks_ = nullptr; |
OLD | NEW |