| 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 <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" |
| 11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 16 #include "chrome/browser/extensions/api/sessions/session_id.h" | 16 #include "chrome/browser/extensions/api/sessions/session_id.h" |
| 17 #include "chrome/browser/extensions/api/tabs/windows_util.h" | 17 #include "chrome/browser/extensions/api/tabs/windows_util.h" |
| 18 #include "chrome/browser/extensions/extension_function_dispatcher.h" | 18 #include "chrome/browser/extensions/extension_function_dispatcher.h" |
| 19 #include "chrome/browser/extensions/extension_function_registry.h" | 19 #include "chrome/browser/extensions/extension_function_registry.h" |
| 20 #include "chrome/browser/extensions/extension_tab_util.h" | 20 #include "chrome/browser/extensions/extension_tab_util.h" |
| 21 #include "chrome/browser/extensions/window_controller.h" | 21 #include "chrome/browser/extensions/window_controller.h" |
| 22 #include "chrome/browser/extensions/window_controller_list.h" | 22 #include "chrome/browser/extensions/window_controller_list.h" |
| 23 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
| 24 #include "chrome/browser/search/search.h" | 24 #include "chrome/browser/search/search.h" |
| 25 #include "chrome/browser/sessions/session_restore.h" | 25 #include "chrome/browser/sessions/session_restore.h" |
| 26 #include "chrome/browser/sessions/tab_restore_service_delegate.h" | 26 #include "chrome/browser/sessions/tab_restore_service_delegate.h" |
| 27 #include "chrome/browser/sessions/tab_restore_service_factory.h" | 27 #include "chrome/browser/sessions/tab_restore_service_factory.h" |
| 28 #include "chrome/browser/sync/glue/session_model_associator.h" | |
| 29 #include "chrome/browser/sync/glue/synced_session.h" | 28 #include "chrome/browser/sync/glue/synced_session.h" |
| 29 #include "chrome/browser/sync/open_tabs_ui_delegate.h" |
| 30 #include "chrome/browser/sync/profile_sync_service.h" | 30 #include "chrome/browser/sync/profile_sync_service.h" |
| 31 #include "chrome/browser/sync/profile_sync_service_factory.h" | 31 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 32 #include "chrome/browser/ui/browser.h" | 32 #include "chrome/browser/ui/browser.h" |
| 33 #include "chrome/browser/ui/browser_finder.h" | 33 #include "chrome/browser/ui/browser_finder.h" |
| 34 #include "chrome/browser/ui/host_desktop.h" | 34 #include "chrome/browser/ui/host_desktop.h" |
| 35 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 35 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 36 #include "chrome/common/pref_names.h" | 36 #include "chrome/common/pref_names.h" |
| 37 #include "content/public/browser/web_contents.h" | 37 #include "content/public/browser/web_contents.h" |
| 38 #include "extensions/common/error_utils.h" | 38 #include "extensions/common/error_utils.h" |
| 39 #include "net/base/net_util.h" | 39 #include "net/base/net_util.h" |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 bool SessionsGetDevicesFunction::RunImpl() { | 352 bool SessionsGetDevicesFunction::RunImpl() { |
| 353 ProfileSyncService* service = | 353 ProfileSyncService* service = |
| 354 ProfileSyncServiceFactory::GetInstance()->GetForProfile(GetProfile()); | 354 ProfileSyncServiceFactory::GetInstance()->GetForProfile(GetProfile()); |
| 355 if (!(service && service->GetPreferredDataTypes().Has(syncer::SESSIONS))) { | 355 if (!(service && service->GetPreferredDataTypes().Has(syncer::SESSIONS))) { |
| 356 // Sync not enabled. | 356 // Sync not enabled. |
| 357 results_ = GetDevices::Results::Create( | 357 results_ = GetDevices::Results::Create( |
| 358 std::vector<linked_ptr<api::sessions::Device> >()); | 358 std::vector<linked_ptr<api::sessions::Device> >()); |
| 359 return true; | 359 return true; |
| 360 } | 360 } |
| 361 | 361 |
| 362 browser_sync::SessionModelAssociator* associator = | 362 browser_sync::OpenTabsUIDelegate* open_tabs = |
| 363 service->GetSessionModelAssociator(); | 363 service->GetOpenTabsUIDelegate(); |
| 364 std::vector<const browser_sync::SyncedSession*> sessions; | 364 std::vector<const browser_sync::SyncedSession*> sessions; |
| 365 if (!(associator && associator->GetAllForeignSessions(&sessions))) { | 365 if (!(open_tabs && open_tabs->GetAllForeignSessions(&sessions))) { |
| 366 results_ = GetDevices::Results::Create( | 366 results_ = GetDevices::Results::Create( |
| 367 std::vector<linked_ptr<api::sessions::Device> >()); | 367 std::vector<linked_ptr<api::sessions::Device> >()); |
| 368 return true; | 368 return true; |
| 369 } | 369 } |
| 370 | 370 |
| 371 scoped_ptr<GetDevices::Params> params(GetDevices::Params::Create(*args_)); | 371 scoped_ptr<GetDevices::Params> params(GetDevices::Params::Create(*args_)); |
| 372 EXTENSION_FUNCTION_VALIDATE(params); | 372 EXTENSION_FUNCTION_VALIDATE(params); |
| 373 if (params->filter && params->filter->max_results) { | 373 if (params->filter && params->filter->max_results) { |
| 374 EXTENSION_FUNCTION_VALIDATE(*params->filter->max_results >= 0 && | 374 EXTENSION_FUNCTION_VALIDATE(*params->filter->max_results >= 0 && |
| 375 *params->filter->max_results <= api::sessions::MAX_SESSION_RESULTS); | 375 *params->filter->max_results <= api::sessions::MAX_SESSION_RESULTS); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 } | 497 } |
| 498 | 498 |
| 499 bool SessionsRestoreFunction::RestoreForeignSession(const SessionId& session_id, | 499 bool SessionsRestoreFunction::RestoreForeignSession(const SessionId& session_id, |
| 500 Browser* browser) { | 500 Browser* browser) { |
| 501 ProfileSyncService* service = | 501 ProfileSyncService* service = |
| 502 ProfileSyncServiceFactory::GetInstance()->GetForProfile(GetProfile()); | 502 ProfileSyncServiceFactory::GetInstance()->GetForProfile(GetProfile()); |
| 503 if (!(service && service->GetPreferredDataTypes().Has(syncer::SESSIONS))) { | 503 if (!(service && service->GetPreferredDataTypes().Has(syncer::SESSIONS))) { |
| 504 SetError(kSessionSyncError); | 504 SetError(kSessionSyncError); |
| 505 return false; | 505 return false; |
| 506 } | 506 } |
| 507 browser_sync::SessionModelAssociator* associator = | 507 browser_sync::OpenTabsUIDelegate* open_tabs = |
| 508 service->GetSessionModelAssociator(); | 508 service->GetOpenTabsUIDelegate(); |
| 509 if (!associator) { | 509 if (!open_tabs) { |
| 510 SetError(kSessionSyncError); | 510 SetError(kSessionSyncError); |
| 511 return false; | 511 return false; |
| 512 } | 512 } |
| 513 | 513 |
| 514 const SessionTab* tab = NULL; | 514 const SessionTab* tab = NULL; |
| 515 if (associator->GetForeignTab(session_id.session_tag(), | 515 if (open_tabs->GetForeignTab(session_id.session_tag(), |
| 516 session_id.id(), | 516 session_id.id(), |
| 517 &tab)) { | 517 &tab)) { |
| 518 TabStripModel* tab_strip = browser->tab_strip_model(); | 518 TabStripModel* tab_strip = browser->tab_strip_model(); |
| 519 content::WebContents* contents = tab_strip->GetActiveWebContents(); | 519 content::WebContents* contents = tab_strip->GetActiveWebContents(); |
| 520 | 520 |
| 521 content::WebContents* tab_contents = | 521 content::WebContents* tab_contents = |
| 522 SessionRestore::RestoreForeignSessionTab(contents, *tab, | 522 SessionRestore::RestoreForeignSessionTab(contents, *tab, |
| 523 NEW_FOREGROUND_TAB); | 523 NEW_FOREGROUND_TAB); |
| 524 SetResultRestoredTab(tab_contents); | 524 SetResultRestoredTab(tab_contents); |
| 525 return true; | 525 return true; |
| 526 } | 526 } |
| 527 | 527 |
| 528 // Restoring a full window. | 528 // Restoring a full window. |
| 529 std::vector<const SessionWindow*> windows; | 529 std::vector<const SessionWindow*> windows; |
| 530 if (!associator->GetForeignSession(session_id.session_tag(), &windows)) { | 530 if (!open_tabs->GetForeignSession(session_id.session_tag(), &windows)) { |
| 531 SetInvalidIdError(session_id.ToString()); | 531 SetInvalidIdError(session_id.ToString()); |
| 532 return false; | 532 return false; |
| 533 } | 533 } |
| 534 | 534 |
| 535 std::vector<const SessionWindow*>::const_iterator window = windows.begin(); | 535 std::vector<const SessionWindow*>::const_iterator window = windows.begin(); |
| 536 while (window != windows.end() | 536 while (window != windows.end() |
| 537 && (*window)->window_id.id() != session_id.id()) { | 537 && (*window)->window_id.id() != session_id.id()) { |
| 538 ++window; | 538 ++window; |
| 539 } | 539 } |
| 540 if (window == windows.end()) { | 540 if (window == windows.end()) { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 static base::LazyInstance<ProfileKeyedAPIFactory<SessionsAPI> > | 585 static base::LazyInstance<ProfileKeyedAPIFactory<SessionsAPI> > |
| 586 g_factory = LAZY_INSTANCE_INITIALIZER; | 586 g_factory = LAZY_INSTANCE_INITIALIZER; |
| 587 | 587 |
| 588 // static | 588 // static |
| 589 ProfileKeyedAPIFactory<SessionsAPI>* | 589 ProfileKeyedAPIFactory<SessionsAPI>* |
| 590 SessionsAPI::GetFactoryInstance() { | 590 SessionsAPI::GetFactoryInstance() { |
| 591 return &g_factory.Get(); | 591 return &g_factory.Get(); |
| 592 } | 592 } |
| 593 | 593 |
| 594 } // namespace extensions | 594 } // namespace extensions |
| OLD | NEW |