channel_info_fuchsia.cc 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // Copyright 2021 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. // TODO(crbug.com/1231926): Implement support for update channels.
  5. #include "chrome/common/channel_info.h"
  6. #include "base/check.h"
  7. #include "base/notreached.h"
  8. #include "build/branding_buildflags.h"
  9. #include "components/version_info/version_info.h"
  10. namespace chrome {
  11. namespace {
  12. struct ChannelState {
  13. version_info::Channel channel;
  14. bool is_extended_stable;
  15. };
  16. // Determine the state of the browser based on branding and channel.
  17. // TODO(crbug.com/1253820): Update implementation when channel are implemented.
  18. ChannelState DetermineChannelState() {
  19. #if BUILDFLAG(GOOGLE_CHROME_BRANDING)
  20. NOTIMPLEMENTED_LOG_ONCE();
  21. return {version_info::Channel::STABLE, /*is_extended_stable=*/false};
  22. #else // BUILDFLAG(GOOGLE_CHROME_BRANDING)
  23. return {version_info::Channel::UNKNOWN, /*is_extended_stable=*/false};
  24. #endif // BUILDFLAG(GOOGLE_CHROME_BRANDING)
  25. }
  26. // Returns the channel state for the browser.
  27. ChannelState& GetChannelImpl() {
  28. static ChannelState channel = DetermineChannelState();
  29. return channel;
  30. }
  31. } // namespace
  32. std::string GetChannelName(WithExtendedStable with_extended_stable) {
  33. #if BUILDFLAG(GOOGLE_CHROME_BRANDING)
  34. const auto& channel_state = GetChannelImpl();
  35. switch (channel_state.channel) {
  36. case version_info::Channel::UNKNOWN:
  37. return "unknown";
  38. case version_info::Channel::CANARY:
  39. return "canary";
  40. case version_info::Channel::DEV:
  41. return "dev";
  42. case version_info::Channel::BETA:
  43. return "beta";
  44. case version_info::Channel::STABLE:
  45. if (with_extended_stable && channel_state.is_extended_stable)
  46. return "extended";
  47. return std::string();
  48. }
  49. #else // BUILDFLAG(GOOGLE_CHROME_BRANDING)
  50. return std::string();
  51. #endif // BUILDFLAG(GOOGLE_CHROME_BRANDING)
  52. }
  53. version_info::Channel GetChannel() {
  54. return GetChannelImpl().channel;
  55. }
  56. bool IsExtendedStableChannel() {
  57. return GetChannelImpl().is_extended_stable;
  58. }
  59. #if BUILDFLAG(GOOGLE_CHROME_BRANDING)
  60. void SetChannelForTesting(version_info::Channel channel,
  61. bool is_extended_stable) {
  62. GetChannelImpl() = {channel, is_extended_stable};
  63. }
  64. void ClearChannelForTesting() {
  65. GetChannelImpl() = DetermineChannelState();
  66. }
  67. #endif // BUILDFLAG(GOOGLE_CHROME_BRANDING)
  68. } // namespace chrome