diff options
-rw-r--r-- | chrome/browser/autofill/autofill_download.cc | 20 | ||||
-rw-r--r-- | chrome/browser/autofill/autofill_download_url.cc | 45 | ||||
-rw-r--r-- | chrome/browser/autofill/autofill_download_url.h | 18 | ||||
-rw-r--r-- | chrome/browser/autofill/autofill_download_url_unittest.cc | 23 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 2 | ||||
-rw-r--r-- | chrome/chrome_tests.gypi | 1 | ||||
-rw-r--r-- | chrome/common/chrome_switches.cc | 3 | ||||
-rw-r--r-- | chrome/common/chrome_switches.h | 1 |
8 files changed, 98 insertions, 15 deletions
diff --git a/chrome/browser/autofill/autofill_download.cc b/chrome/browser/autofill/autofill_download.cc index 26c0af1..3b835cc 100644 --- a/chrome/browser/autofill/autofill_download.cc +++ b/chrome/browser/autofill/autofill_download.cc @@ -13,6 +13,7 @@ #include "base/rand_util.h" #include "base/stl_util.h" #include "base/string_util.h" +#include "chrome/browser/autofill/autofill_download_url.h" #include "chrome/browser/autofill/autofill_metrics.h" #include "chrome/browser/autofill/autofill_xml_parser.h" #include "chrome/browser/autofill/form_structure.h" @@ -27,18 +28,8 @@ using content::BrowserContext; namespace { -const char kAutofillQueryServerRequestUrl[] = - "https://clients1.google.com/tbproxy/af/query?client="; -const char kAutofillUploadServerRequestUrl[] = - "https://clients1.google.com/tbproxy/af/upload?client="; const char kAutofillQueryServerNameStartInHeader[] = "GFE/"; -#if defined(GOOGLE_CHROME_BUILD) -const char kClientName[] = "Google Chrome"; -#else -const char kClientName[] = "Chromium"; -#endif // defined(GOOGLE_CHROME_BUILD) - const size_t kMaxFormCacheSize = 16; // Log the contents of the upload request @@ -179,17 +170,16 @@ bool AutofillDownloadManager::StartRequest( net::URLRequestContextGetter* request_context = browser_context_->GetRequestContext(); DCHECK(request_context); - std::string request_url; + GURL request_url; if (request_data.request_type == AutofillDownloadManager::REQUEST_QUERY) - request_url = kAutofillQueryServerRequestUrl; + request_url = autofill::GetAutofillQueryUrl(); else - request_url = kAutofillUploadServerRequestUrl; - request_url += kClientName; + request_url = autofill::GetAutofillUploadUrl(); // Id is ignored for regular chrome, in unit test id's for fake fetcher // factory will be 0, 1, 2, ... net::URLFetcher* fetcher = net::URLFetcher::Create( - fetcher_id_for_unittest_++, GURL(request_url), net::URLFetcher::POST, + fetcher_id_for_unittest_++, request_url, net::URLFetcher::POST, this); url_fetchers_[fetcher] = request_data; fetcher->SetAutomaticallyRetryOn5xx(false); diff --git a/chrome/browser/autofill/autofill_download_url.cc b/chrome/browser/autofill/autofill_download_url.cc new file mode 100644 index 0000000..8bf1602 --- /dev/null +++ b/chrome/browser/autofill/autofill_download_url.cc @@ -0,0 +1,45 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/autofill/autofill_download_url.h" + +#include <string> + +#include "base/command_line.h" +#include "chrome/common/chrome_switches.h" +#include "googleurl/src/gurl.h" + +namespace { + +const char kDefaultAutofillServiceUrl[] = + "https://clients1.google.com/tbproxy/af/"; + +#if defined(GOOGLE_CHROME_BUILD) +const char kClientName[] = "Google Chrome"; +#else +const char kClientName[] = "Chromium"; +#endif // defined(GOOGLE_CHROME_BUILD) + +std::string GetBaseAutofillUrl() { + const CommandLine& command_line = *CommandLine::ForCurrentProcess(); + std::string baseAutofillServiceUrl = command_line.GetSwitchValueASCII( + switches::kAutofillServiceUrl); + if (baseAutofillServiceUrl.empty()) + return kDefaultAutofillServiceUrl; + + return baseAutofillServiceUrl; +} + +} // anonymous namespace + +GURL autofill::GetAutofillQueryUrl() { + std::string baseAutofillServiceUrl = GetBaseAutofillUrl(); + return GURL(baseAutofillServiceUrl + "query?client=" + kClientName); +} + +GURL autofill::GetAutofillUploadUrl() { + std::string baseAutofillServiceUrl = GetBaseAutofillUrl(); + return GURL(baseAutofillServiceUrl + "upload?client=" + kClientName); +} + diff --git a/chrome/browser/autofill/autofill_download_url.h b/chrome/browser/autofill/autofill_download_url.h new file mode 100644 index 0000000..fcad83b --- /dev/null +++ b/chrome/browser/autofill/autofill_download_url.h @@ -0,0 +1,18 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_AUTOFILL_AUTOFILL_DOWNLOAD_URL_H_ +#define CHROME_BROWSER_AUTOFILL_AUTOFILL_DOWNLOAD_URL_H_ + +class GURL; + +namespace autofill { + +GURL GetAutofillQueryUrl(); +GURL GetAutofillUploadUrl(); + +} + +#endif // CHROME_BROWSER_AUTOFILL_AUTOFILL_DOWNLOAD_URL_H_ + diff --git a/chrome/browser/autofill/autofill_download_url_unittest.cc b/chrome/browser/autofill/autofill_download_url_unittest.cc new file mode 100644 index 0000000..a7a37e1 --- /dev/null +++ b/chrome/browser/autofill/autofill_download_url_unittest.cc @@ -0,0 +1,23 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/autofill/autofill_download_url.h" +#include "googleurl/src/gurl.h" +#include "testing/gmock/include/gmock/gmock.h" +#include "testing/gtest/include/gtest/gtest.h" + +using testing::StartsWith; + +TEST(AutofillDownloadUrlTest, CheckDefaultUrls) { + std::string query_url = + autofill::GetAutofillQueryUrl().spec(); + EXPECT_THAT(query_url, + StartsWith("https://clients1.google.com/tbproxy/af/query?client=")); + + std::string upload_url = + autofill::GetAutofillUploadUrl().spec(); + EXPECT_THAT(upload_url, + StartsWith("https://clients1.google.com/tbproxy/af/upload?client=")); +} + diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 2e53b38..a01c7bb 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -227,6 +227,8 @@ 'browser/autofill/autofill_country.h', 'browser/autofill/autofill_download.cc', 'browser/autofill/autofill_download.h', + 'browser/autofill/autofill_download_url.cc', + 'browser/autofill/autofill_download_url.h', 'browser/autofill/autofill_external_delegate.cc', 'browser/autofill/autofill_external_delegate.h', 'browser/autofill/autofill_field.cc', diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 6bf99ab..a8a9c22 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -1090,6 +1090,7 @@ 'browser/autofill/autocomplete_history_manager_unittest.cc', 'browser/autofill/autofill_country_unittest.cc', 'browser/autofill/autofill_download_unittest.cc', + 'browser/autofill/autofill_download_url_unittest.cc', 'browser/autofill/autofill_external_delegate_unittest.cc', 'browser/autofill/autofill_field_unittest.cc', 'browser/autofill/autofill_ie_toolbar_import_win_unittest.cc', diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc index e580567..efe8d9f 100644 --- a/chrome/common/chrome_switches.cc +++ b/chrome/common/chrome_switches.cc @@ -123,6 +123,9 @@ const char kAuthServerWhitelist[] = "auth-server-whitelist"; // computer startup and not by some user action. const char kAutoLaunchAtStartup[] = "auto-launch-at-startup"; +// Flag used to tell Chrome the base url of the Autofill service. +const char kAutofillServiceUrl[] = "autofill-service-url"; + // The value of this switch tells the app to listen for and broadcast // automation-related messages on IPC channel with the given ID. const char kAutomationClientChannelID[] = "automation-channel"; diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h index 8eade3d..a54447f 100644 --- a/chrome/common/chrome_switches.h +++ b/chrome/common/chrome_switches.h @@ -49,6 +49,7 @@ extern const char kAuthNegotiateDelegateWhitelist[]; extern const char kAuthSchemes[]; extern const char kAuthServerWhitelist[]; extern const char kAutoLaunchAtStartup[]; +extern const char kAutofillServiceUrl[]; extern const char kAutomationClientChannelID[]; extern const char kAutomationReinitializeOnChannelError[]; extern const char kCheckForUpdateIntervalSec[]; |