OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_HISTORY_UI_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_HISTORY_UI_H_ |
6 #define CHROME_BROWSER_UI_WEBUI_HISTORY_UI_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_HISTORY_UI_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| 11 #include "base/scoped_observer.h" |
11 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
12 #include "base/task/cancelable_task_tracker.h" | 13 #include "base/task/cancelable_task_tracker.h" |
13 #include "base/timer/timer.h" | 14 #include "base/timer/timer.h" |
14 #include "base/values.h" | 15 #include "base/values.h" |
15 #include "chrome/browser/history/history_service.h" | 16 #include "chrome/browser/history/history_service.h" |
16 #include "chrome/browser/history/web_history_service.h" | 17 #include "chrome/browser/history/web_history_service.h" |
17 #include "content/public/browser/notification_registrar.h" | 18 #include "components/history/core/browser/history_service_observer.h" |
18 #include "content/public/browser/web_ui_controller.h" | 19 #include "content/public/browser/web_ui_controller.h" |
19 #include "content/public/browser/web_ui_message_handler.h" | 20 #include "content/public/browser/web_ui_message_handler.h" |
20 | 21 |
21 class BookmarkModel; | 22 class BookmarkModel; |
22 class ProfileSyncService; | 23 class ProfileSyncService; |
23 class SupervisedUserService; | 24 class SupervisedUserService; |
24 | 25 |
25 // The handler for Javascript messages related to the "history" view. | 26 // The handler for Javascript messages related to the "history" view. |
26 class BrowsingHistoryHandler : public content::WebUIMessageHandler, | 27 class BrowsingHistoryHandler : public content::WebUIMessageHandler, |
27 public content::NotificationObserver { | 28 public history::HistoryServiceObserver { |
28 public: | 29 public: |
29 // Represents a history entry to be shown to the user, representing either | 30 // Represents a history entry to be shown to the user, representing either |
30 // a local or remote visit. A single entry can represent multiple visits, | 31 // a local or remote visit. A single entry can represent multiple visits, |
31 // since only the most recent visit on a particular day is shown. | 32 // since only the most recent visit on a particular day is shown. |
32 struct HistoryEntry { | 33 struct HistoryEntry { |
33 // Values indicating whether an entry represents only local visits, only | 34 // Values indicating whether an entry represents only local visits, only |
34 // remote visits, or a mixture of both. | 35 // remote visits, or a mixture of both. |
35 enum EntryType { | 36 enum EntryType { |
36 EMPTY_ENTRY = 0, | 37 EMPTY_ENTRY = 0, |
37 LOCAL_ENTRY, | 38 LOCAL_ENTRY, |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 | 100 |
100 // Handler for the "removeVisits" message. | 101 // Handler for the "removeVisits" message. |
101 void HandleRemoveVisits(const base::ListValue* args); | 102 void HandleRemoveVisits(const base::ListValue* args); |
102 | 103 |
103 // Handler for "clearBrowsingData" message. | 104 // Handler for "clearBrowsingData" message. |
104 void HandleClearBrowsingData(const base::ListValue* args); | 105 void HandleClearBrowsingData(const base::ListValue* args); |
105 | 106 |
106 // Handler for "removeBookmark" message. | 107 // Handler for "removeBookmark" message. |
107 void HandleRemoveBookmark(const base::ListValue* args); | 108 void HandleRemoveBookmark(const base::ListValue* args); |
108 | 109 |
109 // content::NotificationObserver implementation. | |
110 void Observe(int type, | |
111 const content::NotificationSource& source, | |
112 const content::NotificationDetails& details) override; | |
113 | |
114 // Merges duplicate entries from the query results, only retaining the most | 110 // Merges duplicate entries from the query results, only retaining the most |
115 // recent visit to a URL on a particular day. That visit contains the | 111 // recent visit to a URL on a particular day. That visit contains the |
116 // timestamps of the other visits. | 112 // timestamps of the other visits. |
117 static void MergeDuplicateResults( | 113 static void MergeDuplicateResults( |
118 std::vector<BrowsingHistoryHandler::HistoryEntry>* results); | 114 std::vector<BrowsingHistoryHandler::HistoryEntry>* results); |
119 | 115 |
120 private: | 116 private: |
121 // The range for which to return results: | 117 // The range for which to return results: |
122 // - ALLTIME: allows access to all the results in a paginated way. | 118 // - ALLTIME: allows access to all the results in a paginated way. |
123 // - WEEK: the last 7 days. | 119 // - WEEK: the last 7 days. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 | 159 |
164 // Sets the query options for a week-wide query, |offset| weeks ago. | 160 // Sets the query options for a week-wide query, |offset| weeks ago. |
165 void SetQueryTimeInWeeks(int offset, history::QueryOptions* options); | 161 void SetQueryTimeInWeeks(int offset, history::QueryOptions* options); |
166 | 162 |
167 // Sets the query options for a monthly query, |offset| months ago. | 163 // Sets the query options for a monthly query, |offset| months ago. |
168 void SetQueryTimeInMonths(int offset, history::QueryOptions* options); | 164 void SetQueryTimeInMonths(int offset, history::QueryOptions* options); |
169 | 165 |
170 // kAcceptLanguages pref value. | 166 // kAcceptLanguages pref value. |
171 std::string GetAcceptLanguages() const; | 167 std::string GetAcceptLanguages() const; |
172 | 168 |
173 content::NotificationRegistrar registrar_; | 169 // history::HistoryServiceObserver: |
| 170 void OnURLsDeleted( |
| 171 HistoryService* history_service, |
| 172 const history::URLsDeletedDetails& deleted_details) override; |
174 | 173 |
175 // Tracker for search requests to the history service. | 174 // Tracker for search requests to the history service. |
176 base::CancelableTaskTracker query_task_tracker_; | 175 base::CancelableTaskTracker query_task_tracker_; |
177 | 176 |
178 // The currently-executing request for synced history results. | 177 // The currently-executing request for synced history results. |
179 // Deleting the request will cancel it. | 178 // Deleting the request will cancel it. |
180 scoped_ptr<history::WebHistoryService::Request> web_history_request_; | 179 scoped_ptr<history::WebHistoryService::Request> web_history_request_; |
181 | 180 |
182 // True if there is a pending delete requests to the history service. | 181 // True if there is a pending delete requests to the history service. |
183 bool has_pending_delete_request_; | 182 bool has_pending_delete_request_; |
184 | 183 |
185 // Tracker for delete requests to the history service. | 184 // Tracker for delete requests to the history service. |
186 base::CancelableTaskTracker delete_task_tracker_; | 185 base::CancelableTaskTracker delete_task_tracker_; |
187 | 186 |
188 // The list of URLs that are in the process of being deleted. | 187 // The list of URLs that are in the process of being deleted. |
189 std::set<GURL> urls_to_be_deleted_; | 188 std::set<GURL> urls_to_be_deleted_; |
190 | 189 |
191 // The info value that is returned to the front end with the query results. | 190 // The info value that is returned to the front end with the query results. |
192 base::DictionaryValue results_info_value_; | 191 base::DictionaryValue results_info_value_; |
193 | 192 |
194 // The list of query results received from the history service. | 193 // The list of query results received from the history service. |
195 std::vector<HistoryEntry> query_results_; | 194 std::vector<HistoryEntry> query_results_; |
196 | 195 |
197 // The list of query results received from the history server. | 196 // The list of query results received from the history server. |
198 std::vector<HistoryEntry> web_history_query_results_; | 197 std::vector<HistoryEntry> web_history_query_results_; |
199 | 198 |
200 // Timer used to implement a timeout on a Web History response. | 199 // Timer used to implement a timeout on a Web History response. |
201 base::OneShotTimer<BrowsingHistoryHandler> web_history_timer_; | 200 base::OneShotTimer<BrowsingHistoryHandler> web_history_timer_; |
202 | 201 |
| 202 ScopedObserver<HistoryService, HistoryServiceObserver> |
| 203 history_service_observer_; |
| 204 |
203 base::WeakPtrFactory<BrowsingHistoryHandler> weak_factory_; | 205 base::WeakPtrFactory<BrowsingHistoryHandler> weak_factory_; |
204 | 206 |
205 DISALLOW_COPY_AND_ASSIGN(BrowsingHistoryHandler); | 207 DISALLOW_COPY_AND_ASSIGN(BrowsingHistoryHandler); |
206 }; | 208 }; |
207 | 209 |
208 class HistoryUI : public content::WebUIController { | 210 class HistoryUI : public content::WebUIController { |
209 public: | 211 public: |
210 explicit HistoryUI(content::WebUI* web_ui); | 212 explicit HistoryUI(content::WebUI* web_ui); |
211 | 213 |
212 static base::RefCountedMemory* GetFaviconResourceBytes( | 214 static base::RefCountedMemory* GetFaviconResourceBytes( |
213 ui::ScaleFactor scale_factor); | 215 ui::ScaleFactor scale_factor); |
214 | 216 |
215 private: | 217 private: |
216 DISALLOW_COPY_AND_ASSIGN(HistoryUI); | 218 DISALLOW_COPY_AND_ASSIGN(HistoryUI); |
217 }; | 219 }; |
218 | 220 |
219 #endif // CHROME_BROWSER_UI_WEBUI_HISTORY_UI_H_ | 221 #endif // CHROME_BROWSER_UI_WEBUI_HISTORY_UI_H_ |
OLD | NEW |