diff options
| author | pbond <pbond@chromium.org> | 2016-03-21 03:57:03 -0700 |
|---|---|---|
| committer | Commit bot <commit-bot@chromium.org> | 2016-03-21 10:58:24 +0000 |
| commit | 33cc17d626fd54020cacc43e1cf2c08298ae8d52 (patch) | |
| tree | d8c3c58db51276843056424f522df8cc2d6a6748 /chrome/browser | |
| parent | adc7b8b7f37f3135c0e5c464680f6e0bb98dfc1c (diff) | |
| download | chromium_src-33cc17d626fd54020cacc43e1cf2c08298ae8d52.zip chromium_src-33cc17d626fd54020cacc43e1cf2c08298ae8d52.tar.gz chromium_src-33cc17d626fd54020cacc43e1cf2c08298ae8d52.tar.bz2 | |
Add ArcEnabled policy implementation
Hide "ARC OptIn" control from Chrome:Settings for enterprise users,
map ArcEnabled policy to ArcEnabled pref.
BUG=582440
Review URL: https://codereview.chromium.org/1684063002
Cr-Commit-Position: refs/heads/master@{#382266}
Diffstat (limited to 'chrome/browser')
7 files changed, 124 insertions, 28 deletions
diff --git a/chrome/browser/chromeos/arc/arc_auth_service.cc b/chrome/browser/chromeos/arc/arc_auth_service.cc index 7dba38b..60802a3 100644 --- a/chrome/browser/chromeos/arc/arc_auth_service.cc +++ b/chrome/browser/chromeos/arc/arc_auth_service.cc @@ -202,24 +202,17 @@ void ArcAuthService::OnPrimaryUserProfilePrepared(Profile* profile) { profile_, GURL(site_url)); CHECK(storage_partition_); - // In case UI is disabled we assume that ARC is opted-in. - if (!IsOptInVerificationDisabled()) { - pref_change_registrar_.Init(profile_->GetPrefs()); - pref_change_registrar_.Add( - prefs::kArcEnabled, - base::Bind(&ArcAuthService::OnOptInPreferenceChanged, - base::Unretained(this))); - if (profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled)) { - OnOptInPreferenceChanged(); - } else { - if (!disable_ui_for_testing && profile_->IsNewProfile()) { - PrefServiceSyncableFromProfile(profile_)->AddObserver(this); - OnIsSyncingChanged(); - } - } + pref_change_registrar_.Init(profile_->GetPrefs()); + pref_change_registrar_.Add( + prefs::kArcEnabled, base::Bind(&ArcAuthService::OnOptInPreferenceChanged, + base::Unretained(this))); + if (profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled)) { + OnOptInPreferenceChanged(); } else { - auth_code_.clear(); - StartArc(); + if (!disable_ui_for_testing && profile_->IsNewProfile()) { + PrefServiceSyncableFromProfile(profile_)->AddObserver(this); + OnIsSyncingChanged(); + } } } @@ -298,16 +291,20 @@ void ArcAuthService::OnOptInPreferenceChanged() { if (profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled)) { if (state_ != State::ACTIVE) { - CloseUI(); auth_code_.clear(); - if (!profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn)) { - // Need pre-fetch auth code and show OptIn UI if needed. - initial_opt_in_ = true; - SetState(State::FETCHING_CODE); - FetchAuthCode(); + if (!IsOptInVerificationDisabled()) { + CloseUI(); + if (!profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn)) { + // Need pre-fetch auth code and show OptIn UI if needed. + initial_opt_in_ = true; + SetState(State::FETCHING_CODE); + FetchAuthCode(); + } else { + // Ready to start Arc. + StartArc(); + } } else { - // Ready to start Arc. StartArc(); } } diff --git a/chrome/browser/policy/DEPS b/chrome/browser/policy/DEPS index 468cb59..382e9d0 100644 --- a/chrome/browser/policy/DEPS +++ b/chrome/browser/policy/DEPS @@ -1,6 +1,7 @@ include_rules = [ "+chrome", "+chromeos", + "+components/arc/test", "+components/drive/drive_pref_names.h", "+components/user_manager", "+content/public/browser", diff --git a/chrome/browser/policy/configuration_policy_handler_list_factory.cc b/chrome/browser/policy/configuration_policy_handler_list_factory.cc index 5ee927f..ba007c9 100644 --- a/chrome/browser/policy/configuration_policy_handler_list_factory.cc +++ b/chrome/browser/policy/configuration_policy_handler_list_factory.cc @@ -502,6 +502,9 @@ const PolicyToPreferenceMapEntry kSimplePolicyMap[] = { { key::kUnifiedDesktopEnabledByDefault, prefs::kUnifiedDesktopEnabledByDefault, base::Value::TYPE_BOOLEAN }, + { key::kArcEnabled, + prefs::kArcEnabled, + base::Value::TYPE_BOOLEAN }, #endif // defined(OS_CHROMEOS) // Metrics reporting is controlled by a platform specific policy for ChromeOS diff --git a/chrome/browser/policy/policy_browsertest.cc b/chrome/browser/policy/policy_browsertest.cc index eb72c63..be00c54 100644 --- a/chrome/browser/policy/policy_browsertest.cc +++ b/chrome/browser/policy/policy_browsertest.cc @@ -191,9 +191,20 @@ #include "ash/shell.h" #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" #include "chrome/browser/chromeos/accessibility/magnification_manager.h" +#include "chrome/browser/chromeos/arc/arc_auth_service.h" #include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/ui/ash/chrome_screenshot_grabber.h" +#include "chrome/browser/ui/ash/multi_user/multi_user_util.h" #include "chromeos/audio/cras_audio_handler.h" +#include "chromeos/chromeos_switches.h" +#include "chromeos/dbus/dbus_thread_manager.h" +#include "chromeos/dbus/fake_session_manager_client.h" +#include "chromeos/dbus/session_manager_client.h" +#include "components/arc/arc_bridge_service.h" +#include "components/arc/arc_bridge_service_impl.h" +#include "components/arc/arc_service_manager.h" +#include "components/arc/test/fake_arc_bridge_bootstrap.h" +#include "components/arc/test/fake_arc_bridge_instance.h" #include "ui/chromeos/accessibility_types.h" #include "ui/keyboard/keyboard_util.h" #include "ui/snapshot/screenshot_grabber.h" @@ -3991,6 +4002,87 @@ IN_PROC_BROWSER_TEST_F(PolicyTest, UnifiedDesktopEnabledByDefault) { UpdateProviderPolicy(policies); EXPECT_FALSE(display_manager->unified_desktop_enabled()); } + +class ArcPolicyTest : public PolicyTest { + public: + ArcPolicyTest() {} + ~ArcPolicyTest() override {} + + protected: + void SetUpTest() { + base::CommandLine::ForCurrentProcess()->AppendSwitch( + chromeos::switches::kDisableArcOptInVerification); + arc::ArcAuthService::DisableUIForTesting(); + + arc::ArcServiceManager::Get()->OnPrimaryUserProfilePrepared( + multi_user_util::GetAccountIdFromProfile(browser()->profile())); + arc::ArcAuthService::Get()->OnPrimaryUserProfilePrepared( + browser()->profile()); + } + + void TearDownTest() { + arc::ArcAuthService::Get()->Shutdown(); + } + + void SetUpInProcessBrowserTestFixture() override { + PolicyTest::SetUpInProcessBrowserTestFixture(); + fake_session_manager_client_ = new chromeos::FakeSessionManagerClient; + fake_session_manager_client_->set_arc_available(true); + chromeos::DBusThreadManager::GetSetterForTesting()->SetSessionManagerClient( + scoped_ptr<chromeos::SessionManagerClient>( + fake_session_manager_client_)); + + fake_arc_bridge_instance_.reset(new arc::FakeArcBridgeInstance); + arc::ArcServiceManager::SetArcBridgeServiceForTesting(make_scoped_ptr( + new arc::ArcBridgeServiceImpl(make_scoped_ptr( + new arc::FakeArcBridgeBootstrap( + fake_arc_bridge_instance_.get()))))); + } + + private: + chromeos::FakeSessionManagerClient *fake_session_manager_client_; + scoped_ptr<arc::FakeArcBridgeInstance> fake_arc_bridge_instance_; + + DISALLOW_COPY_AND_ASSIGN(ArcPolicyTest); +}; + +// Test ArcEnabled policy. +IN_PROC_BROWSER_TEST_F(ArcPolicyTest, ArcEnabled) { + SetUpTest(); + + const PrefService* const pref = browser()->profile()->GetPrefs(); + const arc::ArcBridgeService* const arc_bridge_service + = arc::ArcBridgeService::Get(); + + // ARC is switched off by default. + EXPECT_EQ(arc::ArcBridgeService::State::STOPPED, arc_bridge_service->state()); + EXPECT_FALSE(pref->GetBoolean(prefs::kArcEnabled)); + + // Enable ARC. + PolicyMap policies; + policies.Set(key::kArcEnabled, + POLICY_LEVEL_MANDATORY, + POLICY_SCOPE_USER, + POLICY_SOURCE_CLOUD, + new base::FundamentalValue(true), + nullptr); + UpdateProviderPolicy(policies); + EXPECT_TRUE(pref->GetBoolean(prefs::kArcEnabled)); + EXPECT_EQ(arc::ArcBridgeService::State::READY, arc_bridge_service->state()); + + // Disable ARC. + policies.Set(key::kArcEnabled, + POLICY_LEVEL_MANDATORY, + POLICY_SCOPE_USER, + POLICY_SOURCE_CLOUD, + new base::FundamentalValue(false), + nullptr); + UpdateProviderPolicy(policies); + EXPECT_FALSE(pref->GetBoolean(prefs::kArcEnabled)); + EXPECT_EQ(arc::ArcBridgeService::State::STOPPED, arc_bridge_service->state()); + + TearDownTest(); +} #endif // defined(OS_CHROMEOS) } // namespace policy diff --git a/chrome/browser/resources/options/browser_options.html b/chrome/browser/resources/options/browser_options.html index 77ee6a1..478ec4d 100644 --- a/chrome/browser/resources/options/browser_options.html +++ b/chrome/browser/resources/options/browser_options.html @@ -222,7 +222,7 @@ </div> </section> <if expr="chromeos"> - <section id="andorid-apps-section" guest-visibility="hidden"> + <section id="android-apps-section" guest-visibility="hidden"> <h3 i18n-content="androidAppsTitle"></h3> <div class="checkbox controlled-setting-with-label"> <label> @@ -230,6 +230,8 @@ metric="Options_AndroidApps" type="checkbox"> <span> <span i18n-content="androidAppsEnabled"></span> + <span class="controlled-setting-indicator" + pref="arc.enabled"></span> </span> </label> </div> diff --git a/chrome/browser/resources/options/browser_options.js b/chrome/browser/resources/options/browser_options.js index 2b63e80..60c23a2 100644 --- a/chrome/browser/resources/options/browser_options.js +++ b/chrome/browser/resources/options/browser_options.js @@ -2327,10 +2327,11 @@ cr.define('options', function() { }; /** - * Hides Android Apps settings when they are not available (ChromeOS only). + * Hides Android Apps settings when they are not available. + * (Chrome OS only). */ BrowserOptions.hideAndroidAppsSection = function() { - var section = $('andorid-apps-section'); + var section = $('android-apps-section'); if (section) section.hidden = true; }; diff --git a/chrome/browser/ui/webui/options/chromeos/guest_mode_options_browsertest.js b/chrome/browser/ui/webui/options/chromeos/guest_mode_options_browsertest.js index b7a52858..f4a0d0e 100644 --- a/chrome/browser/ui/webui/options/chromeos/guest_mode_options_browsertest.js +++ b/chrome/browser/ui/webui/options/chromeos/guest_mode_options_browsertest.js @@ -44,7 +44,7 @@ GuestModeOptionsUIBrowserTest.prototype = { TEST_F('GuestModeOptionsUIBrowserTest', 'testSections', function() { this.expectHidden($('startup-section')); this.expectHidden($('appearance-section')); - this.expectHidden($('andorid-apps-section')); + this.expectHidden($('android-apps-section')); this.expectHidden($('sync-users-section')); this.expectHidden($('easy-unlock-section')); this.expectHidden($('reset-profile-settings-section')); |
