diff options
author | sorin <sorin@chromium.org> | 2015-01-05 17:09:08 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-01-06 01:10:07 +0000 |
commit | 39eab2f9d3d0435422f65c6664276fdd72326f89 (patch) | |
tree | 83a3b3e4a880f6928cc59eeb0a04b6dae4fcc317 /components/update_client | |
parent | d5f87c03637894f86fa9565c86d9dac6160c3616 (diff) | |
download | chromium_src-39eab2f9d3d0435422f65c6664276fdd72326f89.zip chromium_src-39eab2f9d3d0435422f65c6664276fdd72326f89.tar.gz chromium_src-39eab2f9d3d0435422f65c6664276fdd72326f89.tar.bz2 |
Rename omaha_client and similar tokens to update_client in all contexts.
This is a mechanical change.
The idea here is to refactor the common code involved in installing
components and extensions in a common module. In the future, we want
more update-related Chrome stuff to go in this module.
Therefore, it is desirable that this module have a name that describes
its purpose.
BUG=445949
Review URL: https://codereview.chromium.org/803313003
Cr-Commit-Position: refs/heads/master@{#310022}
Diffstat (limited to 'components/update_client')
-rw-r--r-- | components/update_client/BUILD.gn | 16 | ||||
-rw-r--r-- | components/update_client/DEPS | 4 | ||||
-rw-r--r-- | components/update_client/OWNERS | 2 | ||||
-rw-r--r-- | components/update_client/update_query_params.cc | 131 | ||||
-rw-r--r-- | components/update_client/update_query_params.h | 60 | ||||
-rw-r--r-- | components/update_client/update_query_params_delegate.cc | 15 | ||||
-rw-r--r-- | components/update_client/update_query_params_delegate.h | 32 | ||||
-rw-r--r-- | components/update_client/update_query_params_unittest.cc | 55 |
8 files changed, 315 insertions, 0 deletions
diff --git a/components/update_client/BUILD.gn b/components/update_client/BUILD.gn new file mode 100644 index 0000000..d51bd9d --- /dev/null +++ b/components/update_client/BUILD.gn @@ -0,0 +1,16 @@ +# 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. + +source_set("update_client") { + sources = [ + "update_query_params.cc", + "update_query_params.h", + "update_query_params_delegate.cc", + "update_query_params_delegate.h", + ] + + deps = [ + "//base", + ] +} diff --git a/components/update_client/DEPS b/components/update_client/DEPS new file mode 100644 index 0000000..beabace --- /dev/null +++ b/components/update_client/DEPS @@ -0,0 +1,4 @@ +include_rules = [ + "+base", + "+testing", +] diff --git a/components/update_client/OWNERS b/components/update_client/OWNERS new file mode 100644 index 0000000..c089b54 --- /dev/null +++ b/components/update_client/OWNERS @@ -0,0 +1,2 @@ +asargent@chromium.org +cpu@chromium.org diff --git a/components/update_client/update_query_params.cc b/components/update_client/update_query_params.cc new file mode 100644 index 0000000..7bb4db5 --- /dev/null +++ b/components/update_client/update_query_params.cc @@ -0,0 +1,131 @@ +// 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/update_client/update_query_params.h" + +#include "base/compiler_specific.h" +#include "base/logging.h" +#include "base/strings/stringprintf.h" +#include "base/win/windows_version.h" +#include "components/update_client/update_query_params_delegate.h" + +namespace update_client { + +namespace { + +const char kUnknown[] = "unknown"; + +// The request extra information is the OS and architecture, this helps +// the server select the right package to be delivered. +const char kOs[] = +#if defined(OS_MACOSX) + "mac"; +#elif defined(OS_WIN) + "win"; +#elif defined(OS_ANDROID) + "android"; +#elif defined(OS_CHROMEOS) + "cros"; +#elif defined(OS_LINUX) + "linux"; +#elif defined(OS_OPENBSD) + "openbsd"; +#else +#error "unknown os" +#endif + +const char kArch[] = +#if defined(__amd64__) || defined(_WIN64) + "x64"; +#elif defined(__i386__) || defined(_WIN32) + "x86"; +#elif defined(__arm__) + "arm"; +#elif defined(__aarch64__) + "arm64"; +#elif defined(__mips__) + "mipsel"; +#else +#error "unknown arch" +#endif + +const char kChrome[] = "chrome"; + +#if defined(GOOGLE_CHROME_BUILD) +const char kChromeCrx[] = "chromecrx"; +#else +const char kChromiumCrx[] = "chromiumcrx"; +#endif // defined(GOOGLE_CHROME_BUILD) + +UpdateQueryParamsDelegate* g_delegate = NULL; + +} // namespace + +// static +std::string UpdateQueryParams::Get(ProdId prod) { + return base::StringPrintf( + "os=%s&arch=%s&nacl_arch=%s&prod=%s%s", kOs, kArch, GetNaclArch(), + GetProdIdString(prod), + g_delegate ? g_delegate->GetExtraParams().c_str() : ""); +} + +// static +const char* UpdateQueryParams::GetProdIdString(UpdateQueryParams::ProdId prod) { + switch (prod) { + case UpdateQueryParams::CHROME: + return kChrome; + break; + case UpdateQueryParams::CRX: +#if defined(GOOGLE_CHROME_BUILD) + return kChromeCrx; +#else + return kChromiumCrx; +#endif + break; + } + return kUnknown; +} + +// static +const char* UpdateQueryParams::GetOS() { + return kOs; +} + +// static +const char* UpdateQueryParams::GetArch() { + return kArch; +} + +// static +const char* UpdateQueryParams::GetNaclArch() { +#if defined(ARCH_CPU_X86_FAMILY) +#if defined(ARCH_CPU_X86_64) + return "x86-64"; +#elif defined(OS_WIN) + bool x86_64 = (base::win::OSInfo::GetInstance()->wow64_status() == + base::win::OSInfo::WOW64_ENABLED); + return x86_64 ? "x86-64" : "x86-32"; +#else + return "x86-32"; +#endif +#elif defined(ARCH_CPU_ARMEL) + return "arm"; +#elif defined(ARCH_CPU_ARM64) + return "arm64"; +#elif defined(ARCH_CPU_MIPSEL) + return "mips32"; +#else +// NOTE: when adding new values here, please remember to update the +// comment in the .h file about possible return values from this function. +#error "You need to add support for your architecture here" +#endif +} + +// static +void UpdateQueryParams::SetDelegate(UpdateQueryParamsDelegate* delegate) { + DCHECK(!g_delegate || !delegate); + g_delegate = delegate; +} + +} // namespace update_client diff --git a/components/update_client/update_query_params.h b/components/update_client/update_query_params.h new file mode 100644 index 0000000..48f7acf --- /dev/null +++ b/components/update_client/update_query_params.h @@ -0,0 +1,60 @@ +// 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_UPDATE_CLIENT_UPDATE_QUERY_PARAMS_H_ +#define COMPONENTS_UPDATE_CLIENT_UPDATE_QUERY_PARAMS_H_ + +#include <string> + +#include "base/basictypes.h" + +namespace update_client { + +class UpdateQueryParamsDelegate; + +// 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 UpdateQueryParams { + public: + enum ProdId { + CHROME = 0, + CRX, + }; + + // Generates a string of URL query parameters for Omaha. Includes the + // following fields: "os", "arch", "nacl_arch", "prod", "prodchannel", + // "prodversion", and "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(ProdId prod); + + // Returns the value we use for the "os=" parameter. Possible return values + // include: "mac", "win", "android", "cros", "linux", and "openbsd". + static const char* GetOS(); + + // Returns the value we use for the "arch=" parameter. Possible return values + // include: "x86", "x64", and "arm". + static const char* GetArch(); + + // Returns the value we use for the "nacl_arch" parameter. Note that this may + // be different from the "arch" parameter above (e.g. one may be 32-bit and + // the other 64-bit). Possible return values include: "x86-32", "x86-64", + // "arm", and "mips32". + static const char* GetNaclArch(); + + // Use this delegate. + static void SetDelegate(UpdateQueryParamsDelegate* delegate); + + private: + DISALLOW_IMPLICIT_CONSTRUCTORS(UpdateQueryParams); +}; + +} // namespace update_client + +#endif // COMPONENTS_UPDATE_CLIENT_UPDATE_QUERY_PARAMS_H_ diff --git a/components/update_client/update_query_params_delegate.cc b/components/update_client/update_query_params_delegate.cc new file mode 100644 index 0000000..e14665a --- /dev/null +++ b/components/update_client/update_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/update_client/update_query_params_delegate.h" + +namespace update_client { + +UpdateQueryParamsDelegate::UpdateQueryParamsDelegate() { +} + +UpdateQueryParamsDelegate::~UpdateQueryParamsDelegate() { +} + +} // namespace update_client diff --git a/components/update_client/update_query_params_delegate.h b/components/update_client/update_query_params_delegate.h new file mode 100644 index 0000000..0dd97ff --- /dev/null +++ b/components/update_client/update_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_UPDATE_CLIENT_UPDATE_QUERY_PARAMS_DELEGATE_H_ +#define COMPONENTS_UPDATE_CLIENT_UPDATE_QUERY_PARAMS_DELEGATE_H_ + +#include <string> + +#include "base/basictypes.h" + +namespace update_client { + +// Embedders can specify an UpdateQueryParamsDelegate to provide additional +// custom parameters. If not specified (Set is never called), no additional +// parameters are added. +class UpdateQueryParamsDelegate { + public: + UpdateQueryParamsDelegate(); + virtual ~UpdateQueryParamsDelegate(); + + // 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(UpdateQueryParamsDelegate); +}; + +} // namespace update_client + +#endif // COMPONENTS_UPDATE_CLIENT_UPDATE_QUERY_PARAMS_DELEGATE_H_ diff --git a/components/update_client/update_query_params_unittest.cc b/components/update_client/update_query_params_unittest.cc new file mode 100644 index 0000000..992dbd37 --- /dev/null +++ b/components/update_client/update_query_params_unittest.cc @@ -0,0 +1,55 @@ +// 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 "components/update_client/update_query_params.h" +#include "components/update_client/update_query_params_delegate.h" +#include "testing/gtest/include/gtest/gtest.h" + +using base::StringPrintf; + +namespace update_client { + +namespace { + +bool Contains(const std::string& source, const std::string& target) { + return source.find(target) != std::string::npos; +} + +class TestUpdateQueryParamsDelegate : public UpdateQueryParamsDelegate { + std::string GetExtraParams() override { return "&cat=dog"; } +}; + +} // namespace + +void TestParams(UpdateQueryParams::ProdId prod_id, bool extra_params) { + std::string params = UpdateQueryParams::Get(prod_id); + + // This doesn't so much test what the values are (since that would be an + // almost exact duplication of code with update_query_params.cc, and wouldn't + // really test anything) as it is a verification that all the params are + // present in the generated string. + EXPECT_TRUE( + Contains(params, StringPrintf("os=%s", UpdateQueryParams::GetOS()))); + EXPECT_TRUE( + Contains(params, StringPrintf("arch=%s", UpdateQueryParams::GetArch()))); + EXPECT_TRUE(Contains( + params, + StringPrintf("prod=%s", UpdateQueryParams::GetProdIdString(prod_id)))); + if (extra_params) + EXPECT_TRUE(Contains(params, "cat=dog")); +} + +TEST(UpdateQueryParamsTest, GetParams) { + TestParams(UpdateQueryParams::CRX, false); + TestParams(UpdateQueryParams::CHROME, false); + + TestUpdateQueryParamsDelegate delegate; + UpdateQueryParams::SetDelegate(&delegate); + + TestParams(UpdateQueryParams::CRX, true); + TestParams(UpdateQueryParams::CHROME, true); +} + +} // namespace update_client |