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 27 matching lines...) Expand all Loading... | |
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() { |
48 // Ignored. | 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 | |
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 | |
52 // calback when transitioning between states. This will also capture the case | |
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 | |
55 // becomes availabile. Otherwise we might transition to think we have session | |
56 // data, but invoke our callback while the GetOpenTabsUIDelegate() returns bad | |
57 // results. Fourtunately,this isn'ta problem. GetOpenTabsUIDelegate() is | |
maxbogue
2016/12/19 20:35:16
"Fourtunately,this isn'ta" -> "Fortunately, this i
| |
58 // guarded by verifying the data type is RUNNING, which always means the | |
59 // sessions merge has already happened. | |
60 if (had_session_data_ != HasSessionsData()) { | |
61 InvokeCallback(); | |
62 } | |
49 } | 63 } |
50 | 64 |
51 void TabDelegateSyncAdapter::OnSyncConfigurationCompleted() { | 65 void TabDelegateSyncAdapter::OnSyncConfigurationCompleted() { |
52 InvokeCallback(); | 66 // 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 // possible, and all of the information captured in this event will also be | |
69 // covered by OnStateChange. | |
53 } | 70 } |
54 | 71 |
55 void TabDelegateSyncAdapter::OnForeignSessionUpdated() { | 72 void TabDelegateSyncAdapter::OnForeignSessionUpdated() { |
73 // Foreign tab data changed, always invoke the callback to generate new | |
74 // suggestions. Interestingly, this is only triggered after sync model type | |
75 // apply, not after merge. The merge case should always be handled by | |
76 // OnStateChange. | |
56 InvokeCallback(); | 77 InvokeCallback(); |
57 } | 78 } |
58 | 79 |
59 void TabDelegateSyncAdapter::InvokeCallback() { | 80 void TabDelegateSyncAdapter::InvokeCallback() { |
81 had_session_data_ = HasSessionsData(); | |
60 if (!change_callback_.is_null()) { | 82 if (!change_callback_.is_null()) { |
61 change_callback_.Run(); | 83 change_callback_.Run(); |
62 } | 84 } |
63 } | 85 } |
64 | 86 |
65 } // namespace ntp_snippets | 87 } // namespace ntp_snippets |
OLD | NEW |