diff options
author | newt <newt@chromium.org> | 2014-10-29 15:24:22 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-10-29 22:24:33 +0000 |
commit | b5753f5c3bcbd9871f81537c258c2ac699affef8 (patch) | |
tree | b9fec59ed886636282254b7a377d26e990cab0e4 | |
parent | f264dce3bcaf59187834def5bc2ceee055429953 (diff) | |
download | chromium_src-b5753f5c3bcbd9871f81537c258c2ac699affef8.zip chromium_src-b5753f5c3bcbd9871f81537c258c2ac699affef8.tar.gz chromium_src-b5753f5c3bcbd9871f81537c258c2ac699affef8.tar.bz2 |
Make channel available in Java via ChromeVersionConstants.java.
Channel information is now available statically at build time. There's
no need to call ChromeVersionInfo.init() anymore.
Review URL: https://codereview.chromium.org/668343004
Cr-Commit-Position: refs/heads/master@{#301952}
-rw-r--r-- | chrome/android/BUILD.gn | 2 | ||||
-rw-r--r-- | chrome/android/channel.gni | 16 | ||||
-rw-r--r-- | chrome/android/java/ChromeVersionConstants.java.version | 15 | ||||
-rw-r--r-- | chrome/android/java/src/org/chromium/chrome/browser/ChromeVersionInfo.java | 75 | ||||
-rw-r--r-- | chrome/android/java/src/org/chromium/chrome/browser/ChromiumApplication.java | 6 | ||||
-rw-r--r-- | chrome/chrome_android.gypi | 1 | ||||
-rw-r--r-- | chrome/version.gni | 12 |
7 files changed, 47 insertions, 80 deletions
diff --git a/chrome/android/BUILD.gn b/chrome/android/BUILD.gn index 985e208..f28cb92 100644 --- a/chrome/android/BUILD.gn +++ b/chrome/android/BUILD.gn @@ -6,6 +6,7 @@ import("//build/config/android/config.gni") import("//build/config/android/rules.gni") import("//chrome/version.gni") import("//third_party/icu/config.gni") +import("channel.gni") # GYP: //chrome/chrome.gyp:chrome_java (resources part) android_resources("chrome_java_resources") { @@ -467,6 +468,7 @@ chrome_version_java_file = "$chrome_version_java_dir/org/chromium/chrome/browser process_version("chrome_version_java") { source = "java/ChromeVersionConstants.java.version" output = chrome_version_java_file + extra_args = ["-e", "CHANNEL=str.upper('$android_channel')"] } zip("chrome_version_srcjar") { diff --git a/chrome/android/channel.gni b/chrome/android/channel.gni new file mode 100644 index 0000000..504859c --- /dev/null +++ b/chrome/android/channel.gni @@ -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. + +declare_args() { + # The channel to build on Android: stable, beta, dev, canary, or default. + # "default" should be used on non-official builds. + android_channel = "default" +} + +assert(android_channel == "default" || + android_channel == "canary" || + android_channel == "dev" || + android_channel == "beta" || + android_channel == "stable", + "Invalid channel: " + android_channel) diff --git a/chrome/android/java/ChromeVersionConstants.java.version b/chrome/android/java/ChromeVersionConstants.java.version index d5e8660..83b9a11 100644 --- a/chrome/android/java/ChromeVersionConstants.java.version +++ b/chrome/android/java/ChromeVersionConstants.java.version @@ -4,8 +4,15 @@ package org.chromium.chrome.browser; -public class ChromeVersionConstants { - public static final String PRODUCT_NAME = "@PRODUCT_FULLNAME@"; - public static final String PRODUCT_VERSION = "@MAJOR@.@MINOR@.@BUILD@.@PATCH@"; - public static final boolean IS_OFFICIAL_BUILD = @OFFICIAL_BUILD@ == 1; +class ChromeVersionConstants { + static final String PRODUCT_NAME = "@PRODUCT_FULLNAME@"; + static final String PRODUCT_VERSION = "@MAJOR@.@MINOR@.@BUILD@.@PATCH@"; + static final boolean IS_OFFICIAL_BUILD = @OFFICIAL_BUILD@ == 1; + + static final int CHANNEL_DEFAULT = 0; + static final int CHANNEL_CANARY = 1; + static final int CHANNEL_DEV = 2; + static final int CHANNEL_BETA = 3; + static final int CHANNEL_STABLE = 4; + static final int CHANNEL = CHANNEL_@CHANNEL@; } diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ChromeVersionInfo.java b/chrome/android/java/src/org/chromium/chrome/browser/ChromeVersionInfo.java index 28edca7..d722c01 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/ChromeVersionInfo.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/ChromeVersionInfo.java @@ -4,106 +4,45 @@ package org.chromium.chrome.browser; -import android.content.Context; - -import org.chromium.base.BuildInfo; - /** - * A utility class for determining information about the current Chrome build. + * A utility class for querying information about the current Chrome build. * Intentionally doesn't depend on native so that the data can be accessed before * libchrome.so is loaded. */ public class ChromeVersionInfo { - /** Local builds. */ - private static final int CHANNEL_UNKNOWN = 0x1; - - /** Canary builds. */ - private static final int CHANNEL_CANARY = 0x10; - - /** Dev builds. */ - private static final int CHANNEL_DEV = 0x100; - - /** Beta builds. */ - private static final int CHANNEL_BETA = 0x1000; - - /** Stable builds. */ - private static final int CHANNEL_STABLE = 0x10000; - - /** Signifies that init() hasn't been called yet. */ - private static final int INVALID_CHANNEL = 0x10000000; - - private static final String CHANNEL_STRING_CANARY = "Chrome Canary"; - private static final String CHANNEL_STRING_DEV = "Chrome Dev"; - private static final String CHANNEL_STRING_BETA = "Chrome Beta"; - private static final String CHANNEL_STRING_STABLE = "Chrome"; - - private static int sChannel = INVALID_CHANNEL; - - /** - * This must be called before any other method in this class is called. - * @param context The context to query the build channel from. - */ - public static void init(Context context) { - final String channel = BuildInfo.getPackageLabel(context); - if (CHANNEL_STRING_STABLE.equals(channel)) { - sChannel = CHANNEL_STABLE; - } else if (CHANNEL_STRING_BETA.equals(channel)) { - sChannel = CHANNEL_BETA; - } else if (CHANNEL_STRING_DEV.equals(channel)) { - sChannel = CHANNEL_DEV; - } else if (CHANNEL_STRING_CANARY.equals(channel)) { - sChannel = CHANNEL_CANARY; - } else { - sChannel = CHANNEL_UNKNOWN; - } - } - /** * @return Whether this build is a local build. */ public static boolean isLocalBuild() { - return getBuildChannel() == CHANNEL_UNKNOWN; + return ChromeVersionConstants.CHANNEL == ChromeVersionConstants.CHANNEL_DEFAULT; } /** * @return Whether this build is a canary build. */ public static boolean isCanaryBuild() { - return getBuildChannel() == CHANNEL_CANARY; + return ChromeVersionConstants.CHANNEL == ChromeVersionConstants.CHANNEL_CANARY; } /** * @return Whether this build is a dev build. */ public static boolean isDevBuild() { - return getBuildChannel() == CHANNEL_DEV; + return ChromeVersionConstants.CHANNEL == ChromeVersionConstants.CHANNEL_DEV; } /** * @return Whether this build is a beta build. */ public static boolean isBetaBuild() { - return getBuildChannel() == CHANNEL_BETA; + return ChromeVersionConstants.CHANNEL == ChromeVersionConstants.CHANNEL_BETA; } /** * @return Whether this build is a stable build. */ public static boolean isStableBuild() { - return getBuildChannel() == CHANNEL_STABLE; - } - - /** - * Determines which channel this build is. - * @return What channel this build is. Can be one of {@link #CHANNEL_UNKNOWN}, - * {@link #CHANNEL_CANARY}, {@link #CHANNEL_DEV}, {@link #CHANNEL_BETA}, or - * {@link #CHANNEL_STABLE}. - */ - public static int getBuildChannel() { - if (sChannel == INVALID_CHANNEL) { - throw new RuntimeException("ChannelInfo.init() was not called"); - } - return sChannel; + return ChromeVersionConstants.CHANNEL == ChromeVersionConstants.CHANNEL_STABLE; } /** @@ -112,4 +51,4 @@ public class ChromeVersionInfo { public static boolean isOfficialBuild() { return ChromeVersionConstants.IS_OFFICIAL_BUILD; } -}
\ No newline at end of file +} diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ChromiumApplication.java b/chrome/android/java/src/org/chromium/chrome/browser/ChromiumApplication.java index 0f9e309..6bd7825 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/ChromiumApplication.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/ChromiumApplication.java @@ -12,12 +12,6 @@ import org.chromium.content.app.ContentApplication; * chrome layer. */ public abstract class ChromiumApplication extends ContentApplication { - @Override - public void onCreate() { - super.onCreate(); - ChromeVersionInfo.init(this); - } - /** * Opens a protected content settings page, if available. */ diff --git a/chrome/chrome_android.gypi b/chrome/chrome_android.gypi index 125ae1a..071a5da 100644 --- a/chrome/chrome_android.gypi +++ b/chrome/chrome_android.gypi @@ -100,6 +100,7 @@ '<(version_py_path)', '-f', '<(version_path)', '-f', '<(branding_path)', + '-e', 'CHANNEL=str.upper("<(android_channel)")', '<(template_input_path)', '<(output_path)', ], diff --git a/chrome/version.gni b/chrome/version.gni index 771ea28..4a96dd6 100644 --- a/chrome/version.gni +++ b/chrome/version.gni @@ -15,12 +15,16 @@ # output: # File name of file to write. # +# extra_args: +# Extra arguments to pass to version.py. +# # visibility (optional) # # Example: # process_version("myversion") { # source = "myfile.h.in" # output = "$target_gen_dir/myfile.h" +# extra_args = ["-e", "FOO=42"] # } template("process_version") { assert(defined(invoker.source), "Source must be defined for $target_name") @@ -53,8 +57,12 @@ template("process_version") { "-f", rebase_path(version_path, root_build_dir), "-f", rebase_path(branding_path, root_build_dir), "-f", rebase_path(lastchange_path, root_build_dir), - rebase_path(invoker.source, root_build_dir), - rebase_path(invoker.output, root_build_dir), + "-i", rebase_path(invoker.source, root_build_dir), + "-o", rebase_path(invoker.output, root_build_dir), ] + + if (defined(invoker.extra_args)) { + args += invoker.extra_args + } } } |