version_utils.cc 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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.
  4. #include "components/metrics/version_utils.h"
  5. #include "base/notreached.h"
  6. #include "build/branding_buildflags.h"
  7. #include "build/build_config.h"
  8. #include "components/version_info/version_info.h"
  9. #if BUILDFLAG(IS_ANDROID)
  10. #include "base/android/build_info.h"
  11. #endif
  12. namespace metrics {
  13. std::string GetVersionString() {
  14. std::string version = version_info::GetVersionNumber();
  15. #if defined(ARCH_CPU_64_BITS)
  16. version += "-64";
  17. #endif // defined(ARCH_CPU_64_BITS)
  18. #if BUILDFLAG(GOOGLE_CHROME_BRANDING)
  19. bool is_chrome_branded = true;
  20. #else
  21. bool is_chrome_branded = false;
  22. #endif
  23. if (!is_chrome_branded || !version_info::IsOfficialBuild())
  24. version.append("-devel");
  25. return version;
  26. }
  27. SystemProfileProto::Channel AsProtobufChannel(version_info::Channel channel) {
  28. switch (channel) {
  29. case version_info::Channel::UNKNOWN:
  30. return SystemProfileProto::CHANNEL_UNKNOWN;
  31. case version_info::Channel::CANARY:
  32. return SystemProfileProto::CHANNEL_CANARY;
  33. case version_info::Channel::DEV:
  34. return SystemProfileProto::CHANNEL_DEV;
  35. case version_info::Channel::BETA:
  36. return SystemProfileProto::CHANNEL_BETA;
  37. case version_info::Channel::STABLE:
  38. return SystemProfileProto::CHANNEL_STABLE;
  39. }
  40. NOTREACHED();
  41. return SystemProfileProto::CHANNEL_UNKNOWN;
  42. }
  43. std::string GetAppPackageName() {
  44. #if BUILDFLAG(IS_ANDROID)
  45. return base::android::BuildInfo::GetInstance()->package_name();
  46. #else
  47. return std::string();
  48. #endif
  49. }
  50. } // namespace metrics