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

Side by Side Diff: chrome/browser/enhanced_bookmarks/chrome_bookmark_server_cluster_service.cc

Issue 682933002: Reduce frequency of requesting bookmark clusters. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « chrome/browser/enhanced_bookmarks/chrome_bookmark_server_cluster_service.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chrome/browser/enhanced_bookmarks/chrome_bookmark_server_cluster_servi ce.h" 5 #include "chrome/browser/enhanced_bookmarks/chrome_bookmark_server_cluster_servi ce.h"
6 6
7 #include "chrome/browser/sync/profile_sync_service.h" 7 #include "chrome/browser/sync/profile_sync_service.h"
8 #include "components/enhanced_bookmarks/enhanced_bookmark_model.h" 8 #include "components/enhanced_bookmarks/enhanced_bookmark_model.h"
9 9
10 namespace enhanced_bookmarks { 10 namespace enhanced_bookmarks {
(...skipping 19 matching lines...) Expand all
30 30
31 ChromeBookmarkServerClusterService::~ChromeBookmarkServerClusterService() { 31 ChromeBookmarkServerClusterService::~ChromeBookmarkServerClusterService() {
32 if (sync_service_) 32 if (sync_service_)
33 sync_service_->RemoveObserver(this); 33 sync_service_->RemoveObserver(this);
34 } 34 }
35 35
36 void ChromeBookmarkServerClusterService::AddObserver( 36 void ChromeBookmarkServerClusterService::AddObserver(
37 BookmarkServerServiceObserver* observer) { 37 BookmarkServerServiceObserver* observer) {
38 BookmarkServerClusterService::AddObserver(observer); 38 BookmarkServerClusterService::AddObserver(observer);
39 if (sync_refresh_skipped_) { 39 if (sync_refresh_skipped_) {
40 TriggerTokenRequest(false);
40 sync_refresh_skipped_ = false; 41 sync_refresh_skipped_ = false;
41 TriggerTokenRequest(false);
42 } 42 }
43 } 43 }
44 44
45 void ChromeBookmarkServerClusterService::OnStateChanged() { 45 void ChromeBookmarkServerClusterService::OnStateChanged() {
46 // Do nothing. 46 // Do nothing.
47 } 47 }
48 48
49 void ChromeBookmarkServerClusterService::OnSyncCycleCompleted() { 49 void ChromeBookmarkServerClusterService::OnSyncCycleCompleted() {
50 // The stars cluster API relies on the information in chrome-sync. Sending a 50 // The stars cluster API relies on the information in chrome-sync. Sending a
51 // cluster request immediately after a bookmark is changed from the bookmark 51 // cluster request immediately after a bookmark is changed from the bookmark
52 // observer notification will yield the wrong results. The request must be 52 // observer notification will yield the wrong results. The request must be
53 // delayed until the sync cycle has completed. In fact, the ideal signal would 53 // delayed until the sync cycle has completed.
54 // be "bookmark changed by sync", but we don't have that yet, and this is a
55 // compromise.
56 // Note that we will be skipping calling this cluster API if there is no 54 // Note that we will be skipping calling this cluster API if there is no
57 // observer attached, because calling that is meaningless without UI to show. 55 // observer attached, because calling that is meaningless without UI to show.
58 if (model_->loaded()) { 56 // We also will avoid requesting for clusters if the bookmark data hasn't
57 // changed.
58 if (refreshes_needed_ > 0 && model_->loaded()) {
59 if (observers_.might_have_observers()) { 59 if (observers_.might_have_observers()) {
60 TriggerTokenRequest(false); 60 TriggerTokenRequest(false);
61 sync_refresh_skipped_ = false; 61 sync_refresh_skipped_ = false;
62 } else { 62 } else {
63 sync_refresh_skipped_ = true; 63 sync_refresh_skipped_ = true;
64 } 64 }
65 --refreshes_needed_;
65 } 66 }
66 } 67 }
67 68
69 void ChromeBookmarkServerClusterService::EnhancedBookmarkAdded(
70 const BookmarkNode* node) {
71 BookmarkServerClusterService::EnhancedBookmarkAdded(node);
72 InvalidateCache();
73 }
74
75 void ChromeBookmarkServerClusterService::EnhancedBookmarkRemoved(
76 const BookmarkNode* node) {
77 BookmarkServerClusterService::EnhancedBookmarkRemoved(node);
78 InvalidateCache();
79 }
Kibeom Kim (inactive) 2014/10/28 17:27:08 Q: Mark, will listening BookmarkAdded and removed
Mark 2014/10/28 18:17:00 IMO, yes. You could listen on deletes too. The k
80
81 void ChromeBookmarkServerClusterService::InvalidateCache() {
82 // Bookmark changes can happen locally or via sync. It is difficult to
83 // determine if a given SyncCycle contains all the local modifications.
84 //
85 // Consider the following sequence:
86 // 1. SyncCycleBeginning (bookmark version:1)
87 // 2. Bookmarks mutate locally (bookmark version:2)
88 // 3. SyncCycleCompleted (bookmark version:1)
89 //
90 // In this case, the bookmarks modified locally won't be sent to the server
91 // until the next SyncCycleCompleted. Since we can't accurately determine
92 // if a bookmark change has been sent on a SyncCycleCompleted, we're always
93 // assuming that we need to wait for 2 sync cycles.
94 refreshes_needed_ = 2;
Yaron 2014/10/28 17:48:27 This seems a little too optimistic and tailored to
danduong 2014/10/28 17:50:18 It actually means you'll (at most) fetch twice as
Yaron 2014/10/28 17:52:23 Ugh. Of course. For some reason I assumed it was a
95 }
96
68 } // namespace enhanced_bookmarks 97 } // namespace enhanced_bookmarks
OLDNEW
« no previous file with comments | « chrome/browser/enhanced_bookmarks/chrome_bookmark_server_cluster_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698