OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/extensions/api/sessions/sessions_api.h" | 5 #include "chrome/browser/extensions/api/sessions/sessions_api.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 scoped_ptr<windows::Window> window(windows::Window::FromValue( | 439 scoped_ptr<windows::Window> window(windows::Window::FromValue( |
440 *window_value)); | 440 *window_value)); |
441 results_ = Restore::Results::Create(*CreateSessionModelHelper( | 441 results_ = Restore::Results::Create(*CreateSessionModelHelper( |
442 base::Time::Now().ToTimeT(), scoped_ptr<tabs::Tab>(), std::move(window))); | 442 base::Time::Now().ToTimeT(), scoped_ptr<tabs::Tab>(), std::move(window))); |
443 return true; | 443 return true; |
444 } | 444 } |
445 | 445 |
446 bool SessionsRestoreFunction::RestoreMostRecentlyClosed(Browser* browser) { | 446 bool SessionsRestoreFunction::RestoreMostRecentlyClosed(Browser* browser) { |
447 sessions::TabRestoreService* tab_restore_service = | 447 sessions::TabRestoreService* tab_restore_service = |
448 TabRestoreServiceFactory::GetForProfile(GetProfile()); | 448 TabRestoreServiceFactory::GetForProfile(GetProfile()); |
449 chrome::HostDesktopType host_desktop_type = browser->host_desktop_type(); | |
450 sessions::TabRestoreService::Entries entries = tab_restore_service->entries(); | 449 sessions::TabRestoreService::Entries entries = tab_restore_service->entries(); |
451 | 450 |
452 if (entries.empty()) { | 451 if (entries.empty()) { |
453 SetError(kNoRecentlyClosedSessionsError); | 452 SetError(kNoRecentlyClosedSessionsError); |
454 return false; | 453 return false; |
455 } | 454 } |
456 | 455 |
457 bool is_window = is_window_entry(entries.front()); | 456 bool is_window = is_window_entry(entries.front()); |
458 sessions::LiveTabContext* context = | 457 sessions::LiveTabContext* context = |
459 BrowserLiveTabContext::FindContextForWebContents( | 458 BrowserLiveTabContext::FindContextForWebContents( |
460 browser->tab_strip_model()->GetActiveWebContents()); | 459 browser->tab_strip_model()->GetActiveWebContents()); |
461 std::vector<sessions::LiveTab*> restored_tabs = | 460 std::vector<sessions::LiveTab*> restored_tabs = |
462 tab_restore_service->RestoreMostRecentEntry(context, host_desktop_type); | 461 tab_restore_service->RestoreMostRecentEntry(context); |
463 DCHECK(restored_tabs.size()); | 462 DCHECK(restored_tabs.size()); |
464 | 463 |
465 sessions::ContentLiveTab* first_tab = | 464 sessions::ContentLiveTab* first_tab = |
466 static_cast<sessions::ContentLiveTab*>(restored_tabs[0]); | 465 static_cast<sessions::ContentLiveTab*>(restored_tabs[0]); |
467 if (is_window) { | 466 if (is_window) { |
468 return SetResultRestoredWindow( | 467 return SetResultRestoredWindow( |
469 ExtensionTabUtil::GetWindowIdOfTab(first_tab->web_contents())); | 468 ExtensionTabUtil::GetWindowIdOfTab(first_tab->web_contents())); |
470 } | 469 } |
471 | 470 |
472 SetResultRestoredTab(first_tab->web_contents()); | 471 SetResultRestoredTab(first_tab->web_contents()); |
473 return true; | 472 return true; |
474 } | 473 } |
475 | 474 |
476 bool SessionsRestoreFunction::RestoreLocalSession(const SessionId& session_id, | 475 bool SessionsRestoreFunction::RestoreLocalSession(const SessionId& session_id, |
477 Browser* browser) { | 476 Browser* browser) { |
478 sessions::TabRestoreService* tab_restore_service = | 477 sessions::TabRestoreService* tab_restore_service = |
479 TabRestoreServiceFactory::GetForProfile(GetProfile()); | 478 TabRestoreServiceFactory::GetForProfile(GetProfile()); |
480 chrome::HostDesktopType host_desktop_type = browser->host_desktop_type(); | |
481 sessions::TabRestoreService::Entries entries = tab_restore_service->entries(); | 479 sessions::TabRestoreService::Entries entries = tab_restore_service->entries(); |
482 | 480 |
483 if (entries.empty()) { | 481 if (entries.empty()) { |
484 SetInvalidIdError(session_id.ToString()); | 482 SetInvalidIdError(session_id.ToString()); |
485 return false; | 483 return false; |
486 } | 484 } |
487 | 485 |
488 // Check if the recently closed list contains an entry with the provided id. | 486 // Check if the recently closed list contains an entry with the provided id. |
489 bool is_window = false; | 487 bool is_window = false; |
490 for (sessions::TabRestoreService::Entries::iterator it = entries.begin(); | 488 for (sessions::TabRestoreService::Entries::iterator it = entries.begin(); |
491 it != entries.end(); ++it) { | 489 it != entries.end(); ++it) { |
492 if ((*it)->id == session_id.id()) { | 490 if ((*it)->id == session_id.id()) { |
493 // The only time a full window is being restored is if the entry ID | 491 // The only time a full window is being restored is if the entry ID |
494 // matches the provided ID and the entry type is Window. | 492 // matches the provided ID and the entry type is Window. |
495 is_window = is_window_entry(*it); | 493 is_window = is_window_entry(*it); |
496 break; | 494 break; |
497 } | 495 } |
498 } | 496 } |
499 | 497 |
500 sessions::LiveTabContext* context = | 498 sessions::LiveTabContext* context = |
501 BrowserLiveTabContext::FindContextForWebContents( | 499 BrowserLiveTabContext::FindContextForWebContents( |
502 browser->tab_strip_model()->GetActiveWebContents()); | 500 browser->tab_strip_model()->GetActiveWebContents()); |
503 std::vector<sessions::LiveTab*> restored_tabs = | 501 std::vector<sessions::LiveTab*> restored_tabs = |
504 tab_restore_service->RestoreEntryById(context, session_id.id(), | 502 tab_restore_service->RestoreEntryById(context, session_id.id(), UNKNOWN); |
505 host_desktop_type, UNKNOWN); | |
506 // If the ID is invalid, restored_tabs will be empty. | 503 // If the ID is invalid, restored_tabs will be empty. |
507 if (!restored_tabs.size()) { | 504 if (!restored_tabs.size()) { |
508 SetInvalidIdError(session_id.ToString()); | 505 SetInvalidIdError(session_id.ToString()); |
509 return false; | 506 return false; |
510 } | 507 } |
511 | 508 |
512 sessions::ContentLiveTab* first_tab = | 509 sessions::ContentLiveTab* first_tab = |
513 static_cast<sessions::ContentLiveTab*>(restored_tabs[0]); | 510 static_cast<sessions::ContentLiveTab*>(restored_tabs[0]); |
514 | 511 |
515 // Retrieve the window through any of the tabs in restored_tabs. | 512 // Retrieve the window through any of the tabs in restored_tabs. |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 return g_factory.Pointer(); | 652 return g_factory.Pointer(); |
656 } | 653 } |
657 | 654 |
658 void SessionsAPI::OnListenerAdded(const EventListenerInfo& details) { | 655 void SessionsAPI::OnListenerAdded(const EventListenerInfo& details) { |
659 sessions_event_router_.reset( | 656 sessions_event_router_.reset( |
660 new SessionsEventRouter(Profile::FromBrowserContext(browser_context_))); | 657 new SessionsEventRouter(Profile::FromBrowserContext(browser_context_))); |
661 EventRouter::Get(browser_context_)->UnregisterObserver(this); | 658 EventRouter::Get(browser_context_)->UnregisterObserver(this); |
662 } | 659 } |
663 | 660 |
664 } // namespace extensions | 661 } // namespace extensions |
OLD | NEW |