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 #import <Foundation/Foundation.h>
9 #import "base/mac/bundle_locations.h"
10 #include "base/profiler/scoped_tracker.h"
11 #import "base/strings/sys_string_conversions.h"
12 #include "components/version_info/version_info.h"
16 // Returns the channel and if |channel_string| is not null, it is set
17 // to the string representation of the channel (only ever return one
18 // of "", "unknown", "beta", "dev" or "canary" in branded build).
19 version_info::Channel GetChannelImpl(std::string* channel_string) {
20 #if defined(GOOGLE_CHROME_BUILD)
21 NSBundle* bundle = base::mac::OuterBundle();
22 NSString* channel = [bundle objectForInfoDictionaryKey:@"KSChannelID"];
24 // Only Keystone-enabled build can have a channel.
25 if ([bundle objectForInfoDictionaryKey:@"KSProductID"]) {
26 // KSChannelID is unset for the stable channel.
29 channel_string->clear();
30 return version_info::Channel::STABLE;
33 if ([channel isEqualToString:@"beta"]) {
35 channel_string->assign(base::SysNSStringToUTF8(channel));
36 return version_info::Channel::BETA;
39 if ([channel isEqualToString:@"dev"]) {
41 channel_string->assign(base::SysNSStringToUTF8(channel));
42 return version_info::Channel::DEV;
45 if ([channel isEqualToString:@"canary"]) {
47 channel_string->assign(base::SysNSStringToUTF8(channel));
48 return version_info::Channel::CANARY;
53 channel_string->assign("unknown");
54 return version_info::Channel::UNKNOWN;
56 // Always return empty string for non-branded builds.
57 return version_info::Channel::UNKNOWN;
63 std::string GetVersionString() {
64 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is
66 tracked_objects::ScopedTracker tracking_profile(
67 FROM_HERE_WITH_EXPLICIT_FUNCTION(
68 "422460 VersionInfo::CreateVersionString"));
70 return version_info::GetVersionStringWithModifier(GetChannelString());
73 std::string GetChannelString() {
75 GetChannelImpl(&channel);
79 version_info::Channel GetChannel() {
80 return GetChannelImpl(nullptr);