| 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/string16.h" | 10 #include "base/string16.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 class ManagedUserService; | 23 class ManagedUserService; |
| 24 | 24 |
| 25 // The handler for Javascript messages related to the "history" view. | 25 // The handler for Javascript messages related to the "history" view. |
| 26 class BrowsingHistoryHandler : public content::WebUIMessageHandler, | 26 class BrowsingHistoryHandler : public content::WebUIMessageHandler, |
| 27 public content::NotificationObserver { | 27 public content::NotificationObserver { |
| 28 public: | 28 public: |
| 29 // Represents a history entry to be shown to the user, representing either | 29 // 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, | 30 // 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. | 31 // since only the most recent visit on a particular day is shown. |
| 32 struct HistoryEntry { | 32 struct HistoryEntry { |
| 33 HistoryEntry(const GURL& url, const string16& title, base::Time time, | 33 // Values indicating whether an entry represents only local visits, only |
| 34 const std::set<int64>& timestamps, bool is_search_result, | 34 // remote visits, or a mixture of both. |
| 35 const string16& snippet); | 35 enum EntryType { |
| 36 LOCAL_ENTRY, |
| 37 REMOTE_ENTRY, |
| 38 COMBINED_ENTRY |
| 39 }; |
| 40 |
| 41 HistoryEntry(EntryType type, const GURL& url, const string16& title, |
| 42 base::Time time, const std::set<int64>& timestamps, |
| 43 bool is_search_result, const string16& snippet); |
| 36 HistoryEntry(); | 44 HistoryEntry(); |
| 37 virtual ~HistoryEntry(); | 45 virtual ~HistoryEntry(); |
| 38 | 46 |
| 39 // Formats this entry's URL and title and adds them to |result|. | 47 // Formats this entry's URL and title and adds them to |result|. |
| 40 void SetUrlAndTitle(DictionaryValue* result); | 48 void SetUrlAndTitle(DictionaryValue* result) const; |
| 41 | 49 |
| 42 // Converts the entry to a DictionaryValue to be owned by the caller. | 50 // Converts the entry to a DictionaryValue to be owned by the caller. |
| 43 scoped_ptr<DictionaryValue> ToValue( | 51 scoped_ptr<DictionaryValue> ToValue( |
| 44 BookmarkModel* bookmark_model, | 52 BookmarkModel* bookmark_model, |
| 45 ManagedUserService* managed_user_service); | 53 ManagedUserService* managed_user_service) const; |
| 46 | 54 |
| 47 // Comparison function for sorting HistoryEntries from newest to oldest. | 55 // Comparison function for sorting HistoryEntries from newest to oldest. |
| 48 static bool SortByTimeDescending( | 56 static bool SortByTimeDescending( |
| 49 const HistoryEntry& entry1, const HistoryEntry& entry2); | 57 const HistoryEntry& entry1, const HistoryEntry& entry2); |
| 50 | 58 |
| 59 // The type of visits this entry represents: local, remote, or both. |
| 60 EntryType entry_type; |
| 61 |
| 51 GURL url; | 62 GURL url; |
| 52 string16 title; // Title of the entry. May be empty. | 63 string16 title; // Title of the entry. May be empty. |
| 53 | 64 |
| 54 // The time of the entry. Usually this will be the time of the most recent | 65 // The time of the entry. Usually this will be the time of the most recent |
| 55 // visit to |url| on a particular day as defined in the local timezone. | 66 // visit to |url| on a particular day as defined in the local timezone. |
| 56 base::Time time; | 67 base::Time time; |
| 57 | 68 |
| 58 // Timestamps of all local or remote visits the same URL on the same day. | 69 // Timestamps of all local or remote visits the same URL on the same day. |
| 59 std::set<int64> all_timestamps; | 70 std::set<int64> all_timestamps; |
| 60 | 71 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 // - MONTH: the last calendar month. | 132 // - MONTH: the last calendar month. |
| 122 enum Range { | 133 enum Range { |
| 123 ALL_TIME = 0, | 134 ALL_TIME = 0, |
| 124 WEEK = 1, | 135 WEEK = 1, |
| 125 MONTH = 2 | 136 MONTH = 2 |
| 126 }; | 137 }; |
| 127 | 138 |
| 128 // Core implementation of history querying. | 139 // Core implementation of history querying. |
| 129 void QueryHistory(string16 search_text, const history::QueryOptions& options); | 140 void QueryHistory(string16 search_text, const history::QueryOptions& options); |
| 130 | 141 |
| 131 // Sends the accumulated results of the query to the front end, truncating | 142 // Combines the query results from the local history database and the history |
| 132 // the number to |max_count| if necessary. If |max_count| is 0, the results | 143 // server, and sends the combined results to the front end. |
| 133 // are not truncated. | 144 void ReturnResultsToFrontEnd(); |
| 134 // If |remove_duplicates| is true, duplicate visits on the same day are | |
| 135 // removed. | |
| 136 void ReturnResultsToFrontEnd(bool remove_duplicates, int max_count); | |
| 137 | 145 |
| 138 // Callback from |web_history_timer_| when a response from web history has | 146 // Callback from |web_history_timer_| when a response from web history has |
| 139 // not been received in time. | 147 // not been received in time. |
| 140 void WebHistoryTimeout(); | 148 void WebHistoryTimeout(); |
| 141 | 149 |
| 142 // Callback from the history system when a history query has completed. | 150 // Callback from the history system when a history query has completed. |
| 143 void QueryComplete(const string16& search_text, | 151 void QueryComplete(const string16& search_text, |
| 144 const history::QueryOptions& options, | 152 const history::QueryOptions& options, |
| 145 HistoryService::Handle request_handle, | 153 HistoryService::Handle request_handle, |
| 146 history::QueryResults* results); | 154 history::QueryResults* results); |
| 147 | 155 |
| 148 // Callback from the WebHistoryService when a query has completed. | 156 // Callback from the WebHistoryService when a query has completed. |
| 149 void WebHistoryQueryComplete(const string16& search_text, | 157 void WebHistoryQueryComplete(const string16& search_text, |
| 150 const history::QueryOptions& options, | 158 const history::QueryOptions& options, |
| 159 base::TimeTicks start_time, |
| 151 history::WebHistoryService::Request* request, | 160 history::WebHistoryService::Request* request, |
| 152 const base::DictionaryValue* results_value); | 161 const base::DictionaryValue* results_value); |
| 153 | 162 |
| 154 // Callback from the history system when visits were deleted. | 163 // Callback from the history system when visits were deleted. |
| 155 void RemoveComplete(); | 164 void RemoveComplete(); |
| 156 | 165 |
| 157 // Callback from history server when visits were deleted. | 166 // Callback from history server when visits were deleted. |
| 158 void RemoveWebHistoryComplete(history::WebHistoryService::Request* request, | 167 void RemoveWebHistoryComplete(history::WebHistoryService::Request* request, |
| 159 bool success); | 168 bool success); |
| 160 | 169 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 187 | 196 |
| 188 // Tracker for delete requests to the history service. | 197 // Tracker for delete requests to the history service. |
| 189 CancelableTaskTracker delete_task_tracker_; | 198 CancelableTaskTracker delete_task_tracker_; |
| 190 | 199 |
| 191 // The list of URLs that are in the process of being deleted. | 200 // The list of URLs that are in the process of being deleted. |
| 192 std::set<GURL> urls_to_be_deleted_; | 201 std::set<GURL> urls_to_be_deleted_; |
| 193 | 202 |
| 194 // The info value that is returned to the front end with the query results. | 203 // The info value that is returned to the front end with the query results. |
| 195 base::DictionaryValue results_info_value_; | 204 base::DictionaryValue results_info_value_; |
| 196 | 205 |
| 197 // The list of query results that is returned to the front end. | 206 // The list of query results received from the history service. |
| 198 std::vector<HistoryEntry> query_results_; | 207 std::vector<HistoryEntry> query_results_; |
| 199 | 208 |
| 209 // The list of query results received from the history server. |
| 210 std::vector<HistoryEntry> web_history_query_results_; |
| 211 |
| 200 // Timer used to implement a timeout on a Web History response. | 212 // Timer used to implement a timeout on a Web History response. |
| 201 base::OneShotTimer<BrowsingHistoryHandler> web_history_timer_; | 213 base::OneShotTimer<BrowsingHistoryHandler> web_history_timer_; |
| 202 | 214 |
| 203 DISALLOW_COPY_AND_ASSIGN(BrowsingHistoryHandler); | 215 DISALLOW_COPY_AND_ASSIGN(BrowsingHistoryHandler); |
| 204 }; | 216 }; |
| 205 | 217 |
| 206 class HistoryUI : public content::WebUIController { | 218 class HistoryUI : public content::WebUIController { |
| 207 public: | 219 public: |
| 208 explicit HistoryUI(content::WebUI* web_ui); | 220 explicit HistoryUI(content::WebUI* web_ui); |
| 209 | 221 |
| 210 // Return the URL for a given search term. | 222 // Return the URL for a given search term. |
| 211 static const GURL GetHistoryURLWithSearchText(const string16& text); | 223 static const GURL GetHistoryURLWithSearchText(const string16& text); |
| 212 | 224 |
| 213 static base::RefCountedMemory* GetFaviconResourceBytes( | 225 static base::RefCountedMemory* GetFaviconResourceBytes( |
| 214 ui::ScaleFactor scale_factor); | 226 ui::ScaleFactor scale_factor); |
| 215 | 227 |
| 216 private: | 228 private: |
| 217 DISALLOW_COPY_AND_ASSIGN(HistoryUI); | 229 DISALLOW_COPY_AND_ASSIGN(HistoryUI); |
| 218 }; | 230 }; |
| 219 | 231 |
| 220 #endif // CHROME_BROWSER_UI_WEBUI_HISTORY_UI_H_ | 232 #endif // CHROME_BROWSER_UI_WEBUI_HISTORY_UI_H_ |
| OLD | NEW |