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

Side by Side Diff: chrome/browser/extensions/api/sessions/sessions_api.cc

Issue 1336823003: Move chrome::HostDesktopType to ui::HostDesktopType (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@base_session_service_delegate_impl
Patch Set: Fix build on Mac and CrOS Created 5 years, 3 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
OLDNEW
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 <vector> 7 #include <vector>
8 8
9 #include "base/i18n/rtl.h" 9 #include "base/i18n/rtl.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 results_ = Restore::Results::Create(*CreateSessionModelHelper( 435 results_ = Restore::Results::Create(*CreateSessionModelHelper(
436 base::Time::Now().ToTimeT(), 436 base::Time::Now().ToTimeT(),
437 scoped_ptr<tabs::Tab>(), 437 scoped_ptr<tabs::Tab>(),
438 window.Pass())); 438 window.Pass()));
439 return true; 439 return true;
440 } 440 }
441 441
442 bool SessionsRestoreFunction::RestoreMostRecentlyClosed(Browser* browser) { 442 bool SessionsRestoreFunction::RestoreMostRecentlyClosed(Browser* browser) {
443 TabRestoreService* tab_restore_service = 443 TabRestoreService* tab_restore_service =
444 TabRestoreServiceFactory::GetForProfile(GetProfile()); 444 TabRestoreServiceFactory::GetForProfile(GetProfile());
445 chrome::HostDesktopType host_desktop_type = browser->host_desktop_type(); 445 ui::HostDesktopType host_desktop_type = browser->host_desktop_type();
446 TabRestoreService::Entries entries = tab_restore_service->entries(); 446 TabRestoreService::Entries entries = tab_restore_service->entries();
447 447
448 if (entries.empty()) { 448 if (entries.empty()) {
449 SetError(kNoRecentlyClosedSessionsError); 449 SetError(kNoRecentlyClosedSessionsError);
450 return false; 450 return false;
451 } 451 }
452 452
453 bool is_window = is_window_entry(entries.front()); 453 bool is_window = is_window_entry(entries.front());
454 TabRestoreServiceDelegate* delegate = 454 TabRestoreServiceDelegate* delegate =
455 TabRestoreServiceDelegate::FindDelegateForWebContents( 455 TabRestoreServiceDelegate::FindDelegateForWebContents(
456 browser->tab_strip_model()->GetActiveWebContents()); 456 browser->tab_strip_model()->GetActiveWebContents());
457 std::vector<content::WebContents*> contents = 457 std::vector<content::WebContents*> contents =
458 tab_restore_service->RestoreMostRecentEntry(delegate, host_desktop_type); 458 tab_restore_service->RestoreMostRecentEntry(delegate, host_desktop_type);
459 DCHECK(contents.size()); 459 DCHECK(contents.size());
460 460
461 if (is_window) { 461 if (is_window) {
462 return SetResultRestoredWindow( 462 return SetResultRestoredWindow(
463 ExtensionTabUtil::GetWindowIdOfTab(contents[0])); 463 ExtensionTabUtil::GetWindowIdOfTab(contents[0]));
464 } 464 }
465 465
466 SetResultRestoredTab(contents[0]); 466 SetResultRestoredTab(contents[0]);
467 return true; 467 return true;
468 } 468 }
469 469
470 bool SessionsRestoreFunction::RestoreLocalSession(const SessionId& session_id, 470 bool SessionsRestoreFunction::RestoreLocalSession(const SessionId& session_id,
471 Browser* browser) { 471 Browser* browser) {
472 TabRestoreService* tab_restore_service = 472 TabRestoreService* tab_restore_service =
473 TabRestoreServiceFactory::GetForProfile(GetProfile()); 473 TabRestoreServiceFactory::GetForProfile(GetProfile());
474 chrome::HostDesktopType host_desktop_type = browser->host_desktop_type(); 474 ui::HostDesktopType host_desktop_type = browser->host_desktop_type();
475 TabRestoreService::Entries entries = tab_restore_service->entries(); 475 TabRestoreService::Entries entries = tab_restore_service->entries();
476 476
477 if (entries.empty()) { 477 if (entries.empty()) {
478 SetInvalidIdError(session_id.ToString()); 478 SetInvalidIdError(session_id.ToString());
479 return false; 479 return false;
480 } 480 }
481 481
482 // Check if the recently closed list contains an entry with the provided id. 482 // Check if the recently closed list contains an entry with the provided id.
483 bool is_window = false; 483 bool is_window = false;
484 for (TabRestoreService::Entries::iterator it = entries.begin(); 484 for (TabRestoreService::Entries::iterator it = entries.begin();
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 windows.begin(); 554 windows.begin();
555 while (window != windows.end() 555 while (window != windows.end()
556 && (*window)->window_id.id() != session_id.id()) { 556 && (*window)->window_id.id() != session_id.id()) {
557 ++window; 557 ++window;
558 } 558 }
559 if (window == windows.end()) { 559 if (window == windows.end()) {
560 SetInvalidIdError(session_id.ToString()); 560 SetInvalidIdError(session_id.ToString());
561 return false; 561 return false;
562 } 562 }
563 563
564 chrome::HostDesktopType host_desktop_type = browser->host_desktop_type(); 564 ui::HostDesktopType host_desktop_type = browser->host_desktop_type();
565 // Only restore one window at a time. 565 // Only restore one window at a time.
566 std::vector<Browser*> browsers = SessionRestore::RestoreForeignSessionWindows( 566 std::vector<Browser*> browsers = SessionRestore::RestoreForeignSessionWindows(
567 GetProfile(), host_desktop_type, window, window + 1); 567 GetProfile(), host_desktop_type, window, window + 1);
568 // Will always create one browser because we only restore one window per call. 568 // Will always create one browser because we only restore one window per call.
569 DCHECK_EQ(1u, browsers.size()); 569 DCHECK_EQ(1u, browsers.size());
570 return SetResultRestoredWindow(ExtensionTabUtil::GetWindowId(browsers[0])); 570 return SetResultRestoredWindow(ExtensionTabUtil::GetWindowId(browsers[0]));
571 } 571 }
572 572
573 bool SessionsRestoreFunction::RunSync() { 573 bool SessionsRestoreFunction::RunSync() {
574 scoped_ptr<Restore::Params> params(Restore::Params::Create(*args_)); 574 scoped_ptr<Restore::Params> params(Restore::Params::Create(*args_));
575 EXTENSION_FUNCTION_VALIDATE(params); 575 EXTENSION_FUNCTION_VALIDATE(params);
576 576
577 Browser* browser = chrome::FindBrowserWithProfile( 577 Browser* browser = chrome::FindBrowserWithProfile(
578 GetProfile(), chrome::HOST_DESKTOP_TYPE_NATIVE); 578 GetProfile(), ui::HOST_DESKTOP_TYPE_NATIVE);
579 if (!browser) { 579 if (!browser) {
580 SetError(kNoBrowserToRestoreSession); 580 SetError(kNoBrowserToRestoreSession);
581 return false; 581 return false;
582 } 582 }
583 583
584 if (GetProfile() != GetProfile()->GetOriginalProfile()) { 584 if (GetProfile() != GetProfile()->GetOriginalProfile()) {
585 SetError(kRestoreInIncognitoError); 585 SetError(kRestoreInIncognitoError);
586 return false; 586 return false;
587 } 587 }
588 588
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 return g_factory.Pointer(); 650 return g_factory.Pointer();
651 } 651 }
652 652
653 void SessionsAPI::OnListenerAdded(const EventListenerInfo& details) { 653 void SessionsAPI::OnListenerAdded(const EventListenerInfo& details) {
654 sessions_event_router_.reset( 654 sessions_event_router_.reset(
655 new SessionsEventRouter(Profile::FromBrowserContext(browser_context_))); 655 new SessionsEventRouter(Profile::FromBrowserContext(browser_context_)));
656 EventRouter::Get(browser_context_)->UnregisterObserver(this); 656 EventRouter::Get(browser_context_)->UnregisterObserver(this);
657 } 657 }
658 658
659 } // namespace extensions 659 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698