| Index: chrome/browser/history/browsing_history_service.h
|
| diff --git a/chrome/browser/ui/webui/browsing_history_handler.h b/chrome/browser/history/browsing_history_service.h
|
| similarity index 70%
|
| copy from chrome/browser/ui/webui/browsing_history_handler.h
|
| copy to chrome/browser/history/browsing_history_service.h
|
| index 38dc34f3900d173a7d37dcc8d607e53add6db6f8..165b59b761bfe2f19c3ad13d528a035f83203358 100644
|
| --- a/chrome/browser/ui/webui/browsing_history_handler.h
|
| +++ b/chrome/browser/history/browsing_history_service.h
|
| @@ -1,9 +1,9 @@
|
| -// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#ifndef CHROME_BROWSER_UI_WEBUI_BROWSING_HISTORY_HANDLER_H_
|
| -#define CHROME_BROWSER_UI_WEBUI_BROWSING_HISTORY_HANDLER_H_
|
| +#ifndef CHROME_BROWSER_HISTORY_BROWSING_HISTORY_SERVICE_H_
|
| +#define CHROME_BROWSER_HISTORY_BROWSING_HISTORY_SERVICE_H_
|
|
|
| #include <stdint.h>
|
|
|
| @@ -25,15 +25,8 @@
|
| #include "components/history/core/browser/web_history_service.h"
|
| #include "components/history/core/browser/web_history_service_observer.h"
|
| #include "components/sync/driver/sync_service_observer.h"
|
| -#include "content/public/browser/web_ui_message_handler.h"
|
| #include "url/gurl.h"
|
|
|
| -class SupervisedUserService;
|
| -
|
| -namespace bookmarks {
|
| -class BookmarkModel;
|
| -} // namespace bookmarks
|
| -
|
| namespace browser_sync {
|
| class ProfileSyncService;
|
| } // namespace browser_sync
|
| @@ -48,9 +41,13 @@ namespace syncer {
|
| class SyncServiceObserver;
|
| } // namespace syncer
|
|
|
| -// The handler for Javascript messages related to the "history" view.
|
| -class BrowsingHistoryHandler : public content::WebUIMessageHandler,
|
| - public history::HistoryServiceObserver,
|
| +class Profile;
|
| +
|
| +class BrowsingHistoryServiceHandler;
|
| +
|
| +// Interacts with HistoryService, WebHistoryService, and SyncService to query
|
| +// history and provide results to the associated BrowsingHistoryServiceHandler.
|
| +class BrowsingHistoryService : public history::HistoryServiceObserver,
|
| public history::WebHistoryServiceObserver,
|
| public syncer::SyncServiceObserver {
|
| public:
|
| @@ -80,17 +77,6 @@ class BrowsingHistoryHandler : public content::WebUIMessageHandler,
|
| HistoryEntry(const HistoryEntry& other);
|
| virtual ~HistoryEntry();
|
|
|
| - // Formats this entry's URL and title and adds them to |result|.
|
| - void SetUrlAndTitle(base::DictionaryValue* result,
|
| - bool limit_title_length) const;
|
| -
|
| - // Converts the entry to a DictionaryValue to be owned by the caller.
|
| - std::unique_ptr<base::DictionaryValue> ToValue(
|
| - bookmarks::BookmarkModel* bookmark_model,
|
| - SupervisedUserService* supervised_user_service,
|
| - const browser_sync::ProfileSyncService* sync_service,
|
| - bool limit_title_length) const;
|
| -
|
| // Comparison function for sorting HistoryEntries from newest to oldest.
|
| static bool SortByTimeDescending(
|
| const HistoryEntry& entry1, const HistoryEntry& entry2);
|
| @@ -123,68 +109,64 @@ class BrowsingHistoryHandler : public content::WebUIMessageHandler,
|
| base::Clock* clock; // Weak reference.
|
| };
|
|
|
| - BrowsingHistoryHandler();
|
| - ~BrowsingHistoryHandler() override;
|
| + // Contains information about a completed history query.
|
| + struct QueryResultsInfo {
|
| + QueryResultsInfo();
|
| + ~QueryResultsInfo();
|
|
|
| - // WebUIMessageHandler implementation.
|
| - void RegisterMessages() override;
|
| + // The query search text.
|
| + base::string16 search_text;
|
|
|
| - // SyncServiceObserver implementation.
|
| - void OnStateChanged() override;
|
| + // Whether the query reached the beginning of the database.
|
| + bool reached_beginning;
|
|
|
| - // Handler for the "queryHistory" message.
|
| - void HandleQueryHistory(const base::ListValue* args);
|
| + // Whether the last call to Web History returned synced results.
|
| + bool has_synced_results;
|
|
|
| - // Handler for the "removeVisits" message.
|
| - void HandleRemoveVisits(const base::ListValue* args);
|
| + // The localized query start time.
|
| + base::Time start_time;
|
|
|
| - // Handler for "clearBrowsingData" message.
|
| - void HandleClearBrowsingData(const base::ListValue* args);
|
| + // The localized query end time.
|
| + base::Time end_time;
|
| + };
|
|
|
| - // Handler for "removeBookmark" message.
|
| - void HandleRemoveBookmark(const base::ListValue* args);
|
| + BrowsingHistoryService(
|
| + Profile* profile,
|
| + BrowsingHistoryServiceHandler* handler);
|
| + ~BrowsingHistoryService() override;
|
| +
|
| + // Core implementation of history querying.
|
| + void QueryHistory(const base::string16& search_text,
|
| + const history::QueryOptions& options);
|
| +
|
| + // Removes |items| from history.
|
| + void RemoveVisits(
|
| + std::vector<std::unique_ptr<BrowsingHistoryService::HistoryEntry>>*
|
| + items);
|
| +
|
| + // SyncServiceObserver implementation.
|
| + void OnStateChanged() override;
|
|
|
| // Merges duplicate entries from the query results, only retaining the most
|
| // recent visit to a URL on a particular day. That visit contains the
|
| // timestamps of the other visits.
|
| static void MergeDuplicateResults(
|
| - std::vector<BrowsingHistoryHandler::HistoryEntry>* results);
|
| + std::vector<BrowsingHistoryService::HistoryEntry>* results);
|
|
|
| - protected:
|
| // Callback from the history system when a history query has completed.
|
| // Exposed for testing.
|
| void QueryComplete(const base::string16& search_text,
|
| const history::QueryOptions& options,
|
| history::QueryResults* results);
|
|
|
| - // For tests.
|
| - void set_clock(std::unique_ptr<base::Clock> clock) {
|
| - clock_ = std::move(clock);
|
| - }
|
| -
|
| private:
|
| FRIEND_TEST_ALL_PREFIXES(BrowsingHistoryHandlerTest,
|
| ObservingWebHistoryDeletions);
|
| - FRIEND_TEST_ALL_PREFIXES(BrowsingHistoryHandlerTest, SetQueryTimeInWeeks);
|
| - FRIEND_TEST_ALL_PREFIXES(BrowsingHistoryHandlerTest, SetQueryTimeInMonths);
|
| -
|
| - // The range for which to return results:
|
| - // - ALLTIME: allows access to all the results in a paginated way.
|
| - // - WEEK: the last 7 days.
|
| - // - MONTH: the last calendar month.
|
| - enum Range {
|
| - ALL_TIME = 0,
|
| - WEEK = 1,
|
| - MONTH = 2
|
| - };
|
| -
|
| - // Core implementation of history querying.
|
| - void QueryHistory(const base::string16& search_text,
|
| - const history::QueryOptions& options);
|
|
|
| // Combines the query results from the local history database and the history
|
| - // server, and sends the combined results to the front end.
|
| - void ReturnResultsToFrontEnd();
|
| + // server, and sends the combined results to the
|
| + // BrowsingHistoryServiceHandler.
|
| + void ReturnResultsToHandler();
|
|
|
| // Callback from |web_history_timer_| when a response from web history has
|
| // not been received in time.
|
| @@ -208,18 +190,6 @@ class BrowsingHistoryHandler : public content::WebUIMessageHandler,
|
| // Callback from history server when visits were deleted.
|
| void RemoveWebHistoryComplete(bool success);
|
|
|
| - bool ExtractIntegerValueAtIndex(
|
| - const base::ListValue* value, int index, int* out_int);
|
| -
|
| - // Sets the query options for a week-wide query, |offset| weeks ago.
|
| - void SetQueryTimeInWeeks(int offset, history::QueryOptions* options);
|
| -
|
| - // Sets the query options for a monthly query, |offset| months ago.
|
| - void SetQueryTimeInMonths(int offset, history::QueryOptions* options);
|
| -
|
| - // kAcceptLanguages pref value.
|
| - std::string GetAcceptLanguages() const;
|
| -
|
| // history::HistoryServiceObserver:
|
| void OnURLsDeleted(history::HistoryService* history_service,
|
| bool all_history,
|
| @@ -246,8 +216,8 @@ class BrowsingHistoryHandler : public content::WebUIMessageHandler,
|
| // The list of URLs that are in the process of being deleted.
|
| std::set<GURL> urls_to_be_deleted_;
|
|
|
| - // The info value that is returned to the front end with the query results.
|
| - base::DictionaryValue results_info_value_;
|
| + // The info value that is returned to the handler with the query results.
|
| + BrowsingHistoryService::QueryResultsInfo query_results_info_;
|
|
|
| // The list of query results received from the history service.
|
| std::vector<HistoryEntry> query_results_;
|
| @@ -276,12 +246,16 @@ class BrowsingHistoryHandler : public content::WebUIMessageHandler,
|
| // Whether there are other forms of browsing history on the history server.
|
| bool has_other_forms_of_browsing_history_;
|
|
|
| + Profile* profile_;
|
| +
|
| + BrowsingHistoryServiceHandler* handler_;
|
| +
|
| // The clock used to vend times.
|
| std::unique_ptr<base::Clock> clock_;
|
|
|
| - base::WeakPtrFactory<BrowsingHistoryHandler> weak_factory_;
|
| + base::WeakPtrFactory<BrowsingHistoryService> weak_factory_;
|
|
|
| - DISALLOW_COPY_AND_ASSIGN(BrowsingHistoryHandler);
|
| + DISALLOW_COPY_AND_ASSIGN(BrowsingHistoryService);
|
| };
|
|
|
| -#endif // CHROME_BROWSER_UI_WEBUI_BROWSING_HISTORY_HANDLER_H_
|
| +#endif // CHROME_BROWSER_HISTORY_BROWSING_HISTORY_SERVICE_H_
|
|
|