1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96
   97
   98
   99
  100
  101
  102
  103
  104
  105
  106
  107
  108
  109
  110
  111
  112
  113
  114

ash / components / arc / chrome_feature_flags / arc_chrome_feature_flags_bridge.cc [blame]

// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ash/components/arc/chrome_feature_flags/arc_chrome_feature_flags_bridge.h"

#include "ash/components/arc/arc_browser_context_keyed_service_factory_base.h"
#include "ash/components/arc/arc_features.h"
#include "ash/components/arc/session/arc_bridge_service.h"
#include "ash/components/arc/session/arc_service_manager.h"
#include "ash/constants/ash_features.h"
#include "base/feature_list.h"
#include "base/memory/singleton.h"
#include "base/metrics/field_trial_params.h"
#include "chromeos/constants/chromeos_features.h"

namespace arc {

namespace {

// Singleton factory for ArcChromeFeatureFlagsBridge.
class ArcChromeFeatureFlagsBridgeFactory
    : public internal::ArcBrowserContextKeyedServiceFactoryBase<
          ArcChromeFeatureFlagsBridge,
          ArcChromeFeatureFlagsBridgeFactory> {
 public:
  // Factory name used by ArcBrowserContextKeyedServiceFactoryBase.
  static constexpr const char* kName = "ArcChromeFeatureFlagsBridgeFactory";

  static ArcChromeFeatureFlagsBridgeFactory* GetInstance() {
    return base::Singleton<ArcChromeFeatureFlagsBridgeFactory>::get();
  }

 private:
  friend base::DefaultSingletonTraits<ArcChromeFeatureFlagsBridgeFactory>;
  ArcChromeFeatureFlagsBridgeFactory() = default;
  ~ArcChromeFeatureFlagsBridgeFactory() override = default;
};

}  // namespace

// static
ArcChromeFeatureFlagsBridge* ArcChromeFeatureFlagsBridge::GetForBrowserContext(
    content::BrowserContext* context) {
  return ArcChromeFeatureFlagsBridgeFactory::GetForBrowserContext(context);
}

// static
ArcChromeFeatureFlagsBridge*
ArcChromeFeatureFlagsBridge::GetForBrowserContextForTesting(
    content::BrowserContext* context) {
  return ArcChromeFeatureFlagsBridgeFactory::GetForBrowserContextForTesting(
      context);
}

ArcChromeFeatureFlagsBridge::ArcChromeFeatureFlagsBridge(
    content::BrowserContext* context,
    ArcBridgeService* bridge_service)
    : arc_bridge_service_(bridge_service) {
  arc_bridge_service_->chrome_feature_flags()->AddObserver(this);
}

ArcChromeFeatureFlagsBridge::~ArcChromeFeatureFlagsBridge() {
  arc_bridge_service_->chrome_feature_flags()->RemoveObserver(this);
}

void ArcChromeFeatureFlagsBridge::OnConnectionReady() {
  NotifyFeatureFlags();
}

void ArcChromeFeatureFlagsBridge::NotifyFeatureFlags() {
  mojom::ChromeFeatureFlagsInstance* chrome_feature_flags_instance =
      ARC_GET_INSTANCE_FOR_METHOD(arc_bridge_service_->chrome_feature_flags(),
                                  NotifyFeatureFlags);
  if (!chrome_feature_flags_instance) {
    return;
  }
  mojom::FeatureFlagsPtr flags = mojom::FeatureFlags::New();
  flags->jelly_colors = true;
  flags->touchscreen_emulation = true;
  flags->rounded_window_compat_strategy =
      base::FeatureList::IsEnabled(arc::kRoundedWindowCompat)
          ? static_cast<mojom::RoundedWindowCompatStrategy>(
                base::GetFieldTrialParamByFeatureAsInt(
                    kRoundedWindowCompat, kRoundedWindowCompatStrategy,
                    static_cast<int>(mojom::RoundedWindowCompatStrategy::
                                         kLeftRightBottomGesture)))
          : mojom::RoundedWindowCompatStrategy::kDisabled;
  flags->rounded_window_radius = chromeos::features::RoundedWindowsRadius();
  flags->enable_pip_double_tap = ash::features::IsPipDoubleTapToResizeEnabled();
  flags->render_arc_notifications_by_chrome =
      ash::features::IsRenderArcNotificationsByChromeEnabled();
  flags->resize_compat = base::FeatureList::IsEnabled(arc::kResizeCompat);
  flags->ignore_hover_event_anr = true;
  // TODO(yunfanc): Remove this flag together with ARC++ side removal.
  flags->extend_input_anr_timeout = true;
  flags->extend_intent_anr_timeout =
      base::FeatureList::IsEnabled(arc::kExtendIntentAnrTimeout);
  flags->extend_service_anr_timeout =
      base::FeatureList::IsEnabled(arc::kExtendServiceAnrTimeout);
  flags->notification_width_increase =
      chromeos::features::IsNotificationWidthIncreaseEnabled();
  flags->enable_friendlier_error_dialog =
      base::FeatureList::IsEnabled(arc::kEnableFriendlierErrorDialog);

  chrome_feature_flags_instance->NotifyFeatureFlags(std::move(flags));
}

// static
void ArcChromeFeatureFlagsBridge::EnsureFactoryBuilt() {
  ArcChromeFeatureFlagsBridgeFactory::GetInstance();
}

}  // namespace arc