OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 "components/ntp_snippets/sessions/tab_delegate_sync_adapter.h" | 5 #include "components/ntp_snippets/sessions/tab_delegate_sync_adapter.h" |
6 | 6 |
7 #include "components/sync/driver/sync_service.h" | 7 #include "components/sync/driver/sync_service.h" |
8 #include "components/sync_sessions/open_tabs_ui_delegate.h" | 8 #include "components/sync_sessions/open_tabs_ui_delegate.h" |
9 | 9 |
10 using syncer::SyncService; | 10 using syncer::SyncService; |
(...skipping 26 matching lines...) Expand all Loading... |
37 } | 37 } |
38 return sessions; | 38 return sessions; |
39 } | 39 } |
40 | 40 |
41 void TabDelegateSyncAdapter::SubscribeForForeignTabChange( | 41 void TabDelegateSyncAdapter::SubscribeForForeignTabChange( |
42 const base::Closure& change_callback) { | 42 const base::Closure& change_callback) { |
43 DCHECK(change_callback_.is_null()); | 43 DCHECK(change_callback_.is_null()); |
44 change_callback_ = change_callback; | 44 change_callback_ = change_callback; |
45 } | 45 } |
46 | 46 |
47 void TabDelegateSyncAdapter::OnStateChanged() { | 47 void TabDelegateSyncAdapter::OnStateChanged(syncer::SyncService* sync) { |
48 // OnStateChanged gets called very frequently, and usually is not important. | 48 // OnStateChanged gets called very frequently, and usually is not important. |
49 // But there are some events, like disabling sync and signing out, that are | 49 // But there are some events, like disabling sync and signing out, that are |
50 // only captured through OnStateChange. In an attempt to send as few messages | 50 // only captured through OnStateChange. In an attempt to send as few messages |
51 // as possible, track if there was session data, and always/only invoke the | 51 // as possible, track if there was session data, and always/only invoke the |
52 // callback when transitioning between states. This will also capture the case | 52 // callback when transitioning between states. This will also capture the case |
53 // when Open Tab is added/removed from syncing types. Note that this requires | 53 // when Open Tab is added/removed from syncing types. Note that this requires |
54 // the object behind GetOpenTabsUIDelegate() to have its real data when it | 54 // the object behind GetOpenTabsUIDelegate() to have its real data when it |
55 // becomes available. Otherwise we might transition to think we have session | 55 // becomes available. Otherwise we might transition to think we have session |
56 // data, but invoke our callback while the GetOpenTabsUIDelegate() returns bad | 56 // data, but invoke our callback while the GetOpenTabsUIDelegate() returns bad |
57 // results. Fortunately, this isn't a problem. GetOpenTabsUIDelegate() is | 57 // results. Fortunately, this isn't a problem. GetOpenTabsUIDelegate() is |
58 // guarded by verifying the data type is RUNNING, which always means the | 58 // guarded by verifying the data type is RUNNING, which always means the |
59 // sessions merge has already happened. | 59 // sessions merge has already happened. |
60 if (had_session_data_ != HasSessionsData()) { | 60 if (had_session_data_ != HasSessionsData()) { |
61 InvokeCallback(); | 61 InvokeCallback(); |
62 } | 62 } |
63 } | 63 } |
64 | 64 |
65 void TabDelegateSyncAdapter::OnSyncConfigurationCompleted() { | 65 void TabDelegateSyncAdapter::OnSyncConfigurationCompleted( |
| 66 syncer::SyncService* sync) { |
66 // Ignored. This event can let us know when the set of enabled data types | 67 // Ignored. This event can let us know when the set of enabled data types |
67 // change. However, we want to avoid useless notifications as much as | 68 // change. However, we want to avoid useless notifications as much as |
68 // possible, and all of the information captured in this event will also be | 69 // possible, and all of the information captured in this event will also be |
69 // covered by OnStateChange. | 70 // covered by OnStateChange. |
70 } | 71 } |
71 | 72 |
72 void TabDelegateSyncAdapter::OnForeignSessionUpdated() { | 73 void TabDelegateSyncAdapter::OnForeignSessionUpdated( |
| 74 syncer::SyncService* sync) { |
73 // Foreign tab data changed, always invoke the callback to generate new | 75 // Foreign tab data changed, always invoke the callback to generate new |
74 // suggestions. Interestingly, this is only triggered after sync model type | 76 // suggestions. Interestingly, this is only triggered after sync model type |
75 // apply, not after merge. The merge case should always be handled by | 77 // apply, not after merge. The merge case should always be handled by |
76 // OnStateChange. | 78 // OnStateChange. |
77 InvokeCallback(); | 79 InvokeCallback(); |
78 } | 80 } |
79 | 81 |
80 void TabDelegateSyncAdapter::InvokeCallback() { | 82 void TabDelegateSyncAdapter::InvokeCallback() { |
81 had_session_data_ = HasSessionsData(); | 83 had_session_data_ = HasSessionsData(); |
82 if (!change_callback_.is_null()) { | 84 if (!change_callback_.is_null()) { |
83 change_callback_.Run(); | 85 change_callback_.Run(); |
84 } | 86 } |
85 } | 87 } |
86 | 88 |
87 } // namespace ntp_snippets | 89 } // namespace ntp_snippets |
OLD | NEW |