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

Unified Diff: chrome/browser/ui/history_ui_service.h

Issue 2450453002: Refactor BrowsingHistoryHandler, create BrowsingHistoryService (Closed)
Patch Set: Created 4 years, 2 months 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/history_ui_service.h
diff --git a/chrome/browser/ui/webui/browsing_history_handler.h b/chrome/browser/ui/history_ui_service.h
similarity index 69%
copy from chrome/browser/ui/webui/browsing_history_handler.h
copy to chrome/browser/ui/history_ui_service.h
index 2ad459a0d770fe49e45613b29868ee1d8fae8965..e9572e206c810d755284391decb81252f9cb299f 100644
--- a/chrome/browser/ui/webui/browsing_history_handler.h
+++ b/chrome/browser/ui/history_ui_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_UI_HISTORY_UI_SERVICE_H_
+#define CHROME_BROWSER_UI_HISTORY_UI_SERVICE_H_
#include <stdint.h>
@@ -24,15 +24,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
@@ -47,11 +40,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,
- public history::WebHistoryServiceObserver,
- public syncer::SyncServiceObserver {
+class Profile;
+
+// Interacts with HistoryService, WebHistoryService, and SyncService to query
+// history and provide results to the associated HistoryUiServiceHandler.
+class HistoryUiService : public history::HistoryServiceObserver,
+ public history::WebHistoryServiceObserver,
+ public syncer::SyncServiceObserver {
public:
// Represents a history entry to be shown to the user, representing either
// a local or remote visit. A single entry can represent multiple visits,
@@ -74,17 +69,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);
@@ -115,34 +99,72 @@ class BrowsingHistoryHandler : public content::WebUIMessageHandler,
bool blocked_visit;
};
- BrowsingHistoryHandler();
- ~BrowsingHistoryHandler() override;
+ // Contains information about a completed history query.
+ struct QueryResultsInfo {
Theresa 2016/10/24 15:40:29 This new struct is used to pass information about
+ 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;
+
+ // Whether the last call to Web History returned synced results.
+ bool has_synced_results;
+
+ // The localized query start time.
+ base::Time start_time;
+
+ // The localized query end time.
+ base::Time end_time;
+ };
+
+ // Interface for handling calls from the HistoryUiService.
+ class HistoryUiServiceHandler {
Theresa 2016/10/24 15:40:29 Places where BrowsingHistoryHandler called JS meth
+ public:
+ // Callback for QueryHistory().
+ virtual void OnQueryComplete(
+ std::vector<HistoryUiService::HistoryEntry>* results,
+ HistoryUiService::QueryResultsInfo* query_results_info) = 0;
+
+ // Callback for RemoveVisits().
+ virtual void OnRemoveVisitsComplete() = 0;
+
+ // Callback for RemoveVisits() that fails.
+ virtual void OnRemoveVisitsFailed() = 0;
+
+ // Called when HistoryService or WebHistoryService deletes one or more
+ // items.
+ virtual void HistoryDeleted() = 0;
+
+ // Whether other forms of browsing history were found on the history
+ // service.
+ virtual void HasOtherFormsOfBrowsingHistory(
+ bool has_other_forms, bool has_synced_results) = 0;
+ };
- // Handler for the "queryHistory" message.
- void HandleQueryHistory(const base::ListValue* args);
+ HistoryUiService(Profile* profile,
+ HistoryUiService::HistoryUiServiceHandler* handler);
+ ~HistoryUiService() override;
- // Handler for the "removeVisits" message.
- void HandleRemoveVisits(const base::ListValue* args);
+ // Core implementation of history querying.
+ void QueryHistory(const base::string16& search_text,
+ const history::QueryOptions& options);
- // Handler for "clearBrowsingData" message.
- void HandleClearBrowsingData(const base::ListValue* args);
+ // Removes |items| from history.
+ void RemoveVisits(
+ std::vector<std::unique_ptr<HistoryUiService::HistoryEntry>>* items);
- // Handler for "removeBookmark" message.
- void HandleRemoveBookmark(const base::ListValue* args);
+ // 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<HistoryUiService::HistoryEntry>* results);
- protected:
// Callback from the history system when a history query has completed.
// Exposed for testing.
void QueryComplete(const base::string16& search_text,
@@ -150,23 +172,9 @@ class BrowsingHistoryHandler : public content::WebUIMessageHandler,
history::QueryResults* results);
private:
- // 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 HistoryUiServiceHandler.
+ void ReturnResultsToHandler();
// Callback from |web_history_timer_| when a response from web history has
// not been received in time.
@@ -190,18 +198,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,
@@ -228,8 +224,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.
+ HistoryUiService::QueryResultsInfo query_results_info_;
// The list of query results received from the history service.
std::vector<HistoryEntry> query_results_;
@@ -258,9 +254,13 @@ class BrowsingHistoryHandler : public content::WebUIMessageHandler,
// Whether there are other forms of browsing history on the history server.
bool has_other_forms_of_browsing_history_;
- base::WeakPtrFactory<BrowsingHistoryHandler> weak_factory_;
+ Profile* profile_;
+
+ HistoryUiServiceHandler* handler_;
+
+ base::WeakPtrFactory<HistoryUiService> weak_factory_;
- DISALLOW_COPY_AND_ASSIGN(BrowsingHistoryHandler);
+ DISALLOW_COPY_AND_ASSIGN(HistoryUiService);
};
-#endif // CHROME_BROWSER_UI_WEBUI_BROWSING_HISTORY_HANDLER_H_
+#endif // CHROME_BROWSER_UI_HISTORY_UI_SERVICE_H_

Powered by Google App Engine
This is Rietveld 408576698