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/history/core/browser/web_history_service_observer.h" |
| 24 #include "components/sync/driver/sync_service_observer.h" |
23 #include "content/public/browser/web_ui_message_handler.h" | 25 #include "content/public/browser/web_ui_message_handler.h" |
24 #include "url/gurl.h" | 26 #include "url/gurl.h" |
25 | 27 |
26 class ProfileSyncService; | 28 class ProfileSyncService; |
27 class SupervisedUserService; | 29 class SupervisedUserService; |
28 | 30 |
29 namespace bookmarks { | 31 namespace bookmarks { |
30 class BookmarkModel; | 32 class BookmarkModel; |
31 } | 33 } |
32 | 34 |
33 namespace history { | 35 namespace history { |
34 class HistoryService; | 36 class HistoryService; |
35 struct QueryOptions; | 37 struct QueryOptions; |
36 class QueryResults; | 38 class QueryResults; |
37 } | 39 } |
38 | 40 |
| 41 namespace sync_driver { |
| 42 class SyncServiceObserver; |
| 43 } |
| 44 |
39 // The handler for Javascript messages related to the "history" view. | 45 // The handler for Javascript messages related to the "history" view. |
40 class BrowsingHistoryHandler : public content::WebUIMessageHandler, | 46 class BrowsingHistoryHandler : public content::WebUIMessageHandler, |
41 public history::HistoryServiceObserver { | 47 public history::HistoryServiceObserver, |
| 48 public history::WebHistoryServiceObserver, |
| 49 public sync_driver::SyncServiceObserver { |
42 public: | 50 public: |
43 // Represents a history entry to be shown to the user, representing either | 51 // 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, | 52 // 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. | 53 // since only the most recent visit on a particular day is shown. |
46 struct HistoryEntry { | 54 struct HistoryEntry { |
47 // Values indicating whether an entry represents only local visits, only | 55 // Values indicating whether an entry represents only local visits, only |
48 // remote visits, or a mixture of both. | 56 // remote visits, or a mixture of both. |
49 enum EntryType { | 57 enum EntryType { |
50 EMPTY_ENTRY = 0, | 58 EMPTY_ENTRY = 0, |
51 LOCAL_ENTRY, | 59 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. | 107 // Whether this entry was blocked when it was attempted. |
100 bool blocked_visit; | 108 bool blocked_visit; |
101 }; | 109 }; |
102 | 110 |
103 BrowsingHistoryHandler(); | 111 BrowsingHistoryHandler(); |
104 ~BrowsingHistoryHandler() override; | 112 ~BrowsingHistoryHandler() override; |
105 | 113 |
106 // WebUIMessageHandler implementation. | 114 // WebUIMessageHandler implementation. |
107 void RegisterMessages() override; | 115 void RegisterMessages() override; |
108 | 116 |
| 117 // SyncServiceObserver implementation. |
| 118 void OnStateChanged() override; |
| 119 |
109 // Handler for the "queryHistory" message. | 120 // Handler for the "queryHistory" message. |
110 void HandleQueryHistory(const base::ListValue* args); | 121 void HandleQueryHistory(const base::ListValue* args); |
111 | 122 |
112 // Handler for the "removeVisits" message. | 123 // Handler for the "removeVisits" message. |
113 void HandleRemoveVisits(const base::ListValue* args); | 124 void HandleRemoveVisits(const base::ListValue* args); |
114 | 125 |
115 // Handler for "clearBrowsingData" message. | 126 // Handler for "clearBrowsingData" message. |
116 void HandleClearBrowsingData(const base::ListValue* args); | 127 void HandleClearBrowsingData(const base::ListValue* args); |
117 | 128 |
118 // Handler for "removeBookmark" message. | 129 // Handler for "removeBookmark" message. |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 // kAcceptLanguages pref value. | 193 // kAcceptLanguages pref value. |
183 std::string GetAcceptLanguages() const; | 194 std::string GetAcceptLanguages() const; |
184 | 195 |
185 // history::HistoryServiceObserver: | 196 // history::HistoryServiceObserver: |
186 void OnURLsDeleted(history::HistoryService* history_service, | 197 void OnURLsDeleted(history::HistoryService* history_service, |
187 bool all_history, | 198 bool all_history, |
188 bool expired, | 199 bool expired, |
189 const history::URLRows& deleted_rows, | 200 const history::URLRows& deleted_rows, |
190 const std::set<GURL>& favicon_urls) override; | 201 const std::set<GURL>& favicon_urls) override; |
191 | 202 |
| 203 // history::WebHistoryServiceObserver: |
| 204 void OnWebHistoryDeleted() override; |
| 205 |
192 // Tracker for search requests to the history service. | 206 // Tracker for search requests to the history service. |
193 base::CancelableTaskTracker query_task_tracker_; | 207 base::CancelableTaskTracker query_task_tracker_; |
194 | 208 |
195 // The currently-executing request for synced history results. | 209 // The currently-executing request for synced history results. |
196 // Deleting the request will cancel it. | 210 // Deleting the request will cancel it. |
197 std::unique_ptr<history::WebHistoryService::Request> web_history_request_; | 211 std::unique_ptr<history::WebHistoryService::Request> web_history_request_; |
198 | 212 |
199 // True if there is a pending delete requests to the history service. | 213 // True if there is a pending delete requests to the history service. |
200 bool has_pending_delete_request_; | 214 bool has_pending_delete_request_; |
201 | 215 |
202 // Tracker for delete requests to the history service. | 216 // Tracker for delete requests to the history service. |
203 base::CancelableTaskTracker delete_task_tracker_; | 217 base::CancelableTaskTracker delete_task_tracker_; |
204 | 218 |
205 // The list of URLs that are in the process of being deleted. | 219 // The list of URLs that are in the process of being deleted. |
206 std::set<GURL> urls_to_be_deleted_; | 220 std::set<GURL> urls_to_be_deleted_; |
207 | 221 |
208 // The info value that is returned to the front end with the query results. | 222 // The info value that is returned to the front end with the query results. |
209 base::DictionaryValue results_info_value_; | 223 base::DictionaryValue results_info_value_; |
210 | 224 |
211 // The list of query results received from the history service. | 225 // The list of query results received from the history service. |
212 std::vector<HistoryEntry> query_results_; | 226 std::vector<HistoryEntry> query_results_; |
213 | 227 |
214 // The list of query results received from the history server. | 228 // The list of query results received from the history server. |
215 std::vector<HistoryEntry> web_history_query_results_; | 229 std::vector<HistoryEntry> web_history_query_results_; |
216 | 230 |
217 // Timer used to implement a timeout on a Web History response. | 231 // Timer used to implement a timeout on a Web History response. |
218 base::OneShotTimer web_history_timer_; | 232 base::OneShotTimer web_history_timer_; |
219 | 233 |
| 234 // HistoryService (local history) observer. |
220 ScopedObserver<history::HistoryService, history::HistoryServiceObserver> | 235 ScopedObserver<history::HistoryService, history::HistoryServiceObserver> |
221 history_service_observer_; | 236 history_service_observer_; |
222 | 237 |
| 238 // WebHistoryService (synced history) observer. |
| 239 ScopedObserver<history::WebHistoryService, history::WebHistoryServiceObserver> |
| 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 |