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

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

Issue 2578293002: Foreign tab suggestions should update when disabling sync or signing out. (Closed)
Patch Set: Adding the const back to .cc Created 4 years 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
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
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. It is important to
54 // realize that this approach requires the data returned by
maxbogue 2016/12/16 22:21:34 Parse error, plz fix this sentence.
skym 2016/12/19 20:31:43 Done.
55 // GetOpenTabsUIDelegate() on a transition to having session data must be
56 // returning the real and most current information as soon as it becomes not
57 // nullptr. This is currently the case, as GetOpenTabsUIDelegate() is gaurded
maxbogue 2016/12/16 22:21:34 guarded*
skym 2016/12/19 20:31:43 Done.
58 // by verifying the data type is RUNNING, which always means the model type
59 // merge has already happened.
60 if (had_session_data_ != HasSessionsData()) {
61 had_session_data_ = !had_session_data_;
62 InvokeCallback();
63 }
49 } 64 }
50 65
51 void TabDelegateSyncAdapter::OnSyncConfigurationCompleted() { 66 void TabDelegateSyncAdapter::OnSyncConfigurationCompleted() {
67 // Ignored. This event can let us know when the set of enabled data types
68 // change. However, we want to avoid useless notifications as much as
69 // possible, and all of the information captured in this event will also be
70 // covered by OnStateChange.
71 }
72
73 void TabDelegateSyncAdapter::OnForeignSessionUpdated() {
74 // Foreign tab data changed, always invoke the callback to generate new
75 // suggestions. The updating of |had_session_data_| here is a best effort to
76 // reduce spam, but may not be completely effective. Interestingly, this is
77 // only triggered after sync model type apply, not after merge. The merge case
78 // should always be handled by OnStateChange.
79 had_session_data_ = HasSessionsData();
Marc Treib 2016/12/19 11:47:53 I think updating had_sessions_data_ should happen
skym 2016/12/19 20:31:43 Done.
52 InvokeCallback(); 80 InvokeCallback();
53 } 81 }
54 82
55 void TabDelegateSyncAdapter::OnForeignSessionUpdated() {
56 InvokeCallback();
57 }
58
59 void TabDelegateSyncAdapter::InvokeCallback() { 83 void TabDelegateSyncAdapter::InvokeCallback() {
60 if (!change_callback_.is_null()) { 84 if (!change_callback_.is_null()) {
61 change_callback_.Run(); 85 change_callback_.Run();
62 } 86 }
63 } 87 }
64 88
65 } // namespace ntp_snippets 89 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698