1 // Copyright (c) 2012 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 "chrome/common/channel_info.h"
7 #import <Foundation/Foundation.h>
9 #include "base/basictypes.h"
10 #include "base/mac/bundle_locations.h"
11 #include "base/strings/sys_string_conversions.h"
12 #include "components/version_info/version_info.h"
16 std::string GetChannelString() {
17 #if defined(GOOGLE_CHROME_BUILD)
18 // Use the main Chrome application bundle and not the framework bundle.
19 // Keystone keys don't live in the framework.
20 NSBundle* bundle = base::mac::OuterBundle();
21 NSString* channel = [bundle objectForInfoDictionaryKey:@"KSChannelID"];
23 // Only ever return "", "unknown", "beta", "dev", or "canary" in a branded
25 if (![bundle objectForInfoDictionaryKey:@"KSProductID"]) {
26 // This build is not Keystone-enabled, it can't have a channel.
28 } else if (!channel) {
29 // For the stable channel, KSChannelID is not set.
31 } else if ([channel isEqual:@"beta"] ||
32 [channel isEqual:@"dev"] ||
33 [channel isEqual:@"canary"]) {
39 return base::SysNSStringToUTF8(channel);
45 version_info::Channel GetChannel() {
46 #if defined(GOOGLE_CHROME_BUILD)
47 std::string channel = GetChannelString();
48 if (channel.empty()) {
49 return version_info::Channel::STABLE;
50 } else if (channel == "beta") {
51 return version_info::Channel::BETA;
52 } else if (channel == "dev") {
53 return version_info::Channel::DEV;
54 } else if (channel == "canary") {
55 return version_info::Channel::CANARY;
59 return version_info::Channel::UNKNOWN;