OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef CHROME_BROWSER_UI_WEBUI_BROWSING_HISTORY_HANDLER_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_BROWSING_HISTORY_HANDLER_H_ |
6 #define CHROME_BROWSER_UI_WEBUI_BROWSING_HISTORY_HANDLER_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_BROWSING_HISTORY_HANDLER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
15 #include "base/scoped_observer.h" | 15 #include "base/scoped_observer.h" |
16 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
17 #include "base/task/cancelable_task_tracker.h" | 17 #include "base/task/cancelable_task_tracker.h" |
18 #include "base/timer/timer.h" | 18 #include "base/timer/timer.h" |
19 #include "base/values.h" | 19 #include "base/values.h" |
20 #include "components/history/core/browser/history_service_observer.h" | 20 #include "components/history/core/browser/history_service_observer.h" |
21 #include "components/history/core/browser/url_row.h" | 21 #include "components/history/core/browser/url_row.h" |
22 #include "components/history/core/browser/web_history_service.h" | 22 #include "components/history/core/browser/web_history_service.h" |
| 23 #include "components/sync/driver/sync_service_observer.h" |
23 #include "content/public/browser/web_ui_message_handler.h" | 24 #include "content/public/browser/web_ui_message_handler.h" |
24 #include "url/gurl.h" | 25 #include "url/gurl.h" |
25 | 26 |
26 class ProfileSyncService; | 27 class ProfileSyncService; |
27 class SupervisedUserService; | 28 class SupervisedUserService; |
28 | 29 |
29 namespace bookmarks { | 30 namespace bookmarks { |
30 class BookmarkModel; | 31 class BookmarkModel; |
31 } | 32 } |
32 | 33 |
33 namespace history { | 34 namespace history { |
34 class HistoryService; | 35 class HistoryService; |
35 struct QueryOptions; | 36 struct QueryOptions; |
36 class QueryResults; | 37 class QueryResults; |
37 } | 38 } |
38 | 39 |
| 40 namespace sync_driver { |
| 41 class SyncServiceObserver; |
| 42 } |
| 43 |
39 // The handler for Javascript messages related to the "history" view. | 44 // The handler for Javascript messages related to the "history" view. |
40 class BrowsingHistoryHandler : public content::WebUIMessageHandler, | 45 class BrowsingHistoryHandler : public content::WebUIMessageHandler, |
41 public history::HistoryServiceObserver { | 46 public history::HistoryServiceObserver, |
| 47 public history::WebHistoryService::Observer, |
| 48 public sync_driver::SyncServiceObserver { |
42 public: | 49 public: |
43 // Represents a history entry to be shown to the user, representing either | 50 // Represents a history entry to be shown to the user, representing either |
44 // a local or remote visit. A single entry can represent multiple visits, | 51 // a local or remote visit. A single entry can represent multiple visits, |
45 // since only the most recent visit on a particular day is shown. | 52 // since only the most recent visit on a particular day is shown. |
46 struct HistoryEntry { | 53 struct HistoryEntry { |
47 // Values indicating whether an entry represents only local visits, only | 54 // Values indicating whether an entry represents only local visits, only |
48 // remote visits, or a mixture of both. | 55 // remote visits, or a mixture of both. |
49 enum EntryType { | 56 enum EntryType { |
50 EMPTY_ENTRY = 0, | 57 EMPTY_ENTRY = 0, |
51 LOCAL_ENTRY, | 58 LOCAL_ENTRY, |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 // Whether this entry was blocked when it was attempted. | 106 // Whether this entry was blocked when it was attempted. |
100 bool blocked_visit; | 107 bool blocked_visit; |
101 }; | 108 }; |
102 | 109 |
103 BrowsingHistoryHandler(); | 110 BrowsingHistoryHandler(); |
104 ~BrowsingHistoryHandler() override; | 111 ~BrowsingHistoryHandler() override; |
105 | 112 |
106 // WebUIMessageHandler implementation. | 113 // WebUIMessageHandler implementation. |
107 void RegisterMessages() override; | 114 void RegisterMessages() override; |
108 | 115 |
| 116 // SyncServiceObserver implementation. |
| 117 void OnStateChanged() override; |
| 118 |
109 // Handler for the "queryHistory" message. | 119 // Handler for the "queryHistory" message. |
110 void HandleQueryHistory(const base::ListValue* args); | 120 void HandleQueryHistory(const base::ListValue* args); |
111 | 121 |
112 // Handler for the "removeVisits" message. | 122 // Handler for the "removeVisits" message. |
113 void HandleRemoveVisits(const base::ListValue* args); | 123 void HandleRemoveVisits(const base::ListValue* args); |
114 | 124 |
115 // Handler for "clearBrowsingData" message. | 125 // Handler for "clearBrowsingData" message. |
116 void HandleClearBrowsingData(const base::ListValue* args); | 126 void HandleClearBrowsingData(const base::ListValue* args); |
117 | 127 |
118 // Handler for "removeBookmark" message. | 128 // Handler for "removeBookmark" message. |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 // kAcceptLanguages pref value. | 192 // kAcceptLanguages pref value. |
183 std::string GetAcceptLanguages() const; | 193 std::string GetAcceptLanguages() const; |
184 | 194 |
185 // history::HistoryServiceObserver: | 195 // history::HistoryServiceObserver: |
186 void OnURLsDeleted(history::HistoryService* history_service, | 196 void OnURLsDeleted(history::HistoryService* history_service, |
187 bool all_history, | 197 bool all_history, |
188 bool expired, | 198 bool expired, |
189 const history::URLRows& deleted_rows, | 199 const history::URLRows& deleted_rows, |
190 const std::set<GURL>& favicon_urls) override; | 200 const std::set<GURL>& favicon_urls) override; |
191 | 201 |
| 202 // history::WebHistoryService::Observer: |
| 203 void OnWebHistoryDeleted() override; |
| 204 |
192 // Tracker for search requests to the history service. | 205 // Tracker for search requests to the history service. |
193 base::CancelableTaskTracker query_task_tracker_; | 206 base::CancelableTaskTracker query_task_tracker_; |
194 | 207 |
195 // The currently-executing request for synced history results. | 208 // The currently-executing request for synced history results. |
196 // Deleting the request will cancel it. | 209 // Deleting the request will cancel it. |
197 std::unique_ptr<history::WebHistoryService::Request> web_history_request_; | 210 std::unique_ptr<history::WebHistoryService::Request> web_history_request_; |
198 | 211 |
199 // True if there is a pending delete requests to the history service. | 212 // True if there is a pending delete requests to the history service. |
200 bool has_pending_delete_request_; | 213 bool has_pending_delete_request_; |
201 | 214 |
202 // Tracker for delete requests to the history service. | 215 // Tracker for delete requests to the history service. |
203 base::CancelableTaskTracker delete_task_tracker_; | 216 base::CancelableTaskTracker delete_task_tracker_; |
204 | 217 |
205 // The list of URLs that are in the process of being deleted. | 218 // The list of URLs that are in the process of being deleted. |
206 std::set<GURL> urls_to_be_deleted_; | 219 std::set<GURL> urls_to_be_deleted_; |
207 | 220 |
208 // The info value that is returned to the front end with the query results. | 221 // The info value that is returned to the front end with the query results. |
209 base::DictionaryValue results_info_value_; | 222 base::DictionaryValue results_info_value_; |
210 | 223 |
211 // The list of query results received from the history service. | 224 // The list of query results received from the history service. |
212 std::vector<HistoryEntry> query_results_; | 225 std::vector<HistoryEntry> query_results_; |
213 | 226 |
214 // The list of query results received from the history server. | 227 // The list of query results received from the history server. |
215 std::vector<HistoryEntry> web_history_query_results_; | 228 std::vector<HistoryEntry> web_history_query_results_; |
216 | 229 |
217 // Timer used to implement a timeout on a Web History response. | 230 // Timer used to implement a timeout on a Web History response. |
218 base::OneShotTimer web_history_timer_; | 231 base::OneShotTimer web_history_timer_; |
219 | 232 |
| 233 // HistoryService (local history) observer. |
220 ScopedObserver<history::HistoryService, history::HistoryServiceObserver> | 234 ScopedObserver<history::HistoryService, history::HistoryServiceObserver> |
221 history_service_observer_; | 235 history_service_observer_; |
222 | 236 |
| 237 // WebHistoryService (synced history) observer. |
| 238 ScopedObserver<history::WebHistoryService, |
| 239 history::WebHistoryService::Observer> |
| 240 web_history_service_observer_; |
| 241 |
| 242 // ProfileSyncService observer listens to late initialization of history sync. |
| 243 ScopedObserver<ProfileSyncService, sync_driver::SyncServiceObserver> |
| 244 sync_service_observer_; |
| 245 |
223 // Whether the last call to Web History returned synced results. | 246 // Whether the last call to Web History returned synced results. |
224 bool has_synced_results_; | 247 bool has_synced_results_; |
225 | 248 |
226 // Whether there are other forms of browsing history on the history server. | 249 // Whether there are other forms of browsing history on the history server. |
227 bool has_other_forms_of_browsing_history_; | 250 bool has_other_forms_of_browsing_history_; |
228 | 251 |
229 base::WeakPtrFactory<BrowsingHistoryHandler> weak_factory_; | 252 base::WeakPtrFactory<BrowsingHistoryHandler> weak_factory_; |
230 | 253 |
231 DISALLOW_COPY_AND_ASSIGN(BrowsingHistoryHandler); | 254 DISALLOW_COPY_AND_ASSIGN(BrowsingHistoryHandler); |
232 }; | 255 }; |
233 | 256 |
234 #endif // CHROME_BROWSER_UI_WEBUI_BROWSING_HISTORY_HANDLER_H_ | 257 #endif // CHROME_BROWSER_UI_WEBUI_BROWSING_HISTORY_HANDLER_H_ |
OLD | NEW |