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 15 matching lines...) Expand all Loading... |
26 sync_service_(sync_service) { | 26 sync_service_(sync_service) { |
27 if (sync_service_) | 27 if (sync_service_) |
28 sync_service_->AddObserver(this); | 28 sync_service_->AddObserver(this); |
29 } | 29 } |
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( |
| 37 BookmarkServerServiceObserver* observer) { |
| 38 BookmarkServerClusterService::AddObserver(observer); |
| 39 if (sync_refresh_skipped_) { |
| 40 sync_refresh_skipped_ = false; |
| 41 TriggerTokenRequest(false); |
| 42 } |
| 43 } |
| 44 |
36 void ChromeBookmarkServerClusterService::OnStateChanged() { | 45 void ChromeBookmarkServerClusterService::OnStateChanged() { |
37 // Do nothing. | 46 // Do nothing. |
38 } | 47 } |
39 | 48 |
40 void ChromeBookmarkServerClusterService::OnSyncCycleCompleted() { | 49 void ChromeBookmarkServerClusterService::OnSyncCycleCompleted() { |
41 // 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 |
42 // cluster request immediately after a bookmark is changed from the bookmark | 51 // cluster request immediately after a bookmark is changed from the bookmark |
43 // observer notification will yield the wrong results. The request must be | 52 // observer notification will yield the wrong results. The request must be |
44 // delayed until the sync cycle has completed. | 53 // delayed until the sync cycle has completed. In fact, the ideal signal would |
45 // TODO(noyau): This might happen too often, need a way to coalesce and delay | 54 // be "bookmark changed by sync", but we don't have that yet, and this is a |
46 // the notifications. | 55 // compromise. |
47 if (model_->loaded()) | 56 // Note that we will be skipping calling this cluster API if there is no |
48 TriggerTokenRequest(false); | 57 // observer attached, because calling that is meaningless without UI to show. |
| 58 if (model_->loaded()) { |
| 59 if (observers_.might_have_observers()) { |
| 60 TriggerTokenRequest(false); |
| 61 sync_refresh_skipped_ = false; |
| 62 } else { |
| 63 sync_refresh_skipped_ = true; |
| 64 } |
| 65 } |
49 } | 66 } |
50 | 67 |
51 } // namespace enhanced_bookmarks | 68 } // namespace enhanced_bookmarks |
OLD | NEW |