1 // Copyright 2015 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "components/metrics/version_utils.h" 6 7 #include "base/notreached.h" 8 #include "build/branding_buildflags.h" 9 #include "build/build_config.h" 10 #include "components/version_info/version_info.h" 11 12 #if BUILDFLAG(IS_ANDROID) 13 #include "base/android/build_info.h" 14 #endif 15 16 namespace metrics { 17 GetVersionString()18std::string GetVersionString() { 19 std::string version(version_info::GetVersionNumber()); 20 #if defined(ARCH_CPU_64_BITS) 21 version += "-64"; 22 #endif // defined(ARCH_CPU_64_BITS) 23 24 #if BUILDFLAG(GOOGLE_CHROME_BRANDING) 25 bool is_chrome_branded = true; 26 #else 27 bool is_chrome_branded = false; 28 #endif 29 if (!is_chrome_branded || !version_info::IsOfficialBuild()) 30 version.append("-devel"); 31 return version; 32 } 33 AsProtobufChannel(version_info::Channel channel)34SystemProfileProto::Channel AsProtobufChannel(version_info::Channel channel) { 35 switch (channel) { 36 case version_info::Channel::UNKNOWN: 37 return SystemProfileProto::CHANNEL_UNKNOWN; 38 case version_info::Channel::CANARY: 39 return SystemProfileProto::CHANNEL_CANARY; 40 case version_info::Channel::DEV: 41 return SystemProfileProto::CHANNEL_DEV; 42 case version_info::Channel::BETA: 43 return SystemProfileProto::CHANNEL_BETA; 44 case version_info::Channel::STABLE: 45 return SystemProfileProto::CHANNEL_STABLE; 46 } 47 NOTREACHED(); 48 return SystemProfileProto::CHANNEL_UNKNOWN; 49 } 50 GetAppPackageName()51std::string GetAppPackageName() { 52 #if BUILDFLAG(IS_ANDROID) 53 return base::android::BuildInfo::GetInstance()->package_name(); 54 #else 55 return std::string(); 56 #endif 57 } 58 59 } // namespace metrics 60