diff options
Diffstat (limited to 'chrome/browser/autofill/autofill_download.h')
-rw-r--r-- | chrome/browser/autofill/autofill_download.h | 85 |
1 files changed, 64 insertions, 21 deletions
diff --git a/chrome/browser/autofill/autofill_download.h b/chrome/browser/autofill/autofill_download.h index c9e6ed2..620ac6f 100644 --- a/chrome/browser/autofill/autofill_download.h +++ b/chrome/browser/autofill/autofill_download.h @@ -6,6 +6,7 @@ #define CHROME_BROWSER_AUTOFILL_AUTOFILL_DOWNLOAD_H_ #include <map> +#include <vector> #include <string> #include "base/scoped_ptr.h" @@ -19,14 +20,18 @@ // Handles getting and updating AutoFill heuristics. class AutoFillDownloadManager : public URLFetcher::Delegate { public: + enum AutoFillRequestType { + REQUEST_QUERY, + REQUEST_UPLOAD, + }; // An interface used to notify clients of AutoFillDownloadManager. class Observer { public: // Called when heuristic successfully received from server. - // |form_signature| - the signature of the requesting form. + // |form_signatures| - the signatures of the requesting forms. // |heuristic_xml| - server response. virtual void OnLoadedAutoFillHeuristics( - const std::string& form_signature, + const std::vector<std::string>& form_signatures, const std::string& heuristic_xml) = 0; // Called when heuristic either successfully considered for upload and // not send or uploaded. @@ -35,8 +40,10 @@ class AutoFillDownloadManager : public URLFetcher::Delegate { const std::string& form_signature) = 0; // Called when there was an error during the request. // |form_signature| - the signature of the requesting form. + // |request_type| - type of request that failed. // |http_error| - http error code. virtual void OnHeuristicsRequestError(const std::string& form_signature, + AutoFillRequestType request_type, int http_error) = 0; protected: virtual ~Observer() {} @@ -48,21 +55,53 @@ class AutoFillDownloadManager : public URLFetcher::Delegate { // |observer| - observer to notify on successful completion or error. void SetObserver(AutoFillDownloadManager::Observer *observer); - // Initiates request to AutoFill servers to download/upload heuristics + // Starts a query request to AutoFill servers. The observer is called with the + // list of the fields of all requested forms. + // |forms| - array of forms aggregated in this request. + bool StartQueryRequest(const ScopedVector<FormStructure>& forms); + + // Start upload request if necessary. The probability of request going + // over the wire are |positive_upload_rate_| if it was matched by + // AutoFill, |negative_download_rate_| otherwise. Observer will be called + // even if there was no actual trip over the wire. + // |form| - form sent in this request. + // |form_was_matched| - true if form was matched by the AutoFill. + bool StartUploadRequest(const FormStructure& form, bool form_was_matched); + + // Cancels pending request. + // |form_signature| - signature of the form being cancelled. Warning: + // for query request if more than one form sent in the request, all other + // forms will be cancelled as well. + // |request_type| - type of the request. + bool CancelRequest(const std::string& form_signature, + AutoFillRequestType request_type); + + void SetPositiveUploadRate(double rate) { + DCHECK(rate >= 0.0 && rate <= 1.0); + positive_upload_rate_ = rate; + } + + void SetNegativeUploadRate(double rate) { + DCHECK(rate >= 0.0 && rate <= 1.0); + negative_upload_rate_ = rate; + } + + private: + friend class AutoFillDownloadTestHelper; // unit-test. + struct FormRequestData { + std::vector<std::string> form_signatures; + AutoFillRequestType request_type; + }; + + // Initiates request to AutoFill servers to download/upload heuristics. // |form_xml| - form structure XML to upload/download. - // |form_signature| - form signature hash. - // |query_data| - if true the data is queried and observer notified with new - // data, if available. If false heuristic data is uploaded to our servers. - // |form_was_matched| - if |query_data| is false indicates if the form was - // matched. Ignored otherwise. + // |request_data| - form signature hash(es) and indicator if it was a query. + // |request_data.query| - if true the data is queried and observer notified + // with new data, if available. If false heuristic data is uploaded to our + // servers. bool StartRequest(const std::string& form_xml, - const std::string& form_signature, - bool query_data, - bool form_was_matched); - - bool CancelRequest(const std::string& form_signature, bool query_data); + const FormRequestData& request_data); - protected: // URLFetcher::Delegate implementation: virtual void OnURLFetchComplete(const URLFetcher* source, const GURL& url, @@ -71,17 +110,21 @@ class AutoFillDownloadManager : public URLFetcher::Delegate { const ResponseCookies& cookies, const std::string& data); - private: - struct FormRequestData { - std::string form_signature; - bool query; - }; - // For each requested form for both query and upload we create a separate // request and save its info. As url fetcher is identified by its address // we use a map between fetchers and info. - std::map<URLFetcher *, FormRequestData> url_fetchers_; + std::map<URLFetcher*, FormRequestData> url_fetchers_; AutoFillDownloadManager::Observer *observer_; + + // Probability of the form upload. Between 0 (no upload) and 1 (upload all). + // |positive_upload_rate_| is for matched forms, + // |negative_upload_rate_| for non matched. + double positive_upload_rate_; + double negative_upload_rate_; + + // Needed for unit-test. + int fetcher_id_for_unittest_; + bool is_testing_; }; #endif // CHROME_BROWSER_AUTOFILL_AUTOFILL_DOWNLOAD_H_ |