| OLD | NEW |
| 1 // Copyright (c) 2010 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" |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 delete this; | 291 delete this; |
| 292 return; | 292 return; |
| 293 } | 293 } |
| 294 | 294 |
| 295 if (browser_) { | 295 if (browser_) { |
| 296 registrar_.Add(this, NotificationType::BROWSER_CLOSED, | 296 registrar_.Add(this, NotificationType::BROWSER_CLOSED, |
| 297 Source<Browser>(browser_)); | 297 Source<Browser>(browser_)); |
| 298 } | 298 } |
| 299 } | 299 } |
| 300 | 300 |
| 301 void RestoreForeignSession(std::vector<SessionWindow*>* windows) { | |
| 302 tab_loader_.reset(new TabLoader()); | |
| 303 // Create a browser instance to put the restored tabs in. | |
| 304 bool has_tabbed_browser = false; | |
| 305 for (std::vector<SessionWindow*>::iterator i = (*windows).begin(); | |
| 306 i != (*windows).end(); ++i) { | |
| 307 Browser* browser = NULL; | |
| 308 if (!has_tabbed_browser && (*i)->type == Browser::TYPE_NORMAL) | |
| 309 has_tabbed_browser = true; | |
| 310 browser = new Browser(static_cast<Browser::Type>((*i)->type), | |
| 311 profile_); | |
| 312 browser->set_override_bounds((*i)->bounds); | |
| 313 browser->set_maximized_state((*i)->is_maximized ? | |
| 314 Browser::MAXIMIZED_STATE_MAXIMIZED : | |
| 315 Browser::MAXIMIZED_STATE_UNMAXIMIZED); | |
| 316 browser->CreateBrowserWindow(); | |
| 317 | |
| 318 // Restore and show the browser. | |
| 319 const int initial_tab_count = browser->tab_count(); | |
| 320 RestoreTabsToBrowser(*(*i), browser); | |
| 321 ShowBrowser(browser, initial_tab_count, | |
| 322 (*i)->selected_tab_index); | |
| 323 NotifySessionServiceOfRestoredTabs(browser, initial_tab_count); | |
| 324 FinishedTabCreation(true, has_tabbed_browser); | |
| 325 } | |
| 326 } | |
| 327 | |
| 328 ~SessionRestoreImpl() { | 301 ~SessionRestoreImpl() { |
| 329 STLDeleteElements(&windows_); | 302 STLDeleteElements(&windows_); |
| 330 restoring = false; | 303 restoring = false; |
| 331 } | 304 } |
| 332 | 305 |
| 333 virtual void Observe(NotificationType type, | 306 virtual void Observe(NotificationType type, |
| 334 const NotificationSource& source, | 307 const NotificationSource& source, |
| 335 const NotificationDetails& details) { | 308 const NotificationDetails& details) { |
| 336 switch (type.value) { | 309 switch (type.value) { |
| 337 case NotificationType::BROWSER_CLOSED: | 310 case NotificationType::BROWSER_CLOSED: |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 634 void SessionRestore::RestoreSession(Profile* profile, | 607 void SessionRestore::RestoreSession(Profile* profile, |
| 635 Browser* browser, | 608 Browser* browser, |
| 636 bool clobber_existing_window, | 609 bool clobber_existing_window, |
| 637 bool always_create_tabbed_browser, | 610 bool always_create_tabbed_browser, |
| 638 const std::vector<GURL>& urls_to_open) { | 611 const std::vector<GURL>& urls_to_open) { |
| 639 Restore(profile, browser, false, clobber_existing_window, | 612 Restore(profile, browser, false, clobber_existing_window, |
| 640 always_create_tabbed_browser, urls_to_open); | 613 always_create_tabbed_browser, urls_to_open); |
| 641 } | 614 } |
| 642 | 615 |
| 643 // static | 616 // static |
| 644 void SessionRestore::RestoreForeignSessionWindows(Profile* profile, | |
| 645 std::vector<SessionWindow*>* windows) { | |
| 646 // Create a SessionRestore object to eventually restore the tabs. | |
| 647 std::vector<GURL> gurls; | |
| 648 SessionRestoreImpl restorer(profile, | |
| 649 static_cast<Browser*>(NULL), true, false, true, gurls); | |
| 650 restorer.RestoreForeignSession(windows); | |
| 651 } | |
| 652 | |
| 653 // static | |
| 654 void SessionRestore::RestoreSessionSynchronously( | 617 void SessionRestore::RestoreSessionSynchronously( |
| 655 Profile* profile, | 618 Profile* profile, |
| 656 const std::vector<GURL>& urls_to_open) { | 619 const std::vector<GURL>& urls_to_open) { |
| 657 Restore(profile, NULL, true, false, true, urls_to_open); | 620 Restore(profile, NULL, true, false, true, urls_to_open); |
| 658 } | 621 } |
| 659 | 622 |
| 660 // static | 623 // static |
| 661 bool SessionRestore::IsRestoring() { | 624 bool SessionRestore::IsRestoring() { |
| 662 return restoring; | 625 return restoring; |
| 663 } | 626 } |
| OLD | NEW |