OLD | NEW |
---|---|
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 Loading... | |
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()) { | |
noyau (Ping after 24h)
2014/10/29 10:23:04
model_->loaded is now redundant as refreshes_neede
danduong
2014/10/29 20:26:09
Done.
Yaron
2014/10/29 23:07:56
I agree with Eric that it should go inside this if
| |
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 } | |
80 | |
81 void ChromeBookmarkServerClusterService::EnhancedBookmarkNodeChanged( | |
82 BookmarkModel* model, | |
83 const BookmarkNode* node) { | |
84 BookmarkServerClusterService::EnhancedBookmarkNodeChanged(model, 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 | |
68 } // namespace enhanced_bookmarks | 104 } // namespace enhanced_bookmarks |
OLD | NEW |