| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_DOWNLOAD_H_ | 5 #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_DOWNLOAD_H_ |
| 6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_DOWNLOAD_H_ | 6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_DOWNLOAD_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <list> | 9 #include <list> |
| 10 #include <map> | 10 #include <map> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <utility> | 12 #include <utility> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
| 16 #include "base/gtest_prod_util.h" | 16 #include "base/gtest_prod_util.h" |
| 17 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 18 #include "components/autofill/core/browser/autofill_type.h" | 18 #include "components/autofill/core/browser/autofill_type.h" |
| 19 #include "net/url_request/url_fetcher_delegate.h" | 19 #include "net/url_request/url_fetcher_delegate.h" |
| 20 | 20 |
| 21 class PrefService; |
| 22 |
| 21 namespace content { | 23 namespace content { |
| 22 class BrowserContext; | 24 class BrowserContext; |
| 23 } // namespace content | 25 } // namespace content |
| 24 | 26 |
| 25 namespace net { | 27 namespace net { |
| 26 class URLFetcher; | 28 class URLFetcher; |
| 27 } // namespace net | 29 } // namespace net |
| 28 | 30 |
| 29 namespace autofill { | 31 namespace autofill { |
| 30 | 32 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 55 // |request_type| - type of request that failed. | 57 // |request_type| - type of request that failed. |
| 56 // |http_error| - HTTP error code. | 58 // |http_error| - HTTP error code. |
| 57 virtual void OnServerRequestError(const std::string& form_signature, | 59 virtual void OnServerRequestError(const std::string& form_signature, |
| 58 AutofillRequestType request_type, | 60 AutofillRequestType request_type, |
| 59 int http_error) {} | 61 int http_error) {} |
| 60 | 62 |
| 61 protected: | 63 protected: |
| 62 virtual ~Observer() {} | 64 virtual ~Observer() {} |
| 63 }; | 65 }; |
| 64 | 66 |
| 67 // |context| and |pref_service| must outlive this instance. |
| 65 // |observer| - observer to notify on successful completion or error. | 68 // |observer| - observer to notify on successful completion or error. |
| 66 AutofillDownloadManager(content::BrowserContext* context, | 69 AutofillDownloadManager(content::BrowserContext* context, |
| 70 PrefService* pref_service, |
| 67 Observer* observer); | 71 Observer* observer); |
| 68 virtual ~AutofillDownloadManager(); | 72 virtual ~AutofillDownloadManager(); |
| 69 | 73 |
| 70 // Starts a query request to Autofill servers. The observer is called with the | 74 // Starts a query request to Autofill servers. The observer is called with the |
| 71 // list of the fields of all requested forms. | 75 // list of the fields of all requested forms. |
| 72 // |forms| - array of forms aggregated in this request. | 76 // |forms| - array of forms aggregated in this request. |
| 73 bool StartQueryRequest(const std::vector<FormStructure*>& forms, | 77 bool StartQueryRequest(const std::vector<FormStructure*>& forms, |
| 74 const AutofillMetrics& metric_logger); | 78 const AutofillMetrics& metric_logger); |
| 75 | 79 |
| 76 // Starts an upload request for the given |form|, unless throttled by the | 80 // Starts an upload request for the given |form|, unless throttled by the |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 129 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
| 126 | 130 |
| 127 // Probability of the form upload. Between 0 (no upload) and 1 (upload all). | 131 // Probability of the form upload. Between 0 (no upload) and 1 (upload all). |
| 128 // GetPositiveUploadRate() is for matched forms, | 132 // GetPositiveUploadRate() is for matched forms, |
| 129 // GetNegativeUploadRate() for non-matched. | 133 // GetNegativeUploadRate() for non-matched. |
| 130 double GetPositiveUploadRate() const; | 134 double GetPositiveUploadRate() const; |
| 131 double GetNegativeUploadRate() const; | 135 double GetNegativeUploadRate() const; |
| 132 void SetPositiveUploadRate(double rate); | 136 void SetPositiveUploadRate(double rate); |
| 133 void SetNegativeUploadRate(double rate); | 137 void SetNegativeUploadRate(double rate); |
| 134 | 138 |
| 135 // The pointer value is const, so this can only be set in the | 139 // The BrowserContext that this instance will use. Must not be null, and must |
| 136 // constructor. Must not be null. | 140 // outlive this instance. |
| 137 content::BrowserContext* const browser_context_; // WEAK | 141 content::BrowserContext* const browser_context_; // WEAK |
| 138 | 142 |
| 143 // The PrefService that this instance will use. Must not be null, and must |
| 144 // outlive this instance. |
| 145 PrefService* const pref_service_; // WEAK |
| 146 |
| 139 // The observer to notify when server predictions are successfully received. | 147 // The observer to notify when server predictions are successfully received. |
| 140 // The pointer value is const, so this can only be set in the constructor. | |
| 141 // Must not be null. | 148 // Must not be null. |
| 142 AutofillDownloadManager::Observer* const observer_; // WEAK | 149 AutofillDownloadManager::Observer* const observer_; // WEAK |
| 143 | 150 |
| 144 // For each requested form for both query and upload we create a separate | 151 // For each requested form for both query and upload we create a separate |
| 145 // request and save its info. As url fetcher is identified by its address | 152 // request and save its info. As url fetcher is identified by its address |
| 146 // we use a map between fetchers and info. | 153 // we use a map between fetchers and info. |
| 147 std::map<net::URLFetcher*, FormRequestData> url_fetchers_; | 154 std::map<net::URLFetcher*, FormRequestData> url_fetchers_; |
| 148 | 155 |
| 149 // Cached QUERY requests. | 156 // Cached QUERY requests. |
| 150 QueryRequestCache cached_forms_; | 157 QueryRequestCache cached_forms_; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 161 double positive_upload_rate_; | 168 double positive_upload_rate_; |
| 162 double negative_upload_rate_; | 169 double negative_upload_rate_; |
| 163 | 170 |
| 164 // Needed for unit-test. | 171 // Needed for unit-test. |
| 165 int fetcher_id_for_unittest_; | 172 int fetcher_id_for_unittest_; |
| 166 }; | 173 }; |
| 167 | 174 |
| 168 } // namespace autofill | 175 } // namespace autofill |
| 169 | 176 |
| 170 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_DOWNLOAD_H_ | 177 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_DOWNLOAD_H_ |
| OLD | NEW |