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