1 // Copyright (c) 2012 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.
5 #ifndef CHROME_BROWSER_HISTORY_WEB_HISTORY_SERVICE_H_
6 #define CHROME_BROWSER_HISTORY_WEB_HISTORY_SERVICE_H_
10 #include "base/memory/weak_ptr.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "components/history/core/browser/history_types.h"
13 #include "components/keyed_service/core/keyed_service.h"
16 class DictionaryValue;
25 // Provides an API for querying Google servers for a signed-in user's
26 // synced history visits. It is roughly analogous to HistoryService, and
27 // supports a similar API.
28 class WebHistoryService : public KeyedService {
30 // Handles all the work of making an API request. This class encapsulates
31 // the entire state of the request. When an instance is destroyed, all
32 // aspects of the request are cancelled.
37 // Returns true if the request is "pending" (i.e., it has been started, but
38 // is not yet been complete).
39 virtual bool is_pending() = 0;
45 // Callback with the result of a call to QueryHistory(). Currently, the
46 // DictionaryValue is just the parsed JSON response from the server.
47 // TODO(dubroy): Extract the DictionaryValue into a structured results object.
48 typedef base::Callback<void(Request*, const base::DictionaryValue*)>
49 QueryWebHistoryCallback;
51 typedef base::Callback<void(bool success)> ExpireWebHistoryCallback;
53 explicit WebHistoryService(Profile* profile);
54 virtual ~WebHistoryService();
56 // Searches synced history for visits matching |text_query|. The timeframe to
57 // search, along with other options, is specified in |options|. If
58 // |text_query| is empty, all visits in the timeframe will be returned.
59 // This method is the equivalent of HistoryService::QueryHistory.
60 // The caller takes ownership of the returned Request. If it is destroyed, the
61 // request is cancelled.
62 scoped_ptr<Request> QueryHistory(
63 const base::string16& text_query,
64 const QueryOptions& options,
65 const QueryWebHistoryCallback& callback);
67 // Removes all visits to specified URLs in specific time ranges.
68 // This is the of equivalent HistoryService::ExpireHistory().
69 void ExpireHistory(const std::vector<ExpireHistoryArgs>& expire_list,
70 const ExpireWebHistoryCallback& callback);
72 // Removes all visits to specified URLs in the given time range.
73 // This is the of equivalent HistoryService::ExpireHistoryBetween().
74 void ExpireHistoryBetween(const std::set<GURL>& restrict_urls,
75 base::Time begin_time,
77 const ExpireWebHistoryCallback& callback);
80 // Called by |request| when a web history query has completed. Unpacks the
81 // response and calls |callback|, which is the original callback that was
82 // passed to QueryHistory().
83 static void QueryHistoryCompletionCallback(
84 const WebHistoryService::QueryWebHistoryCallback& callback,
85 WebHistoryService::Request* request,
88 // Called by |request| when a request to delete history from the server has
89 // completed. Unpacks the response and calls |callback|, which is the original
90 // callback that was passed to ExpireHistory().
91 void ExpireHistoryCompletionCallback(
92 const WebHistoryService::ExpireWebHistoryCallback& callback,
93 WebHistoryService::Request* request,
98 // Stores the version_info token received from the server in response to
99 // a mutation operation (e.g., deleting history). This is used to ensure that
100 // subsequent reads see a version of the data that includes the mutation.
101 std::string server_version_info_;
103 // Pending expiration requests to be canceled if not complete by profile
105 std::set<Request*> pending_expire_requests_;
107 base::WeakPtrFactory<WebHistoryService> weak_ptr_factory_;
109 DISALLOW_COPY_AND_ASSIGN(WebHistoryService);
112 } // namespace history
114 #endif // CHROME_BROWSER_HISTORY_WEB_HISTORY_SERVICE_H_