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

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

Issue 693513003: Revert of 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
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 sync_refresh_skipped_ = false;
40 TriggerTokenRequest(false); 41 TriggerTokenRequest(false);
41 sync_refresh_skipped_ = 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. 53 // delayed until the sync cycle has completed. In fact, the ideal signal would
54 // be "bookmark changed by sync", but we don't have that yet, and this is a
55 // compromise.
54 // Note that we will be skipping calling this cluster API if there is no 56 // Note that we will be skipping calling this cluster API if there is no
55 // observer attached, because calling that is meaningless without UI to show. 57 // observer attached, because calling that is meaningless without UI to show.
56 // We also will avoid requesting for clusters if the bookmark data hasn't 58 if (model_->loaded()) {
57 // changed.
58 if (refreshes_needed_ > 0) {
59 DCHECK(model_->loaded());
60 if (observers_.might_have_observers()) { 59 if (observers_.might_have_observers()) {
61 TriggerTokenRequest(false); 60 TriggerTokenRequest(false);
62 sync_refresh_skipped_ = false; 61 sync_refresh_skipped_ = false;
63 } else { 62 } else {
64 sync_refresh_skipped_ = true; 63 sync_refresh_skipped_ = true;
65 } 64 }
66 --refreshes_needed_;
67 } 65 }
68 } 66 }
69 67
70 void ChromeBookmarkServerClusterService::EnhancedBookmarkAdded(
71 const BookmarkNode* node) {
72 BookmarkServerClusterService::EnhancedBookmarkAdded(node);
73 InvalidateCache();
74 }
75
76 void ChromeBookmarkServerClusterService::EnhancedBookmarkRemoved(
77 const BookmarkNode* node) {
78 BookmarkServerClusterService::EnhancedBookmarkRemoved(node);
79 InvalidateCache();
80 }
81
82 void ChromeBookmarkServerClusterService::EnhancedBookmarkNodeChanged(
83 const BookmarkNode* node) {
84 BookmarkServerClusterService::EnhancedBookmarkNodeChanged(node);
85 InvalidateCache();
86 }
87
88 void ChromeBookmarkServerClusterService::InvalidateCache() {
89 // Bookmark changes can happen locally or via sync. It is difficult to
90 // determine if a given SyncCycle contains all the local modifications.
91 //
92 // Consider the following sequence:
93 // 1. SyncCycleBeginning (bookmark version:1)
94 // 2. Bookmarks mutate locally (bookmark version:2)
95 // 3. SyncCycleCompleted (bookmark version:1)
96 //
97 // In this case, the bookmarks modified locally won't be sent to the server
98 // until the next SyncCycleCompleted. Since we can't accurately determine
99 // if a bookmark change has been sent on a SyncCycleCompleted, we're always
100 // assuming that we need to wait for 2 sync cycles.
101 refreshes_needed_ = 2;
102 }
103
104 } // namespace enhanced_bookmarks 68 } // namespace enhanced_bookmarks
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698