1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ios/chrome/common/channel_info.h"
7 #include <dispatch/dispatch.h>
8 #import <Foundation/Foundation.h>
10 #import "base/mac/bundle_locations.h"
11 #include "base/profiler/scoped_tracker.h"
12 #import "base/strings/sys_string_conversions.h"
13 #include "components/version_info/version_info.h"
17 #if defined(GOOGLE_CHROME_BUILD)
18 // Channel of the running application, initialized by the first call to
19 // GetChannel() and cached for the whole application lifetime.
20 version_info::Channel g_channel = version_info::Channel::UNKNOWN;
25 std::string GetVersionString() {
26 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is
28 tracked_objects::ScopedTracker tracking_profile(
29 FROM_HERE_WITH_EXPLICIT_FUNCTION(
30 "422460 VersionInfo::CreateVersionString"));
32 return version_info::GetVersionStringWithModifier(GetChannelString());
35 std::string GetChannelString() {
36 #if defined(GOOGLE_CHROME_BUILD)
37 // Only ever return one of "" (for STABLE channel), "unknown", "beta", "dev"
38 // or "canary" in branded build.
39 switch (GetChannel()) {
40 case version_info::Channel::STABLE:
43 case version_info::Channel::BETA:
46 case version_info::Channel::DEV:
49 case version_info::Channel::CANARY:
52 case version_info::Channel::UNKNOWN:
56 // Always return empty string for non-branded builds.
61 version_info::Channel GetChannel() {
62 #if defined(GOOGLE_CHROME_BUILD)
63 static dispatch_once_t channel_dispatch_token;
64 dispatch_once(&channel_dispatch_token, ^{
65 NSBundle* bundle = base::mac::OuterBundle();
67 // Only Keystone-enabled build can have a channel.
68 if (![bundle objectForInfoDictionaryKey:@"KSProductID"])
71 NSString* channel = [bundle objectForInfoDictionaryKey:@"KSChannelID"];
73 // KSChannelID is unset for the stable channel.
74 g_channel = version_info::Channel::STABLE;
75 } else if ([channel isEqualToString:@"beta"]) {
76 g_channel = version_info::Channel::BETA;
77 } else if ([channel isEqualToString:@"dev"]) {
78 g_channel = version_info::Channel::DEV;
79 } else if ([channel isEqualToString:@"canary"]) {
80 g_channel = version_info::Channel::CANARY;
86 return version_info::Channel::UNKNOWN;