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

Side by Side Diff: components/ntp_snippets/sessions/tab_delegate_sync_adapter.cc

Issue 2279123002: [Sync] Initial implementation of foreign sessions suggestions provider. (Closed)
Patch Set: Updating for comments, again! Created 4 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
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/ntp_snippets/sessions/tab_delegate_sync_adapter.h"
6
7 #include "components/sync/driver/sync_service.h"
8 #include "components/sync_sessions/open_tabs_ui_delegate.h"
9
10 using sync_driver::SyncService;
11 using sync_sessions::OpenTabsUIDelegate;
12
13 namespace ntp_snippets {
14
15 TabDelegateSyncAdapter::TabDelegateSyncAdapter(SyncService* sync_service)
16 : sync_service_(sync_service) {
17 sync_service_->AddObserver(this);
18 }
19
20 TabDelegateSyncAdapter::~TabDelegateSyncAdapter() {
21 sync_service_->RemoveObserver(this);
22 }
23
24 bool TabDelegateSyncAdapter::HasSessionsData() {
25 // GetOpenTabsUIDelegate will be a nullptr if sync has not started, or if the
26 // sessions data type is not enabled.
27 return sync_service_->GetOpenTabsUIDelegate() != nullptr;
28 }
29
30 std::vector<const sync_sessions::SyncedSession*>
31 TabDelegateSyncAdapter::GetAllForeignSessions() {
32 std::vector<const sync_sessions::SyncedSession*> sessions;
33 OpenTabsUIDelegate* delegate = sync_service_->GetOpenTabsUIDelegate();
34 if (delegate != nullptr) {
35 // The return bool from GetAllForeignSessions(...) is ignored.
36 delegate->GetAllForeignSessions(&sessions);
37 }
38 return sessions;
39 }
40
41 void TabDelegateSyncAdapter::SubscribeForForeignTabChange(
42 const base::Closure& change_callback) {
43 DCHECK(change_callback_.is_null());
44 change_callback_ = change_callback;
45 }
46
47 void TabDelegateSyncAdapter::OnStateChanged() {
48 // Ignored.
49 }
50
51 void TabDelegateSyncAdapter::OnSyncConfigurationCompleted() {
52 InvokeCallback();
53 }
54
55 void TabDelegateSyncAdapter::OnForeignSessionUpdated() {
56 InvokeCallback();
57 }
58
59 void TabDelegateSyncAdapter::InvokeCallback() {
60 if (!change_callback_.is_null())
61 change_callback_.Run();
62 }
63
64 } // namespace ntp_snippets
OLDNEW
« no previous file with comments | « components/ntp_snippets/sessions/tab_delegate_sync_adapter.h ('k') | components/ntp_snippets_strings.grdp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698