| OLD | NEW |
| 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 18 matching lines...) Expand all Loading... |
| 29 public: | 29 public: |
| 30 // Handles all the work of making an API request. This class encapsulates | 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 | 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 IsPending() = 0; |
| 40 |
| 41 // Returns the response code received from the server, which will only be |
| 42 // valid if the request succeeded. |
| 43 virtual int GetResponseCode() = 0; |
| 44 |
| 45 // Returns the contents of the response body received from the server. |
| 46 virtual const std::string& GetResponseBody() = 0; |
| 47 |
| 48 virtual void SetPostData(const std::string& post_data) = 0; |
| 49 |
| 50 // Tells the request to begin. |
| 51 virtual void Start() = 0; |
| 40 | 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 |
| 56 // Searches synced history for visits matching |text_query|. The timeframe to | 73 // Searches synced history for visits matching |text_query|. The timeframe to |
| 57 // search, along with other options, is specified in |options|. If | 74 // search, along with other options, is specified in |options|. If |
| 58 // |text_query| is empty, all visits in the timeframe will be returned. | 75 // |text_query| is empty, all visits in the timeframe will be returned. |
| 59 // This method is the equivalent of HistoryService::QueryHistory. | 76 // This method is the equivalent of HistoryService::QueryHistory. |
| 60 // The caller takes ownership of the returned Request. If it is destroyed, the | 77 // The caller takes ownership of the returned Request. If it is destroyed, the |
| 61 // request is cancelled. | 78 // request is cancelled. |
| 62 scoped_ptr<Request> QueryHistory( | 79 scoped_ptr<Request> QueryHistory( |
| 63 const base::string16& text_query, | 80 const base::string16& text_query, |
| 64 const QueryOptions& options, | 81 const QueryOptions& options, |
| 65 const QueryWebHistoryCallback& callback); | 82 const QueryWebHistoryCallback& callback); |
| 66 | 83 |
| 67 // Removes all visits to specified URLs in specific time ranges. | 84 // Removes all visits to specified URLs in specific time ranges. |
| 68 // This is the of equivalent HistoryService::ExpireHistory(). | 85 // This is the of equivalent HistoryService::ExpireHistory(). |
| 69 void ExpireHistory(const std::vector<ExpireHistoryArgs>& expire_list, | 86 void ExpireHistory(const std::vector<ExpireHistoryArgs>& expire_list, |
| 70 const ExpireWebHistoryCallback& callback); | 87 const ExpireWebHistoryCallback& callback); |
| 71 | 88 |
| 72 // Removes all visits to specified URLs in the given time range. | 89 // Removes all visits to specified URLs in the given time range. |
| 73 // This is the of equivalent HistoryService::ExpireHistoryBetween(). | 90 // This is the of equivalent HistoryService::ExpireHistoryBetween(). |
| 74 void ExpireHistoryBetween(const std::set<GURL>& restrict_urls, | 91 void ExpireHistoryBetween(const std::set<GURL>& restrict_urls, |
| 75 base::Time begin_time, | 92 base::Time begin_time, |
| 76 base::Time end_time, | 93 base::Time end_time, |
| 77 const ExpireWebHistoryCallback& callback); | 94 const ExpireWebHistoryCallback& callback); |
| 78 | 95 |
| 79 private: | 96 // Requests whether audio history recording is enabled. |
| 97 void GetAudioHistoryEnabled(const AudioWebHistoryCallback& callback); |
| 98 |
| 99 // Sets the state of audio history recording to |new_enabled_value|. |
| 100 void SetAudioHistoryEnabled(bool new_enabled_value, |
| 101 const AudioWebHistoryCallback& callback); |
| 102 |
| 103 // Used for tests. |
| 104 size_t GetNumberOfPendingAudioHistoryRequests(); |
| 105 |
| 106 protected: |
| 107 // This function is pulled out for testing purposes. Caller takes ownership of |
| 108 // the new Request. |
| 109 virtual Request* CreateRequest(const GURL& url, |
| 110 const CompletionCallback& callback); |
| 111 |
| 112 // Extracts a JSON-encoded HTTP response into a DictionaryValue. |
| 113 // If |request|'s HTTP response code indicates failure, or if the response |
| 114 // body is not JSON, a null pointer is returned. |
| 115 static scoped_ptr<base::DictionaryValue> ReadResponse(Request* request); |
| 116 |
| 80 // Called by |request| when a web history query has completed. Unpacks the | 117 // Called by |request| when a web history query has completed. Unpacks the |
| 81 // response and calls |callback|, which is the original callback that was | 118 // response and calls |callback|, which is the original callback that was |
| 82 // passed to QueryHistory(). | 119 // passed to QueryHistory(). |
| 83 static void QueryHistoryCompletionCallback( | 120 static void QueryHistoryCompletionCallback( |
| 84 const WebHistoryService::QueryWebHistoryCallback& callback, | 121 const WebHistoryService::QueryWebHistoryCallback& callback, |
| 85 WebHistoryService::Request* request, | 122 WebHistoryService::Request* request, |
| 86 bool success); | 123 bool success); |
| 87 | 124 |
| 88 // Called by |request| when a request to delete history from the server has | 125 // 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 | 126 // completed. Unpacks the response and calls |callback|, which is the original |
| 90 // callback that was passed to ExpireHistory(). | 127 // callback that was passed to ExpireHistory(). |
| 91 void ExpireHistoryCompletionCallback( | 128 void ExpireHistoryCompletionCallback( |
| 92 const WebHistoryService::ExpireWebHistoryCallback& callback, | 129 const WebHistoryService::ExpireWebHistoryCallback& callback, |
| 93 WebHistoryService::Request* request, | 130 WebHistoryService::Request* request, |
| 94 bool success); | 131 bool success); |
| 95 | 132 |
| 133 // Called by |request| when a request to get or set audio history from the |
| 134 // server has completed. Unpacks the response and calls |callback|, which is |
| 135 // the original callback that was passed to AudioHistory(). |
| 136 void AudioHistoryCompletionCallback( |
| 137 const WebHistoryService::AudioWebHistoryCallback& callback, |
| 138 WebHistoryService::Request* request, |
| 139 bool success); |
| 140 |
| 141 private: |
| 142 friend class WebHistoryServiceTest; |
| 143 |
| 96 Profile* profile_; | 144 Profile* profile_; |
| 97 | 145 |
| 98 // Stores the version_info token received from the server in response to | 146 // 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 | 147 // 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. | 148 // subsequent reads see a version of the data that includes the mutation. |
| 101 std::string server_version_info_; | 149 std::string server_version_info_; |
| 102 | 150 |
| 103 // Pending expiration requests to be canceled if not complete by profile | 151 // Pending expiration requests to be canceled if not complete by profile |
| 104 // shutdown. | 152 // shutdown. |
| 105 std::set<Request*> pending_expire_requests_; | 153 std::set<Request*> pending_expire_requests_; |
| 106 | 154 |
| 155 // Pending requests to be canceled if not complete by profile shutdown. |
| 156 std::set<Request*> pending_audio_history_requests_; |
| 157 |
| 107 base::WeakPtrFactory<WebHistoryService> weak_ptr_factory_; | 158 base::WeakPtrFactory<WebHistoryService> weak_ptr_factory_; |
| 108 | 159 |
| 109 DISALLOW_COPY_AND_ASSIGN(WebHistoryService); | 160 DISALLOW_COPY_AND_ASSIGN(WebHistoryService); |
| 110 }; | 161 }; |
| 111 | 162 |
| 112 } // namespace history | 163 } // namespace history |
| 113 | 164 |
| 114 #endif // CHROME_BROWSER_HISTORY_WEB_HISTORY_SERVICE_H_ | 165 #endif // CHROME_BROWSER_HISTORY_WEB_HISTORY_SERVICE_H_ |
| OLD | NEW |