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

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

Issue 2464323004: Fix grouped history query range for months. (Closed)
Patch Set: give a valid time to all tests 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
« no previous file with comments | « no previous file | chrome/browser/ui/webui/browsing_history_handler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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; // Weak reference.
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 16 matching lines...) Expand all
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
160 // For tests.
161 void set_clock(std::unique_ptr<base::Clock> clock) {
162 clock_ = std::move(clock);
163 }
164
152 private: 165 private:
153 FRIEND_TEST_ALL_PREFIXES(BrowsingHistoryHandlerTest, 166 FRIEND_TEST_ALL_PREFIXES(BrowsingHistoryHandlerTest,
154 ObservingWebHistoryDeletions); 167 ObservingWebHistoryDeletions);
168 FRIEND_TEST_ALL_PREFIXES(BrowsingHistoryHandlerTest, SetQueryTimeInWeeks);
169 FRIEND_TEST_ALL_PREFIXES(BrowsingHistoryHandlerTest, SetQueryTimeInMonths);
155 170
156 // The range for which to return results: 171 // The range for which to return results:
157 // - ALLTIME: allows access to all the results in a paginated way. 172 // - ALLTIME: allows access to all the results in a paginated way.
158 // - WEEK: the last 7 days. 173 // - WEEK: the last 7 days.
159 // - MONTH: the last calendar month. 174 // - MONTH: the last calendar month.
160 enum Range { 175 enum Range {
161 ALL_TIME = 0, 176 ALL_TIME = 0,
162 WEEK = 1, 177 WEEK = 1,
163 MONTH = 2 178 MONTH = 2
164 }; 179 };
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 // ProfileSyncService observer listens to late initialization of history sync. 269 // ProfileSyncService observer listens to late initialization of history sync.
255 ScopedObserver<browser_sync::ProfileSyncService, syncer::SyncServiceObserver> 270 ScopedObserver<browser_sync::ProfileSyncService, syncer::SyncServiceObserver>
256 sync_service_observer_; 271 sync_service_observer_;
257 272
258 // Whether the last call to Web History returned synced results. 273 // Whether the last call to Web History returned synced results.
259 bool has_synced_results_; 274 bool has_synced_results_;
260 275
261 // Whether there are other forms of browsing history on the history server. 276 // Whether there are other forms of browsing history on the history server.
262 bool has_other_forms_of_browsing_history_; 277 bool has_other_forms_of_browsing_history_;
263 278
279 // The clock used to vend times.
280 std::unique_ptr<base::Clock> clock_;
281
264 base::WeakPtrFactory<BrowsingHistoryHandler> weak_factory_; 282 base::WeakPtrFactory<BrowsingHistoryHandler> weak_factory_;
265 283
266 DISALLOW_COPY_AND_ASSIGN(BrowsingHistoryHandler); 284 DISALLOW_COPY_AND_ASSIGN(BrowsingHistoryHandler);
267 }; 285 };
268 286
269 #endif // CHROME_BROWSER_UI_WEBUI_BROWSING_HISTORY_HANDLER_H_ 287 #endif // CHROME_BROWSER_UI_WEBUI_BROWSING_HISTORY_HANDLER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/webui/browsing_history_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698