OLD | NEW |
---|---|
(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::OpenTabsUIDelegate; | |
11 using sync_driver::SyncService; | |
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 OpenTabsUIDelegate* TabDelegateSyncAdapter::GetOpenTabsUIDelegate() { | |
25 return sync_service_->GetOpenTabsUIDelegate(); | |
26 } | |
27 | |
28 void TabDelegateSyncAdapter::SubscribeForForeignTabChange( | |
29 const OnChangeWithDelegate& change_callback) { | |
30 change_callback_ = change_callback; | |
Marc Treib
2016/09/16 12:26:49
Maybe DCHECK that change_callback_ was null before
tschumann
2016/09/16 13:33:20
yes, please. Also add a comment to the OpenTabsUID
skym
2016/09/16 18:18:49
Done.
skym
2016/09/16 18:18:49
Done.
| |
31 } | |
32 | |
33 void TabDelegateSyncAdapter::OnStateChanged() { | |
34 // Ignored. | |
35 } | |
36 | |
37 void TabDelegateSyncAdapter::OnSyncConfigurationCompleted() { | |
38 InvokeCallback(); | |
39 } | |
40 | |
41 void TabDelegateSyncAdapter::OnForeignSessionUpdated() { | |
42 InvokeCallback(); | |
43 } | |
44 | |
45 void TabDelegateSyncAdapter::InvokeCallback() { | |
46 if (!change_callback_.is_null()) | |
47 change_callback_.Run(sync_service_->GetOpenTabsUIDelegate()); | |
48 } | |
49 | |
50 } // namespace ntp_snippets | |
OLD | NEW |