Skip to content

Commit

Permalink
Move OmahaQueryParams to a component and add a delegate interface.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
yoz@chromium.org committed Jun 26, 2014
1 parent 3a4bd5d commit 8f4b69e
Show file tree
Hide file tree
Showing 34 changed files with 414 additions and 116 deletions.
3 changes: 3 additions & 0 deletions apps/shell/app_shell.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions apps/shell/browser/DEPS
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
include_rules = [
"+chromeos",
"+components/omaha_query_params",
"+components/pref_registry",
"+components/user_prefs",
"+third_party/cros_system_api",
Expand Down
7 changes: 7 additions & 0 deletions apps/shell/browser/shell_browser_main_parts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down
5 changes: 3 additions & 2 deletions apps/shell/browser/shell_browser_main_parts.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
#include "ui/aura/window_tree_host_observer.h"

namespace content {
class ShellBrowserContext;
class ShellDevToolsDelegate;
struct MainFunctionParams;
}

namespace extensions {
class ShellExtensionsBrowserClient;
class ShellExtensionSystem;
class ShellOmahaQueryParamsDelegate;
}

namespace views {
Expand Down Expand Up @@ -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_;
Expand Down
22 changes: 22 additions & 0 deletions apps/shell/browser/shell_omaha_query_params_delegate.cc
Original file line number Diff line number Diff line change
@@ -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
26 changes: 26 additions & 0 deletions apps/shell/browser/shell_omaha_query_params_delegate.h
Original file line number Diff line number Diff line change
@@ -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_
1 change: 1 addition & 0 deletions chrome/browser/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions chrome/browser/browser_process_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -202,6 +204,9 @@ BrowserProcessImpl::BrowserProcessImpl(
ExtensionRendererState::GetInstance()->Init();

message_center::MessageCenter::Initialize();

omaha_query_params::OmahaQueryParams::SetDelegate(
ChromeOmahaQueryParamsDelegate::GetInstance());
}

BrowserProcessImpl::~BrowserProcessImpl() {
Expand Down
29 changes: 17 additions & 12 deletions chrome/browser/component_updater/component_updater_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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\"?>"
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);

Expand Down
5 changes: 3 additions & 2 deletions chrome/browser/extensions/updater/manifest_fetch_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions chrome/browser/extensions/webstore_installer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 6 additions & 4 deletions chrome/browser/extensions/webstore_installer_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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
Loading

0 comments on commit 8f4b69e

Please sign in to comment.