summaryrefslogtreecommitdiffstats
path: root/chrome/browser/autofill/autofill_download.cc
diff options
context:
space:
mode:
authorKristian Monsen <kristianm@google.com>2011-05-31 20:30:28 +0100
committerKristian Monsen <kristianm@google.com>2011-06-14 20:31:41 -0700
commit72a454cd3513ac24fbdd0e0cb9ad70b86a99b801 (patch)
tree382278a54ce7a744d62fa510a9a80688cc12434b /chrome/browser/autofill/autofill_download.cc
parentc4becdd46e31d261b930e4b5a539cbc1d45c23a6 (diff)
downloadexternal_chromium-72a454cd3513ac24fbdd0e0cb9ad70b86a99b801.zip
external_chromium-72a454cd3513ac24fbdd0e0cb9ad70b86a99b801.tar.gz
external_chromium-72a454cd3513ac24fbdd0e0cb9ad70b86a99b801.tar.bz2
Merge Chromium.org at r11.0.672.0: Initial merge by git.
Change-Id: I8b4aaf611a2a405fe3fe10e8a94ea7658645c192
Diffstat (limited to 'chrome/browser/autofill/autofill_download.cc')
-rw-r--r--chrome/browser/autofill/autofill_download.cc96
1 files changed, 83 insertions, 13 deletions
diff --git a/chrome/browser/autofill/autofill_download.cc b/chrome/browser/autofill/autofill_download.cc
index 091c0ec..c571d7b 100644
--- a/chrome/browser/autofill/autofill_download.cc
+++ b/chrome/browser/autofill/autofill_download.cc
@@ -17,8 +17,13 @@
#include "chrome/common/pref_names.h"
#include "net/http/http_response_headers.h"
-#define DISABLED_REQUEST_URL "http://disabled"
+#define AUTO_FILL_QUERY_SERVER_REQUEST_URL \
+ "http://toolbarqueries.clients.google.com:80/tbproxy/af/query"
+#define AUTO_FILL_UPLOAD_SERVER_REQUEST_URL \
+ "http://toolbarqueries.clients.google.com:80/tbproxy/af/upload"
+#define AUTO_FILL_QUERY_SERVER_NAME_START_IN_HEADER "GFE/"
+<<<<<<< HEAD
#if defined(GOOGLE_CHROME_BUILD) || (defined(ANDROID) && defined(HAVE_AUTOFILL_DOWNLOAD_INTERNAL_H) && HAVE_AUTOFILL_DOWNLOAD_INTERNAL_H)
#include "chrome/browser/autofill/internal/autofill_download_internal.h"
#else
@@ -26,6 +31,11 @@
#define AUTO_FILL_UPLOAD_SERVER_REQUEST_URL DISABLED_REQUEST_URL
#define AUTO_FILL_QUERY_SERVER_NAME_START_IN_HEADER "SOMESERVER/"
#endif
+=======
+namespace {
+const size_t kMaxFormCacheSize = 16;
+};
+>>>>>>> chromium.org at r11.0.672.0
struct AutoFillDownloadManager::FormRequestData {
std::vector<std::string> form_signatures;
@@ -41,12 +51,12 @@ const double kAutoFillNegativeUploadRateDefaultValue = 0.01;
AutoFillDownloadManager::AutoFillDownloadManager(Profile* profile)
: profile_(profile),
observer_(NULL),
+ max_form_cache_size_(kMaxFormCacheSize),
next_query_request_(base::Time::Now()),
next_upload_request_(base::Time::Now()),
positive_upload_rate_(0),
negative_upload_rate_(0),
- fetcher_id_for_unittest_(0),
- is_testing_(false) {
+ fetcher_id_for_unittest_(0) {
// |profile_| could be NULL in some unit-tests.
#ifdef ANDROID
positive_upload_rate_ = kAutoFillPositiveUploadRateDefaultValue;
@@ -55,9 +65,9 @@ AutoFillDownloadManager::AutoFillDownloadManager(Profile* profile)
if (profile_) {
PrefService* preferences = profile_->GetPrefs();
positive_upload_rate_ =
- preferences->GetReal(prefs::kAutoFillPositiveUploadRate);
+ preferences->GetDouble(prefs::kAutoFillPositiveUploadRate);
negative_upload_rate_ =
- preferences->GetReal(prefs::kAutoFillNegativeUploadRate);
+ preferences->GetDouble(prefs::kAutoFillNegativeUploadRate);
}
#endif
}
@@ -87,12 +97,22 @@ bool AutoFillDownloadManager::StartQueryRequest(
std::string form_xml;
FormRequestData request_data;
if (!FormStructure::EncodeQueryRequest(forms, &request_data.form_signatures,
- &form_xml))
+ &form_xml)) {
return false;
+ }
request_data.request_type = AutoFillDownloadManager::REQUEST_QUERY;
metric_logger.Log(AutoFillMetrics::QUERY_SENT);
+ std::string query_data;
+ if (CheckCacheForQueryRequest(request_data.form_signatures, &query_data)) {
+ VLOG(1) << "AutoFillDownloadManager: query request has been retrieved from"
+ << "the cache";
+ if (observer_)
+ observer_->OnLoadedAutoFillHeuristics(query_data);
+ return true;
+ }
+
return StartRequest(form_xml, request_data);
}
@@ -157,7 +177,7 @@ void AutoFillDownloadManager::SetPositiveUploadRate(double rate) {
DCHECK_LE(rate, 1.0);
DCHECK(profile_);
PrefService* preferences = profile_->GetPrefs();
- preferences->SetReal(prefs::kAutoFillPositiveUploadRate, rate);
+ preferences->SetDouble(prefs::kAutoFillPositiveUploadRate, rate);
}
void AutoFillDownloadManager::SetNegativeUploadRate(double rate) {
@@ -168,7 +188,7 @@ void AutoFillDownloadManager::SetNegativeUploadRate(double rate) {
DCHECK_LE(rate, 1.0);
DCHECK(profile_);
PrefService* preferences = profile_->GetPrefs();
- preferences->SetReal(prefs::kAutoFillNegativeUploadRate, rate);
+ preferences->SetDouble(prefs::kAutoFillNegativeUploadRate, rate);
}
bool AutoFillDownloadManager::StartRequest(
@@ -180,11 +200,6 @@ bool AutoFillDownloadManager::StartRequest(
else
request_url = AUTO_FILL_UPLOAD_SERVER_REQUEST_URL;
- if (!request_url.compare(DISABLED_REQUEST_URL) && !is_testing_) {
- // We have it disabled - return true as if it succeeded, but do nothing.
- return true;
- }
-
// Id is ignored for regular chrome, in unit test id's for fake fetcher
// factory will be 0, 1, 2, ...
URLFetcher *fetcher = URLFetcher::Create(fetcher_id_for_unittest_++,
@@ -205,6 +220,60 @@ bool AutoFillDownloadManager::StartRequest(
return true;
}
+void AutoFillDownloadManager::CacheQueryRequest(
+ const std::vector<std::string>& forms_in_query,
+ const std::string& query_data) {
+ std::string signature = GetCombinedSignature(forms_in_query);
+ for (QueryRequestCache::iterator it = cached_forms_.begin();
+ it != cached_forms_.end(); ++it) {
+ if (it->first == signature) {
+ // We hit the cache, move to the first position and return.
+ std::pair<std::string, std::string> data = *it;
+ cached_forms_.erase(it);
+ cached_forms_.push_front(data);
+ return;
+ }
+ }
+ std::pair<std::string, std::string> data;
+ data.first = signature;
+ data.second = query_data;
+ cached_forms_.push_front(data);
+ while (cached_forms_.size() > max_form_cache_size_)
+ cached_forms_.pop_back();
+}
+
+bool AutoFillDownloadManager::CheckCacheForQueryRequest(
+ const std::vector<std::string>& forms_in_query,
+ std::string* query_data) const {
+ std::string signature = GetCombinedSignature(forms_in_query);
+ for (QueryRequestCache::const_iterator it = cached_forms_.begin();
+ it != cached_forms_.end(); ++it) {
+ if (it->first == signature) {
+ // We hit the cache, fill the data and return.
+ *query_data = it->second;
+ return true;
+ }
+ }
+ return false;
+}
+
+std::string AutoFillDownloadManager::GetCombinedSignature(
+ const std::vector<std::string>& forms_in_query) const {
+ size_t total_size = forms_in_query.size();
+ for (size_t i = 0; i < forms_in_query.size(); ++i)
+ total_size += forms_in_query[i].length();
+ std::string signature;
+
+ signature.reserve(total_size);
+
+ for (size_t i = 0; i < forms_in_query.size(); ++i) {
+ if (i)
+ signature.append(",");
+ signature.append(forms_in_query[i]);
+ }
+ return signature;
+}
+
void AutoFillDownloadManager::OnURLFetchComplete(
const URLFetcher* source,
const GURL& url,
@@ -267,6 +336,7 @@ void AutoFillDownloadManager::OnURLFetchComplete(
VLOG(1) << "AutoFillDownloadManager: " << type_of_request
<< " request has succeeded";
if (it->second.request_type == AutoFillDownloadManager::REQUEST_QUERY) {
+ CacheQueryRequest(it->second.form_signatures, data);
if (observer_)
observer_->OnLoadedAutoFillHeuristics(data);
} else {