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" |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 *static_cast<const TabRestoreService::Window*>(entry), entry->id); | 188 *static_cast<const TabRestoreService::Window*>(entry), entry->id); |
189 break; | 189 break; |
190 default: | 190 default: |
191 NOTREACHED(); | 191 NOTREACHED(); |
192 } | 192 } |
193 return CreateSessionModelHelper(entry->timestamp.ToTimeT(), | 193 return CreateSessionModelHelper(entry->timestamp.ToTimeT(), |
194 tab.Pass(), | 194 tab.Pass(), |
195 window.Pass()); | 195 window.Pass()); |
196 } | 196 } |
197 | 197 |
198 bool SessionsGetRecentlyClosedFunction::RunImpl() { | 198 bool SessionsGetRecentlyClosedFunction::RunSync() { |
199 scoped_ptr<GetRecentlyClosed::Params> params( | 199 scoped_ptr<GetRecentlyClosed::Params> params( |
200 GetRecentlyClosed::Params::Create(*args_)); | 200 GetRecentlyClosed::Params::Create(*args_)); |
201 EXTENSION_FUNCTION_VALIDATE(params); | 201 EXTENSION_FUNCTION_VALIDATE(params); |
202 int max_results = api::sessions::MAX_SESSION_RESULTS; | 202 int max_results = api::sessions::MAX_SESSION_RESULTS; |
203 if (params->filter && params->filter->max_results) | 203 if (params->filter && params->filter->max_results) |
204 max_results = *params->filter->max_results; | 204 max_results = *params->filter->max_results; |
205 EXTENSION_FUNCTION_VALIDATE(max_results >= 0 && | 205 EXTENSION_FUNCTION_VALIDATE(max_results >= 0 && |
206 max_results <= api::sessions::MAX_SESSION_RESULTS); | 206 max_results <= api::sessions::MAX_SESSION_RESULTS); |
207 | 207 |
208 std::vector<linked_ptr<api::sessions::Session> > result; | 208 std::vector<linked_ptr<api::sessions::Session> > result; |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 static_cast<int>(device_struct->sessions.size()) < max_results; ++it) { | 355 static_cast<int>(device_struct->sessions.size()) < max_results; ++it) { |
356 scoped_ptr<api::sessions::Session> session_model(CreateSessionModel( | 356 scoped_ptr<api::sessions::Session> session_model(CreateSessionModel( |
357 *it->second, session->session_tag)); | 357 *it->second, session->session_tag)); |
358 if (session_model) | 358 if (session_model) |
359 device_struct->sessions.push_back(make_linked_ptr( | 359 device_struct->sessions.push_back(make_linked_ptr( |
360 session_model.release())); | 360 session_model.release())); |
361 } | 361 } |
362 return device_struct.Pass(); | 362 return device_struct.Pass(); |
363 } | 363 } |
364 | 364 |
365 bool SessionsGetDevicesFunction::RunImpl() { | 365 bool SessionsGetDevicesFunction::RunSync() { |
366 ProfileSyncService* service = | 366 ProfileSyncService* service = |
367 ProfileSyncServiceFactory::GetInstance()->GetForProfile(GetProfile()); | 367 ProfileSyncServiceFactory::GetInstance()->GetForProfile(GetProfile()); |
368 if (!(service && service->GetPreferredDataTypes().Has(syncer::SESSIONS))) { | 368 if (!(service && service->GetPreferredDataTypes().Has(syncer::SESSIONS))) { |
369 // Sync not enabled. | 369 // Sync not enabled. |
370 results_ = GetDevices::Results::Create( | 370 results_ = GetDevices::Results::Create( |
371 std::vector<linked_ptr<api::sessions::Device> >()); | 371 std::vector<linked_ptr<api::sessions::Device> >()); |
372 return true; | 372 return true; |
373 } | 373 } |
374 | 374 |
375 browser_sync::OpenTabsUIDelegate* open_tabs = | 375 browser_sync::OpenTabsUIDelegate* open_tabs = |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 | 557 |
558 chrome::HostDesktopType host_desktop_type = browser->host_desktop_type(); | 558 chrome::HostDesktopType host_desktop_type = browser->host_desktop_type(); |
559 // Only restore one window at a time. | 559 // Only restore one window at a time. |
560 std::vector<Browser*> browsers = SessionRestore::RestoreForeignSessionWindows( | 560 std::vector<Browser*> browsers = SessionRestore::RestoreForeignSessionWindows( |
561 GetProfile(), host_desktop_type, window, window + 1); | 561 GetProfile(), host_desktop_type, window, window + 1); |
562 // Will always create one browser because we only restore one window per call. | 562 // Will always create one browser because we only restore one window per call. |
563 DCHECK_EQ(1u, browsers.size()); | 563 DCHECK_EQ(1u, browsers.size()); |
564 return SetResultRestoredWindow(ExtensionTabUtil::GetWindowId(browsers[0])); | 564 return SetResultRestoredWindow(ExtensionTabUtil::GetWindowId(browsers[0])); |
565 } | 565 } |
566 | 566 |
567 bool SessionsRestoreFunction::RunImpl() { | 567 bool SessionsRestoreFunction::RunSync() { |
568 scoped_ptr<Restore::Params> params(Restore::Params::Create(*args_)); | 568 scoped_ptr<Restore::Params> params(Restore::Params::Create(*args_)); |
569 EXTENSION_FUNCTION_VALIDATE(params); | 569 EXTENSION_FUNCTION_VALIDATE(params); |
570 | 570 |
571 Browser* browser = chrome::FindBrowserWithProfile( | 571 Browser* browser = chrome::FindBrowserWithProfile( |
572 GetProfile(), chrome::HOST_DESKTOP_TYPE_NATIVE); | 572 GetProfile(), chrome::HOST_DESKTOP_TYPE_NATIVE); |
573 if (!browser) { | 573 if (!browser) { |
574 SetError(kNoBrowserToRestoreSession); | 574 SetError(kNoBrowserToRestoreSession); |
575 return false; | 575 return false; |
576 } | 576 } |
577 | 577 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
643 return g_factory.Pointer(); | 643 return g_factory.Pointer(); |
644 } | 644 } |
645 | 645 |
646 void SessionsAPI::OnListenerAdded(const EventListenerInfo& details) { | 646 void SessionsAPI::OnListenerAdded(const EventListenerInfo& details) { |
647 sessions_event_router_.reset( | 647 sessions_event_router_.reset( |
648 new SessionsEventRouter(Profile::FromBrowserContext(browser_context_))); | 648 new SessionsEventRouter(Profile::FromBrowserContext(browser_context_))); |
649 EventRouter::Get(browser_context_)->UnregisterObserver(this); | 649 EventRouter::Get(browser_context_)->UnregisterObserver(this); |
650 } | 650 } |
651 | 651 |
652 } // namespace extensions | 652 } // namespace extensions |
OLD | NEW |