Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(852)

Side by Side Diff: ios/chrome/browser/ui/webui/history/browsing_history_handler.h

Issue 2494853003: Remove some unused history resources on iOS (Closed)
Patch Set: add back URL constants Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef IOS_CHROME_BROWSER_UI_WEBUI_HISTORY_BROWSING_HISTORY_HANDLER_H_
6 #define IOS_CHROME_BROWSER_UI_WEBUI_HISTORY_BROWSING_HISTORY_HANDLER_H_
7
8 #include <stdint.h>
9
10 #include <memory>
11 #include <string>
12
13 #include "base/macros.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/scoped_observer.h"
16 #include "base/strings/string16.h"
17 #include "base/task/cancelable_task_tracker.h"
18 #include "base/timer/timer.h"
19 #include "base/values.h"
20 #include "components/history/core/browser/history_service_observer.h"
21 #include "components/history/core/browser/url_row.h"
22 #include "components/history/core/browser/web_history_service.h"
23 #include "ios/web/public/webui/web_ui_ios_message_handler.h"
24 #include "url/gurl.h"
25
26 class SupervisedUserService;
27
28 namespace bookmarks {
29 class BookmarkModel;
30 } // namespace bookmarks
31
32 namespace browser_sync {
33 class ProfileSyncService;
34 } // namespace browser_sync
35
36 namespace history {
37 class HistoryService;
38 struct QueryOptions;
39 class QueryResults;
40 } // namespace history
41
42 // The handler for Javascript messages related to the "history" view.
43 class BrowsingHistoryHandler : public web::WebUIIOSMessageHandler,
44 public history::HistoryServiceObserver {
45 public:
46 // Represents a history entry to be shown to the user, representing either
47 // a local or remote visit. A single entry can represent multiple visits,
48 // since only the most recent visit on a particular day is shown.
49 struct HistoryEntry {
50 // Values indicating whether an entry represents only local visits, only
51 // remote visits, or a mixture of both.
52 enum EntryType {
53 EMPTY_ENTRY = 0,
54 LOCAL_ENTRY,
55 REMOTE_ENTRY,
56 COMBINED_ENTRY
57 };
58
59 HistoryEntry(EntryType type,
60 const GURL& url,
61 const base::string16& title,
62 base::Time time,
63 const std::string& client_id,
64 bool is_search_result,
65 const base::string16& snippet,
66 bool blocked_visit);
67 HistoryEntry(const HistoryEntry& other);
68 HistoryEntry();
69 virtual ~HistoryEntry();
70
71 // Formats this entry's URL and title and adds them to |result|.
72 void SetUrlAndTitle(base::DictionaryValue* result) const;
73
74 // Converts the entry to a DictionaryValue to be owned by the caller.
75 std::unique_ptr<base::DictionaryValue> ToValue(
76 bookmarks::BookmarkModel* bookmark_model,
77 SupervisedUserService* supervised_user_service,
78 const browser_sync::ProfileSyncService* sync_service) const;
79
80 // Comparison function for sorting HistoryEntries from newest to oldest.
81 static bool SortByTimeDescending(const HistoryEntry& entry1,
82 const HistoryEntry& entry2);
83
84 // The type of visits this entry represents: local, remote, or both.
85 EntryType entry_type;
86
87 GURL url;
88 base::string16 title; // Title of the entry. May be empty.
89
90 // The time of the entry. Usually this will be the time of the most recent
91 // visit to |url| on a particular day as defined in the local timezone.
92 base::Time time;
93
94 // The sync ID of the client on which the most recent visit occurred.
95 std::string client_id;
96
97 // Timestamps of all local or remote visits the same URL on the same day.
98 std::set<int64_t> all_timestamps;
99
100 // If true, this entry is a search result.
101 bool is_search_result;
102
103 // The entry's search snippet, if this entry is a search result.
104 base::string16 snippet;
105
106 // Whether this entry was blocked when it was attempted.
107 bool blocked_visit;
108 };
109
110 BrowsingHistoryHandler();
111 ~BrowsingHistoryHandler() override;
112
113 // WebUIMessageHandler implementation.
114 void RegisterMessages() override;
115
116 // Handler for the "queryHistory" message.
117 void HandleQueryHistory(const base::ListValue* args);
118
119 // Handler for the "removeVisits" message.
120 void HandleRemoveVisits(const base::ListValue* args);
121
122 // Handler for "clearBrowsingData" message.
123 void HandleClearBrowsingData(const base::ListValue* args);
124
125 // Handler for "removeBookmark" message.
126 void HandleRemoveBookmark(const base::ListValue* args);
127
128 // Merges duplicate entries from the query results, only retaining the most
129 // recent visit to a URL on a particular day. That visit contains the
130 // timestamps of the other visits.
131 static void MergeDuplicateResults(
132 std::vector<BrowsingHistoryHandler::HistoryEntry>* results);
133
134 private:
135 // The range for which to return results:
136 // - ALLTIME: allows access to all the results in a paginated way.
137 // - WEEK: the last 7 days.
138 // - MONTH: the last calendar month.
139 enum Range { ALL_TIME = 0, WEEK = 1, MONTH = 2 };
140
141 // Core implementation of history querying.
142 void QueryHistory(const base::string16& search_text,
143 const history::QueryOptions& options);
144
145 // Combines the query results from the local history database and the history
146 // server, and sends the combined results to the front end.
147 void ReturnResultsToFrontEnd();
148
149 // Callback from |web_history_timer_| when a response from web history has
150 // not been received in time.
151 void WebHistoryTimeout();
152
153 // Callback from the history system when a history query has completed.
154 void QueryComplete(const base::string16& search_text,
155 const history::QueryOptions& options,
156 history::QueryResults* results);
157
158 // Callback from the WebHistoryService when a query has completed.
159 void WebHistoryQueryComplete(const base::string16& search_text,
160 const history::QueryOptions& options,
161 base::TimeTicks start_time,
162 history::WebHistoryService::Request* request,
163 const base::DictionaryValue* results_value);
164
165 // Callback telling us whether other forms of browsing history were found
166 // on the history server.
167 void OtherFormsOfBrowsingHistoryQueryComplete(
168 bool found_other_forms_of_browsing_history);
169
170 // Callback from the history system when visits were deleted.
171 void RemoveComplete();
172
173 // Callback from history server when visits were deleted.
174 void RemoveWebHistoryComplete(bool success);
175
176 bool ExtractIntegerValueAtIndex(const base::ListValue* value,
177 int index,
178 int* out_int);
179
180 // Sets the query options for a week-wide query, |offset| weeks ago.
181 void SetQueryTimeInWeeks(int offset, history::QueryOptions* options);
182
183 // Sets the query options for a monthly query, |offset| months ago.
184 void SetQueryTimeInMonths(int offset, history::QueryOptions* options);
185
186 // history::HistoryServiceObserver:
187 void OnURLsDeleted(history::HistoryService* history_service,
188 bool all_history,
189 bool expired,
190 const history::URLRows& deleted_rows,
191 const std::set<GURL>& favicon_urls) override;
192
193 // Tracker for search requests to the history service.
194 base::CancelableTaskTracker query_task_tracker_;
195
196 // The currently-executing request for synced history results.
197 // Deleting the request will cancel it.
198 std::unique_ptr<history::WebHistoryService::Request> web_history_request_;
199
200 // True if there is a pending delete requests to the history service.
201 bool has_pending_delete_request_;
202
203 // Tracker for delete requests to the history service.
204 base::CancelableTaskTracker delete_task_tracker_;
205
206 // The list of URLs that are in the process of being deleted.
207 std::set<GURL> urls_to_be_deleted_;
208
209 // The info value that is returned to the front end with the query results.
210 base::DictionaryValue results_info_value_;
211
212 // The list of query results received from the history service.
213 std::vector<HistoryEntry> query_results_;
214
215 // The list of query results received from the history server.
216 std::vector<HistoryEntry> web_history_query_results_;
217
218 // Timer used to implement a timeout on a Web History response.
219 base::OneShotTimer web_history_timer_;
220
221 ScopedObserver<history::HistoryService, history::HistoryServiceObserver>
222 history_service_observer_;
223
224 // Whether the last call to Web History returned synced results.
225 bool has_synced_results_;
226
227 // Whether there are other forms of browsing history on the history server.
228 bool has_other_forms_of_browsing_history_;
229
230 base::WeakPtrFactory<BrowsingHistoryHandler> weak_factory_;
231
232 DISALLOW_COPY_AND_ASSIGN(BrowsingHistoryHandler);
233 };
234
235 #endif // IOS_CHROME_BROWSER_UI_WEBUI_HISTORY_BROWSING_HISTORY_HANDLER_H_
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/webui/history/OWNERS ('k') | ios/chrome/browser/ui/webui/history/browsing_history_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698