Commit f9981101 authored by Elaine Chien's avatar Elaine Chien Committed by Chromium LUCI CQ

ChromeLabs: Dynamic refresh for enterprise policy

Allow Enterprise admins to apply the policy without needing a browser restart.

Bug: 1158427
Change-Id: I52dc1488eb1c29ec4d93c73169e4523efd838244
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2633070
Commit-Queue: Elaine Chien <elainechien@chromium.org>
Reviewed-by: default avatarOwen Min <zmin@chromium.org>
Reviewed-by: default avatarConnie Wan <connily@chromium.org>
Cr-Commit-Position: refs/heads/master@{#844304}
parent f392e62f
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "build/chromeos_buildflags.h" #include "build/chromeos_buildflags.h"
#include "chrome/browser/about_flags.h" #include "chrome/browser/about_flags.h"
#include "chrome/browser/ui/toolbar/chrome_labs_prefs.h"
#include "chrome/browser/ui/ui_features.h" #include "chrome/browser/ui/ui_features.h"
#include "chrome/browser/ui/views/frame/browser_view.h" #include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/frame/test_with_browser_view.h" #include "chrome/browser/ui/views/frame/test_with_browser_view.h"
...@@ -53,9 +54,12 @@ class ChromeLabsBubbleTest : public TestWithBrowserView { ...@@ -53,9 +54,12 @@ class ChromeLabsBubbleTest : public TestWithBrowserView {
{kThirdTestFeatureId, "", "", os_other_than_current, {kThirdTestFeatureId, "", "", os_other_than_current,
FEATURE_VALUE_TYPE(kTestFeature3)}}; FEATURE_VALUE_TYPE(kTestFeature3)}};
about_flags::testing::SetFeatureEntries(entries); about_flags::testing::SetFeatureEntries(entries);
TestWithBrowserView::SetUp(); TestWithBrowserView::SetUp();
ChromeLabsButton* button = chrome_labs_button(); profile()->GetPrefs()->SetBoolean(chrome_labs_prefs::kBrowserLabsEnabled,
true);
ChromeLabsButton* button = chrome_labs_button();
CreateTestLabInfo(); CreateTestLabInfo();
std::unique_ptr<ChromeLabsBubbleViewModel> test_model = std::unique_ptr<ChromeLabsBubbleViewModel> test_model =
std::make_unique<ChromeLabsBubbleViewModel>(); std::make_unique<ChromeLabsBubbleViewModel>();
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "chrome/browser/ui/views/toolbar/chrome_labs_button.h" #include "chrome/browser/ui/views/toolbar/chrome_labs_button.h"
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "chrome/browser/about_flags.h" #include "chrome/browser/about_flags.h"
#include "chrome/browser/ui/toolbar/chrome_labs_prefs.h"
#include "chrome/browser/ui/ui_features.h" #include "chrome/browser/ui/ui_features.h"
#include "chrome/browser/ui/views/frame/browser_view.h" #include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/frame/test_with_browser_view.h" #include "chrome/browser/ui/views/frame/test_with_browser_view.h"
...@@ -24,6 +25,8 @@ class ChromeLabsButtonTest : public TestWithBrowserView { ...@@ -24,6 +25,8 @@ class ChromeLabsButtonTest : public TestWithBrowserView {
void SetUp() override { void SetUp() override {
scoped_feature_list_.InitAndEnableFeature(features::kChromeLabs); scoped_feature_list_.InitAndEnableFeature(features::kChromeLabs);
TestWithBrowserView::SetUp(); TestWithBrowserView::SetUp();
profile()->GetPrefs()->SetBoolean(chrome_labs_prefs::kBrowserLabsEnabled,
true);
} }
private: private:
......
...@@ -270,10 +270,16 @@ void ToolbarView::Init() { ...@@ -270,10 +270,16 @@ void ToolbarView::Init() {
if (extensions_container) if (extensions_container)
extensions_container_ = AddChildView(std::move(extensions_container)); extensions_container_ = AddChildView(std::move(extensions_container));
if (base::FeatureList::IsEnabled(features::kChromeLabs) && if (base::FeatureList::IsEnabled(features::kChromeLabs)) {
browser_->profile()->GetPrefs()->GetBoolean(
chrome_labs_prefs::kBrowserLabsEnabled)) {
chrome_labs_button_ = AddChildView(std::make_unique<ChromeLabsButton>()); chrome_labs_button_ = AddChildView(std::make_unique<ChromeLabsButton>());
profile_pref_service_ = browser_->profile()->GetPrefs();
profile_registrar_ = std::make_unique<PrefChangeRegistrar>();
profile_registrar_->Init(profile_pref_service_);
profile_registrar_->Add(
chrome_labs_prefs::kBrowserLabsEnabled,
base::BindRepeating(&ToolbarView::OnChromeLabsPrefChanged,
base::Unretained(this)));
OnChromeLabsPrefChanged();
} }
if (cast) if (cast)
...@@ -882,6 +888,11 @@ views::View* ToolbarView::GetViewForDrop() { ...@@ -882,6 +888,11 @@ views::View* ToolbarView::GetViewForDrop() {
return this; return this;
} }
void ToolbarView::OnChromeLabsPrefChanged() {
chrome_labs_button_->SetVisible(profile_pref_service_->GetBoolean(
chrome_labs_prefs::kBrowserLabsEnabled));
}
void ToolbarView::LoadImages() { void ToolbarView::LoadImages() {
DCHECK_EQ(display_mode_, DisplayMode::NORMAL); DCHECK_EQ(display_mode_, DisplayMode::NORMAL);
......
...@@ -240,6 +240,9 @@ class ToolbarView : public views::AccessiblePaneView, ...@@ -240,6 +240,9 @@ class ToolbarView : public views::AccessiblePaneView,
const ui::DropTargetEvent& event) override; const ui::DropTargetEvent& event) override;
views::View* GetViewForDrop() override; views::View* GetViewForDrop() override;
// Changes the visibility of the Chrome Labs entry point based on prefs.
void OnChromeLabsPrefChanged();
// Loads the images for all the child views. // Loads the images for all the child views.
void LoadImages(); void LoadImages();
...@@ -280,6 +283,9 @@ class ToolbarView : public views::AccessiblePaneView, ...@@ -280,6 +283,9 @@ class ToolbarView : public views::AccessiblePaneView,
Browser* const browser_; Browser* const browser_;
BrowserView* const browser_view_; BrowserView* const browser_view_;
PrefService* profile_pref_service_;
std::unique_ptr<PrefChangeRegistrar> profile_registrar_;
views::FlexLayout* layout_manager_ = nullptr; views::FlexLayout* layout_manager_ = nullptr;
AppMenuIconController app_menu_icon_controller_; AppMenuIconController app_menu_icon_controller_;
......
...@@ -4479,7 +4479,7 @@ ...@@ -4479,7 +4479,7 @@
'future_on' : ['chrome_os'], 'future_on' : ['chrome_os'],
'example_value': False, 'example_value': False,
'features':{ 'features':{
'dynamic_refresh': False, 'dynamic_refresh': True,
'per_profile': True, 'per_profile': True,
}, },
'items': [ 'items': [
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment