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

Side by Side Diff: chrome/browser/history/web_history_service.h

Issue 687803004: [Hotword] Implement audio history pref accessing and setting. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more compile errors on other platforms Created 6 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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_HISTORY_WEB_HISTORY_SERVICE_H_ 5 #ifndef CHROME_BROWSER_HISTORY_WEB_HISTORY_SERVICE_H_
6 #define CHROME_BROWSER_HISTORY_WEB_HISTORY_SERVICE_H_ 6 #define CHROME_BROWSER_HISTORY_WEB_HISTORY_SERVICE_H_
7 7
8 #include <set> 8 #include <set>
9 9
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
(...skipping 20 matching lines...) Expand all
31 // the entire state of the request. When an instance is destroyed, all 31 // the entire state of the request. When an instance is destroyed, all
32 // aspects of the request are cancelled. 32 // aspects of the request are cancelled.
33 class Request { 33 class Request {
34 public: 34 public:
35 virtual ~Request(); 35 virtual ~Request();
36 36
37 // Returns true if the request is "pending" (i.e., it has been started, but 37 // Returns true if the request is "pending" (i.e., it has been started, but
38 // is not yet been complete). 38 // is not yet been complete).
39 virtual bool is_pending() = 0; 39 virtual bool is_pending() = 0;
40 40
41 // Returns the response code received from the server, which will only be
42 // valid if the request succeeded.
43 virtual int response_code() = 0;
sky 2014/11/19 01:02:41 We don't use unix_hacker_style for virtual methods
rpetterson 2014/11/19 02:04:56 I was following the pre-existing style (see is_pen
sky 2014/11/19 16:02:43 Yes, but if you want to fix up the other feel free
44
45 // Returns the contents of the response body received from the server.
46 virtual const std::string& response_body() = 0;
47
48 virtual void set_post_data(const std::string& post_data) = 0;
49
50 // Tells the request to begin.
51 virtual void Start() = 0;
52
41 protected: 53 protected:
42 Request(); 54 Request();
43 }; 55 };
44 56
45 // Callback with the result of a call to QueryHistory(). Currently, the 57 // Callback with the result of a call to QueryHistory(). Currently, the
46 // DictionaryValue is just the parsed JSON response from the server. 58 // DictionaryValue is just the parsed JSON response from the server.
47 // TODO(dubroy): Extract the DictionaryValue into a structured results object. 59 // TODO(dubroy): Extract the DictionaryValue into a structured results object.
48 typedef base::Callback<void(Request*, const base::DictionaryValue*)> 60 typedef base::Callback<void(Request*, const base::DictionaryValue*)>
49 QueryWebHistoryCallback; 61 QueryWebHistoryCallback;
50 62
51 typedef base::Callback<void(bool success)> ExpireWebHistoryCallback; 63 typedef base::Callback<void(bool success)> ExpireWebHistoryCallback;
52 64
65 typedef base::Callback<void(bool success, bool new_enabled_value)>
66 AudioWebHistoryCallback;
67
68 typedef base::Callback<void(Request*, bool success)> CompletionCallback;
69
53 explicit WebHistoryService(Profile* profile); 70 explicit WebHistoryService(Profile* profile);
54 ~WebHistoryService() override; 71 ~WebHistoryService() override;
55 72
73 // This function is pulled out for testing purposes. Caller takes ownership of
74 // the new Request.
75 virtual Request* CreateRequest(const GURL& url,
sky 2014/11/19 01:02:41 Can this and the next be protected?
rpetterson 2014/11/19 02:04:56 Done.
76 const CompletionCallback& callback);
77
78 // Extracts a JSON-encoded HTTP response into a DictionaryValue.
79 // If |request|'s HTTP response code indicates failure, or if the response
80 // body is not JSON, a null pointer is returned.
81 static scoped_ptr<base::DictionaryValue> ReadResponse(Request* request);
82
56 // Searches synced history for visits matching |text_query|. The timeframe to 83 // Searches synced history for visits matching |text_query|. The timeframe to
57 // search, along with other options, is specified in |options|. If 84 // search, along with other options, is specified in |options|. If
58 // |text_query| is empty, all visits in the timeframe will be returned. 85 // |text_query| is empty, all visits in the timeframe will be returned.
59 // This method is the equivalent of HistoryService::QueryHistory. 86 // This method is the equivalent of HistoryService::QueryHistory.
60 // The caller takes ownership of the returned Request. If it is destroyed, the 87 // The caller takes ownership of the returned Request. If it is destroyed, the
61 // request is cancelled. 88 // request is cancelled.
62 scoped_ptr<Request> QueryHistory( 89 scoped_ptr<Request> QueryHistory(
63 const base::string16& text_query, 90 const base::string16& text_query,
64 const QueryOptions& options, 91 const QueryOptions& options,
65 const QueryWebHistoryCallback& callback); 92 const QueryWebHistoryCallback& callback);
66 93
67 // Removes all visits to specified URLs in specific time ranges. 94 // Removes all visits to specified URLs in specific time ranges.
68 // This is the of equivalent HistoryService::ExpireHistory(). 95 // This is the of equivalent HistoryService::ExpireHistory().
69 void ExpireHistory(const std::vector<ExpireHistoryArgs>& expire_list, 96 void ExpireHistory(const std::vector<ExpireHistoryArgs>& expire_list,
70 const ExpireWebHistoryCallback& callback); 97 const ExpireWebHistoryCallback& callback);
71 98
72 // Removes all visits to specified URLs in the given time range. 99 // Removes all visits to specified URLs in the given time range.
73 // This is the of equivalent HistoryService::ExpireHistoryBetween(). 100 // This is the of equivalent HistoryService::ExpireHistoryBetween().
74 void ExpireHistoryBetween(const std::set<GURL>& restrict_urls, 101 void ExpireHistoryBetween(const std::set<GURL>& restrict_urls,
75 base::Time begin_time, 102 base::Time begin_time,
76 base::Time end_time, 103 base::Time end_time,
77 const ExpireWebHistoryCallback& callback); 104 const ExpireWebHistoryCallback& callback);
78 105
79 private: 106 // Requests whether audio history recording is enabled.
107 void GetAudioHistoryEnabled(const AudioWebHistoryCallback& callback);
108
109 // Sets the state of audio history recording to |new_enabled_value|.
110 void SetAudioHistoryEnabled(bool new_enabled_value,
111 const AudioWebHistoryCallback& callback);
112 protected:
113 friend class WebHistoryServiceTest;
114
80 // Called by |request| when a web history query has completed. Unpacks the 115 // Called by |request| when a web history query has completed. Unpacks the
81 // response and calls |callback|, which is the original callback that was 116 // response and calls |callback|, which is the original callback that was
82 // passed to QueryHistory(). 117 // passed to QueryHistory().
83 static void QueryHistoryCompletionCallback( 118 static void QueryHistoryCompletionCallback(
84 const WebHistoryService::QueryWebHistoryCallback& callback, 119 const WebHistoryService::QueryWebHistoryCallback& callback,
85 WebHistoryService::Request* request, 120 WebHistoryService::Request* request,
86 bool success); 121 bool success);
87 122
88 // Called by |request| when a request to delete history from the server has 123 // 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 124 // completed. Unpacks the response and calls |callback|, which is the original
90 // callback that was passed to ExpireHistory(). 125 // callback that was passed to ExpireHistory().
91 void ExpireHistoryCompletionCallback( 126 void ExpireHistoryCompletionCallback(
92 const WebHistoryService::ExpireWebHistoryCallback& callback, 127 const WebHistoryService::ExpireWebHistoryCallback& callback,
93 WebHistoryService::Request* request, 128 WebHistoryService::Request* request,
94 bool success); 129 bool success);
95 130
131 // Called by |request| when a request to get or set audio history from the
132 // server has completed. Unpacks the response and calls |callback|, which is
133 // the original callback that was passed to AudioHistory().
134 void AudioHistoryCompletionCallback(
135 const WebHistoryService::AudioWebHistoryCallback& callback,
136 WebHistoryService::Request* request,
137 bool success);
138
96 Profile* profile_; 139 Profile* profile_;
sky 2014/11/19 01:02:41 Style guide says no protected fields.
rpetterson 2014/11/19 02:04:56 Done.
97 140
98 // Stores the version_info token received from the server in response to 141 // 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 142 // 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. 143 // subsequent reads see a version of the data that includes the mutation.
101 std::string server_version_info_; 144 std::string server_version_info_;
102 145
103 // Pending expiration requests to be canceled if not complete by profile 146 // Pending expiration requests to be canceled if not complete by profile
104 // shutdown. 147 // shutdown.
105 std::set<Request*> pending_expire_requests_; 148 std::set<Request*> pending_expire_requests_;
106 149
150 // Pending requests to be canceled if not complete by profile shutdown.
151 std::set<Request*> pending_audio_history_requests_;
152
107 base::WeakPtrFactory<WebHistoryService> weak_ptr_factory_; 153 base::WeakPtrFactory<WebHistoryService> weak_ptr_factory_;
108 154
109 DISALLOW_COPY_AND_ASSIGN(WebHistoryService); 155 DISALLOW_COPY_AND_ASSIGN(WebHistoryService);
110 }; 156 };
111 157
112 } // namespace history 158 } // namespace history
113 159
114 #endif // CHROME_BROWSER_HISTORY_WEB_HISTORY_SERVICE_H_ 160 #endif // CHROME_BROWSER_HISTORY_WEB_HISTORY_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698