summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryoz@chromium.org <yoz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-26 00:01:31 +0000
committeryoz@chromium.org <yoz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-26 00:01:31 +0000
commit8f4b69e5058bad5559e07b33c258ec0e5adff1b1 (patch)
treeb7e7444fb54b28d562724517d3148291e2d4b048
parent3a4bd5dc9d0f9c5258dfcf5399ee876e263ae3a3 (diff)
downloadchromium_src-8f4b69e5058bad5559e07b33c258ec0e5adff1b1.zip
chromium_src-8f4b69e5058bad5559e07b33c258ec0e5adff1b1.tar.gz
chromium_src-8f4b69e5058bad5559e07b33c258ec0e5adff1b1.tar.bz2
Move OmahaQueryParams to a component and add a delegate interface.
BUG=376554 Review URL: https://codereview.chromium.org/333353005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@279867 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--apps/shell/app_shell.gyp3
-rw-r--r--apps/shell/browser/DEPS1
-rw-r--r--apps/shell/browser/shell_browser_main_parts.cc7
-rw-r--r--apps/shell/browser/shell_browser_main_parts.h5
-rw-r--r--apps/shell/browser/shell_omaha_query_params_delegate.cc22
-rw-r--r--apps/shell/browser/shell_omaha_query_params_delegate.h26
-rw-r--r--chrome/browser/DEPS1
-rw-r--r--chrome/browser/browser_process_impl.cc5
-rw-r--r--chrome/browser/component_updater/component_updater_utils.cc29
-rw-r--r--chrome/browser/component_updater/pnacl/pnacl_component_installer.cc4
-rw-r--r--chrome/browser/extensions/api/runtime/chrome_runtime_api_delegate.cc8
-rw-r--r--chrome/browser/extensions/updater/extension_updater_unittest.cc6
-rw-r--r--chrome/browser/extensions/updater/manifest_fetch_data.cc5
-rw-r--r--chrome/browser/extensions/webstore_installer.cc8
-rw-r--r--chrome/browser/extensions/webstore_installer_unittest.cc10
-rw-r--r--chrome/browser/omaha_query_params/chrome_omaha_query_params_delegate.cc68
-rw-r--r--chrome/browser/omaha_query_params/chrome_omaha_query_params_delegate.h35
-rw-r--r--chrome/browser/omaha_query_params/chrome_omaha_query_params_delegate_unittest.cc51
-rw-r--r--chrome/browser/ui/webui/app_list/start_page_handler.cc4
-rw-r--r--chrome/chrome_browser.gypi5
-rw-r--r--chrome/chrome_browser_extensions.gypi1
-rw-r--r--chrome/chrome_browser_ui.gypi1
-rw-r--r--chrome/chrome_tests_unit.gypi2
-rw-r--r--chrome/test/base/chrome_unit_test_suite.cc5
-rw-r--r--components/components.gyp1
-rw-r--r--components/components_tests.gyp4
-rw-r--r--components/omaha_query_params.gypi24
-rw-r--r--components/omaha_query_params/DEPS4
-rw-r--r--components/omaha_query_params/OWNERS2
-rw-r--r--components/omaha_query_params/omaha_query_params.cc (renamed from chrome/browser/omaha_query_params/omaha_query_params.cc)60
-rw-r--r--components/omaha_query_params/omaha_query_params.h (renamed from chrome/browser/omaha_query_params/omaha_query_params.h)34
-rw-r--r--components/omaha_query_params/omaha_query_params_delegate.cc15
-rw-r--r--components/omaha_query_params/omaha_query_params_delegate.h32
-rw-r--r--components/omaha_query_params/omaha_query_params_unittest.cc (renamed from chrome/browser/omaha_query_params/omaha_query_params_unittest.cc)42
34 files changed, 414 insertions, 116 deletions
diff --git a/apps/shell/app_shell.gyp b/apps/shell/app_shell.gyp
index 5d69de0..bad66c7 100644
--- a/apps/shell/app_shell.gyp
+++ b/apps/shell/app_shell.gyp
@@ -74,6 +74,7 @@
'<(DEPTH)/apps/shell/common/api/api.gyp:shell_api',
'<(DEPTH)/base/base.gyp:base',
'<(DEPTH)/base/base.gyp:base_prefs_test_support',
+ '<(DEPTH)/components/components.gyp:omaha_query_params',
'<(DEPTH)/components/components.gyp:pref_registry',
'<(DEPTH)/components/components.gyp:user_prefs',
'<(DEPTH)/content/content.gyp:content',
@@ -129,6 +130,8 @@
'browser/shell_extensions_browser_client.h',
'browser/shell_network_controller_chromeos.cc',
'browser/shell_network_controller_chromeos.h',
+ 'browser/shell_omaha_query_params_delegate.cc',
+ 'browser/shell_omaha_query_params_delegate.h',
'browser/shell_runtime_api_delegate.cc',
'browser/shell_runtime_api_delegate.h',
'common/shell_content_client.cc',
diff --git a/apps/shell/browser/DEPS b/apps/shell/browser/DEPS
index a803ec5..235b403 100644
--- a/apps/shell/browser/DEPS
+++ b/apps/shell/browser/DEPS
@@ -1,5 +1,6 @@
include_rules = [
"+chromeos",
+ "+components/omaha_query_params",
"+components/pref_registry",
"+components/user_prefs",
"+third_party/cros_system_api",
diff --git a/apps/shell/browser/shell_browser_main_parts.cc b/apps/shell/browser/shell_browser_main_parts.cc
index 7c1d293..b438021 100644
--- a/apps/shell/browser/shell_browser_main_parts.cc
+++ b/apps/shell/browser/shell_browser_main_parts.cc
@@ -10,9 +10,11 @@
#include "apps/shell/browser/shell_extension_system.h"
#include "apps/shell/browser/shell_extension_system_factory.h"
#include "apps/shell/browser/shell_extensions_browser_client.h"
+#include "apps/shell/browser/shell_omaha_query_params_delegate.h"
#include "apps/shell/common/shell_extensions_client.h"
#include "base/run_loop.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
+#include "components/omaha_query_params/omaha_query_params.h"
#include "content/public/common/result_codes.h"
#include "content/shell/browser/shell_devtools_delegate.h"
#include "content/shell/browser/shell_net_log.h"
@@ -99,6 +101,11 @@ void ShellBrowserMainParts::PreMainMessageLoopRun() {
new extensions::ShellExtensionsBrowserClient(browser_context_.get()));
extensions::ExtensionsBrowserClient::Set(extensions_browser_client_.get());
+ omaha_query_params_delegate_.reset(
+ new extensions::ShellOmahaQueryParamsDelegate);
+ omaha_query_params::OmahaQueryParams::SetDelegate(
+ omaha_query_params_delegate_.get());
+
// Create our custom ExtensionSystem first because other
// KeyedServices depend on it.
// TODO(yoz): Move this after EnsureBrowserContextKeyedServiceFactoriesBuilt.
diff --git a/apps/shell/browser/shell_browser_main_parts.h b/apps/shell/browser/shell_browser_main_parts.h
index e9e1491..e9b8bf3 100644
--- a/apps/shell/browser/shell_browser_main_parts.h
+++ b/apps/shell/browser/shell_browser_main_parts.h
@@ -13,7 +13,6 @@
#include "ui/aura/window_tree_host_observer.h"
namespace content {
-class ShellBrowserContext;
class ShellDevToolsDelegate;
struct MainFunctionParams;
}
@@ -21,6 +20,7 @@ struct MainFunctionParams;
namespace extensions {
class ShellExtensionsBrowserClient;
class ShellExtensionSystem;
+class ShellOmahaQueryParamsDelegate;
}
namespace views {
@@ -80,8 +80,9 @@ class ShellBrowserMainParts : public content::BrowserMainParts {
scoped_ptr<extensions::ShellExtensionsBrowserClient>
extensions_browser_client_;
scoped_ptr<net::NetLog> net_log_;
-
scoped_ptr<content::ShellDevToolsDelegate> devtools_delegate_;
+ scoped_ptr<extensions::ShellOmahaQueryParamsDelegate>
+ omaha_query_params_delegate_;
// Owned by the KeyedService system.
extensions::ShellExtensionSystem* extension_system_;
diff --git a/apps/shell/browser/shell_omaha_query_params_delegate.cc b/apps/shell/browser/shell_omaha_query_params_delegate.cc
new file mode 100644
index 0000000..fa949d1
--- /dev/null
+++ b/apps/shell/browser/shell_omaha_query_params_delegate.cc
@@ -0,0 +1,22 @@
+// Copyright 2014 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 "apps/shell/browser/shell_omaha_query_params_delegate.h"
+
+namespace extensions {
+
+ShellOmahaQueryParamsDelegate::ShellOmahaQueryParamsDelegate() {
+}
+
+ShellOmahaQueryParamsDelegate::~ShellOmahaQueryParamsDelegate() {
+}
+
+std::string ShellOmahaQueryParamsDelegate::GetExtraParams() {
+ // This version number is high enough to be supported by Omaha
+ // (below 31 is unsupported), but it's fake enough to be obviously
+ // not a Chrome release.
+ return "&prodversion=38.1234.5678.9";
+}
+
+} // namespace extensions
diff --git a/apps/shell/browser/shell_omaha_query_params_delegate.h b/apps/shell/browser/shell_omaha_query_params_delegate.h
new file mode 100644
index 0000000..fc30292
--- /dev/null
+++ b/apps/shell/browser/shell_omaha_query_params_delegate.h
@@ -0,0 +1,26 @@
+// Copyright 2014 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 APPS_SHELL_BROWSER_SHELL_OMAHA_QUERY_PARAMS_DELEGATE_H_
+#define APPS_SHELL_BROWSER_SHELL_OMAHA_QUERY_PARAMS_DELEGATE_H_
+
+#include "components/omaha_query_params/omaha_query_params_delegate.h"
+
+namespace extensions {
+
+class ShellOmahaQueryParamsDelegate
+ : public omaha_query_params::OmahaQueryParamsDelegate {
+ public:
+ ShellOmahaQueryParamsDelegate();
+ virtual ~ShellOmahaQueryParamsDelegate();
+
+ virtual std::string GetExtraParams() OVERRIDE;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ShellOmahaQueryParamsDelegate);
+};
+
+} // namespace extensions
+
+#endif // APPS_SHELL_BROWSER_SHELL_OMAHA_QUERY_PARAMS_DELEGATE_H_
diff --git a/chrome/browser/DEPS b/chrome/browser/DEPS
index 60e86e4..9d07346 100644
--- a/chrome/browser/DEPS
+++ b/chrome/browser/DEPS
@@ -38,6 +38,7 @@ include_rules = [
"+components/navigation_interception",
"+components/navigation_metrics",
"+components/network_time",
+ "+components/omaha_query_params",
"+components/os_crypt",
"+components/password_manager",
"+components/policy",
diff --git a/chrome/browser/browser_process_impl.cc b/chrome/browser/browser_process_impl.cc
index 44fbf9c..0abb317 100644
--- a/chrome/browser/browser_process_impl.cc
+++ b/chrome/browser/browser_process_impl.cc
@@ -50,6 +50,7 @@
#include "chrome/browser/net/chrome_net_log.h"
#include "chrome/browser/net/crl_set_fetcher.h"
#include "chrome/browser/notifications/notification_ui_manager.h"
+#include "chrome/browser/omaha_query_params/chrome_omaha_query_params_delegate.h"
#include "chrome/browser/plugins/chrome_plugin_service_filter.h"
#include "chrome/browser/plugins/plugin_finder.h"
#include "chrome/browser/prefs/browser_prefs.h"
@@ -78,6 +79,7 @@
#include "components/gcm_driver/gcm_driver.h"
#include "components/metrics/metrics_service.h"
#include "components/network_time/network_time_tracker.h"
+#include "components/omaha_query_params/omaha_query_params.h"
#include "components/policy/core/common/policy_service.h"
#include "components/signin/core/common/profile_management_switches.h"
#include "components/translate/core/browser/translate_download_manager.h"
@@ -202,6 +204,9 @@ BrowserProcessImpl::BrowserProcessImpl(
ExtensionRendererState::GetInstance()->Init();
message_center::MessageCenter::Initialize();
+
+ omaha_query_params::OmahaQueryParams::SetDelegate(
+ ChromeOmahaQueryParamsDelegate::GetInstance());
}
BrowserProcessImpl::~BrowserProcessImpl() {
diff --git a/chrome/browser/component_updater/component_updater_utils.cc b/chrome/browser/component_updater/component_updater_utils.cc
index bd23865..d7ff01b 100644
--- a/chrome/browser/component_updater/component_updater_utils.cc
+++ b/chrome/browser/component_updater/component_updater_utils.cc
@@ -16,14 +16,17 @@
#include "base/sys_info.h"
#include "base/win/windows_version.h"
#include "chrome/browser/component_updater/crx_update_item.h"
-#include "chrome/browser/omaha_query_params/omaha_query_params.h"
+#include "chrome/browser/omaha_query_params/chrome_omaha_query_params_delegate.h"
#include "chrome/common/chrome_version_info.h"
+#include "components/omaha_query_params/omaha_query_params.h"
#include "extensions/common/extension.h"
#include "net/base/load_flags.h"
#include "net/url_request/url_fetcher.h"
#include "net/url_request/url_request_context_getter.h"
#include "net/url_request/url_request_status.h"
+using omaha_query_params::OmahaQueryParams;
+
namespace component_updater {
namespace {
@@ -39,10 +42,12 @@ int GetPhysicalMemoryGB() {
std::string BuildProtocolRequest(const std::string& request_body,
const std::string& additional_attributes) {
- const std::string prod_id(chrome::OmahaQueryParams::GetProdIdString(
- chrome::OmahaQueryParams::CHROME));
+ const std::string prod_id(
+ OmahaQueryParams::GetProdIdString(OmahaQueryParams::CHROME));
const chrome::VersionInfo chrome_version_info;
const std::string chrome_version(chrome_version_info.Version());
+ const std::string channel(ChromeOmahaQueryParamsDelegate::GetChannelString());
+ const std::string lang(ChromeOmahaQueryParamsDelegate::GetLang());
std::string request(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
@@ -58,15 +63,15 @@ std::string BuildProtocolRequest(const std::string& request_body,
"requestid=\"{%s}\" lang=\"%s\" updaterchannel=\"%s\" prodchannel=\"%s\" "
"os=\"%s\" arch=\"%s\" nacl_arch=\"%s\"",
prod_id.c_str(),
- chrome_version.c_str(), // "version"
- chrome_version.c_str(), // "prodversion"
- base::GenerateGUID().c_str(), // "requestid"
- chrome::OmahaQueryParams::GetLang(), // "lang",
- chrome::OmahaQueryParams::GetChannelString(), // "updaterchannel"
- chrome::OmahaQueryParams::GetChannelString(), // "prodchannel"
- chrome::OmahaQueryParams::GetOS(), // "os"
- chrome::OmahaQueryParams::GetArch(), // "arch"
- chrome::OmahaQueryParams::GetNaclArch()); // "nacl_arch"
+ chrome_version.c_str(), // "version"
+ chrome_version.c_str(), // "prodversion"
+ base::GenerateGUID().c_str(), // "requestid"
+ lang.c_str(), // "lang",
+ channel.c_str(), // "updaterchannel"
+ channel.c_str(), // "prodchannel"
+ OmahaQueryParams::GetOS(), // "os"
+ OmahaQueryParams::GetArch(), // "arch"
+ OmahaQueryParams::GetNaclArch()); // "nacl_arch"
#if defined(OS_WIN)
const bool is_wow64(base::win::OSInfo::GetInstance()->wow64_status() ==
base::win::OSInfo::WOW64_ENABLED);
diff --git a/chrome/browser/component_updater/pnacl/pnacl_component_installer.cc b/chrome/browser/component_updater/pnacl/pnacl_component_installer.cc
index afa95ec..aadff205 100644
--- a/chrome/browser/component_updater/pnacl/pnacl_component_installer.cc
+++ b/chrome/browser/component_updater/pnacl/pnacl_component_installer.cc
@@ -26,13 +26,13 @@
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/component_updater/component_updater_service.h"
-#include "chrome/browser/omaha_query_params/omaha_query_params.h"
#include "chrome/common/chrome_paths.h"
#include "components/nacl/common/nacl_switches.h"
+#include "components/omaha_query_params/omaha_query_params.h"
#include "content/public/browser/browser_thread.h"
-using chrome::OmahaQueryParams;
using content::BrowserThread;
+using omaha_query_params::OmahaQueryParams;
namespace component_updater {
diff --git a/chrome/browser/extensions/api/runtime/chrome_runtime_api_delegate.cc b/chrome/browser/extensions/api/runtime/chrome_runtime_api_delegate.cc
index 9af0600..bc743e9 100644
--- a/chrome/browser/extensions/api/runtime/chrome_runtime_api_delegate.cc
+++ b/chrome/browser/extensions/api/runtime/chrome_runtime_api_delegate.cc
@@ -12,11 +12,11 @@
#include "chrome/browser/extensions/extension_warning_service.h"
#include "chrome/browser/extensions/extension_warning_set.h"
#include "chrome/browser/extensions/updater/extension_updater.h"
-#include "chrome/browser/omaha_query_params/omaha_query_params.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_navigator.h"
#include "chrome/browser/ui/browser_window.h"
+#include "components/omaha_query_params/omaha_query_params.h"
#include "content/public/browser/notification_service.h"
#include "extensions/browser/extension_system.h"
#include "extensions/common/api/runtime.h"
@@ -183,7 +183,7 @@ void ChromeRuntimeAPIDelegate::OpenURL(const GURL& uninstall_url) {
}
bool ChromeRuntimeAPIDelegate::GetPlatformInfo(PlatformInfo* info) {
- const char* os = chrome::OmahaQueryParams::GetOS();
+ const char* os = omaha_query_params::OmahaQueryParams::GetOS();
if (strcmp(os, "mac") == 0) {
info->os = PlatformInfo::OS_MAC_;
} else if (strcmp(os, "win") == 0) {
@@ -201,7 +201,7 @@ bool ChromeRuntimeAPIDelegate::GetPlatformInfo(PlatformInfo* info) {
return false;
}
- const char* arch = chrome::OmahaQueryParams::GetArch();
+ const char* arch = omaha_query_params::OmahaQueryParams::GetArch();
if (strcmp(arch, "arm") == 0) {
info->arch = PlatformInfo::ARCH_ARM;
} else if (strcmp(arch, "x86") == 0) {
@@ -213,7 +213,7 @@ bool ChromeRuntimeAPIDelegate::GetPlatformInfo(PlatformInfo* info) {
return false;
}
- const char* nacl_arch = chrome::OmahaQueryParams::GetNaclArch();
+ const char* nacl_arch = omaha_query_params::OmahaQueryParams::GetNaclArch();
if (strcmp(nacl_arch, "arm") == 0) {
info->nacl_arch = PlatformInfo::NACL_ARCH_ARM;
} else if (strcmp(nacl_arch, "x86-32") == 0) {
diff --git a/chrome/browser/extensions/updater/extension_updater_unittest.cc b/chrome/browser/extensions/updater/extension_updater_unittest.cc
index 0342d8c..ec362c8 100644
--- a/chrome/browser/extensions/updater/extension_updater_unittest.cc
+++ b/chrome/browser/extensions/updater/extension_updater_unittest.cc
@@ -36,10 +36,10 @@
#include "chrome/browser/extensions/updater/manifest_fetch_data.h"
#include "chrome/browser/extensions/updater/request_queue_impl.h"
#include "chrome/browser/google/google_brand.h"
-#include "chrome/browser/omaha_query_params/omaha_query_params.h"
#include "chrome/browser/prefs/pref_service_syncable.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_profile.h"
+#include "components/omaha_query_params/omaha_query_params.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
@@ -508,8 +508,8 @@ static void VerifyQueryAndExtractParameters(
std::map<std::string, std::string> params;
ExtractParameters(query, &params);
- std::string omaha_params =
- chrome::OmahaQueryParams::Get(chrome::OmahaQueryParams::CRX);
+ std::string omaha_params = omaha_query_params::OmahaQueryParams::Get(
+ omaha_query_params::OmahaQueryParams::CRX);
std::map<std::string, std::string> expected;
ExtractParameters(omaha_params, &expected);
diff --git a/chrome/browser/extensions/updater/manifest_fetch_data.cc b/chrome/browser/extensions/updater/manifest_fetch_data.cc
index 9ab495f..4190cbf 100644
--- a/chrome/browser/extensions/updater/manifest_fetch_data.cc
+++ b/chrome/browser/extensions/updater/manifest_fetch_data.cc
@@ -12,7 +12,7 @@
#include "base/strings/string_util.h"
#include "chrome/browser/google/google_brand.h"
#include "chrome/browser/metrics/chrome_metrics_service_accessor.h"
-#include "chrome/browser/omaha_query_params/omaha_query_params.h"
+#include "components/omaha_query_params/omaha_query_params.h"
#include "net/base/escape.h"
namespace {
@@ -30,7 +30,8 @@ ManifestFetchData::ManifestFetchData(const GURL& update_url, int request_id)
full_url_(update_url) {
std::string query = full_url_.has_query() ?
full_url_.query() + "&" : std::string();
- query += chrome::OmahaQueryParams::Get(chrome::OmahaQueryParams::CRX);
+ query += omaha_query_params::OmahaQueryParams::Get(
+ omaha_query_params::OmahaQueryParams::CRX);
GURL::Replacements replacements;
replacements.SetQueryStr(query);
full_url_ = full_url_.ReplaceComponents(replacements);
diff --git a/chrome/browser/extensions/webstore_installer.cc b/chrome/browser/extensions/webstore_installer.cc
index c3d566f..c7279fd 100644
--- a/chrome/browser/extensions/webstore_installer.cc
+++ b/chrome/browser/extensions/webstore_installer.cc
@@ -29,13 +29,13 @@
#include "chrome/browser/extensions/install_tracker_factory.h"
#include "chrome/browser/extensions/install_verifier.h"
#include "chrome/browser/extensions/shared_module_service.h"
-#include "chrome/browser/omaha_query_params/omaha_query_params.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/extension_constants.h"
+#include "components/omaha_query_params/omaha_query_params.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/download_manager.h"
#include "content/public/browser/download_save_info.h"
@@ -60,7 +60,6 @@
#include "chrome/browser/chromeos/drive/file_system_util.h"
#endif
-using chrome::OmahaQueryParams;
using content::BrowserContext;
using content::BrowserThread;
using content::DownloadItem;
@@ -202,8 +201,9 @@ GURL WebstoreInstaller::GetWebstoreInstallURL(
std::string url_string = extension_urls::GetWebstoreUpdateUrl().spec();
GURL url(url_string + "?response=redirect&" +
- OmahaQueryParams::Get(OmahaQueryParams::CRX) + "&x=" +
- net::EscapeQueryParamValue(JoinString(params, '&'), true));
+ omaha_query_params::OmahaQueryParams::Get(
+ omaha_query_params::OmahaQueryParams::CRX) +
+ "&x=" + net::EscapeQueryParamValue(JoinString(params, '&'), true));
DCHECK(url.is_valid());
return url;
diff --git a/chrome/browser/extensions/webstore_installer_unittest.cc b/chrome/browser/extensions/webstore_installer_unittest.cc
index c117003..fbc48cb 100644
--- a/chrome/browser/extensions/webstore_installer_unittest.cc
+++ b/chrome/browser/extensions/webstore_installer_unittest.cc
@@ -6,13 +6,14 @@
#include "base/strings/stringprintf.h"
#include "chrome/browser/extensions/webstore_installer.h"
-#include "chrome/browser/omaha_query_params/omaha_query_params.h"
+#include "chrome/browser/omaha_query_params/chrome_omaha_query_params_delegate.h"
+#include "components/omaha_query_params/omaha_query_params.h"
#include "extensions/common/id_util.h"
#include "net/base/escape.h"
#include "testing/gtest/include/gtest/gtest.h"
using base::StringPrintf;
-using chrome::OmahaQueryParams;
+using omaha_query_params::OmahaQueryParams;
namespace extensions {
@@ -37,8 +38,9 @@ TEST(WebstoreInstallerTest, PlatformParams) {
Contains(query,
net::EscapeQueryParamValue(
StringPrintf("installsource=%s", source.c_str()), true)));
- EXPECT_TRUE(
- Contains(query, StringPrintf("lang=%s", OmahaQueryParams::GetLang())));
+ EXPECT_TRUE(Contains(
+ query,
+ StringPrintf("lang=%s", ChromeOmahaQueryParamsDelegate::GetLang())));
}
} // namespace extensions
diff --git a/chrome/browser/omaha_query_params/chrome_omaha_query_params_delegate.cc b/chrome/browser/omaha_query_params/chrome_omaha_query_params_delegate.cc
new file mode 100644
index 0000000..40d1eed
--- /dev/null
+++ b/chrome/browser/omaha_query_params/chrome_omaha_query_params_delegate.cc
@@ -0,0 +1,68 @@
+// Copyright 2014 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/omaha_query_params/chrome_omaha_query_params_delegate.h"
+
+#include "base/lazy_instance.h"
+#include "base/strings/stringprintf.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/common/chrome_version_info.h"
+
+namespace {
+
+const char kUnknown[] = "unknown";
+const char kStable[] = "stable";
+const char kBeta[] = "beta";
+const char kDev[] = "dev";
+const char kCanary[] = "canary";
+
+base::LazyInstance<ChromeOmahaQueryParamsDelegate> g_delegate =
+ LAZY_INSTANCE_INITIALIZER;
+
+} // namespace
+
+ChromeOmahaQueryParamsDelegate::ChromeOmahaQueryParamsDelegate() {
+}
+
+ChromeOmahaQueryParamsDelegate::~ChromeOmahaQueryParamsDelegate() {
+}
+
+// static
+ChromeOmahaQueryParamsDelegate* ChromeOmahaQueryParamsDelegate::GetInstance() {
+ return g_delegate.Pointer();
+}
+
+std::string ChromeOmahaQueryParamsDelegate::GetExtraParams() {
+ return base::StringPrintf("&prodchannel=%s&prodversion=%s&lang=%s",
+ GetChannelString(),
+ chrome::VersionInfo().Version().c_str(),
+ GetLang());
+}
+
+// static
+const char* ChromeOmahaQueryParamsDelegate::GetChannelString() {
+ switch (chrome::VersionInfo::GetChannel()) {
+ case chrome::VersionInfo::CHANNEL_STABLE:
+ return kStable;
+ break;
+ case chrome::VersionInfo::CHANNEL_BETA:
+ return kBeta;
+ break;
+ case chrome::VersionInfo::CHANNEL_DEV:
+ return kDev;
+ break;
+ case chrome::VersionInfo::CHANNEL_CANARY:
+ return kCanary;
+ break;
+ case chrome::VersionInfo::CHANNEL_UNKNOWN:
+ return kUnknown;
+ break;
+ }
+ return kUnknown;
+}
+
+// static
+const char* ChromeOmahaQueryParamsDelegate::GetLang() {
+ return g_browser_process->GetApplicationLocale().c_str();
+}
diff --git a/chrome/browser/omaha_query_params/chrome_omaha_query_params_delegate.h b/chrome/browser/omaha_query_params/chrome_omaha_query_params_delegate.h
new file mode 100644
index 0000000..26921c2
--- /dev/null
+++ b/chrome/browser/omaha_query_params/chrome_omaha_query_params_delegate.h
@@ -0,0 +1,35 @@
+// Copyright 2014 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_OMAHA_QUERY_PARAMS_CHROME_OMAHA_QUERY_PARAMS_DELEGATE_H_
+#define CHROME_BROWSER_OMAHA_QUERY_PARAMS_CHROME_OMAHA_QUERY_PARAMS_DELEGATE_H_
+
+#include "components/omaha_query_params/omaha_query_params_delegate.h"
+
+class ChromeOmahaQueryParamsDelegate
+ : public omaha_query_params::OmahaQueryParamsDelegate {
+ public:
+ ChromeOmahaQueryParamsDelegate();
+ virtual ~ChromeOmahaQueryParamsDelegate();
+
+ // Gets the LazyInstance for ChromeOmahaQueryParamsDelegate.
+ static ChromeOmahaQueryParamsDelegate* GetInstance();
+
+ // omaha_query_params::OmahaQueryParamsDelegate:
+ virtual std::string GetExtraParams() OVERRIDE;
+
+ // Returns the value we use for the "updaterchannel=" and "prodchannel="
+ // parameters. Possible return values include: "canary", "dev", "beta", and
+ // "stable".
+ static const char* GetChannelString();
+
+ // Returns the language for the present locale. Possible return values are
+ // standard tags for languages, such as "en", "en-US", "de", "fr", "af", etc.
+ static const char* GetLang();
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ChromeOmahaQueryParamsDelegate);
+};
+
+#endif // CHROME_BROWSER_OMAHA_QUERY_PARAMS_CHROME_OMAHA_QUERY_PARAMS_DELEGATE_H_
diff --git a/chrome/browser/omaha_query_params/chrome_omaha_query_params_delegate_unittest.cc b/chrome/browser/omaha_query_params/chrome_omaha_query_params_delegate_unittest.cc
new file mode 100644
index 0000000..f35375f
--- /dev/null
+++ b/chrome/browser/omaha_query_params/chrome_omaha_query_params_delegate_unittest.cc
@@ -0,0 +1,51 @@
+// Copyright 2014 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 "base/strings/stringprintf.h"
+#include "chrome/browser/omaha_query_params/chrome_omaha_query_params_delegate.h"
+#include "chrome/common/chrome_version_info.h"
+#include "components/omaha_query_params/omaha_query_params.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using base::StringPrintf;
+
+namespace {
+
+bool Contains(const std::string& source, const std::string& target) {
+ return source.find(target) != std::string::npos;
+}
+
+} // namespace
+
+void TestParams(omaha_query_params::OmahaQueryParams::ProdId prod_id) {
+ std::string params = omaha_query_params::OmahaQueryParams::Get(prod_id);
+
+ EXPECT_TRUE(Contains(
+ params,
+ StringPrintf("os=%s", omaha_query_params::OmahaQueryParams::GetOS())));
+ EXPECT_TRUE(
+ Contains(params,
+ StringPrintf("arch=%s",
+ omaha_query_params::OmahaQueryParams::GetArch())));
+ EXPECT_TRUE(Contains(
+ params,
+ StringPrintf(
+ "prod=%s",
+ omaha_query_params::OmahaQueryParams::GetProdIdString(prod_id))));
+ EXPECT_TRUE(Contains(
+ params,
+ StringPrintf("prodchannel=%s",
+ ChromeOmahaQueryParamsDelegate::GetChannelString())));
+ EXPECT_TRUE(Contains(
+ params,
+ StringPrintf("prodversion=%s", chrome::VersionInfo().Version().c_str())));
+ EXPECT_TRUE(Contains(
+ params,
+ StringPrintf("lang=%s", ChromeOmahaQueryParamsDelegate::GetLang())));
+}
+
+TEST(ChromeOmahaQueryParamsDelegateTest, GetParams) {
+ TestParams(omaha_query_params::OmahaQueryParams::CRX);
+ TestParams(omaha_query_params::OmahaQueryParams::CHROME);
+}
diff --git a/chrome/browser/ui/webui/app_list/start_page_handler.cc b/chrome/browser/ui/webui/app_list/start_page_handler.cc
index fc6a9d5..f08b082 100644
--- a/chrome/browser/ui/webui/app_list/start_page_handler.cc
+++ b/chrome/browser/ui/webui/app_list/start_page_handler.cc
@@ -10,7 +10,6 @@
#include "base/memory/scoped_ptr.h"
#include "base/values.h"
#include "base/version.h"
-#include "chrome/browser/omaha_query_params/omaha_query_params.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search/hotword_service.h"
#include "chrome/browser/ui/app_list/app_list_controller_delegate.h"
@@ -20,6 +19,7 @@
#include "chrome/browser/ui/host_desktop.h"
#include "chrome/browser/ui/webui/extensions/extension_icon_source.h"
#include "chrome/common/pref_names.h"
+#include "components/omaha_query_params/omaha_query_params.h"
#include "content/public/browser/web_ui.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
@@ -181,7 +181,7 @@ void StartPageHandler::HandleInitialize(const base::ListValue* args) {
web_ui()->CallJavascriptFunction(
"appList.startPage.setNaclArch",
- base::StringValue(chrome::OmahaQueryParams::GetNaclArch()));
+ base::StringValue(omaha_query_params::OmahaQueryParams::GetNaclArch()));
if (!app_list::switches::IsExperimentalAppListEnabled()) {
web_ui()->CallJavascriptFunction(
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index af05255..e5820df 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -1126,8 +1126,8 @@
'browser/net/timed_cache.h',
'browser/net/url_info.cc',
'browser/net/url_info.h',
- 'browser/omaha_query_params/omaha_query_params.h',
- 'browser/omaha_query_params/omaha_query_params.cc',
+ 'browser/omaha_query_params/chrome_omaha_query_params_delegate.cc',
+ 'browser/omaha_query_params/chrome_omaha_query_params_delegate.h',
'browser/omnibox/omnibox_field_trial.cc',
'browser/omnibox/omnibox_field_trial.h',
'browser/omnibox/omnibox_log.cc',
@@ -2710,6 +2710,7 @@
'../components/components.gyp:metrics_net',
'../components/components.gyp:navigation_metrics',
'../components/components.gyp:network_time',
+ '../components/components.gyp:omaha_query_params',
'../components/components.gyp:os_crypt',
'../components/components.gyp:password_manager_core_browser',
'../components/components.gyp:password_manager_core_common',
diff --git a/chrome/chrome_browser_extensions.gypi b/chrome/chrome_browser_extensions.gypi
index a330395..50edc48 100644
--- a/chrome/chrome_browser_extensions.gypi
+++ b/chrome/chrome_browser_extensions.gypi
@@ -29,6 +29,7 @@
'safe_browsing_proto',
'sync_file_system_proto',
'../third_party/re2/re2.gyp:re2',
+ '../components/components.gyp:omaha_query_params',
'../components/components.gyp:onc_component',
'../components/components.gyp:url_matcher',
'../components/components_strings.gyp:components_strings',
diff --git a/chrome/chrome_browser_ui.gypi b/chrome/chrome_browser_ui.gypi
index e0ddcbd..63d3b05 100644
--- a/chrome/chrome_browser_ui.gypi
+++ b/chrome/chrome_browser_ui.gypi
@@ -2600,6 +2600,7 @@
'../components/components.gyp:dom_distiller_webui',
'../components/components.gyp:feedback_proto',
'../components/components.gyp:invalidation',
+ '../components/components.gyp:omaha_query_params',
'../components/components.gyp:onc_component',
'../components/components.gyp:password_manager_core_browser',
'../components/components_resources.gyp:components_resources',
diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi
index 27330a0..dfd6267 100644
--- a/chrome/chrome_tests_unit.gypi
+++ b/chrome/chrome_tests_unit.gypi
@@ -1148,8 +1148,8 @@
'browser/notifications/sync_notifier/sync_notifier_test_utils.cc',
'browser/notifications/sync_notifier/sync_notifier_test_utils.h',
'browser/notifications/sync_notifier/welcome_delegate_unittest.cc',
+ 'browser/omaha_query_params/chrome_omaha_query_params_delegate_unittest.cc',
'browser/omnibox/omnibox_field_trial_unittest.cc',
- 'browser/omaha_query_params/omaha_query_params_unittest.cc',
'browser/parsers/metadata_parser_filebase_unittest.cc',
'browser/password_manager/chrome_password_manager_client_unittest.cc',
'browser/password_manager/native_backend_gnome_x_unittest.cc',
diff --git a/chrome/test/base/chrome_unit_test_suite.cc b/chrome/test/base/chrome_unit_test_suite.cc
index 9e40a65..48cbb63 100644
--- a/chrome/test/base/chrome_unit_test_suite.cc
+++ b/chrome/test/base/chrome_unit_test_suite.cc
@@ -9,10 +9,12 @@
#include "base/metrics/stats_table.h"
#include "base/strings/stringprintf.h"
#include "chrome/browser/chrome_content_browser_client.h"
+#include "chrome/browser/omaha_query_params/chrome_omaha_query_params_delegate.h"
#include "chrome/common/chrome_content_client.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/utility/chrome_content_utility_client.h"
+#include "components/omaha_query_params/omaha_query_params.h"
#include "content/public/common/content_paths.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/resource/resource_bundle.h"
@@ -144,6 +146,9 @@ void ChromeUnitTestSuite::InitializeProviders() {
ChromeWebUIControllerFactory::GetInstance());
gfx::GLSurface::InitializeOneOffForTests();
+
+ omaha_query_params::OmahaQueryParams::SetDelegate(
+ ChromeOmahaQueryParamsDelegate::GetInstance());
#endif
}
diff --git a/components/components.gyp b/components/components.gyp
index b0ee53c..903402d 100644
--- a/components/components.gyp
+++ b/components/components.gyp
@@ -34,6 +34,7 @@
'metrics.gypi',
'navigation_metrics.gypi',
'network_time.gypi',
+ 'omaha_query_params.gypi',
'onc.gypi',
'os_crypt.gypi',
'password_manager.gypi',
diff --git a/components/components_tests.gyp b/components/components_tests.gyp
index a49b664..8a7e618 100644
--- a/components/components_tests.gyp
+++ b/components/components_tests.gyp
@@ -130,6 +130,7 @@
'metrics/persisted_logs_unittest.cc',
'navigation_interception/intercept_navigation_resource_throttle_unittest.cc',
'network_time/network_time_tracker_unittest.cc',
+ 'omaha_query_params/omaha_query_params_unittest.cc',
'os_crypt/ie7_password_win_unittest.cc',
'os_crypt/keychain_password_mac_unittest.mm',
'os_crypt/os_crypt_unittest.cc',
@@ -304,6 +305,9 @@
# Dependencies of network_time
'components.gyp:network_time',
+ # Dependencies of omaha_query_params
+ 'components.gyp:omaha_query_params',
+
# Dependencies of os_crypt
'components.gyp:os_crypt',
diff --git a/components/omaha_query_params.gypi b/components/omaha_query_params.gypi
new file mode 100644
index 0000000..8994532c
--- /dev/null
+++ b/components/omaha_query_params.gypi
@@ -0,0 +1,24 @@
+# Copyright 2014 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.
+
+{
+ 'targets': [
+ {
+ 'target_name': 'omaha_query_params',
+ 'type': 'static_library',
+ 'include_dirs': [
+ '..',
+ ],
+ 'dependencies': [
+ '../base/base.gyp:base',
+ ],
+ 'sources': [
+ 'omaha_query_params/omaha_query_params.cc',
+ 'omaha_query_params/omaha_query_params.h',
+ 'omaha_query_params/omaha_query_params_delegate.cc',
+ 'omaha_query_params/omaha_query_params_delegate.h',
+ ],
+ },
+ ],
+}
diff --git a/components/omaha_query_params/DEPS b/components/omaha_query_params/DEPS
new file mode 100644
index 0000000..beabace
--- /dev/null
+++ b/components/omaha_query_params/DEPS
@@ -0,0 +1,4 @@
+include_rules = [
+ "+base",
+ "+testing",
+]
diff --git a/components/omaha_query_params/OWNERS b/components/omaha_query_params/OWNERS
new file mode 100644
index 0000000..c089b54
--- /dev/null
+++ b/components/omaha_query_params/OWNERS
@@ -0,0 +1,2 @@
+asargent@chromium.org
+cpu@chromium.org
diff --git a/chrome/browser/omaha_query_params/omaha_query_params.cc b/components/omaha_query_params/omaha_query_params.cc
index df4e604..b04116db 100644
--- a/chrome/browser/omaha_query_params/omaha_query_params.cc
+++ b/components/omaha_query_params/omaha_query_params.cc
@@ -2,13 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/omaha_query_params/omaha_query_params.h"
+#include "components/omaha_query_params/omaha_query_params.h"
#include "base/compiler_specific.h"
+#include "base/logging.h"
#include "base/strings/stringprintf.h"
#include "base/win/windows_version.h"
-#include "chrome/browser/browser_process.h"
-#include "chrome/common/chrome_version_info.h"
+#include "components/omaha_query_params/omaha_query_params_delegate.h"
+
+namespace omaha_query_params {
namespace {
@@ -50,43 +52,34 @@ const char kArch[] =
const char kChrome[] = "chrome";
-const char kStable[] = "stable";
-const char kBeta[] = "beta";
-const char kDev[] = "dev";
-const char kCanary[] = "canary";
-
#if defined(GOOGLE_CHROME_BUILD)
const char kChromeCrx[] = "chromecrx";
#else
const char kChromiumCrx[] = "chromiumcrx";
#endif // defined(GOOGLE_CHROME_BUILD)
-} // namespace
+OmahaQueryParamsDelegate* g_delegate = NULL;
-namespace chrome {
+} // namespace
// static
std::string OmahaQueryParams::Get(ProdId prod) {
return base::StringPrintf(
- "os=%s&arch=%s&nacl_arch=%s&prod=%s&prodchannel=%s"
- "&prodversion=%s&lang=%s",
+ "os=%s&arch=%s&nacl_arch=%s&prod=%s%s",
kOs,
kArch,
GetNaclArch(),
GetProdIdString(prod),
- GetChannelString(),
- chrome::VersionInfo().Version().c_str(),
- GetLang());
+ g_delegate ? g_delegate->GetExtraParams().c_str() : "");
}
// static
-const char* OmahaQueryParams::GetProdIdString(
- chrome::OmahaQueryParams::ProdId prod) {
+const char* OmahaQueryParams::GetProdIdString(OmahaQueryParams::ProdId prod) {
switch (prod) {
- case chrome::OmahaQueryParams::CHROME:
+ case OmahaQueryParams::CHROME:
return kChrome;
break;
- case chrome::OmahaQueryParams::CRX:
+ case OmahaQueryParams::CRX:
#if defined(GOOGLE_CHROME_BUILD)
return kChromeCrx;
#else
@@ -132,29 +125,10 @@ const char* OmahaQueryParams::GetNaclArch() {
#endif
}
-const char* OmahaQueryParams::GetChannelString() {
- switch (chrome::VersionInfo::GetChannel()) {
- case chrome::VersionInfo::CHANNEL_STABLE:
- return kStable;
- break;
- case chrome::VersionInfo::CHANNEL_BETA:
- return kBeta;
- break;
- case chrome::VersionInfo::CHANNEL_DEV:
- return kDev;
- break;
- case chrome::VersionInfo::CHANNEL_CANARY:
- return kCanary;
- break;
- case chrome::VersionInfo::CHANNEL_UNKNOWN:
- return kUnknown;
- break;
- }
- return kUnknown;
-}
-
-const char* OmahaQueryParams::GetLang() {
- return g_browser_process->GetApplicationLocale().c_str();
+// static
+void OmahaQueryParams::SetDelegate(OmahaQueryParamsDelegate* delegate) {
+ DCHECK(!g_delegate || !delegate);
+ g_delegate = delegate;
}
-} // namespace chrome
+} // namespace omaha_query_params
diff --git a/chrome/browser/omaha_query_params/omaha_query_params.h b/components/omaha_query_params/omaha_query_params.h
index ac37c3a..d92798a 100644
--- a/chrome/browser/omaha_query_params/omaha_query_params.h
+++ b/components/omaha_query_params/omaha_query_params.h
@@ -2,15 +2,22 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CHROME_BROWSER_OMAHA_QUERY_PARAMS_OMAHA_QUERY_PARAMS_H_
-#define CHROME_BROWSER_OMAHA_QUERY_PARAMS_OMAHA_QUERY_PARAMS_H_
+#ifndef COMPONENTS_OMAHA_QUERY_PARAMS_OMAHA_QUERY_PARAMS_H_
+#define COMPONENTS_OMAHA_QUERY_PARAMS_OMAHA_QUERY_PARAMS_H_
#include <string>
#include "base/basictypes.h"
-namespace chrome {
+namespace omaha_query_params {
+class OmahaQueryParamsDelegate;
+
+// Generates a string of URL query parameters to be used when getting
+// component and extension updates. These parameters generally remain
+// fixed for a particular build. Embedders can use the delegate to
+// define different implementations. This should be used only in the
+// browser process.
class OmahaQueryParams {
public:
enum ProdId {
@@ -18,14 +25,13 @@ class OmahaQueryParams {
CRX,
};
- // Generates a string of URL query paramaters to be used when getting
- // component and extension updates. Includes the following fields: os, arch,
- // prod, prodchannel, prodversion, lang.
+ // Generates a string of URL query parameters for Omaha. Includes the
+ // following fields: os, arch, prod, prodchannel, prodversion, lang.
static std::string Get(ProdId prod);
// Returns the value we use for the "prod=" parameter. Possible return values
// include "chrome", "chromecrx", "chromiumcrx", and "unknown".
- static const char* GetProdIdString(chrome::OmahaQueryParams::ProdId prod);
+ static const char* GetProdIdString(ProdId prod);
// Returns the value we use for the "os=" parameter. Possible return values
// include: "mac", "win", "android", "cros", "linux", and "openbsd".
@@ -41,19 +47,13 @@ class OmahaQueryParams {
// "arm", and "mips32".
static const char* GetNaclArch();
- // Returns the value we use for the "updaterchannel=" and "prodchannel="
- // parameters. Possible return values include: "canary", "dev", "beta", and
- // "stable".
- static const char* GetChannelString();
-
- // Returns the language for the present locale. Possible return values are
- // standard tags for languages, such as "en", "en-US", "de", "fr", "af", etc.
- static const char* GetLang();
+ // Use this delegate.
+ static void SetDelegate(OmahaQueryParamsDelegate* delegate);
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(OmahaQueryParams);
};
-} // namespace chrome
+} // namespace omaha_query_params
-#endif // CHROME_BROWSER_OMAHA_QUERY_PARAMS_OMAHA_QUERY_PARAMS_H_
+#endif // COMPONENTS_OMAHA_QUERY_PARAMS_OMAHA_QUERY_PARAMS_H_
diff --git a/components/omaha_query_params/omaha_query_params_delegate.cc b/components/omaha_query_params/omaha_query_params_delegate.cc
new file mode 100644
index 0000000..9d79a94
--- /dev/null
+++ b/components/omaha_query_params/omaha_query_params_delegate.cc
@@ -0,0 +1,15 @@
+// Copyright 2014 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 "components/omaha_query_params/omaha_query_params_delegate.h"
+
+namespace omaha_query_params {
+
+OmahaQueryParamsDelegate::OmahaQueryParamsDelegate() {
+}
+
+OmahaQueryParamsDelegate::~OmahaQueryParamsDelegate() {
+}
+
+} // namespace omaha_query_params
diff --git a/components/omaha_query_params/omaha_query_params_delegate.h b/components/omaha_query_params/omaha_query_params_delegate.h
new file mode 100644
index 0000000..ebea760
--- /dev/null
+++ b/components/omaha_query_params/omaha_query_params_delegate.h
@@ -0,0 +1,32 @@
+// Copyright 2014 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 COMPONENTS_OMAHA_QUERY_PARAMS_OMAHA_QUERY_PARAMS_DELEGATE_H_
+#define COMPONENTS_OMAHA_QUERY_PARAMS_OMAHA_QUERY_PARAMS_DELEGATE_H_
+
+#include <string>
+
+#include "base/basictypes.h"
+
+namespace omaha_query_params {
+
+// Embedders can specify an OmahaQueryParamsDelegate to provide additional
+// custom parameters. If not specified (Set is never called), no additional
+// parameters are added.
+class OmahaQueryParamsDelegate {
+ public:
+ OmahaQueryParamsDelegate();
+ virtual ~OmahaQueryParamsDelegate();
+
+ // Returns additional parameters, if any. If there are any parameters, the
+ // string should begin with a & character.
+ virtual std::string GetExtraParams() = 0;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(OmahaQueryParamsDelegate);
+};
+
+} // namespace omaha_query_params
+
+#endif // COMPONENTS_OMAHA_QUERY_PARAMS_OMAHA_QUERY_PARAMS_DELEGATE_H_
diff --git a/chrome/browser/omaha_query_params/omaha_query_params_unittest.cc b/components/omaha_query_params/omaha_query_params_unittest.cc
index e8a736a..37a97e9 100644
--- a/chrome/browser/omaha_query_params/omaha_query_params_unittest.cc
+++ b/components/omaha_query_params/omaha_query_params_unittest.cc
@@ -2,21 +2,28 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/omaha_query_params/omaha_query_params.h"
-
#include "base/strings/stringprintf.h"
-#include "chrome/common/chrome_version_info.h"
+#include "components/omaha_query_params/omaha_query_params.h"
+#include "components/omaha_query_params/omaha_query_params_delegate.h"
#include "testing/gtest/include/gtest/gtest.h"
using base::StringPrintf;
-namespace chrome {
+namespace omaha_query_params {
+
+namespace {
bool Contains(const std::string& source, const std::string& target) {
return source.find(target) != std::string::npos;
}
-void TestParams(OmahaQueryParams::ProdId prod_id) {
+class TestOmahaQueryParamsDelegate : public OmahaQueryParamsDelegate {
+ virtual std::string GetExtraParams() OVERRIDE { return "&cat=dog"; }
+};
+
+} // namespace
+
+void TestParams(OmahaQueryParams::ProdId prod_id, bool extra_params) {
std::string params = OmahaQueryParams::Get(prod_id);
// This doesn't so much test what the values are (since that would be an
@@ -30,20 +37,19 @@ void TestParams(OmahaQueryParams::ProdId prod_id) {
EXPECT_TRUE(Contains(
params,
StringPrintf("prod=%s", OmahaQueryParams::GetProdIdString(prod_id))));
- EXPECT_TRUE(Contains(
- params,
- StringPrintf("prodchannel=%s", OmahaQueryParams::GetChannelString())));
- EXPECT_TRUE(Contains(
- params,
- StringPrintf("prodversion=%s", chrome::VersionInfo().Version().c_str())));
- EXPECT_TRUE(Contains(
- params,
- StringPrintf("lang=%s", OmahaQueryParams::GetLang())));
+ if (extra_params)
+ EXPECT_TRUE(Contains(params, "cat=dog"));
}
-TEST(OmahaQueryParams, GetOmahaQueryParams) {
- TestParams(OmahaQueryParams::CRX);
- TestParams(OmahaQueryParams::CHROME);
+TEST(OmahaQueryParamsTest, GetParams) {
+ TestParams(OmahaQueryParams::CRX, false);
+ TestParams(OmahaQueryParams::CHROME, false);
+
+ TestOmahaQueryParamsDelegate delegate;
+ OmahaQueryParams::SetDelegate(&delegate);
+
+ TestParams(OmahaQueryParams::CRX, true);
+ TestParams(OmahaQueryParams::CHROME, true);
}
-} // namespace chrome
+} // namespace omaha_query_params