| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/scoped_ptr.h" | 11 #include "base/scoped_ptr.h" |
| 12 #include "base/stl_util-inl.h" | 12 #include "base/stl_util-inl.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "chrome/browser/browser.h" | 14 #include "chrome/browser/browser.h" |
| 15 #include "chrome/browser/browser_list.h" | 15 #include "chrome/browser/browser_list.h" |
| 16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/browser_window.h" | 17 #include "chrome/browser/browser_window.h" |
| 18 #include "chrome/browser/extensions/extensions_service.h" | 18 #include "chrome/browser/extensions/extensions_service.h" |
| 19 #include "chrome/browser/profile.h" | 19 #include "chrome/browser/profile.h" |
| 20 #include "chrome/browser/sessions/session_service.h" | 20 #include "chrome/browser/sessions/session_service.h" |
| 21 #include "chrome/browser/sessions/session_types.h" | 21 #include "chrome/browser/sessions/session_types.h" |
| 22 #include "chrome/browser/tab_contents/navigation_controller.h" | 22 #include "chrome/browser/tab_contents/navigation_controller.h" |
| 23 #include "chrome/browser/tab_contents/tab_contents.h" | 23 #include "chrome/browser/tab_contents/tab_contents.h" |
| 24 #include "chrome/browser/tab_contents/tab_contents_view.h" | 24 #include "chrome/browser/tab_contents/tab_contents_view.h" |
| 25 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
| 26 #include "chrome/common/notification_registrar.h" | 26 #include "chrome/common/notification_registrar.h" |
| 27 #include "chrome/common/notification_service.h" | 27 #include "chrome/common/notification_service.h" |
| 28 | 28 |
| 29 // Are we in the process of restoring? |
| 30 static bool restoring = false; |
| 31 |
| 29 namespace { | 32 namespace { |
| 30 | 33 |
| 31 // TabLoader ------------------------------------------------------------------ | 34 // TabLoader ------------------------------------------------------------------ |
| 32 | 35 |
| 33 // TabLoader is responsible for ensuring after session restore we have | 36 // TabLoader is responsible for ensuring after session restore we have |
| 34 // at least SessionRestore::num_tabs_to_load_ loading. As tabs finish loading | 37 // at least SessionRestore::num_tabs_to_load_ loading. As tabs finish loading |
| 35 // new tabs are loaded. When all tabs are loading TabLoader deletes itself. | 38 // new tabs are loaded. When all tabs are loading TabLoader deletes itself. |
| 36 // | 39 // |
| 37 // This is not part of SessionRestoreImpl so that synchronous destruction | 40 // This is not part of SessionRestoreImpl so that synchronous destruction |
| 38 // of SessionRestoreImpl doesn't have timing problems. | 41 // of SessionRestoreImpl doesn't have timing problems. |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 } | 207 } |
| 205 | 208 |
| 206 if (browser_) { | 209 if (browser_) { |
| 207 registrar_.Add(this, NotificationType::BROWSER_CLOSED, | 210 registrar_.Add(this, NotificationType::BROWSER_CLOSED, |
| 208 Source<Browser>(browser_)); | 211 Source<Browser>(browser_)); |
| 209 } | 212 } |
| 210 } | 213 } |
| 211 | 214 |
| 212 ~SessionRestoreImpl() { | 215 ~SessionRestoreImpl() { |
| 213 STLDeleteElements(&windows_); | 216 STLDeleteElements(&windows_); |
| 217 restoring = false; |
| 214 } | 218 } |
| 215 | 219 |
| 216 virtual void Observe(NotificationType type, | 220 virtual void Observe(NotificationType type, |
| 217 const NotificationSource& source, | 221 const NotificationSource& source, |
| 218 const NotificationDetails& details) { | 222 const NotificationDetails& details) { |
| 219 switch (type.value) { | 223 switch (type.value) { |
| 220 case NotificationType::BROWSER_CLOSED: | 224 case NotificationType::BROWSER_CLOSED: |
| 221 delete this; | 225 delete this; |
| 222 return; | 226 return; |
| 223 | 227 |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 bool always_create_tabbed_browser, | 499 bool always_create_tabbed_browser, |
| 496 const std::vector<GURL>& urls_to_open) { | 500 const std::vector<GURL>& urls_to_open) { |
| 497 DCHECK(profile); | 501 DCHECK(profile); |
| 498 // Always restore from the original profile (incognito profiles have no | 502 // Always restore from the original profile (incognito profiles have no |
| 499 // session service). | 503 // session service). |
| 500 profile = profile->GetOriginalProfile(); | 504 profile = profile->GetOriginalProfile(); |
| 501 if (!profile->GetSessionService()) { | 505 if (!profile->GetSessionService()) { |
| 502 NOTREACHED(); | 506 NOTREACHED(); |
| 503 return; | 507 return; |
| 504 } | 508 } |
| 509 restoring = true; |
| 505 profile->set_restored_last_session(true); | 510 profile->set_restored_last_session(true); |
| 506 // SessionRestoreImpl takes care of deleting itself when done. | 511 // SessionRestoreImpl takes care of deleting itself when done. |
| 507 SessionRestoreImpl* restorer = | 512 SessionRestoreImpl* restorer = |
| 508 new SessionRestoreImpl(profile, browser, synchronous, | 513 new SessionRestoreImpl(profile, browser, synchronous, |
| 509 clobber_existing_window, | 514 clobber_existing_window, |
| 510 always_create_tabbed_browser, urls_to_open); | 515 always_create_tabbed_browser, urls_to_open); |
| 511 restorer->Restore(); | 516 restorer->Restore(); |
| 512 } | 517 } |
| 513 | 518 |
| 514 // static | 519 // static |
| 515 void SessionRestore::RestoreSession(Profile* profile, | 520 void SessionRestore::RestoreSession(Profile* profile, |
| 516 Browser* browser, | 521 Browser* browser, |
| 517 bool clobber_existing_window, | 522 bool clobber_existing_window, |
| 518 bool always_create_tabbed_browser, | 523 bool always_create_tabbed_browser, |
| 519 const std::vector<GURL>& urls_to_open) { | 524 const std::vector<GURL>& urls_to_open) { |
| 520 Restore(profile, browser, false, clobber_existing_window, | 525 Restore(profile, browser, false, clobber_existing_window, |
| 521 always_create_tabbed_browser, urls_to_open); | 526 always_create_tabbed_browser, urls_to_open); |
| 522 } | 527 } |
| 523 | 528 |
| 524 // static | 529 // static |
| 525 void SessionRestore::RestoreSessionSynchronously( | 530 void SessionRestore::RestoreSessionSynchronously( |
| 526 Profile* profile, | 531 Profile* profile, |
| 527 const std::vector<GURL>& urls_to_open) { | 532 const std::vector<GURL>& urls_to_open) { |
| 528 Restore(profile, NULL, true, false, true, urls_to_open); | 533 Restore(profile, NULL, true, false, true, urls_to_open); |
| 529 } | 534 } |
| 535 |
| 536 // static |
| 537 bool SessionRestore::IsRestoring() { |
| 538 return restoring; |
| 539 } |
| OLD | NEW |