OLD | NEW |
(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_HISTORY_HISTORY_SERVICE_FACADE_H_ |
| 6 #define IOS_CHROME_BROWSER_UI_HISTORY_HISTORY_SERVICE_FACADE_H_ |
| 7 |
| 8 #include <memory> |
| 9 #include <string> |
| 10 |
| 11 #include "base/ios/weak_nsobject.h" |
| 12 #include "base/macros.h" |
| 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/scoped_observer.h" |
| 15 #include "base/strings/string16.h" |
| 16 #include "base/task/cancelable_task_tracker.h" |
| 17 #include "base/timer/timer.h" |
| 18 #include "base/values.h" |
| 19 #include "components/history/core/browser/history_service_observer.h" |
| 20 #include "components/history/core/browser/url_row.h" |
| 21 #include "components/history/core/browser/web_history_service.h" |
| 22 #include "url/gurl.h" |
| 23 |
| 24 namespace history { |
| 25 struct HistoryEntry; |
| 26 class HistoryService; |
| 27 struct QueryOptions; |
| 28 class QueryResults; |
| 29 } |
| 30 |
| 31 namespace ios { |
| 32 class ChromeBrowserState; |
| 33 } |
| 34 |
| 35 @protocol HistoryServiceFacadeDelegate; |
| 36 |
| 37 // Facade for HistoryService and WebHistoryService. Handles history querying and |
| 38 // deletion actions. |
| 39 class HistoryServiceFacade : public history::HistoryServiceObserver { |
| 40 public: |
| 41 // Represents the result of a query to history service. |
| 42 struct QueryResult { |
| 43 QueryResult(); |
| 44 QueryResult(const QueryResult&); |
| 45 ~QueryResult(); |
| 46 base::string16 query; |
| 47 base::string16 query_start_time; |
| 48 base::string16 query_end_time; |
| 49 bool finished; |
| 50 bool has_synced_results; |
| 51 bool sync_finished; |
| 52 std::vector<history::HistoryEntry> entries; |
| 53 }; |
| 54 |
| 55 // Represents a history entry removed by the client. |
| 56 struct RemovedEntry { |
| 57 RemovedEntry(const GURL& url, const base::Time& timestamp); |
| 58 RemovedEntry(const GURL& url, const std::vector<base::Time>& timestamps); |
| 59 RemovedEntry(const RemovedEntry&); |
| 60 ~RemovedEntry(); |
| 61 GURL url; |
| 62 std::vector<base::Time> timestamps; |
| 63 }; |
| 64 |
| 65 HistoryServiceFacade(ios::ChromeBrowserState* browser_state, |
| 66 id<HistoryServiceFacadeDelegate> delegate); |
| 67 ~HistoryServiceFacade() override; |
| 68 |
| 69 // Performs history query with query |search_text| and |options|; |
| 70 void QueryHistory(const base::string16& search_text, |
| 71 const history::QueryOptions& options); |
| 72 |
| 73 // Removes history entries in HistoryService and WebHistoryService. |
| 74 void RemoveHistoryEntries(const std::vector<RemovedEntry>& entries); |
| 75 |
| 76 // Queries WebHistoryService to determine whether notice about other forms |
| 77 // of browsing history should be shown. The response is returned via the |
| 78 // historyServiceFacade:shouldShowNoticeAboutOtherFormsOfBrowsingHistory: |
| 79 // delegate callback. |
| 80 void QueryOtherFormsOfBrowsingHistory(); |
| 81 |
| 82 private: |
| 83 // The range for which to return results: |
| 84 // - ALLTIME: allows access to all the results in a paginated way. |
| 85 // - WEEK: the last 7 days. |
| 86 // - MONTH: the last calendar month. |
| 87 enum Range { ALL_TIME = 0, WEEK = 1, MONTH = 2 }; |
| 88 |
| 89 // Callback from |web_history_timer_| when a response from web history has |
| 90 // not been received in time. |
| 91 void WebHistoryTimeout(); |
| 92 |
| 93 // Callback from the history system when a history query has completed. |
| 94 void QueryComplete(const base::string16& search_text, |
| 95 const history::QueryOptions& options, |
| 96 history::QueryResults* results); |
| 97 |
| 98 // Callback from the WebHistoryService when a query has completed. |
| 99 void WebHistoryQueryComplete(const base::string16& search_text, |
| 100 const history::QueryOptions& options, |
| 101 base::TimeTicks start_time, |
| 102 history::WebHistoryService::Request* request, |
| 103 const base::DictionaryValue* results_value); |
| 104 |
| 105 // Callback from the history system when visits were deleted. |
| 106 void RemoveComplete(); |
| 107 |
| 108 // Callback from history server when visits were deleted. |
| 109 void RemoveWebHistoryComplete(bool success); |
| 110 |
| 111 // Callback telling whether other forms of browsing history were found |
| 112 // on the history server. |
| 113 void OtherFormsOfBrowsingHistoryQueryComplete( |
| 114 bool found_other_forms_of_browsing_history); |
| 115 |
| 116 // Combines the query results from the local history database and the history |
| 117 // server, and sends the combined results to the front end. |
| 118 void ReturnResultsToFrontEnd(); |
| 119 |
| 120 // history::HistoryServiceObserver method. |
| 121 void OnURLsDeleted(history::HistoryService* history_service, |
| 122 bool all_history, |
| 123 bool expired, |
| 124 const history::URLRows& deleted_rows, |
| 125 const std::set<GURL>& favicon_urls) override; |
| 126 |
| 127 // Tracker for search requests to the history service. |
| 128 base::CancelableTaskTracker query_task_tracker_; |
| 129 |
| 130 // The currently-executing request for synced history results. |
| 131 // Deleting the request will cancel it. |
| 132 std::unique_ptr<history::WebHistoryService::Request> web_history_request_; |
| 133 |
| 134 // True if there is a pending delete requests to the history service. |
| 135 bool has_pending_delete_request_; |
| 136 |
| 137 // Tracker for delete requests to the history service. |
| 138 base::CancelableTaskTracker delete_task_tracker_; |
| 139 |
| 140 // The list of URLs that are in the process of being deleted. |
| 141 std::set<GURL> urls_to_be_deleted_; |
| 142 |
| 143 // Information that is returned to the front end with the query results. |
| 144 QueryResult results_info_value_; |
| 145 |
| 146 // The list of query results received from the history service. |
| 147 std::vector<history::HistoryEntry> query_results_; |
| 148 |
| 149 // The list of query results received from the history server. |
| 150 std::vector<history::HistoryEntry> web_history_query_results_; |
| 151 |
| 152 // Timer used to implement a timeout on a Web History response. |
| 153 base::OneShotTimer web_history_timer_; |
| 154 |
| 155 // Observer for HistoryService. |
| 156 ScopedObserver<history::HistoryService, history::HistoryServiceObserver> |
| 157 history_service_observer_; |
| 158 |
| 159 // The current browser state. |
| 160 ios::ChromeBrowserState* browser_state_; // weak |
| 161 |
| 162 // Delegate for HistoryServiceFacade. Serves as client for HistoryService. |
| 163 base::WeakNSProtocol<id<HistoryServiceFacadeDelegate>> delegate_; |
| 164 |
| 165 base::WeakPtrFactory<HistoryServiceFacade> weak_factory_; |
| 166 |
| 167 DISALLOW_COPY_AND_ASSIGN(HistoryServiceFacade); |
| 168 }; |
| 169 |
| 170 #endif // IOS_CHROME_BROWSER_UI_HISTORY_HISTORY_SERVICE_FACADE_H_ |
OLD | NEW |