Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_BROWSING_HISTORY_HANDLER_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_BROWSING_HISTORY_HANDLER_H_ |
| 6 #define CHROME_BROWSER_UI_WEBUI_BROWSING_HISTORY_HANDLER_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_BROWSING_HISTORY_HANDLER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <set> | 11 #include <set> |
| 12 #include <string> | 12 #include <string> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 17 #include "base/scoped_observer.h" | 17 #include "base/scoped_observer.h" |
| 18 #include "base/strings/string16.h" | 18 #include "base/strings/string16.h" |
| 19 #include "base/task/cancelable_task_tracker.h" | 19 #include "base/task/cancelable_task_tracker.h" |
| 20 #include "base/time/clock.h" | |
| 20 #include "base/timer/timer.h" | 21 #include "base/timer/timer.h" |
| 21 #include "base/values.h" | 22 #include "base/values.h" |
| 22 #include "components/history/core/browser/history_service_observer.h" | 23 #include "components/history/core/browser/history_service_observer.h" |
| 23 #include "components/history/core/browser/url_row.h" | 24 #include "components/history/core/browser/url_row.h" |
| 24 #include "components/history/core/browser/web_history_service.h" | 25 #include "components/history/core/browser/web_history_service.h" |
| 25 #include "components/history/core/browser/web_history_service_observer.h" | 26 #include "components/history/core/browser/web_history_service_observer.h" |
| 26 #include "components/sync/driver/sync_service_observer.h" | 27 #include "components/sync/driver/sync_service_observer.h" |
| 27 #include "content/public/browser/web_ui_message_handler.h" | 28 #include "content/public/browser/web_ui_message_handler.h" |
| 28 #include "url/gurl.h" | 29 #include "url/gurl.h" |
| 29 | 30 |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 59 struct HistoryEntry { | 60 struct HistoryEntry { |
| 60 // Values indicating whether an entry represents only local visits, only | 61 // Values indicating whether an entry represents only local visits, only |
| 61 // remote visits, or a mixture of both. | 62 // remote visits, or a mixture of both. |
| 62 enum EntryType { | 63 enum EntryType { |
| 63 EMPTY_ENTRY = 0, | 64 EMPTY_ENTRY = 0, |
| 64 LOCAL_ENTRY, | 65 LOCAL_ENTRY, |
| 65 REMOTE_ENTRY, | 66 REMOTE_ENTRY, |
| 66 COMBINED_ENTRY | 67 COMBINED_ENTRY |
| 67 }; | 68 }; |
| 68 | 69 |
| 69 HistoryEntry(EntryType type, const GURL& url, const base::string16& title, | 70 HistoryEntry(EntryType type, |
| 70 base::Time time, const std::string& client_id, | 71 const GURL& url, |
| 71 bool is_search_result, const base::string16& snippet, | 72 const base::string16& title, |
| 72 bool blocked_visit); | 73 base::Time time, |
| 74 const std::string& client_id, | |
| 75 bool is_search_result, | |
| 76 const base::string16& snippet, | |
| 77 bool blocked_visit, | |
| 78 base::Clock* clock); | |
| 73 HistoryEntry(); | 79 HistoryEntry(); |
| 74 HistoryEntry(const HistoryEntry& other); | 80 HistoryEntry(const HistoryEntry& other); |
| 75 virtual ~HistoryEntry(); | 81 virtual ~HistoryEntry(); |
| 76 | 82 |
| 77 // Formats this entry's URL and title and adds them to |result|. | 83 // Formats this entry's URL and title and adds them to |result|. |
| 78 void SetUrlAndTitle(base::DictionaryValue* result, | 84 void SetUrlAndTitle(base::DictionaryValue* result, |
| 79 bool limit_title_length) const; | 85 bool limit_title_length) const; |
| 80 | 86 |
| 81 // Converts the entry to a DictionaryValue to be owned by the caller. | 87 // Converts the entry to a DictionaryValue to be owned by the caller. |
| 82 std::unique_ptr<base::DictionaryValue> ToValue( | 88 std::unique_ptr<base::DictionaryValue> ToValue( |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 106 std::set<int64_t> all_timestamps; | 112 std::set<int64_t> all_timestamps; |
| 107 | 113 |
| 108 // If true, this entry is a search result. | 114 // If true, this entry is a search result. |
| 109 bool is_search_result; | 115 bool is_search_result; |
| 110 | 116 |
| 111 // The entry's search snippet, if this entry is a search result. | 117 // The entry's search snippet, if this entry is a search result. |
| 112 base::string16 snippet; | 118 base::string16 snippet; |
| 113 | 119 |
| 114 // Whether this entry was blocked when it was attempted. | 120 // Whether this entry was blocked when it was attempted. |
| 115 bool blocked_visit; | 121 bool blocked_visit; |
| 122 | |
| 123 base::Clock* clock; | |
|
Dan Beam
2016/11/10 03:31:34
can you note that this is a weak ref?
calamity
2016/11/10 07:16:27
Done.
| |
| 116 }; | 124 }; |
| 117 | 125 |
| 118 BrowsingHistoryHandler(); | 126 BrowsingHistoryHandler(); |
| 119 ~BrowsingHistoryHandler() override; | 127 ~BrowsingHistoryHandler() override; |
| 120 | 128 |
| 121 // WebUIMessageHandler implementation. | 129 // WebUIMessageHandler implementation. |
| 122 void RegisterMessages() override; | 130 void RegisterMessages() override; |
| 123 | 131 |
| 124 // SyncServiceObserver implementation. | 132 // SyncServiceObserver implementation. |
| 125 void OnStateChanged() override; | 133 void OnStateChanged() override; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 141 // timestamps of the other visits. | 149 // timestamps of the other visits. |
| 142 static void MergeDuplicateResults( | 150 static void MergeDuplicateResults( |
| 143 std::vector<BrowsingHistoryHandler::HistoryEntry>* results); | 151 std::vector<BrowsingHistoryHandler::HistoryEntry>* results); |
| 144 | 152 |
| 145 protected: | 153 protected: |
| 146 // Callback from the history system when a history query has completed. | 154 // Callback from the history system when a history query has completed. |
| 147 // Exposed for testing. | 155 // Exposed for testing. |
| 148 void QueryComplete(const base::string16& search_text, | 156 void QueryComplete(const base::string16& search_text, |
| 149 const history::QueryOptions& options, | 157 const history::QueryOptions& options, |
| 150 history::QueryResults* results); | 158 history::QueryResults* results); |
| 151 | 159 |
|
Dan Beam
2016/11/10 03:31:34
can you mention that this is basically just for te
calamity
2016/11/10 07:16:27
Done.
| |
| 160 void set_clock(std::unique_ptr<base::Clock> clock) { | |
| 161 clock_ = std::move(clock); | |
| 162 } | |
| 163 | |
| 152 private: | 164 private: |
| 165 FRIEND_TEST_ALL_PREFIXES(BrowsingHistoryHandlerTest, SetQueryTimeInWeeks); | |
| 166 FRIEND_TEST_ALL_PREFIXES(BrowsingHistoryHandlerTest, SetQueryTimeInMonths); | |
| 167 | |
| 153 // The range for which to return results: | 168 // The range for which to return results: |
| 154 // - ALLTIME: allows access to all the results in a paginated way. | 169 // - ALLTIME: allows access to all the results in a paginated way. |
| 155 // - WEEK: the last 7 days. | 170 // - WEEK: the last 7 days. |
| 156 // - MONTH: the last calendar month. | 171 // - MONTH: the last calendar month. |
| 157 enum Range { | 172 enum Range { |
| 158 ALL_TIME = 0, | 173 ALL_TIME = 0, |
| 159 WEEK = 1, | 174 WEEK = 1, |
| 160 MONTH = 2 | 175 MONTH = 2 |
| 161 }; | 176 }; |
| 162 | 177 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 251 // ProfileSyncService observer listens to late initialization of history sync. | 266 // ProfileSyncService observer listens to late initialization of history sync. |
| 252 ScopedObserver<browser_sync::ProfileSyncService, syncer::SyncServiceObserver> | 267 ScopedObserver<browser_sync::ProfileSyncService, syncer::SyncServiceObserver> |
| 253 sync_service_observer_; | 268 sync_service_observer_; |
| 254 | 269 |
| 255 // Whether the last call to Web History returned synced results. | 270 // Whether the last call to Web History returned synced results. |
| 256 bool has_synced_results_; | 271 bool has_synced_results_; |
| 257 | 272 |
| 258 // Whether there are other forms of browsing history on the history server. | 273 // Whether there are other forms of browsing history on the history server. |
| 259 bool has_other_forms_of_browsing_history_; | 274 bool has_other_forms_of_browsing_history_; |
| 260 | 275 |
| 276 // The clock used to vend times. | |
| 277 std::unique_ptr<base::Clock> clock_; | |
| 278 | |
| 261 base::WeakPtrFactory<BrowsingHistoryHandler> weak_factory_; | 279 base::WeakPtrFactory<BrowsingHistoryHandler> weak_factory_; |
| 262 | 280 |
| 263 DISALLOW_COPY_AND_ASSIGN(BrowsingHistoryHandler); | 281 DISALLOW_COPY_AND_ASSIGN(BrowsingHistoryHandler); |
| 264 }; | 282 }; |
| 265 | 283 |
| 266 #endif // CHROME_BROWSER_UI_WEBUI_BROWSING_HISTORY_HANDLER_H_ | 284 #endif // CHROME_BROWSER_UI_WEBUI_BROWSING_HISTORY_HANDLER_H_ |
| OLD | NEW |