summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/app/policy/policy_templates.json3
-rw-r--r--chrome/browser/browser_process_impl.cc1
-rw-r--r--chrome/browser/chrome_browser_main.cc1
-rw-r--r--chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chromeos.cc7
-rw-r--r--chrome/browser/managed_mode/managed_mode_browsertest.cc40
-rw-r--r--chrome/browser/managed_mode/managed_mode_resource_throttle_browsertest.cc18
-rw-r--r--chrome/browser/managed_mode/managed_mode_url_filter.cc1
-rw-r--r--chrome/browser/managed_mode/managed_mode_url_filter.h5
-rw-r--r--chrome/browser/managed_mode/managed_user_service.cc38
-rw-r--r--chrome/browser/managed_mode/managed_user_service.h7
-rw-r--r--chrome/browser/managed_mode/managed_user_service_browsertest.cc39
-rw-r--r--chrome/browser/managed_mode/managed_user_settings_service.cc221
-rw-r--r--chrome/browser/managed_mode/managed_user_settings_service.h49
-rw-r--r--chrome/browser/managed_mode/managed_user_settings_service_unittest.cc261
-rw-r--r--chrome/browser/policy/browser_policy_connector.cc1
-rw-r--r--chrome/browser/policy/configuration_policy_handler_list.cc15
-rw-r--r--chrome/browser/policy/managed_mode_policy_provider.cc384
-rw-r--r--chrome/browser/policy/managed_mode_policy_provider.h146
-rw-r--r--chrome/browser/policy/managed_mode_policy_provider_unittest.cc399
-rw-r--r--chrome/browser/policy/profile_policy_connector.cc16
-rw-r--r--chrome/browser/policy/profile_policy_connector.h11
-rw-r--r--chrome/browser/prefs/chrome_pref_service_factory.cc18
-rw-r--r--chrome/browser/prefs/chrome_pref_service_factory.h11
-rw-r--r--chrome/browser/profiles/profile_impl.cc36
-rw-r--r--chrome/browser/sync/profile_sync_components_factory_impl.cc9
-rw-r--r--chrome/browser/sync/test/integration/single_client_managed_user_settings_sync_test.cc25
-rw-r--r--chrome/chrome_browser.gypi4
-rw-r--r--chrome/chrome_tests_unit.gypi2
-rw-r--r--chrome/common/chrome_constants.cc2
-rw-r--r--chrome/common/chrome_constants.h2
-rw-r--r--chrome/test/base/testing_profile.cc13
31 files changed, 669 insertions, 1116 deletions
diff --git a/chrome/app/policy/policy_templates.json b/chrome/app/policy/policy_templates.json
index 9dec4fd..4125efa 100644
--- a/chrome/app/policy/policy_templates.json
+++ b/chrome/app/policy/policy_templates.json
@@ -5377,6 +5377,7 @@
{
'name': 'ContentPackDefaultFilteringBehavior',
'future': True,
+ 'deprecated': True,
'type': 'int-enum',
'schema': {
'type': 'integer',
@@ -5414,6 +5415,7 @@
{
'name': 'ContentPackManualBehaviorHosts',
'future': True,
+ 'deprecated': True,
'type': 'dict',
'schema': {
'type': 'object',
@@ -5439,6 +5441,7 @@
{
'name': 'ContentPackManualBehaviorURLs',
'future': True,
+ 'deprecated': True,
'type': 'dict',
'schema': {
'type': 'object',
diff --git a/chrome/browser/browser_process_impl.cc b/chrome/browser/browser_process_impl.cc
index 96756ee..5dd6eda 100644
--- a/chrome/browser/browser_process_impl.cc
+++ b/chrome/browser/browser_process_impl.cc
@@ -849,7 +849,6 @@ void BrowserProcessImpl::CreateLocalState() {
chrome_prefs::CreateLocalState(local_state_path,
local_state_task_runner_.get(),
policy_service(),
- NULL,
pref_registry,
false));
diff --git a/chrome/browser/chrome_browser_main.cc b/chrome/browser/chrome_browser_main.cc
index 4723a10..fbbff83 100644
--- a/chrome/browser/chrome_browser_main.cc
+++ b/chrome/browser/chrome_browser_main.cc
@@ -273,7 +273,6 @@ PrefService* InitializeLocalState(
parent_profile,
local_state_task_runner,
g_browser_process->policy_service(),
- NULL,
registry,
false));
registry->RegisterStringPref(prefs::kApplicationLocale, std::string());
diff --git a/chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chromeos.cc b/chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chromeos.cc
index 5314e80..90da3f8 100644
--- a/chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chromeos.cc
+++ b/chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chromeos.cc
@@ -104,12 +104,11 @@ scoped_ptr<UserCloudPolicyManagerChromeOS>
CHECK(user);
// Only USER_TYPE_REGULAR users have user cloud policy.
- // USER_TYPE_RETAIL_MODE, USER_TYPE_KIOSK_APP and USER_TYPE_GUEST are not
- // signed in and can't authenticate the policy registration.
+ // USER_TYPE_RETAIL_MODE, USER_TYPE_KIOSK_APP, USER_TYPE_GUEST and
+ // USER_TYPE_LOCALLY_MANAGED are not signed in and can't authenticate the
+ // policy registration.
// USER_TYPE_PUBLIC_ACCOUNT gets its policy from the
// DeviceLocalAccountPolicyService.
- // USER_TYPE_LOCALLY_MANAGED gets its policy from the
- // ManagedModePolicyProvider.
const std::string& username = user->email();
if (user->GetType() != chromeos::User::USER_TYPE_REGULAR ||
BrowserPolicyConnector::IsNonEnterpriseUser(username)) {
diff --git a/chrome/browser/managed_mode/managed_mode_browsertest.cc b/chrome/browser/managed_mode/managed_mode_browsertest.cc
index ab7488d..16877f2 100644
--- a/chrome/browser/managed_mode/managed_mode_browsertest.cc
+++ b/chrome/browser/managed_mode/managed_mode_browsertest.cc
@@ -14,11 +14,11 @@
#include "chrome/browser/infobars/infobar_service.h"
#include "chrome/browser/managed_mode/managed_mode_interstitial.h"
#include "chrome/browser/managed_mode/managed_mode_navigation_observer.h"
+#include "chrome/browser/managed_mode/managed_user_constants.h"
#include "chrome/browser/managed_mode/managed_user_service.h"
#include "chrome/browser/managed_mode/managed_user_service_factory.h"
-#include "chrome/browser/policy/managed_mode_policy_provider.h"
-#include "chrome/browser/policy/profile_policy_connector.h"
-#include "chrome/browser/policy/profile_policy_connector_factory.h"
+#include "chrome/browser/managed_mode/managed_user_settings_service.h"
+#include "chrome/browser/managed_mode/managed_user_settings_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_navigator.h"
@@ -36,7 +36,6 @@
#include "content/public/browser/web_contents_observer.h"
#include "content/public/test/browser_test_utils.h"
#include "grit/generated_resources.h"
-#include "policy/policy_constants.h"
#include "ui/base/l10n/l10n_util.h"
using content::InterstitialPage;
@@ -109,15 +108,12 @@ class ManagedModeBlockModeTest : public InProcessBrowserTest {
Profile* profile = browser()->profile();
managed_user_service_ = ManagedUserServiceFactory::GetForProfile(profile);
managed_user_service_->InitForTesting();
- policy::ProfilePolicyConnector* connector =
- policy::ProfilePolicyConnectorFactory::GetForProfile(profile);
- policy::ManagedModePolicyProvider* policy_provider =
- connector->managed_mode_policy_provider();
- policy_provider->SetLocalPolicyForTesting(
- policy::key::kContentPackDefaultFilteringBehavior,
+ ManagedUserSettingsService* managed_user_settings_service =
+ ManagedUserSettingsServiceFactory::GetForProfile(profile);
+ managed_user_settings_service->SetLocalSettingForTesting(
+ managed_users::kContentPackDefaultFilteringBehavior,
scoped_ptr<base::Value>(
new base::FundamentalValue(ManagedModeURLFilter::BLOCK)));
- base::RunLoop().RunUntilIdle();
}
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
@@ -187,14 +183,11 @@ IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest,
// Set the host as allowed.
scoped_ptr<DictionaryValue> dict(new DictionaryValue);
dict->SetBooleanWithoutPathExpansion(allowed_url.host(), true);
- policy::ProfilePolicyConnector* connector =
- policy::ProfilePolicyConnectorFactory::GetForProfile(
+ ManagedUserSettingsService* managed_user_settings_service =
+ ManagedUserSettingsServiceFactory::GetForProfile(
browser()->profile());
- policy::ManagedModePolicyProvider* policy_provider =
- connector->managed_mode_policy_provider();
- policy_provider->SetLocalPolicyForTesting(
- policy::key::kContentPackManualBehaviorHosts, dict.PassAs<Value>());
- base::RunLoop().RunUntilIdle();
+ managed_user_settings_service->SetLocalSettingForTesting(
+ managed_users::kContentPackManualBehaviorHosts, dict.PassAs<Value>());
EXPECT_EQ(
ManagedUserService::MANUAL_ALLOW,
managed_user_service_->GetManualBehaviorForHost(allowed_url.host()));
@@ -254,14 +247,11 @@ IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest, Unblock) {
// Set the host as allowed.
scoped_ptr<DictionaryValue> dict(new DictionaryValue);
dict->SetBooleanWithoutPathExpansion(test_url.host(), true);
- policy::ProfilePolicyConnector* connector =
- policy::ProfilePolicyConnectorFactory::GetForProfile(
+ ManagedUserSettingsService* managed_user_settings_service =
+ ManagedUserSettingsServiceFactory::GetForProfile(
browser()->profile());
- policy::ManagedModePolicyProvider* policy_provider =
- connector->managed_mode_policy_provider();
- policy_provider->SetLocalPolicyForTesting(
- policy::key::kContentPackManualBehaviorHosts, dict.PassAs<Value>());
- base::RunLoop().RunUntilIdle();
+ managed_user_settings_service->SetLocalSettingForTesting(
+ managed_users::kContentPackManualBehaviorHosts, dict.PassAs<Value>());
EXPECT_EQ(
ManagedUserService::MANUAL_ALLOW,
managed_user_service_->GetManualBehaviorForHost(test_url.host()));
diff --git a/chrome/browser/managed_mode/managed_mode_resource_throttle_browsertest.cc b/chrome/browser/managed_mode/managed_mode_resource_throttle_browsertest.cc
index 8fc1a53..9fdf8a6 100644
--- a/chrome/browser/managed_mode/managed_mode_resource_throttle_browsertest.cc
+++ b/chrome/browser/managed_mode/managed_mode_resource_throttle_browsertest.cc
@@ -6,11 +6,11 @@
#include "base/prefs/pref_service.h"
#include "base/values.h"
+#include "chrome/browser/managed_mode/managed_user_constants.h"
#include "chrome/browser/managed_mode/managed_user_service.h"
#include "chrome/browser/managed_mode/managed_user_service_factory.h"
-#include "chrome/browser/policy/managed_mode_policy_provider.h"
-#include "chrome/browser/policy/profile_policy_connector.h"
-#include "chrome/browser/policy/profile_policy_connector_factory.h"
+#include "chrome/browser/managed_mode/managed_user_settings_service.h"
+#include "chrome/browser/managed_mode/managed_user_settings_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/test/base/in_process_browser_test.h"
@@ -21,7 +21,6 @@
#include "content/public/test/test_navigation_observer.h"
#include "content/public/test/test_utils.h"
#include "content/public/test/test_utils.h"
-#include "policy/policy_constants.h"
using content::MessageLoopRunner;
using content::NavigationController;
@@ -49,15 +48,12 @@ void ManagedModeResourceThrottleTest::SetUpOnMainThread() {
IN_PROC_BROWSER_TEST_F(ManagedModeResourceThrottleTest,
NoNavigationObserverBlock) {
Profile* profile = browser()->profile();
- policy::ProfilePolicyConnector* connector =
- policy::ProfilePolicyConnectorFactory::GetForProfile(profile);
- policy::ManagedModePolicyProvider* policy_provider =
- connector->managed_mode_policy_provider();
- policy_provider->SetLocalPolicyForTesting(
- policy::key::kContentPackDefaultFilteringBehavior,
+ ManagedUserSettingsService* managed_user_settings_service =
+ ManagedUserSettingsServiceFactory::GetForProfile(profile);
+ managed_user_settings_service->SetLocalSettingForTesting(
+ managed_users::kContentPackDefaultFilteringBehavior,
scoped_ptr<base::Value>(
new base::FundamentalValue(ManagedModeURLFilter::BLOCK)));
- base::RunLoop().RunUntilIdle();
scoped_ptr<WebContents> web_contents(
WebContents::Create(WebContents::CreateParams(profile)));
diff --git a/chrome/browser/managed_mode/managed_mode_url_filter.cc b/chrome/browser/managed_mode/managed_mode_url_filter.cc
index 67d7f66..382e444 100644
--- a/chrome/browser/managed_mode/managed_mode_url_filter.cc
+++ b/chrome/browser/managed_mode/managed_mode_url_filter.cc
@@ -13,6 +13,7 @@
#include "base/strings/string_util.h"
#include "base/task_runner_util.h"
#include "base/threading/sequenced_worker_pool.h"
+#include "chrome/browser/policy/url_blacklist_manager.h"
#include "content/public/browser/browser_thread.h"
#include "extensions/common/matcher/url_matcher.h"
#include "url/gurl.h"
diff --git a/chrome/browser/managed_mode/managed_mode_url_filter.h b/chrome/browser/managed_mode/managed_mode_url_filter.h
index 22ec145..c0874a3 100644
--- a/chrome/browser/managed_mode/managed_mode_url_filter.h
+++ b/chrome/browser/managed_mode/managed_mode_url_filter.h
@@ -14,11 +14,6 @@
#include "base/values.h"
#include "chrome/browser/managed_mode/managed_mode_site_list.h"
#include "chrome/browser/managed_mode/managed_users.h"
-#include "chrome/browser/policy/url_blacklist_manager.h"
-
-namespace policy {
-class URLBlacklist;
-} // namespace policy
class GURL;
diff --git a/chrome/browser/managed_mode/managed_user_service.cc b/chrome/browser/managed_mode/managed_user_service.cc
index 017aaac..96bb3a1 100644
--- a/chrome/browser/managed_mode/managed_user_service.cc
+++ b/chrome/browser/managed_mode/managed_user_service.cc
@@ -17,12 +17,12 @@
#include "chrome/browser/managed_mode/custodian_profile_downloader_service.h"
#include "chrome/browser/managed_mode/custodian_profile_downloader_service_factory.h"
#include "chrome/browser/managed_mode/managed_mode_site_list.h"
+#include "chrome/browser/managed_mode/managed_user_constants.h"
#include "chrome/browser/managed_mode/managed_user_registration_utility.h"
+#include "chrome/browser/managed_mode/managed_user_settings_service.h"
+#include "chrome/browser/managed_mode/managed_user_settings_service_factory.h"
#include "chrome/browser/managed_mode/managed_user_sync_service.h"
#include "chrome/browser/managed_mode/managed_user_sync_service_factory.h"
-#include "chrome/browser/policy/managed_mode_policy_provider.h"
-#include "chrome/browser/policy/profile_policy_connector.h"
-#include "chrome/browser/policy/profile_policy_connector_factory.h"
#include "chrome/browser/prefs/scoped_user_pref_update.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/signin_manager.h"
@@ -48,7 +48,6 @@
#include "google_apis/gaia/google_service_auth_error.h"
#include "grit/generated_resources.h"
#include "net/base/escape.h"
-#include "policy/policy_constants.h"
#include "ui/base/l10n/l10n_util.h"
#if defined(OS_CHROMEOS)
@@ -58,7 +57,6 @@
using base::DictionaryValue;
using base::Value;
using content::BrowserThread;
-using policy::ManagedModePolicyProvider;
namespace {
@@ -449,10 +447,8 @@ ScopedVector<ManagedModeSiteList> ManagedUserService::GetActiveSiteLists() {
return site_lists.Pass();
}
-ManagedModePolicyProvider* ManagedUserService::GetPolicyProvider() {
- policy::ProfilePolicyConnector* connector =
- policy::ProfilePolicyConnectorFactory::GetForProfile(profile_);
- return connector->managed_mode_policy_provider();
+ManagedUserSettingsService* ManagedUserService::GetSettingsService() {
+ return ManagedUserSettingsServiceFactory::GetForProfile(profile_);
}
void ManagedUserService::OnDefaultFilteringBehaviorChanged() {
@@ -487,7 +483,7 @@ void ManagedUserService::AddAccessRequest(const GURL& url) {
std::string output(net::EscapeQueryParamValue(normalized_url.spec(), true));
// Add the prefix.
- std::string key = ManagedModePolicyProvider::MakeSplitSettingKey(
+ std::string key = ManagedUserSettingsService::MakeSplitSettingKey(
kManagedUserAccessRequestKeyPrefix, output);
scoped_ptr<DictionaryValue> dict(new DictionaryValue);
@@ -495,7 +491,7 @@ void ManagedUserService::AddAccessRequest(const GURL& url) {
// TODO(sergiu): Use sane time here when it's ready.
dict->SetDouble(kManagedUserAccessRequestTime, base::Time::Now().ToJsTime());
- GetPolicyProvider()->UploadItem(key, dict.PassAs<Value>());
+ GetSettingsService()->UploadItem(key, dict.PassAs<Value>());
}
ManagedUserService::ManualBehavior ManagedUserService::GetManualBehaviorForHost(
@@ -564,14 +560,15 @@ const char* ManagedUserService::GetManagedUserPseudoEmail() {
}
void ManagedUserService::Init() {
- ManagedModePolicyProvider* policy_provider = GetPolicyProvider();
+ ManagedUserSettingsService* settings_service = GetSettingsService();
+ DCHECK(settings_service->IsReady());
if (!ProfileIsManaged()) {
- if (policy_provider)
- policy_provider->Clear();
-
+ settings_service->Clear();
return;
}
+ settings_service->Activate();
+
CommandLine* command_line = CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(switches::kManagedUserSyncToken)) {
InitSync(
@@ -609,9 +606,6 @@ void ManagedUserService::Init() {
BrowserList::AddObserver(this);
- if (policy_provider)
- policy_provider->InitLocalPolicies();
-
// Initialize the filter.
OnDefaultFilteringBehaviorChanged();
UpdateSiteLists();
@@ -720,7 +714,8 @@ void ManagedUserService::OnBrowserSetLastActive(Browser* browser) {
void ManagedUserService::RecordProfileAndBrowserEventsHelper(
const char* key_prefix) {
- std::string key = ManagedModePolicyProvider::MakeSplitSettingKey(key_prefix,
+ std::string key = ManagedUserSettingsService::MakeSplitSettingKey(
+ key_prefix,
base::Int64ToString(base::TimeTicks::Now().ToInternalValue()));
scoped_ptr<DictionaryValue> dict(new DictionaryValue);
@@ -728,8 +723,5 @@ void ManagedUserService::RecordProfileAndBrowserEventsHelper(
// TODO(bauerb): Use sane time when ready.
dict->SetDouble(kEventTimestamp, base::Time::Now().ToJsTime());
- ManagedModePolicyProvider* provider = GetPolicyProvider();
- // It is NULL in tests.
- if (provider)
- provider->UploadItem(key, dict.PassAs<Value>());
+ GetSettingsService()->UploadItem(key, dict.PassAs<Value>());
}
diff --git a/chrome/browser/managed_mode/managed_user_service.h b/chrome/browser/managed_mode/managed_user_service.h
index de1b604..b2d05f6 100644
--- a/chrome/browser/managed_mode/managed_user_service.h
+++ b/chrome/browser/managed_mode/managed_user_service.h
@@ -27,12 +27,9 @@ class GoogleServiceAuthError;
class ManagedModeURLFilter;
class ManagedModeSiteList;
class ManagedUserRegistrationUtility;
+class ManagedUserSettingsService;
class Profile;
-namespace policy {
-class ManagedModePolicyProvider;
-}
-
namespace user_prefs {
class PrefRegistrySyncable;
}
@@ -230,7 +227,7 @@ class ManagedUserService : public BrowserContextKeyedService,
// managed profile.
ScopedVector<ManagedModeSiteList> GetActiveSiteLists();
- policy::ManagedModePolicyProvider* GetPolicyProvider();
+ ManagedUserSettingsService* GetSettingsService();
void OnDefaultFilteringBehaviorChanged();
diff --git a/chrome/browser/managed_mode/managed_user_service_browsertest.cc b/chrome/browser/managed_mode/managed_user_service_browsertest.cc
index b83247f..9af82f6 100644
--- a/chrome/browser/managed_mode/managed_user_service_browsertest.cc
+++ b/chrome/browser/managed_mode/managed_user_service_browsertest.cc
@@ -5,11 +5,11 @@
#include "base/prefs/pref_service.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/managed_mode/managed_user_constants.h"
#include "chrome/browser/managed_mode/managed_user_service.h"
#include "chrome/browser/managed_mode/managed_user_service_factory.h"
-#include "chrome/browser/policy/managed_mode_policy_provider.h"
-#include "chrome/browser/policy/profile_policy_connector.h"
-#include "chrome/browser/policy/profile_policy_connector_factory.h"
+#include "chrome/browser/managed_mode/managed_user_settings_service.h"
+#include "chrome/browser/managed_mode/managed_user_settings_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_info_cache.h"
#include "chrome/browser/profiles/profile_manager.h"
@@ -17,7 +17,6 @@
#include "chrome/common/pref_names.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "content/public/test/test_utils.h"
-#include "policy/policy_constants.h"
typedef InProcessBrowserTest ManagedUserServiceTest;
@@ -25,21 +24,20 @@ IN_PROC_BROWSER_TEST_F(ManagedUserServiceTest, LocalPolicies) {
Profile* profile = browser()->profile();
PrefService* prefs = profile->GetPrefs();
EXPECT_FALSE(prefs->GetBoolean(prefs::kForceSafeSearch));
- EXPECT_FALSE(prefs->IsManagedPreference(prefs::kForceSafeSearch));
+ EXPECT_TRUE(prefs->IsUserModifiablePreference(prefs::kForceSafeSearch));
ManagedUserService* managed_user_service =
ManagedUserServiceFactory::GetForProfile(profile);
managed_user_service->InitForTesting();
- content::RunAllPendingInMessageLoop();
EXPECT_TRUE(prefs->GetBoolean(prefs::kForceSafeSearch));
- EXPECT_TRUE(prefs->IsManagedPreference(prefs::kForceSafeSearch));
+ EXPECT_FALSE(prefs->IsUserModifiablePreference(prefs::kForceSafeSearch));
}
IN_PROC_BROWSER_TEST_F(ManagedUserServiceTest, ProfileName) {
Profile* profile = browser()->profile();
PrefService* prefs = profile->GetPrefs();
- EXPECT_FALSE(prefs->IsManagedPreference(prefs::kProfileName));
+ EXPECT_TRUE(prefs->IsUserModifiablePreference(prefs::kProfileName));
std::string original_name = prefs->GetString(prefs::kProfileName);
ProfileManager* profile_manager = g_browser_process->profile_manager();
@@ -52,36 +50,31 @@ IN_PROC_BROWSER_TEST_F(ManagedUserServiceTest, ProfileName) {
ManagedUserService* managed_user_service =
ManagedUserServiceFactory::GetForProfile(profile);
managed_user_service->InitForTesting();
- policy::ProfilePolicyConnector* connector =
- policy::ProfilePolicyConnectorFactory::GetForProfile(profile);
- policy::ManagedModePolicyProvider* provider =
- connector->managed_mode_policy_provider();
+ ManagedUserSettingsService* settings =
+ ManagedUserSettingsServiceFactory::GetForProfile(profile);
std::string name = "Managed User Test Name";
- provider->SetLocalPolicyForTesting(
- policy::key::kUserDisplayName,
+ settings->SetLocalSettingForTesting(
+ managed_users::kUserName,
scoped_ptr<base::Value>(new base::StringValue(name)));
- content::RunAllPendingInMessageLoop();
- EXPECT_TRUE(prefs->IsManagedPreference(prefs::kProfileName));
+ EXPECT_FALSE(prefs->IsUserModifiablePreference(prefs::kProfileName));
EXPECT_EQ(name, prefs->GetString(prefs::kProfileName));
profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath());
EXPECT_EQ(name, UTF16ToUTF8(cache.GetNameOfProfileAtIndex(profile_index)));
// Change the name once more.
std::string new_name = "New Managed User Test Name";
- provider->SetLocalPolicyForTesting(
- policy::key::kUserDisplayName,
+ settings->SetLocalSettingForTesting(
+ managed_users::kUserName,
scoped_ptr<base::Value>(new base::StringValue(new_name)));
- content::RunAllPendingInMessageLoop();;
EXPECT_EQ(new_name, prefs->GetString(prefs::kProfileName));
profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath());
EXPECT_EQ(new_name,
UTF16ToUTF8(cache.GetNameOfProfileAtIndex(profile_index)));
- // Remove the policy.
- provider->SetLocalPolicyForTesting(policy::key::kUserDisplayName,
- scoped_ptr<base::Value>());
- content::RunAllPendingInMessageLoop();
+ // Remove the setting.
+ settings->SetLocalSettingForTesting(managed_users::kUserName,
+ scoped_ptr<base::Value>());
EXPECT_EQ(original_name, prefs->GetString(prefs::kProfileName));
profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath());
EXPECT_EQ(original_name,
diff --git a/chrome/browser/managed_mode/managed_user_settings_service.cc b/chrome/browser/managed_mode/managed_user_settings_service.cc
index 7f86b07..6f47210 100644
--- a/chrome/browser/managed_mode/managed_user_settings_service.cc
+++ b/chrome/browser/managed_mode/managed_user_settings_service.cc
@@ -15,11 +15,25 @@
#include "chrome/common/chrome_constants.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/user_metrics.h"
+#include "sync/api/sync_change.h"
+#include "sync/api/sync_error_factory.h"
+#include "sync/protocol/sync.pb.h"
using base::DictionaryValue;
+using base::JSONReader;
using base::Value;
using content::BrowserThread;
using content::UserMetricsAction;
+using syncer::MANAGED_USER_SETTINGS;
+using syncer::ModelType;
+using syncer::SyncChange;
+using syncer::SyncChangeList;
+using syncer::SyncChangeProcessor;
+using syncer::SyncData;
+using syncer::SyncDataList;
+using syncer::SyncError;
+using syncer::SyncErrorFactory;
+using syncer::SyncMergeResult;
const char kAtomicSettings[] = "atomic_settings";
const char kManagedUserInternalItemPrefix[] = "X-";
@@ -41,6 +55,20 @@ ManagedUserSettingsService::ManagedUserSettingsService()
ManagedUserSettingsService::~ManagedUserSettingsService() {}
void ManagedUserSettingsService::Init(
+ base::FilePath profile_path,
+ base::SequencedTaskRunner* sequenced_task_runner,
+ bool load_synchronously) {
+ base::FilePath path =
+ profile_path.Append(chrome::kManagedUserSettingsFilename);
+ PersistentPrefStore* store = new JsonPrefStore(path, sequenced_task_runner);
+ Init(store);
+ if (load_synchronously)
+ store_->ReadPrefs();
+ else
+ store_->ReadPrefsAsync(NULL);
+}
+
+void ManagedUserSettingsService::Init(
scoped_refptr<PersistentPrefStore> store) {
DCHECK(!store_);
store_ = store;
@@ -69,6 +97,42 @@ void ManagedUserSettingsService::Clear() {
store_->RemoveValue(kAtomicSettings);
store_->RemoveValue(kSplitSettings);
}
+
+// static
+std::string ManagedUserSettingsService::MakeSplitSettingKey(
+ const std::string& prefix,
+ const std::string& key) {
+ return prefix + kSplitSettingKeySeparator + key;
+}
+
+void ManagedUserSettingsService::UploadItem(const std::string& key,
+ scoped_ptr<Value> value) {
+ DCHECK(!SettingShouldApplyToPrefs(key));
+
+ std::string key_suffix = key;
+ DictionaryValue* dict = NULL;
+ if (sync_processor_) {
+ content::RecordAction(UserMetricsAction("ManagedUsers_UploadItem_Syncing"));
+ dict = GetDictionaryAndSplitKey(&key_suffix);
+ DCHECK(GetQueuedItems()->empty());
+ SyncChangeList change_list;
+ SyncData data = CreateSyncDataForSetting(key, *value);
+ SyncChange::SyncChangeType change_type =
+ dict->HasKey(key_suffix) ? SyncChange::ACTION_UPDATE
+ : SyncChange::ACTION_ADD;
+ change_list.push_back(SyncChange(FROM_HERE, change_type, data));
+ SyncError error =
+ sync_processor_->ProcessSyncChanges(FROM_HERE, change_list);
+ DCHECK(!error.IsSet()) << error.ToString();
+ } else {
+ // Queue the item up to be uploaded when we start syncing
+ // (in MergeDataAndStartSyncing()).
+ content::RecordAction(UserMetricsAction("ManagedUsers_UploadItem_Queued"));
+ dict = GetQueuedItems();
+ }
+ dict->SetWithoutPathExpansion(key_suffix, value.release());
+}
+
void ManagedUserSettingsService::SetLocalSettingForTesting(
const std::string& key,
scoped_ptr<Value> value) {
@@ -80,9 +144,148 @@ void ManagedUserSettingsService::SetLocalSettingForTesting(
InformSubscribers();
}
+// static
+SyncData ManagedUserSettingsService::CreateSyncDataForSetting(
+ const std::string& name,
+ const Value& value) {
+ std::string json_value;
+ base::JSONWriter::Write(&value, &json_value);
+ ::sync_pb::EntitySpecifics specifics;
+ specifics.mutable_managed_user_setting()->set_name(name);
+ specifics.mutable_managed_user_setting()->set_value(json_value);
+ return SyncData::CreateLocalData(name, name, specifics);
+}
+
void ManagedUserSettingsService::Shutdown() {
store_->RemoveObserver(this);
}
+
+SyncMergeResult ManagedUserSettingsService::MergeDataAndStartSyncing(
+ ModelType type,
+ const SyncDataList& initial_sync_data,
+ scoped_ptr<SyncChangeProcessor> sync_processor,
+ scoped_ptr<SyncErrorFactory> error_handler) {
+ DCHECK_EQ(MANAGED_USER_SETTINGS, type);
+ sync_processor_ = sync_processor.Pass();
+ error_handler_ = error_handler.Pass();
+
+ // Clear all atomic and split settings, then recreate them from Sync data.
+ Clear();
+ for (SyncDataList::const_iterator it = initial_sync_data.begin();
+ it != initial_sync_data.end(); ++it) {
+ DCHECK_EQ(MANAGED_USER_SETTINGS, it->GetDataType());
+ const ::sync_pb::ManagedUserSettingSpecifics& managed_user_setting =
+ it->GetSpecifics().managed_user_setting();
+ scoped_ptr<Value> value(JSONReader::Read(managed_user_setting.value()));
+ std::string name_suffix = managed_user_setting.name();
+ DictionaryValue* dict = GetDictionaryAndSplitKey(&name_suffix);
+ dict->SetWithoutPathExpansion(name_suffix, value.release());
+ }
+ store_->ReportValueChanged(kAtomicSettings);
+ store_->ReportValueChanged(kSplitSettings);
+ InformSubscribers();
+
+ // Upload all the queued up items (either with an ADD or an UPDATE action,
+ // depending on whether they already exist) and move them to split settings.
+ SyncChangeList change_list;
+ DictionaryValue* queued_items = GetQueuedItems();
+ for (DictionaryValue::Iterator it(*queued_items); !it.IsAtEnd();
+ it.Advance()) {
+ std::string key_suffix = it.key();
+ DictionaryValue* dict = GetDictionaryAndSplitKey(&key_suffix);
+ SyncData data = CreateSyncDataForSetting(it.key(), it.value());
+ SyncChange::SyncChangeType change_type =
+ dict->HasKey(key_suffix) ? SyncChange::ACTION_UPDATE
+ : SyncChange::ACTION_ADD;
+ change_list.push_back(SyncChange(FROM_HERE, change_type, data));
+ dict->SetWithoutPathExpansion(key_suffix, it.value().DeepCopy());
+ }
+ queued_items->Clear();
+
+ SyncMergeResult result(MANAGED_USER_SETTINGS);
+ // Process all the accumulated changes from the queued items.
+ if (change_list.size() > 0) {
+ store_->ReportValueChanged(kQueuedItems);
+ result.set_error(
+ sync_processor_->ProcessSyncChanges(FROM_HERE, change_list));
+ }
+
+ // TODO(bauerb): Statistics?
+ return result;
+}
+
+void ManagedUserSettingsService::StopSyncing(ModelType type) {
+ DCHECK_EQ(syncer::MANAGED_USER_SETTINGS, type);
+ sync_processor_.reset();
+ error_handler_.reset();
+}
+
+SyncDataList ManagedUserSettingsService::GetAllSyncData(
+ ModelType type) const {
+ DCHECK_EQ(syncer::MANAGED_USER_SETTINGS, type);
+ SyncDataList data;
+ for (DictionaryValue::Iterator it(*GetAtomicSettings()); !it.IsAtEnd();
+ it.Advance()) {
+ data.push_back(CreateSyncDataForSetting(it.key(), it.value()));
+ }
+ for (DictionaryValue::Iterator it(*GetSplitSettings()); !it.IsAtEnd();
+ it.Advance()) {
+ const DictionaryValue* dict = NULL;
+ it.value().GetAsDictionary(&dict);
+ for (DictionaryValue::Iterator jt(*dict); !jt.IsAtEnd(); jt.Advance()) {
+ data.push_back(CreateSyncDataForSetting(
+ MakeSplitSettingKey(it.key(), jt.key()), jt.value()));
+ }
+ }
+ DCHECK_EQ(0u, GetQueuedItems()->size());
+ return data;
+}
+
+SyncError ManagedUserSettingsService::ProcessSyncChanges(
+ const tracked_objects::Location& from_here,
+ const SyncChangeList& change_list) {
+ for (SyncChangeList::const_iterator it = change_list.begin();
+ it != change_list.end(); ++it) {
+ SyncData data = it->sync_data();
+ DCHECK_EQ(MANAGED_USER_SETTINGS, data.GetDataType());
+ const ::sync_pb::ManagedUserSettingSpecifics& managed_user_setting =
+ data.GetSpecifics().managed_user_setting();
+ std::string key = managed_user_setting.name();
+ DictionaryValue* dict = GetDictionaryAndSplitKey(&key);
+ switch (it->change_type()) {
+ case SyncChange::ACTION_ADD:
+ case SyncChange::ACTION_UPDATE: {
+ scoped_ptr<Value> value(JSONReader::Read(managed_user_setting.value()));
+ if (dict->HasKey(key)) {
+ DLOG_IF(WARNING, it->change_type() == SyncChange::ACTION_ADD)
+ << "Value for key " << key << " already exists";
+ } else {
+ DLOG_IF(WARNING, it->change_type() == SyncChange::ACTION_UPDATE)
+ << "Value for key " << key << " doesn't exist yet";
+ }
+ dict->SetWithoutPathExpansion(key, value.release());
+ break;
+ }
+ case SyncChange::ACTION_DELETE: {
+ DLOG_IF(WARNING, !dict->HasKey(key)) << "Trying to delete nonexistent "
+ << "key " << key;
+ dict->RemoveWithoutPathExpansion(key, NULL);
+ break;
+ }
+ case SyncChange::ACTION_INVALID: {
+ NOTREACHED();
+ break;
+ }
+ }
+ }
+ store_->ReportValueChanged(kAtomicSettings);
+ store_->ReportValueChanged(kSplitSettings);
+ InformSubscribers();
+
+ SyncError error;
+ return error;
+}
+
void ManagedUserSettingsService::OnPrefValueChanged(const std::string& key) {}
void ManagedUserSettingsService::OnInitializationCompleted(bool success) {
@@ -118,6 +321,24 @@ DictionaryValue* ManagedUserSettingsService::GetQueuedItems() const {
return GetOrCreateDictionary(kQueuedItems);
}
+DictionaryValue* ManagedUserSettingsService::GetDictionaryAndSplitKey(
+ std::string* key) const {
+ size_t pos = key->find_first_of(kSplitSettingKeySeparator);
+ if (pos == std::string::npos)
+ return GetAtomicSettings();
+
+ DictionaryValue* split_settings = GetSplitSettings();
+ std::string prefix = key->substr(0, pos);
+ DictionaryValue* dict = NULL;
+ if (!split_settings->GetDictionary(prefix, &dict)) {
+ dict = new DictionaryValue;
+ DCHECK(!split_settings->HasKey(prefix));
+ split_settings->Set(prefix, dict);
+ }
+ key->erase(0, pos + 1);
+ return dict;
+}
+
scoped_ptr<DictionaryValue> ManagedUserSettingsService::GetSettings() {
DCHECK(IsReady());
if (!active_)
diff --git a/chrome/browser/managed_mode/managed_user_settings_service.h b/chrome/browser/managed_mode/managed_user_settings_service.h
index 70bb0c8..cc03c01 100644
--- a/chrome/browser/managed_mode/managed_user_settings_service.h
+++ b/chrome/browser/managed_mode/managed_user_settings_service.h
@@ -15,6 +15,7 @@
#include "base/values.h"
#include "chrome/browser/managed_mode/managed_users.h"
#include "components/browser_context_keyed_service/browser_context_keyed_service.h"
+#include "sync/api/syncable_service.h"
class PersistentPrefStore;
class Profile;
@@ -24,7 +25,6 @@ class FilePath;
class SequencedTaskRunner;
}
-// TODO(bauerb): This class is not yet fully functional.
// This class syncs managed user settings from a server, which are mapped to
// preferences. The downloaded settings are persisted in a PrefStore (which is
// not directly hooked up to the PrefService; it's just used internally).
@@ -50,6 +50,7 @@ class SequencedTaskRunner;
// would be encoded as two sync items, one with key "Moose:foo" and value "bar",
// and one with key "Moose:baz" and value "blurp".
class ManagedUserSettingsService : public BrowserContextKeyedService,
+ public syncer::SyncableService,
public PrefStore::Observer {
public:
// A callback whose first parameter is a dictionary containing all managed
@@ -60,6 +61,14 @@ class ManagedUserSettingsService : public BrowserContextKeyedService,
ManagedUserSettingsService();
virtual ~ManagedUserSettingsService();
+ // Initializes the service by loading its settings from a file underneath the
+ // |profile_path|. File I/O will be serialized via the
+ // |sequenced_task_runner|. If |load_synchronously| is true, the settings will
+ // be loaded synchronously, otherwise asynchronously.
+ void Init(base::FilePath profile_path,
+ base::SequencedTaskRunner* sequenced_task_runner,
+ bool load_synchronously);
+
// Initializes the service by loading its settings from the |pref_store|.
// Use this method in tests to inject a different PrefStore than the
// default one.
@@ -78,13 +87,42 @@ class ManagedUserSettingsService : public BrowserContextKeyedService,
// Clears all managed user settings and items.
void Clear();
+ // Constructs a key for a split managed user setting from a prefix and a
+ // variable key.
+ static std::string MakeSplitSettingKey(const std::string& prefix,
+ const std::string& key);
+
+ // Uploads an item to the Sync server. Items are the same data structure as
+ // managed user settings (i.e. key-value pairs, as described at the top of
+ // the file), but they are only uploaded (whereas managed user settings are
+ // only downloaded), and never passed to the preference system.
+ // An example of an uploaded item is an access request to a blocked URL.
+ void UploadItem(const std::string& key, scoped_ptr<base::Value> value);
+
// Sets the setting with the given |key| to a copy of the given |value|.
void SetLocalSettingForTesting(const std::string& key,
scoped_ptr<base::Value> value);
+ // Public for testing.
+ static syncer::SyncData CreateSyncDataForSetting(const std::string& name,
+ const base::Value& value);
+
// BrowserContextKeyedService implementation:
virtual void Shutdown() OVERRIDE;
+ // SyncableService implementation:
+ virtual syncer::SyncMergeResult MergeDataAndStartSyncing(
+ syncer::ModelType type,
+ const syncer::SyncDataList& initial_sync_data,
+ scoped_ptr<syncer::SyncChangeProcessor> sync_processor,
+ scoped_ptr<syncer::SyncErrorFactory> error_handler) OVERRIDE;
+ virtual void StopSyncing(syncer::ModelType type) OVERRIDE;
+ virtual syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const
+ OVERRIDE;
+ virtual syncer::SyncError ProcessSyncChanges(
+ const tracked_objects::Location& from_here,
+ const syncer::SyncChangeList& change_list) OVERRIDE;
+
// PrefStore::Observer implementation:
virtual void OnPrefValueChanged(const std::string& key) OVERRIDE;
virtual void OnInitializationCompleted(bool success) OVERRIDE;
@@ -95,6 +133,12 @@ class ManagedUserSettingsService : public BrowserContextKeyedService,
base::DictionaryValue* GetSplitSettings() const;
base::DictionaryValue* GetQueuedItems() const;
+ // Returns the dictionary where a given Sync item should be stored, depending
+ // on whether the managed user setting is atomic or split. In case of a split
+ // setting, the split setting prefix of |key| is removed, so that |key| can
+ // be used to update the returned dictionary.
+ base::DictionaryValue* GetDictionaryAndSplitKey(std::string* key) const;
+
// Returns a dictionary with all managed user settings if the service is
// active, or NULL otherwise.
scoped_ptr<base::DictionaryValue> GetSettings();
@@ -114,6 +158,9 @@ class ManagedUserSettingsService : public BrowserContextKeyedService,
std::vector<SettingsCallback> subscribers_;
+ scoped_ptr<syncer::SyncChangeProcessor> sync_processor_;
+ scoped_ptr<syncer::SyncErrorFactory> error_handler_;
+
DISALLOW_COPY_AND_ASSIGN(ManagedUserSettingsService);
};
diff --git a/chrome/browser/managed_mode/managed_user_settings_service_unittest.cc b/chrome/browser/managed_mode/managed_user_settings_service_unittest.cc
index bef9d7a..e48d584 100644
--- a/chrome/browser/managed_mode/managed_user_settings_service_unittest.cc
+++ b/chrome/browser/managed_mode/managed_user_settings_service_unittest.cc
@@ -4,10 +4,81 @@
#include "base/bind.h"
#include "base/callback.h"
+#include "base/json/json_reader.h"
#include "base/prefs/testing_pref_store.h"
+#include "base/strings/string_util.h"
#include "chrome/browser/managed_mode/managed_user_settings_service.h"
+#include "sync/api/sync_change.h"
+#include "sync/api/sync_error_factory_mock.h"
+#include "sync/protocol/sync.pb.h"
#include "testing/gtest/include/gtest/gtest.h"
+namespace {
+
+class MockChangeProcessor : public syncer::SyncChangeProcessor {
+ public:
+ MockChangeProcessor() {}
+ virtual ~MockChangeProcessor() {}
+
+ // SyncChangeProcessor implementation:
+ virtual syncer::SyncError ProcessSyncChanges(
+ const tracked_objects::Location& from_here,
+ const syncer::SyncChangeList& change_list) OVERRIDE;
+ virtual syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const
+ OVERRIDE;
+
+ const syncer::SyncChangeList& changes() const { return change_list_; }
+
+ private:
+ syncer::SyncChangeList change_list_;
+
+ DISALLOW_COPY_AND_ASSIGN(MockChangeProcessor);
+};
+
+syncer::SyncError MockChangeProcessor::ProcessSyncChanges(
+ const tracked_objects::Location& from_here,
+ const syncer::SyncChangeList& change_list) {
+ change_list_ = change_list;
+ return syncer::SyncError();
+}
+
+syncer::SyncDataList MockChangeProcessor::GetAllSyncData(
+ syncer::ModelType type) const {
+ return syncer::SyncDataList();
+}
+
+class MockSyncErrorFactory : public syncer::SyncErrorFactory {
+ public:
+ explicit MockSyncErrorFactory(syncer::ModelType type);
+ virtual ~MockSyncErrorFactory();
+
+ // SyncErrorFactory implementation:
+ virtual syncer::SyncError CreateAndUploadError(
+ const tracked_objects::Location& location,
+ const std::string& message) OVERRIDE;
+
+ private:
+ syncer::ModelType type_;
+
+ DISALLOW_COPY_AND_ASSIGN(MockSyncErrorFactory);
+};
+
+MockSyncErrorFactory::MockSyncErrorFactory(syncer::ModelType type)
+ : type_(type) {}
+
+MockSyncErrorFactory::~MockSyncErrorFactory() {}
+
+syncer::SyncError MockSyncErrorFactory::CreateAndUploadError(
+ const tracked_objects::Location& location,
+ const std::string& message) {
+ return syncer::SyncError(location,
+ syncer::SyncError::DATATYPE_ERROR,
+ message,
+ type_);
+}
+
+} // namespace
+
const char kAtomicItemName[] = "X-Wombat";
const char kSettingsName[] = "TestingSetting";
const char kSettingsValue[] = "SettingsValue";
@@ -18,6 +89,57 @@ class ManagedUserSettingsServiceTest : public ::testing::Test {
ManagedUserSettingsServiceTest() {}
virtual ~ManagedUserSettingsServiceTest() {}
+ scoped_ptr<syncer::SyncChangeProcessor> CreateSyncProcessor() {
+ sync_processor_ = new MockChangeProcessor();
+ return scoped_ptr<syncer::SyncChangeProcessor>(sync_processor_);
+ }
+
+ void StartSyncing(const syncer::SyncDataList& initial_sync_data) {
+ scoped_ptr<syncer::SyncErrorFactory> error_handler(
+ new MockSyncErrorFactory(syncer::MANAGED_USER_SETTINGS));
+ syncer::SyncMergeResult result = settings_service_.MergeDataAndStartSyncing(
+ syncer::MANAGED_USER_SETTINGS,
+ initial_sync_data,
+ CreateSyncProcessor(),
+ error_handler.Pass());
+ EXPECT_FALSE(result.error().IsSet());
+ }
+
+ void UploadSplitItem(const std::string& key, const std::string& value) {
+ split_items_.SetStringWithoutPathExpansion(key, value);
+ settings_service_.UploadItem(
+ ManagedUserSettingsService::MakeSplitSettingKey(kSplitItemName,
+ key),
+ scoped_ptr<base::Value>(new base::StringValue(value)));
+ }
+
+ void UploadAtomicItem(const std::string& value) {
+ atomic_setting_value_.reset(new base::StringValue(value));
+ settings_service_.UploadItem(
+ kAtomicItemName,
+ scoped_ptr<base::Value>(new base::StringValue(value)));
+ }
+
+ void VerifySyncDataItem(syncer::SyncData sync_data) {
+ const sync_pb::ManagedUserSettingSpecifics& managed_user_setting =
+ sync_data.GetSpecifics().managed_user_setting();
+ base::Value* expected_value = NULL;
+ if (managed_user_setting.name() == kAtomicItemName) {
+ expected_value = atomic_setting_value_.get();
+ } else {
+ EXPECT_TRUE(StartsWithASCII(managed_user_setting.name(),
+ std::string(kSplitItemName) + ':',
+ true));
+ std::string key =
+ managed_user_setting.name().substr(strlen(kSplitItemName) + 1);
+ EXPECT_TRUE(split_items_.GetWithoutPathExpansion(key, &expected_value));
+ }
+
+ scoped_ptr<Value> value(
+ base::JSONReader::Read(managed_user_setting.value()));
+ EXPECT_TRUE(expected_value->Equals(value.get()));
+ }
+
void OnNewSettingsAvailable(const base::DictionaryValue* settings) {
if (!settings)
settings_.reset();
@@ -46,8 +168,66 @@ class ManagedUserSettingsServiceTest : public ::testing::Test {
scoped_ptr<base::Value> atomic_setting_value_;
ManagedUserSettingsService settings_service_;
scoped_ptr<base::DictionaryValue> settings_;
+
+ // Owned by the ManagedUserSettingsService.
+ MockChangeProcessor* sync_processor_;
};
+TEST_F(ManagedUserSettingsServiceTest, ProcessAtomicSetting) {
+ StartSyncing(syncer::SyncDataList());
+ ASSERT_TRUE(settings_);
+ const base::Value* value = NULL;
+ EXPECT_FALSE(settings_->GetWithoutPathExpansion(kSettingsName, &value));
+
+ settings_.reset();
+ syncer::SyncData data =
+ ManagedUserSettingsService::CreateSyncDataForSetting(
+ kSettingsName, base::StringValue(kSettingsValue));
+ syncer::SyncChangeList change_list;
+ change_list.push_back(
+ syncer::SyncChange(FROM_HERE, syncer::SyncChange::ACTION_ADD, data));
+ syncer::SyncError error =
+ settings_service_.ProcessSyncChanges(FROM_HERE, change_list);
+ EXPECT_FALSE(error.IsSet()) << error.ToString();
+ ASSERT_TRUE(settings_);
+ ASSERT_TRUE(settings_->GetWithoutPathExpansion(kSettingsName, &value));
+ std::string string_value;
+ EXPECT_TRUE(value->GetAsString(&string_value));
+ EXPECT_EQ(kSettingsValue, string_value);
+}
+
+TEST_F(ManagedUserSettingsServiceTest, ProcessSplitSetting) {
+ StartSyncing(syncer::SyncDataList());
+ ASSERT_TRUE(settings_);
+ const base::Value* value = NULL;
+ EXPECT_FALSE(settings_->GetWithoutPathExpansion(kSettingsName, &value));
+
+ base::DictionaryValue dict;
+ dict.SetString("foo", "bar");
+ dict.SetBoolean("awesomesauce", true);
+ dict.SetInteger("eaudecologne", 4711);
+
+ settings_.reset();
+ syncer::SyncChangeList change_list;
+ for (base::DictionaryValue::Iterator it(dict); !it.IsAtEnd(); it.Advance()) {
+ syncer::SyncData data =
+ ManagedUserSettingsService::CreateSyncDataForSetting(
+ ManagedUserSettingsService::MakeSplitSettingKey(kSettingsName,
+ it.key()),
+ it.value());
+ change_list.push_back(
+ syncer::SyncChange(FROM_HERE, syncer::SyncChange::ACTION_ADD, data));
+ }
+ syncer::SyncError error =
+ settings_service_.ProcessSyncChanges(FROM_HERE, change_list);
+ EXPECT_FALSE(error.IsSet()) << error.ToString();
+ ASSERT_TRUE(settings_);
+ ASSERT_TRUE(settings_->GetWithoutPathExpansion(kSettingsName, &value));
+ const base::DictionaryValue* dict_value = NULL;
+ ASSERT_TRUE(value->GetAsDictionary(&dict_value));
+ EXPECT_TRUE(dict_value->Equals(&dict));
+}
+
TEST_F(ManagedUserSettingsServiceTest, SetLocalSetting) {
const base::Value* value = NULL;
EXPECT_FALSE(settings_->GetWithoutPathExpansion(kSettingsName, &value));
@@ -62,3 +242,84 @@ TEST_F(ManagedUserSettingsServiceTest, SetLocalSetting) {
EXPECT_TRUE(value->GetAsString(&string_value));
EXPECT_EQ(kSettingsValue, string_value);
}
+
+TEST_F(ManagedUserSettingsServiceTest, UploadItem) {
+ UploadSplitItem("foo", "bar");
+ UploadSplitItem("blurp", "baz");
+ UploadAtomicItem("hurdle");
+
+ // Uploading should produce changes when we start syncing.
+ StartSyncing(syncer::SyncDataList());
+ const syncer::SyncChangeList& changes = sync_processor_->changes();
+ ASSERT_EQ(3u, changes.size());
+ for (syncer::SyncChangeList::const_iterator it = changes.begin();
+ it != changes.end(); ++it) {
+ ASSERT_TRUE(it->IsValid());
+ EXPECT_EQ(syncer::SyncChange::ACTION_ADD, it->change_type());
+ VerifySyncDataItem(it->sync_data());
+ }
+
+ // It should also show up in local Sync data.
+ syncer::SyncDataList sync_data =
+ settings_service_.GetAllSyncData(syncer::MANAGED_USER_SETTINGS);
+ EXPECT_EQ(3u, sync_data.size());
+ for (syncer::SyncDataList::const_iterator it = sync_data.begin();
+ it != sync_data.end(); ++it) {
+ VerifySyncDataItem(*it);
+ }
+
+ // Uploading after we have started syncing should work too.
+ UploadSplitItem("froodle", "narf");
+ ASSERT_EQ(1u, sync_processor_->changes().size());
+ syncer::SyncChange change = sync_processor_->changes()[0];
+ ASSERT_TRUE(change.IsValid());
+ EXPECT_EQ(syncer::SyncChange::ACTION_ADD, change.change_type());
+ VerifySyncDataItem(change.sync_data());
+
+ sync_data = settings_service_.GetAllSyncData(syncer::MANAGED_USER_SETTINGS);
+ EXPECT_EQ(4u, sync_data.size());
+ for (syncer::SyncDataList::const_iterator it = sync_data.begin();
+ it != sync_data.end(); ++it) {
+ VerifySyncDataItem(*it);
+ }
+
+ // Uploading an item with a previously seen key should create an UPDATE
+ // action.
+ UploadSplitItem("blurp", "snarl");
+ ASSERT_EQ(1u, sync_processor_->changes().size());
+ change = sync_processor_->changes()[0];
+ ASSERT_TRUE(change.IsValid());
+ EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, change.change_type());
+ VerifySyncDataItem(change.sync_data());
+
+ sync_data = settings_service_.GetAllSyncData(syncer::MANAGED_USER_SETTINGS);
+ EXPECT_EQ(4u, sync_data.size());
+ for (syncer::SyncDataList::const_iterator it = sync_data.begin();
+ it != sync_data.end(); ++it) {
+ VerifySyncDataItem(*it);
+ }
+
+ UploadAtomicItem("fjord");
+ ASSERT_EQ(1u, sync_processor_->changes().size());
+ change = sync_processor_->changes()[0];
+ ASSERT_TRUE(change.IsValid());
+ EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, change.change_type());
+ VerifySyncDataItem(change.sync_data());
+
+ sync_data = settings_service_.GetAllSyncData(syncer::MANAGED_USER_SETTINGS);
+ EXPECT_EQ(4u, sync_data.size());
+ for (syncer::SyncDataList::const_iterator it = sync_data.begin();
+ it != sync_data.end(); ++it) {
+ VerifySyncDataItem(*it);
+ }
+
+ // The uploaded items should not show up as settings.
+ const base::Value* value = NULL;
+ EXPECT_FALSE(settings_->GetWithoutPathExpansion(kAtomicItemName, &value));
+ EXPECT_FALSE(settings_->GetWithoutPathExpansion(kSplitItemName, &value));
+
+ // Restarting sync should not create any new changes.
+ settings_service_.StopSyncing(syncer::MANAGED_USER_SETTINGS);
+ StartSyncing(sync_data);
+ ASSERT_EQ(0u, sync_processor_->changes().size());
+}
diff --git a/chrome/browser/policy/browser_policy_connector.cc b/chrome/browser/policy/browser_policy_connector.cc
index 2949dac..c2bf9b6 100644
--- a/chrome/browser/policy/browser_policy_connector.cc
+++ b/chrome/browser/policy/browser_policy_connector.cc
@@ -27,7 +27,6 @@
#include "chrome/browser/policy/cloud/cloud_policy_service.h"
#include "chrome/browser/policy/cloud/device_management_service.h"
#include "chrome/browser/policy/configuration_policy_provider.h"
-#include "chrome/browser/policy/managed_mode_policy_provider.h"
#include "chrome/browser/policy/policy_domain_descriptor.h"
#include "chrome/browser/policy/policy_service_impl.h"
#include "chrome/browser/policy/policy_statistics_collector.h"
diff --git a/chrome/browser/policy/configuration_policy_handler_list.cc b/chrome/browser/policy/configuration_policy_handler_list.cc
index c11ca73..b46454e 100644
--- a/chrome/browser/policy/configuration_policy_handler_list.cc
+++ b/chrome/browser/policy/configuration_policy_handler_list.cc
@@ -337,21 +337,6 @@ const PolicyToPreferenceMapEntry kSimplePolicyMap[] = {
{ key::kVariationsRestrictParameter,
prefs::kVariationsRestrictParameter,
Value::TYPE_STRING },
- { key::kContentPackDefaultFilteringBehavior,
- prefs::kDefaultManagedModeFilteringBehavior,
- Value::TYPE_INTEGER },
- { key::kContentPackManualBehaviorHosts,
- prefs::kManagedModeManualHosts,
- Value::TYPE_DICTIONARY },
- { key::kContentPackManualBehaviorURLs,
- prefs::kManagedModeManualURLs,
- Value::TYPE_DICTIONARY },
- // TODO(ibraaaa): Remove this when we finish moving
- // managed user settings out of the policy code.
- // http://crbug.com/280674
- { key::kUserDisplayName,
- prefs::kProfileName,
- Value::TYPE_STRING },
{ key::kSupervisedUserCreationEnabled,
prefs::kManagedUserCreationAllowed,
Value::TYPE_BOOLEAN },
diff --git a/chrome/browser/policy/managed_mode_policy_provider.cc b/chrome/browser/policy/managed_mode_policy_provider.cc
deleted file mode 100644
index cff8971..0000000
--- a/chrome/browser/policy/managed_mode_policy_provider.cc
+++ /dev/null
@@ -1,384 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/policy/managed_mode_policy_provider.h"
-
-#include "base/callback.h"
-#include "base/json/json_reader.h"
-#include "base/json/json_writer.h"
-#include "base/prefs/json_pref_store.h"
-#include "base/strings/string_util.h"
-#include "base/threading/sequenced_worker_pool.h"
-#include "chrome/browser/managed_mode/managed_mode_url_filter.h"
-#include "chrome/browser/policy/external_data_fetcher.h"
-#include "chrome/browser/policy/policy_bundle.h"
-#include "chrome/browser/prefs/incognito_mode_prefs.h"
-#include "chrome/browser/profiles/profile.h"
-#include "chrome/common/chrome_constants.h"
-#include "content/public/browser/browser_thread.h"
-#include "content/public/browser/user_metrics.h"
-#include "policy/policy_constants.h"
-#include "sync/api/sync_change.h"
-#include "sync/protocol/sync.pb.h"
-
-using base::DictionaryValue;
-using base::JSONReader;
-using base::Value;
-using content::BrowserThread;
-using content::UserMetricsAction;
-using syncer::MANAGED_USER_SETTINGS;
-using syncer::ModelType;
-using syncer::SyncChange;
-using syncer::SyncChangeList;
-using syncer::SyncChangeProcessor;
-using syncer::SyncData;
-using syncer::SyncDataList;
-using syncer::SyncError;
-using syncer::SyncErrorFactory;
-using syncer::SyncMergeResult;
-
-namespace {
-
-const char kAtomicSettings[] = "atomic_settings";
-const char kManagedUserInternalPolicyPrefix[] = "X-";
-const char kQueuedItems[] = "queued_items";
-const char kSplitSettingKeySeparator = ':';
-const char kSplitSettings[] = "split_settings";
-
-bool SettingShouldApplyToPolicy(const std::string& key) {
- return !StartsWithASCII(key, kManagedUserInternalPolicyPrefix, false);
-}
-
-} // namespace
-
-namespace policy {
-
-
-// static
-scoped_ptr<ManagedModePolicyProvider> ManagedModePolicyProvider::Create(
- Profile* profile,
- base::SequencedTaskRunner* sequenced_task_runner,
- bool force_load) {
- base::FilePath path =
- profile->GetPath().Append(chrome::kManagedModePolicyFilename);
- JsonPrefStore* pref_store = new JsonPrefStore(path, sequenced_task_runner);
- // Load the data synchronously if needed (when creating profiles on startup).
- if (force_load)
- pref_store->ReadPrefs();
- else
- pref_store->ReadPrefsAsync(NULL);
-
- return make_scoped_ptr(new ManagedModePolicyProvider(pref_store));
-}
-
-ManagedModePolicyProvider::ManagedModePolicyProvider(
- PersistentPrefStore* pref_store)
- : store_(pref_store),
- local_policies_(new DictionaryValue) {
- store_->AddObserver(this);
- if (store_->IsInitializationComplete())
- UpdatePolicyFromCache();
-}
-
-ManagedModePolicyProvider::~ManagedModePolicyProvider() {}
-
-void ManagedModePolicyProvider::Clear() {
- store_->RemoveValue(kAtomicSettings);
- store_->RemoveValue(kSplitSettings);
-}
-
-// static
-std::string ManagedModePolicyProvider::MakeSplitSettingKey(
- const std::string& prefix,
- const std::string& key) {
- return prefix + kSplitSettingKeySeparator + key;
-}
-
-void ManagedModePolicyProvider::UploadItem(const std::string& key,
- scoped_ptr<Value> value) {
- DCHECK(!SettingShouldApplyToPolicy(key));
-
- std::string key_suffix = key;
- DictionaryValue* dict = NULL;
- if (sync_processor_) {
- content::RecordAction(
- UserMetricsAction("ManagedUsers_UploadItem_Syncing"));
- dict = GetDictionaryAndSplitKey(&key_suffix);
- DCHECK(GetQueuedItems()->empty());
- SyncChangeList change_list;
- SyncData data = CreateSyncDataForPolicy(key, value.get());
- SyncChange::SyncChangeType change_type =
- dict->HasKey(key_suffix) ? SyncChange::ACTION_UPDATE
- : SyncChange::ACTION_ADD;
- change_list.push_back(SyncChange(FROM_HERE, change_type, data));
- SyncError error =
- sync_processor_->ProcessSyncChanges(FROM_HERE, change_list);
- DCHECK(!error.IsSet()) << error.ToString();
- } else {
- content::RecordAction(
- UserMetricsAction("ManagedUsers_UploadItem_Queued"));
- dict = GetQueuedItems();
- }
- dict->SetWithoutPathExpansion(key_suffix, value.release());
-}
-
-void ManagedModePolicyProvider::SetLocalPolicyForTesting(
- const std::string& key,
- scoped_ptr<Value> value) {
- if (value)
- local_policies_->SetWithoutPathExpansion(key, value.release());
- else
- local_policies_->RemoveWithoutPathExpansion(key, NULL);
-
- UpdatePolicyFromCache();
-}
-
-// static
-SyncData ManagedModePolicyProvider::CreateSyncDataForPolicy(
- const std::string& name,
- const Value* value) {
- std::string json_value;
- base::JSONWriter::Write(value, &json_value);
- ::sync_pb::EntitySpecifics specifics;
- specifics.mutable_managed_user_setting()->set_name(name);
- specifics.mutable_managed_user_setting()->set_value(json_value);
- return SyncData::CreateLocalData(name, name, specifics);
-}
-
-void ManagedModePolicyProvider::Shutdown() {
- store_->RemoveObserver(this);
- ConfigurationPolicyProvider::Shutdown();
-}
-
-void ManagedModePolicyProvider::RefreshPolicies() {
- UpdatePolicyFromCache();
-}
-
-bool ManagedModePolicyProvider::IsInitializationComplete(
- PolicyDomain domain) const {
- if (domain == POLICY_DOMAIN_CHROME)
- return store_->IsInitializationComplete();
- return true;
-}
-
-void ManagedModePolicyProvider::OnPrefValueChanged(const std::string& key) {}
-
-void ManagedModePolicyProvider::OnInitializationCompleted(bool success) {
- DCHECK(success);
- UpdatePolicyFromCache();
-}
-
-SyncMergeResult ManagedModePolicyProvider::MergeDataAndStartSyncing(
- ModelType type,
- const SyncDataList& initial_sync_data,
- scoped_ptr<SyncChangeProcessor> sync_processor,
- scoped_ptr<SyncErrorFactory> error_handler) {
- DCHECK_EQ(MANAGED_USER_SETTINGS, type);
- sync_processor_ = sync_processor.Pass();
- error_handler_ = error_handler.Pass();
-
- // Clear all atomic and split settings, then recreate them from Sync data.
- Clear();
- for (SyncDataList::const_iterator it = initial_sync_data.begin();
- it != initial_sync_data.end(); ++it) {
- DCHECK_EQ(MANAGED_USER_SETTINGS, it->GetDataType());
- const ::sync_pb::ManagedUserSettingSpecifics& managed_user_setting =
- it->GetSpecifics().managed_user_setting();
- scoped_ptr<Value> value(JSONReader::Read(managed_user_setting.value()));
- std::string name_suffix = managed_user_setting.name();
- DictionaryValue* dict = GetDictionaryAndSplitKey(&name_suffix);
- dict->SetWithoutPathExpansion(name_suffix, value.release());
- }
- store_->ReportValueChanged(kAtomicSettings);
- store_->ReportValueChanged(kSplitSettings);
- UpdatePolicyFromCache();
-
- // Upload all the queued up items (either with an ADD or an UPDATE action,
- // depending on whether they already exist) and move them to split settings.
- SyncChangeList change_list;
- DictionaryValue* queued_items = GetQueuedItems();
- for (DictionaryValue::Iterator it(*queued_items); !it.IsAtEnd();
- it.Advance()) {
- std::string key_suffix = it.key();
- DictionaryValue* dict = GetDictionaryAndSplitKey(&key_suffix);
- SyncData data = CreateSyncDataForPolicy(it.key(), &it.value());
- SyncChange::SyncChangeType change_type =
- dict->HasKey(key_suffix) ? SyncChange::ACTION_UPDATE
- : SyncChange::ACTION_ADD;
- change_list.push_back(SyncChange(FROM_HERE, change_type, data));
- dict->SetWithoutPathExpansion(key_suffix, it.value().DeepCopy());
- }
- queued_items->Clear();
-
- SyncMergeResult result(MANAGED_USER_SETTINGS);
- // Process all the accumulated changes from the queued items.
- if (change_list.size() > 0) {
- store_->ReportValueChanged(kQueuedItems);
- result.set_error(
- sync_processor_->ProcessSyncChanges(FROM_HERE, change_list));
- }
-
- // TODO(bauerb): Statistics?
- return result;
-}
-
-void ManagedModePolicyProvider::StopSyncing(ModelType type) {
- DCHECK_EQ(syncer::MANAGED_USER_SETTINGS, type);
- sync_processor_.reset();
- error_handler_.reset();
-}
-
-SyncDataList ManagedModePolicyProvider::GetAllSyncData(ModelType type) const {
- DCHECK_EQ(syncer::MANAGED_USER_SETTINGS, type);
- SyncDataList data;
- for (DictionaryValue::Iterator it(*GetAtomicSettings()); !it.IsAtEnd();
- it.Advance()) {
- data.push_back(CreateSyncDataForPolicy(it.key(), &it.value()));
- }
- for (DictionaryValue::Iterator it(*GetSplitSettings()); !it.IsAtEnd();
- it.Advance()) {
- const DictionaryValue* dict = NULL;
- it.value().GetAsDictionary(&dict);
- for (DictionaryValue::Iterator jt(*dict); !jt.IsAtEnd(); jt.Advance()) {
- data.push_back(CreateSyncDataForPolicy(
- MakeSplitSettingKey(it.key(), jt.key()), &jt.value()));
- }
- }
- DCHECK_EQ(0u, GetQueuedItems()->size());
- return data;
-}
-
-SyncError ManagedModePolicyProvider::ProcessSyncChanges(
- const tracked_objects::Location& from_here,
- const SyncChangeList& change_list) {
- for (SyncChangeList::const_iterator it = change_list.begin();
- it != change_list.end(); ++it) {
- SyncData data = it->sync_data();
- DCHECK_EQ(MANAGED_USER_SETTINGS, data.GetDataType());
- const ::sync_pb::ManagedUserSettingSpecifics& managed_user_setting =
- data.GetSpecifics().managed_user_setting();
- std::string key = managed_user_setting.name();
- DictionaryValue* dict = GetDictionaryAndSplitKey(&key);
- switch (it->change_type()) {
- case SyncChange::ACTION_ADD:
- case SyncChange::ACTION_UPDATE: {
- scoped_ptr<Value> value(JSONReader::Read(managed_user_setting.value()));
- if (dict->HasKey(key)) {
- DLOG_IF(WARNING, it->change_type() == SyncChange::ACTION_ADD)
- << "Value for key " << key << " already exists";
- } else {
- DLOG_IF(WARNING, it->change_type() == SyncChange::ACTION_UPDATE)
- << "Value for key " << key << " doesn't exist yet";
- }
- dict->SetWithoutPathExpansion(key, value.release());
- break;
- }
- case SyncChange::ACTION_DELETE: {
- DLOG_IF(WARNING, !dict->HasKey(key)) << "Trying to delete nonexistent "
- << "key " << key;
- dict->RemoveWithoutPathExpansion(key, NULL);
- break;
- }
- case SyncChange::ACTION_INVALID: {
- NOTREACHED();
- break;
- }
- }
- }
- store_->ReportValueChanged(kAtomicSettings);
- store_->ReportValueChanged(kSplitSettings);
- UpdatePolicyFromCache();
-
- SyncError error;
- return error;
-}
-
-void ManagedModePolicyProvider::InitLocalPolicies() {
- local_policies_->Clear();
- local_policies_->SetBoolean(policy::key::kAllowDeletingBrowserHistory, false);
- local_policies_->SetInteger(policy::key::kContentPackDefaultFilteringBehavior,
- ManagedModeURLFilter::ALLOW);
- local_policies_->SetBoolean(policy::key::kForceSafeSearch, true);
- local_policies_->SetBoolean(policy::key::kHideWebStoreIcon, true);
- local_policies_->SetInteger(policy::key::kIncognitoModeAvailability,
- IncognitoModePrefs::DISABLED);
- local_policies_->SetBoolean(policy::key::kSigninAllowed, false);
- UpdatePolicyFromCache();
-}
-
-DictionaryValue* ManagedModePolicyProvider::GetOrCreateDictionary(
- const std::string& key) const {
- Value* value = NULL;
- DictionaryValue* dict = NULL;
- if (store_->GetMutableValue(key, &value)) {
- bool success = value->GetAsDictionary(&dict);
- DCHECK(success);
- } else {
- dict = new base::DictionaryValue;
- store_->SetValue(key, dict);
- }
-
- return dict;
-}
-
-DictionaryValue* ManagedModePolicyProvider::GetAtomicSettings() const {
- return GetOrCreateDictionary(kAtomicSettings);
-}
-
-DictionaryValue* ManagedModePolicyProvider::GetSplitSettings() const {
- return GetOrCreateDictionary(kSplitSettings);
-}
-
-DictionaryValue* ManagedModePolicyProvider::GetQueuedItems() const {
- return GetOrCreateDictionary(kQueuedItems);
-}
-
-DictionaryValue* ManagedModePolicyProvider::GetDictionaryAndSplitKey(
- std::string* key) const {
- size_t pos = key->find_first_of(kSplitSettingKeySeparator);
- if (pos == std::string::npos)
- return GetAtomicSettings();
-
- DictionaryValue* split_settings = GetSplitSettings();
- std::string prefix = key->substr(0, pos);
- DictionaryValue* dict = NULL;
- if (!split_settings->GetDictionary(prefix, &dict)) {
- dict = new DictionaryValue;
- DCHECK(!split_settings->HasKey(prefix));
- split_settings->Set(prefix, dict);
- }
- key->erase(0, pos + 1);
- return dict;
-}
-
-void ManagedModePolicyProvider::UpdatePolicyFromCache() {
- scoped_ptr<PolicyBundle> policy_bundle(new PolicyBundle);
- PolicyMap* policy_map = &policy_bundle->Get(
- PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()));
- policy_map->LoadFrom(
- local_policies_.get(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER);
-
- DictionaryValue* atomic_settings = GetAtomicSettings();
- for (DictionaryValue::Iterator it(*atomic_settings); !it.IsAtEnd();
- it.Advance()) {
- if (!SettingShouldApplyToPolicy(it.key()))
- continue;
-
- policy_map->Set(it.key(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
- it.value().DeepCopy(), NULL);
- }
-
- DictionaryValue* split_settings = GetSplitSettings();
- for (DictionaryValue::Iterator it(*split_settings); !it.IsAtEnd();
- it.Advance()) {
- if (!SettingShouldApplyToPolicy(it.key()))
- continue;
-
- policy_map->Set(it.key(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
- it.value().DeepCopy(), NULL);
- }
- UpdatePolicy(policy_bundle.Pass());
-}
-
-} // namespace policy
diff --git a/chrome/browser/policy/managed_mode_policy_provider.h b/chrome/browser/policy/managed_mode_policy_provider.h
deleted file mode 100644
index bd0327c..0000000
--- a/chrome/browser/policy/managed_mode_policy_provider.h
+++ /dev/null
@@ -1,146 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_POLICY_MANAGED_MODE_POLICY_PROVIDER_H_
-#define CHROME_BROWSER_POLICY_MANAGED_MODE_POLICY_PROVIDER_H_
-
-#include "base/memory/ref_counted.h"
-#include "base/prefs/pref_store.h"
-#include "chrome/browser/policy/configuration_policy_provider.h"
-#include "sync/api/sync_error_factory.h"
-#include "sync/api/syncable_service.h"
-
-class PersistentPrefStore;
-class Profile;
-
-namespace base {
-class SequencedTaskRunner;
-}
-
-namespace policy {
-
-// This class syncs managed user settings from a server, which are mapped to
-// policies. The downloaded settings are persisted in a PrefStore.
-// Settings are key-value pairs. The key uniquely identifies the setting, and
-// in most cases corresponds to a policy key. The value is a string containing
-// a JSON serialization of an arbitrary value, which is the value of the policy.
-//
-// There are two kinds of settings handled by this class: Atomic and split
-// settings.
-// Atomic settings consist of a single key (that corresponds to a policy name)
-// and a single (arbitrary) value.
-// Split settings encode a dictionary value and are stored as multiple Sync
-// items, one for each dictionary entry. The key for each of these Sync items
-// is the key of the split setting, followed by a separator (':') and the key
-// for the dictionary entry. The value of the Sync item is the value of the
-// dictionary entry.
-//
-// As an example, a split setting with key "Moose" and value
-// {
-// "foo": "bar",
-// "baz": "blurp"
-// }
-// would be encoded as two sync items, one with key "Moose:foo" and value "bar",
-// and one with key "Moose:baz" and value "blurp".
-//
-// TODO(bauerb): This should be split up into a SyncableService and a
-// ConfigurationPolicyProvider.
-class ManagedModePolicyProvider
- : public ConfigurationPolicyProvider,
- public PrefStore::Observer,
- public syncer::SyncableService {
- public:
- // Creates a new ManagedModePolicyProvider that caches its policies in a JSON
- // file inside the profile folder. |sequenced_task_runner| ensures that all
- // file I/O operations are executed in the order that does not collide
- // with Profile's file operations. If |force_immediate_policy_load| is true,
- // then the underlying policies are loaded immediately before this call
- // returns, otherwise they will be loaded asynchronously in the background.
- static scoped_ptr<ManagedModePolicyProvider> Create(
- Profile* profile,
- base::SequencedTaskRunner* sequenced_task_runner,
- bool force_immediate_policy_load);
-
- // Use this constructor to inject a different PrefStore (e.g. for testing).
- explicit ManagedModePolicyProvider(PersistentPrefStore* store);
- virtual ~ManagedModePolicyProvider();
-
- // Sets all local policies, i.e. policies that will not be configured via
- // the server.
- void InitLocalPolicies();
-
- // Clears all managed user settings and items.
- void Clear();
-
- // Constructs a key for a split managed user setting from a prefix and a
- // variable key.
- static std::string MakeSplitSettingKey(const std::string& prefix,
- const std::string& key);
-
- // Uploads an item to the Sync server. Items are the same data structure as
- // managed user settings (i.e. key-value pairs, as described at the top of
- // the file), but they are only uploaded (whereas managed user settings are
- // only downloaded), and never passed to the policy system.
- // An example of an uploaded item is an access request to a blocked URL.
- void UploadItem(const std::string& key, scoped_ptr<Value> value);
-
- // Sets the policy with the given |key| to a copy of the given |value|.
- // Note that policies are updated asynchronously, so the policy won't take
- // effect immediately after this method.
- void SetLocalPolicyForTesting(const std::string& key,
- scoped_ptr<base::Value> value);
-
- // Public for testing.
- static syncer::SyncData CreateSyncDataForPolicy(const std::string& name,
- const Value* value);
-
- // ConfigurationPolicyProvider implementation:
- virtual void Shutdown() OVERRIDE;
- virtual void RefreshPolicies() OVERRIDE;
- virtual bool IsInitializationComplete(PolicyDomain domain) const OVERRIDE;
-
- // PrefStore::Observer implementation:
- virtual void OnPrefValueChanged(const std::string& key) OVERRIDE;
- virtual void OnInitializationCompleted(bool success) OVERRIDE;
-
- // SyncableService implementation:
- virtual syncer::SyncMergeResult MergeDataAndStartSyncing(
- syncer::ModelType type,
- const syncer::SyncDataList& initial_sync_data,
- scoped_ptr<syncer::SyncChangeProcessor> sync_processor,
- scoped_ptr<syncer::SyncErrorFactory> error_handler) OVERRIDE;
- virtual void StopSyncing(syncer::ModelType type) OVERRIDE;
- virtual syncer::SyncDataList GetAllSyncData(
- syncer::ModelType type) const OVERRIDE;
- virtual syncer::SyncError ProcessSyncChanges(
- const tracked_objects::Location& from_here,
- const syncer::SyncChangeList& change_list) OVERRIDE;
-
- private:
- base::DictionaryValue* GetOrCreateDictionary(const std::string& key) const;
- base::DictionaryValue* GetAtomicSettings() const;
- base::DictionaryValue* GetSplitSettings() const;
- base::DictionaryValue* GetQueuedItems() const;
-
- // Returns the dictionary where a given Sync item should be stored, depending
- // on whether the managed user setting is atomic or split. In case of a split
- // setting, the split setting prefix of |key| is removed, so that |key| can
- // be used to update the returned dictionary.
- DictionaryValue* GetDictionaryAndSplitKey(std::string* key) const;
- void UpdatePolicyFromCache();
-
- // Used for persisting policies. Unlike other PrefStores, this one is not
- // hooked up to the PrefService.
- scoped_refptr<PersistentPrefStore> store_;
-
- // A set of local policies that are fixed and not configured remotely.
- scoped_ptr<base::DictionaryValue> local_policies_;
-
- scoped_ptr<syncer::SyncChangeProcessor> sync_processor_;
- scoped_ptr<syncer::SyncErrorFactory> error_handler_;
-};
-
-} // namespace policy
-
-#endif // CHROME_BROWSER_POLICY_MANAGED_MODE_POLICY_PROVIDER_H_
diff --git a/chrome/browser/policy/managed_mode_policy_provider_unittest.cc b/chrome/browser/policy/managed_mode_policy_provider_unittest.cc
deleted file mode 100644
index f0106c7e..0000000
--- a/chrome/browser/policy/managed_mode_policy_provider_unittest.cc
+++ /dev/null
@@ -1,399 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "base/callback.h"
-#include "base/json/json_reader.h"
-#include "base/prefs/testing_pref_store.h"
-#include "base/strings/string_util.h"
-#include "chrome/browser/policy/configuration_policy_provider_test.h"
-#include "chrome/browser/policy/external_data_fetcher.h"
-#include "chrome/browser/policy/managed_mode_policy_provider.h"
-#include "chrome/browser/policy/policy_bundle.h"
-#include "chrome/browser/policy/policy_map.h"
-#include "sync/api/sync_change.h"
-#include "sync/api/sync_error_factory_mock.h"
-#include "sync/protocol/sync.pb.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace policy {
-
-namespace {
-
-class MockChangeProcessor : public syncer::SyncChangeProcessor {
- public:
- MockChangeProcessor() {}
- virtual ~MockChangeProcessor() {}
-
- // SyncChangeProcessor implementation:
- virtual syncer::SyncError ProcessSyncChanges(
- const tracked_objects::Location& from_here,
- const syncer::SyncChangeList& change_list) OVERRIDE;
-
- const syncer::SyncChangeList& changes() const { return change_list_; }
-
- virtual syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const
- OVERRIDE {
- return syncer::SyncDataList();
- }
-
- private:
- syncer::SyncChangeList change_list_;
-
- DISALLOW_COPY_AND_ASSIGN(MockChangeProcessor);
-};
-
-syncer::SyncError MockChangeProcessor::ProcessSyncChanges(
- const tracked_objects::Location& from_here,
- const syncer::SyncChangeList& change_list) {
- change_list_ = change_list;
- return syncer::SyncError();
-}
-
-class MockSyncErrorFactory : public syncer::SyncErrorFactory {
- public:
- explicit MockSyncErrorFactory(syncer::ModelType type);
- virtual ~MockSyncErrorFactory();
-
- // SyncErrorFactory implementation:
- virtual syncer::SyncError CreateAndUploadError(
- const tracked_objects::Location& location,
- const std::string& message) OVERRIDE;
-
- private:
- syncer::ModelType type_;
-
- DISALLOW_COPY_AND_ASSIGN(MockSyncErrorFactory);
-};
-
-MockSyncErrorFactory::MockSyncErrorFactory(syncer::ModelType type)
- : type_(type) {}
-
-MockSyncErrorFactory::~MockSyncErrorFactory() {}
-
-syncer::SyncError MockSyncErrorFactory::CreateAndUploadError(
- const tracked_objects::Location& location,
- const std::string& message) {
- return syncer::SyncError(location,
- syncer::SyncError::DATATYPE_ERROR,
- message,
- type_);
-}
-
-class TestHarness : public PolicyProviderTestHarness {
- public:
- TestHarness();
- virtual ~TestHarness();
-
- static PolicyProviderTestHarness* Create();
-
- // PolicyProviderTestHarness implementation:
- virtual void SetUp() OVERRIDE;
-
- virtual ConfigurationPolicyProvider* CreateProvider(
- scoped_refptr<base::SequencedTaskRunner> task_runner,
- const PolicyDefinitionList* policy_definition_list) OVERRIDE;
-
- virtual void InstallEmptyPolicy() OVERRIDE;
- virtual void InstallStringPolicy(const std::string& policy_name,
- const std::string& policy_value) OVERRIDE;
- virtual void InstallIntegerPolicy(const std::string& policy_name,
- int policy_value) OVERRIDE;
- virtual void InstallBooleanPolicy(const std::string& policy_name,
- bool policy_value) OVERRIDE;
- virtual void InstallStringListPolicy(
- const std::string& policy_name,
- const base::ListValue* policy_value) OVERRIDE;
- virtual void InstallDictionaryPolicy(
- const std::string& policy_name,
- const base::DictionaryValue* policy_value) OVERRIDE;
-
- private:
- void InstallSimplePolicy(const std::string& policy_name,
- scoped_ptr<base::Value> policy_value);
-
- scoped_refptr<TestingPrefStore> pref_store_;
-
- // Owned by the test fixture.
- ManagedModePolicyProvider* provider_;
-
- DISALLOW_COPY_AND_ASSIGN(TestHarness);
-};
-
-TestHarness::TestHarness()
- : PolicyProviderTestHarness(POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER),
- pref_store_(new TestingPrefStore) {
- pref_store_->SetInitializationCompleted();
-}
-
-TestHarness::~TestHarness() {}
-
-// static
-PolicyProviderTestHarness* TestHarness::Create() {
- return new TestHarness();
-}
-
-void TestHarness::SetUp() {}
-
-ConfigurationPolicyProvider* TestHarness::CreateProvider(
- scoped_refptr<base::SequencedTaskRunner> task_runner,
- const PolicyDefinitionList* policy_definition_list) {
- provider_ = new ManagedModePolicyProvider(pref_store_.get());
- syncer::SyncDataList initial_sync_data;
- scoped_ptr<syncer::SyncChangeProcessor> sync_processor(
- new MockChangeProcessor());
- scoped_ptr<syncer::SyncErrorFactory> error_handler(
- new MockSyncErrorFactory(syncer::MANAGED_USER_SETTINGS));
- syncer::SyncMergeResult result =
- provider_->MergeDataAndStartSyncing(syncer::MANAGED_USER_SETTINGS,
- initial_sync_data,
- sync_processor.Pass(),
- error_handler.Pass());
- EXPECT_FALSE(result.error().IsSet());
- return provider_;
-}
-
-void TestHarness::InstallSimplePolicy(const std::string& policy_name,
- scoped_ptr<base::Value> policy_value) {
- syncer::SyncData data = ManagedModePolicyProvider::CreateSyncDataForPolicy(
- policy_name, policy_value.get());
- syncer::SyncChangeList change_list;
- change_list.push_back(
- syncer::SyncChange(FROM_HERE, syncer::SyncChange::ACTION_ADD, data));
- syncer::SyncError error =
- provider_->ProcessSyncChanges(FROM_HERE, change_list);
- EXPECT_FALSE(error.IsSet()) << error.ToString();
-}
-
-void TestHarness::InstallEmptyPolicy() {}
-
-void TestHarness::InstallStringPolicy(const std::string& policy_name,
- const std::string& policy_value) {
- InstallSimplePolicy(
- policy_name,
- scoped_ptr<base::Value>(base::Value::CreateStringValue(policy_value)));
-}
-
-void TestHarness::InstallIntegerPolicy(const std::string& policy_name,
- int policy_value) {
- InstallSimplePolicy(
- policy_name,
- scoped_ptr<base::Value>(new base::FundamentalValue(policy_value)));
-}
-
-void TestHarness::InstallBooleanPolicy(const std::string& policy_name,
- bool policy_value) {
- InstallSimplePolicy(
- policy_name,
- scoped_ptr<base::Value>(new base::FundamentalValue(policy_value)));
-}
-
-void TestHarness::InstallStringListPolicy(const std::string& policy_name,
- const base::ListValue* policy_value) {
- InstallSimplePolicy(policy_name,
- scoped_ptr<base::Value>(policy_value->DeepCopy()));
-}
-
-void TestHarness::InstallDictionaryPolicy(
- const std::string& policy_name,
- const base::DictionaryValue* policy_value) {
- syncer::SyncChangeList change_list;
- for (base::DictionaryValue::Iterator it(*policy_value); !it.IsAtEnd();
- it.Advance()) {
- syncer::SyncData data = ManagedModePolicyProvider::CreateSyncDataForPolicy(
- ManagedModePolicyProvider::MakeSplitSettingKey(policy_name, it.key()),
- &it.value());
- change_list.push_back(
- syncer::SyncChange(FROM_HERE, syncer::SyncChange::ACTION_ADD, data));
- }
- syncer::SyncError error =
- provider_->ProcessSyncChanges(FROM_HERE, change_list);
- EXPECT_FALSE(error.IsSet()) << error.ToString();
-}
-
-} // namespace
-
-// Instantiate abstract test case for basic policy reading tests.
-INSTANTIATE_TEST_CASE_P(
- ManagedModePolicyProviderTest,
- ConfigurationPolicyProviderTest,
- testing::Values(TestHarness::Create));
-
-const char kAtomicItemName[] = "X-Wombat";
-const char kSplitItemName[] = "X-SuperMoosePowers";
-
-class ManagedModePolicyProviderAPITest : public PolicyTestBase {
- protected:
- ManagedModePolicyProviderAPITest()
- : pref_store_(new TestingPrefStore), provider_(pref_store_.get()) {
- pref_store_->SetInitializationCompleted();
- }
- virtual ~ManagedModePolicyProviderAPITest() {}
-
- scoped_ptr<syncer::SyncChangeProcessor> CreateSyncProcessor() {
- sync_processor_ = new MockChangeProcessor();
- return scoped_ptr<syncer::SyncChangeProcessor>(sync_processor_);
- }
-
- void StartSyncing(const syncer::SyncDataList& initial_sync_data) {
- scoped_ptr<syncer::SyncErrorFactory> error_handler(
- new MockSyncErrorFactory(syncer::MANAGED_USER_SETTINGS));
- syncer::SyncMergeResult result =
- provider_.MergeDataAndStartSyncing(syncer::MANAGED_USER_SETTINGS,
- initial_sync_data,
- CreateSyncProcessor(),
- error_handler.Pass());
- EXPECT_FALSE(result.error().IsSet());
- }
-
- void UploadSplitItem(const std::string& key, const std::string& value) {
- dict_.SetStringWithoutPathExpansion(key, value);
- provider_.UploadItem(
- ManagedModePolicyProvider::MakeSplitSettingKey(kSplitItemName, key),
- scoped_ptr<base::Value>(base::Value::CreateStringValue(value)));
- }
-
- void UploadAtomicItem(const std::string& value) {
- atomic_setting_value_.reset(new base::StringValue(value));
- provider_.UploadItem(
- kAtomicItemName,
- scoped_ptr<base::Value>(base::Value::CreateStringValue(value)));
- }
-
- void VerifySyncDataItem(syncer::SyncData sync_data) {
- const sync_pb::ManagedUserSettingSpecifics& managed_user_setting =
- sync_data.GetSpecifics().managed_user_setting();
- base::Value* expected_value = NULL;
- if (managed_user_setting.name() == kAtomicItemName) {
- expected_value = atomic_setting_value_.get();
- } else {
- EXPECT_TRUE(StartsWithASCII(managed_user_setting.name(),
- std::string(kSplitItemName) + ':',
- true));
- std::string key =
- managed_user_setting.name().substr(strlen(kSplitItemName) + 1);
- EXPECT_TRUE(dict_.GetWithoutPathExpansion(key, &expected_value));
- }
-
- scoped_ptr<Value> value(
- base::JSONReader::Read(managed_user_setting.value()));
- EXPECT_TRUE(expected_value->Equals(value.get()));
- }
-
- // PolicyTestBase overrides:
- virtual void TearDown() OVERRIDE {
- provider_.Shutdown();
- PolicyTestBase::TearDown();
- }
-
- base::DictionaryValue dict_;
- scoped_ptr<base::Value> atomic_setting_value_;
- scoped_refptr<TestingPrefStore> pref_store_;
- ManagedModePolicyProvider provider_;
-
- // Owned by the ManagedModePolicyProvider.
- MockChangeProcessor* sync_processor_;
-};
-
-TEST_F(ManagedModePolicyProviderAPITest, UploadItem) {
- UploadSplitItem("foo", "bar");
- UploadSplitItem("blurp", "baz");
- UploadAtomicItem("hurdle");
-
- // Uploading should produce changes when we start syncing.
- StartSyncing(syncer::SyncDataList());
- const syncer::SyncChangeList& changes = sync_processor_->changes();
- ASSERT_EQ(3u, changes.size());
- for (syncer::SyncChangeList::const_iterator it = changes.begin();
- it != changes.end(); ++it) {
- ASSERT_TRUE(it->IsValid());
- EXPECT_EQ(syncer::SyncChange::ACTION_ADD, it->change_type());
- VerifySyncDataItem(it->sync_data());
- }
-
- // It should also show up in local Sync data.
- syncer::SyncDataList sync_data =
- provider_.GetAllSyncData(syncer::MANAGED_USER_SETTINGS);
- EXPECT_EQ(3u, sync_data.size());
- for (syncer::SyncDataList::const_iterator it = sync_data.begin();
- it != sync_data.end(); ++it) {
- VerifySyncDataItem(*it);
- }
-
- // Uploading after we have started syncing should work too.
- UploadSplitItem("froodle", "narf");
- ASSERT_EQ(1u, sync_processor_->changes().size());
- syncer::SyncChange change = sync_processor_->changes()[0];
- ASSERT_TRUE(change.IsValid());
- EXPECT_EQ(syncer::SyncChange::ACTION_ADD, change.change_type());
- VerifySyncDataItem(change.sync_data());
-
- sync_data = provider_.GetAllSyncData(syncer::MANAGED_USER_SETTINGS);
- EXPECT_EQ(4u, sync_data.size());
- for (syncer::SyncDataList::const_iterator it = sync_data.begin();
- it != sync_data.end(); ++it) {
- VerifySyncDataItem(*it);
- }
-
- // Uploading an item with a previously seen key should create an UPDATE
- // action.
- UploadSplitItem("blurp", "snarl");
- ASSERT_EQ(1u, sync_processor_->changes().size());
- change = sync_processor_->changes()[0];
- ASSERT_TRUE(change.IsValid());
- EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, change.change_type());
- VerifySyncDataItem(change.sync_data());
-
- sync_data = provider_.GetAllSyncData(syncer::MANAGED_USER_SETTINGS);
- EXPECT_EQ(4u, sync_data.size());
- for (syncer::SyncDataList::const_iterator it = sync_data.begin();
- it != sync_data.end(); ++it) {
- VerifySyncDataItem(*it);
- }
-
- UploadAtomicItem("fjord");
- ASSERT_EQ(1u, sync_processor_->changes().size());
- change = sync_processor_->changes()[0];
- ASSERT_TRUE(change.IsValid());
- EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, change.change_type());
- VerifySyncDataItem(change.sync_data());
-
- sync_data = provider_.GetAllSyncData(syncer::MANAGED_USER_SETTINGS);
- EXPECT_EQ(4u, sync_data.size());
- for (syncer::SyncDataList::const_iterator it = sync_data.begin();
- it != sync_data.end(); ++it) {
- VerifySyncDataItem(*it);
- }
-
- // The uploaded items should not show up as policies.
- PolicyBundle empty_bundle;
- EXPECT_TRUE(provider_.policies().Equals(empty_bundle));
-
- // Restarting sync should not create any new changes.
- provider_.StopSyncing(syncer::MANAGED_USER_SETTINGS);
- StartSyncing(sync_data);
- ASSERT_EQ(0u, sync_processor_->changes().size());
-}
-
-const char kPolicyKey[] = "TestingPolicy";
-
-TEST_F(ManagedModePolicyProviderAPITest, SetLocalPolicy) {
- PolicyBundle empty_bundle;
- EXPECT_TRUE(provider_.policies().Equals(empty_bundle));
-
- base::StringValue policy_value("PolicyValue");
- provider_.SetLocalPolicyForTesting(
- kPolicyKey, scoped_ptr<base::Value>(policy_value.DeepCopy()));
-
- PolicyBundle expected_bundle;
- PolicyMap* policy_map = &expected_bundle.Get(
- PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()));
- policy_map->Set(kPolicyKey,
- POLICY_LEVEL_MANDATORY,
- POLICY_SCOPE_USER,
- policy_value.DeepCopy(),
- NULL);
- EXPECT_TRUE(provider_.policies().Equals(expected_bundle));
-}
-
-} // namespace policy
diff --git a/chrome/browser/policy/profile_policy_connector.cc b/chrome/browser/policy/profile_policy_connector.cc
index 311d743..76826be 100644
--- a/chrome/browser/policy/profile_policy_connector.cc
+++ b/chrome/browser/policy/profile_policy_connector.cc
@@ -12,10 +12,6 @@
#include "chrome/browser/policy/configuration_policy_provider.h"
#include "chrome/browser/policy/policy_service_impl.h"
-#if defined(ENABLE_MANAGED_USERS)
-#include "chrome/browser/policy/managed_mode_policy_provider.h"
-#endif
-
#if defined(OS_CHROMEOS)
#include "base/bind.h"
#include "base/prefs/pref_service.h"
@@ -97,13 +93,6 @@ void ProfilePolicyConnector::Init(
providers.push_back(cloud_policy_manager);
#endif
-#if defined(ENABLE_MANAGED_USERS)
- managed_mode_policy_provider_ = ManagedModePolicyProvider::Create(
- profile_, sequenced_task_runner, force_immediate_load);
- managed_mode_policy_provider_->Init();
- providers.push_back(managed_mode_policy_provider_.get());
-#endif
-
policy_service_ = connector->CreatePolicyService(providers);
#if defined(OS_CHROMEOS)
@@ -140,11 +129,6 @@ void ProfilePolicyConnector::Shutdown() {
if (special_user_policy_provider_)
special_user_policy_provider_->Shutdown();
#endif
-
-#if defined(ENABLE_MANAGED_USERS)
- if (managed_mode_policy_provider_)
- managed_mode_policy_provider_->Shutdown();
-#endif
}
#if defined(OS_CHROMEOS)
diff --git a/chrome/browser/policy/profile_policy_connector.h b/chrome/browser/policy/profile_policy_connector.h
index 209a053..26af539 100644
--- a/chrome/browser/policy/profile_policy_connector.h
+++ b/chrome/browser/policy/profile_policy_connector.h
@@ -37,7 +37,6 @@ typedef std::vector<scoped_refptr<X509Certificate> > CertificateList;
namespace policy {
class ConfigurationPolicyProvider;
-class ManagedModePolicyProvider;
class UserNetworkConfigurationUpdater;
class PolicyService;
class PolicyCertVerifier;
@@ -61,12 +60,6 @@ class ProfilePolicyConnector : public BrowserContextKeyedService {
// This is never NULL.
PolicyService* policy_service() const { return policy_service_.get(); }
-#if defined(ENABLE_MANAGED_USERS) && defined(ENABLE_CONFIGURATION_POLICY)
- ManagedModePolicyProvider* managed_mode_policy_provider() const {
- return managed_mode_policy_provider_.get();
- }
-#endif
-
#if defined(OS_CHROMEOS)
// Sets the CertVerifier on which the current list of Web trusted server and
// CA certificates will be set. Policy updates will trigger further calls to
@@ -115,10 +108,6 @@ class ProfilePolicyConnector : public BrowserContextKeyedService {
Profile* profile_;
-#if defined(ENABLE_MANAGED_USERS) && defined(ENABLE_CONFIGURATION_POLICY)
- scoped_ptr<ManagedModePolicyProvider> managed_mode_policy_provider_;
-#endif
-
#endif // ENABLE_CONFIGURATION_POLICY
scoped_ptr<PolicyService> policy_service_;
diff --git a/chrome/browser/prefs/chrome_pref_service_factory.cc b/chrome/browser/prefs/chrome_pref_service_factory.cc
index 699a0d1..67e8d6f 100644
--- a/chrome/browser/prefs/chrome_pref_service_factory.cc
+++ b/chrome/browser/prefs/chrome_pref_service_factory.cc
@@ -32,6 +32,10 @@
#include "chrome/browser/policy/policy_types.h"
#endif
+#if defined(ENABLE_MANAGED_USERS)
+#include "chrome/browser/managed_mode/supervised_user_pref_store.h"
+#endif
+
using content::BrowserContext;
using content::BrowserThread;
@@ -72,6 +76,7 @@ void PrepareBuilder(
const base::FilePath& pref_filename,
base::SequencedTaskRunner* pref_io_task_runner,
policy::PolicyService* policy_service,
+ ManagedUserSettingsService* managed_user_settings,
const scoped_refptr<PrefStore>& extension_prefs,
bool async) {
#if defined(OS_LINUX)
@@ -99,6 +104,13 @@ void PrepareBuilder(
policy::POLICY_LEVEL_RECOMMENDED));
#endif // ENABLE_CONFIGURATION_POLICY
+#if defined(ENABLE_MANAGED_USERS)
+ if (managed_user_settings) {
+ builder->WithSupervisedUserPrefs(
+ new SupervisedUserPrefStore(managed_user_settings));
+ }
+#endif
+
builder->WithAsync(async);
builder->WithExtensionPrefs(extension_prefs.get());
builder->WithCommandLinePrefs(
@@ -115,7 +127,6 @@ PrefService* CreateLocalState(
const base::FilePath& pref_filename,
base::SequencedTaskRunner* pref_io_task_runner,
policy::PolicyService* policy_service,
- const scoped_refptr<PrefStore>& extension_prefs,
const scoped_refptr<PrefRegistry>& pref_registry,
bool async) {
PrefServiceSyncableBuilder builder;
@@ -123,7 +134,8 @@ PrefService* CreateLocalState(
pref_filename,
pref_io_task_runner,
policy_service,
- extension_prefs,
+ NULL,
+ NULL,
async);
return builder.Create(pref_registry.get());
}
@@ -132,6 +144,7 @@ PrefServiceSyncable* CreateProfilePrefs(
const base::FilePath& pref_filename,
base::SequencedTaskRunner* pref_io_task_runner,
policy::PolicyService* policy_service,
+ ManagedUserSettingsService* managed_user_settings,
const scoped_refptr<PrefStore>& extension_prefs,
const scoped_refptr<user_prefs::PrefRegistrySyncable>& pref_registry,
bool async) {
@@ -141,6 +154,7 @@ PrefServiceSyncable* CreateProfilePrefs(
pref_filename,
pref_io_task_runner,
policy_service,
+ managed_user_settings,
extension_prefs,
async);
return builder.CreateSyncable(pref_registry.get());
diff --git a/chrome/browser/prefs/chrome_pref_service_factory.h b/chrome/browser/prefs/chrome_pref_service_factory.h
index 7c308eb..eb6b4fc 100644
--- a/chrome/browser/prefs/chrome_pref_service_factory.h
+++ b/chrome/browser/prefs/chrome_pref_service_factory.h
@@ -16,15 +16,16 @@ namespace policy {
class PolicyService;
}
+namespace user_prefs {
+class PrefRegistrySyncable;
+}
+
+class ManagedUserSettingsService;
class PrefRegistry;
class PrefService;
class PrefServiceSyncable;
class PrefStore;
-namespace user_prefs {
-class PrefRegistrySyncable;
-}
-
namespace chrome_prefs {
// Factory methods that create and initialize a new instance of a
@@ -46,7 +47,6 @@ PrefService* CreateLocalState(
const base::FilePath& pref_filename,
base::SequencedTaskRunner* pref_io_task_runner,
policy::PolicyService* policy_service,
- const scoped_refptr<PrefStore>& extension_prefs,
const scoped_refptr<PrefRegistry>& pref_registry,
bool async);
@@ -54,6 +54,7 @@ PrefServiceSyncable* CreateProfilePrefs(
const base::FilePath& pref_filename,
base::SequencedTaskRunner* pref_io_task_runner,
policy::PolicyService* policy_service,
+ ManagedUserSettingsService* managed_user_settings,
const scoped_refptr<PrefStore>& extension_prefs,
const scoped_refptr<user_prefs::PrefRegistrySyncable>& pref_registry,
bool async);
diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc
index d66a66f..a6790df 100644
--- a/chrome/browser/profiles/profile_impl.cc
+++ b/chrome/browser/profiles/profile_impl.cc
@@ -97,6 +97,21 @@
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
+#if defined(ENABLE_CONFIGURATION_POLICY)
+#if defined(OS_CHROMEOS)
+#include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h"
+#include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chromeos.h"
+#else
+#include "chrome/browser/policy/cloud/user_cloud_policy_manager.h"
+#include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h"
+#endif
+#endif
+
+#if defined(ENABLE_MANAGED_USERS)
+#include "chrome/browser/managed_mode/managed_user_settings_service.h"
+#include "chrome/browser/managed_mode/managed_user_settings_service_factory.h"
+#endif
+
#if defined(OS_WIN)
#include "chrome/installer/util/install_util.h"
#endif
@@ -109,16 +124,6 @@
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#endif
-#if defined(ENABLE_CONFIGURATION_POLICY)
-#if defined(OS_CHROMEOS)
-#include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h"
-#include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chromeos.h"
-#else
-#include "chrome/browser/policy/cloud/user_cloud_policy_manager.h"
-#include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h"
-#endif
-#endif
-
using base::Time;
using base::TimeDelta;
using content::BrowserThread;
@@ -407,7 +412,15 @@ ProfileImpl::ProfileImpl(
chrome::RegisterLoginProfilePrefs(pref_registry_.get());
else
#endif
- chrome::RegisterUserProfilePrefs(pref_registry_.get());
+ chrome::RegisterUserProfilePrefs(pref_registry_.get());
+
+ ManagedUserSettingsService* managed_user_settings = NULL;
+#if defined(ENABLE_MANAGED_USERS)
+ managed_user_settings =
+ ManagedUserSettingsServiceFactory::GetForProfile(this);
+ managed_user_settings->Init(
+ path_, sequenced_task_runner, create_mode == CREATE_MODE_SYNCHRONOUS);
+#endif
{
// On startup, preference loading is always synchronous so a scoped timer
@@ -418,6 +431,7 @@ ProfileImpl::ProfileImpl(
GetPrefFilePath(),
sequenced_task_runner,
profile_policy_connector_->policy_service(),
+ managed_user_settings,
new ExtensionPrefStore(
ExtensionPrefValueMapFactory::GetForProfile(this), false),
pref_registry_,
diff --git a/chrome/browser/sync/profile_sync_components_factory_impl.cc b/chrome/browser/sync/profile_sync_components_factory_impl.cc
index e8e8702..c8f8a3a 100644
--- a/chrome/browser/sync/profile_sync_components_factory_impl.cc
+++ b/chrome/browser/sync/profile_sync_components_factory_impl.cc
@@ -62,11 +62,10 @@
#if defined(ENABLE_MANAGED_USERS)
#include "chrome/browser/managed_mode/managed_user_service.h"
+#include "chrome/browser/managed_mode/managed_user_settings_service.h"
+#include "chrome/browser/managed_mode/managed_user_settings_service_factory.h"
#include "chrome/browser/managed_mode/managed_user_sync_service.h"
#include "chrome/browser/managed_mode/managed_user_sync_service_factory.h"
-#include "chrome/browser/policy/managed_mode_policy_provider.h"
-#include "chrome/browser/policy/profile_policy_connector.h"
-#include "chrome/browser/policy/profile_policy_connector_factory.h"
#endif
#if !defined(OS_ANDROID)
@@ -392,8 +391,8 @@ base::WeakPtr<syncer::SyncableService> ProfileSyncComponentsFactoryImpl::
}
#if defined(ENABLE_MANAGED_USERS)
case syncer::MANAGED_USER_SETTINGS:
- return policy::ProfilePolicyConnectorFactory::GetForProfile(profile_)->
- managed_mode_policy_provider()->AsWeakPtr();
+ return ManagedUserSettingsServiceFactory::GetForProfile(profile_)->
+ AsWeakPtr();
case syncer::MANAGED_USERS:
return ManagedUserSyncServiceFactory::GetForProfile(profile_)->
AsWeakPtr();
diff --git a/chrome/browser/sync/test/integration/single_client_managed_user_settings_sync_test.cc b/chrome/browser/sync/test/integration/single_client_managed_user_settings_sync_test.cc
index 460f346..51b25fd 100644
--- a/chrome/browser/sync/test/integration/single_client_managed_user_settings_sync_test.cc
+++ b/chrome/browser/sync/test/integration/single_client_managed_user_settings_sync_test.cc
@@ -4,15 +4,14 @@
#include "base/prefs/pref_service.h"
#include "base/values.h"
+#include "chrome/browser/managed_mode/managed_user_constants.h"
#include "chrome/browser/managed_mode/managed_user_service.h"
#include "chrome/browser/managed_mode/managed_user_service_factory.h"
-#include "chrome/browser/policy/managed_mode_policy_provider.h"
-#include "chrome/browser/policy/profile_policy_connector.h"
-#include "chrome/browser/policy/profile_policy_connector_factory.h"
+#include "chrome/browser/managed_mode/managed_user_settings_service.h"
+#include "chrome/browser/managed_mode/managed_user_settings_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sync/profile_sync_service_harness.h"
#include "chrome/browser/sync/test/integration/sync_test.h"
-#include "policy/policy_constants.h"
class SingleClientManagedUserSettingsSyncTest : public SyncTest {
public:
@@ -21,7 +20,7 @@ class SingleClientManagedUserSettingsSyncTest : public SyncTest {
virtual ~SingleClientManagedUserSettingsSyncTest() {}
};
-// TODO(pavely): Fix this test.
+// TODO(pavely): Fix this test. See also: http://crbug.com/279307
IN_PROC_BROWSER_TEST_F(SingleClientManagedUserSettingsSyncTest,
DISABLED_Sanity) {
ASSERT_TRUE(SetupClients());
@@ -31,16 +30,14 @@ IN_PROC_BROWSER_TEST_F(SingleClientManagedUserSettingsSyncTest,
// Managed users are prohibited from signing into the browser. Currently
// that means they're also unable to sync anything, so override that for
// this test.
- // TODO(pamg): Remove this override (and the several #includes it requires)
- // once sync and signin are properly separated for managed users. See
- // http://crbug.com/239785.
- policy::ProfilePolicyConnector* connector =
- policy::ProfilePolicyConnectorFactory::GetForProfile(profile);
- policy::ManagedModePolicyProvider* policy_provider =
- connector->managed_mode_policy_provider();
+ // TODO(pamg): Remove this override (and the managed user setting it
+ // requires) once sync and signin are properly separated for managed users.
+ // See http://crbug.com/239785.
+ ManagedUserSettingsService* settings_service =
+ ManagedUserSettingsServiceFactory::GetForProfile(profile);
scoped_ptr<base::Value> allow_signin(new base::FundamentalValue(true));
- policy_provider->SetLocalPolicyForTesting(policy::key::kSigninAllowed,
- allow_signin.Pass());
+ settings_service->SetLocalSettingForTesting(managed_users::kSigninAllowed,
+ allow_signin.Pass());
// The user should not be signed in.
std::string username;
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index c8ef6c5..e98f2ad 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -1470,8 +1470,6 @@
'browser/policy/external_data_fetcher.cc',
'browser/policy/external_data_fetcher.h',
'browser/policy/external_data_manager.h',
- 'browser/policy/managed_mode_policy_provider.cc',
- 'browser/policy/managed_mode_policy_provider.h',
'browser/policy/policy_bundle.cc',
'browser/policy/policy_bundle.h',
'browser/policy/policy_domain_descriptor.cc',
@@ -3107,8 +3105,6 @@
'browser/policy/cloud/user_policy_signin_service.h',
'browser/policy/config_dir_policy_loader.cc',
'browser/policy/config_dir_policy_loader.h',
- 'browser/policy/managed_mode_policy_provider.cc',
- 'browser/policy/managed_mode_policy_provider.h',
'browser/profiles/profile_loader.cc',
'browser/profiles/profile_loader.h',
'browser/sessions/persistent_tab_restore_service.cc',
diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi
index 57d2c53..013a610 100644
--- a/chrome/chrome_tests_unit.gypi
+++ b/chrome/chrome_tests_unit.gypi
@@ -1078,7 +1078,6 @@
'browser/policy/configuration_policy_pref_store_unittest.cc',
'browser/policy/configuration_policy_provider_test.cc',
'browser/policy/configuration_policy_provider_test.h',
- 'browser/policy/managed_mode_policy_provider_unittest.cc',
'browser/policy/mock_policy_service.cc',
'browser/policy/mock_policy_service.h',
'browser/policy/policy_bundle_unittest.cc',
@@ -2496,7 +2495,6 @@
'browser/policy/cloud/external_policy_data_updater_unittest.cc',
'browser/policy/cloud/resource_cache_unittest.cc',
'browser/policy/config_dir_policy_loader_unittest.cc',
- 'browser/policy/managed_mode_policy_provider_unittest.cc',
'browser/policy/policy_path_parser_unittest.cc',
'browser/profiles/off_the_record_profile_impl_unittest.cc',
'browser/profiles/profile_loader_unittest.cc',
diff --git a/chrome/common/chrome_constants.cc b/chrome/common/chrome_constants.cc
index 3dd5bd3..e256572 100644
--- a/chrome/common/chrome_constants.cc
+++ b/chrome/common/chrome_constants.cc
@@ -169,7 +169,7 @@ const base::FilePath::CharType kJumpListIconDirname[] = FPL("JumpListIcons");
const base::FilePath::CharType kLocalStateFilename[] = FPL("Local State");
const base::FilePath::CharType kLocalStorePoolName[] = FPL("LocalStorePool");
const base::FilePath::CharType kLoginDataFileName[] = FPL("Login Data");
-const base::FilePath::CharType kManagedModePolicyFilename[] =
+const base::FilePath::CharType kManagedUserSettingsFilename[] =
FPL("Managed Mode Settings");
const base::FilePath::CharType kMediaCacheDirname[] = FPL("Media Cache");
const base::FilePath::CharType kNewTabThumbnailsFilename[] =
diff --git a/chrome/common/chrome_constants.h b/chrome/common/chrome_constants.h
index 1691e56..d06f8d3 100644
--- a/chrome/common/chrome_constants.h
+++ b/chrome/common/chrome_constants.h
@@ -66,7 +66,7 @@ extern const base::FilePath::CharType kJumpListIconDirname[];
extern const base::FilePath::CharType kLocalStateFilename[];
extern const base::FilePath::CharType kLocalStorePoolName[];
extern const base::FilePath::CharType kLoginDataFileName[];
-extern const base::FilePath::CharType kManagedModePolicyFilename[];
+extern const base::FilePath::CharType kManagedUserSettingsFilename[];
extern const base::FilePath::CharType kMediaCacheDirname[];
extern const base::FilePath::CharType kNewTabThumbnailsFilename[];
extern const base::FilePath::CharType kOBCertFilename[];
diff --git a/chrome/test/base/testing_profile.cc b/chrome/test/base/testing_profile.cc
index f53c423..b301b5a 100644
--- a/chrome/test/base/testing_profile.cc
+++ b/chrome/test/base/testing_profile.cc
@@ -81,6 +81,11 @@
#include "chrome/browser/policy/policy_service_stub.h"
#endif // defined(ENABLE_CONFIGURATION_POLICY)
+#if defined(ENABLE_MANAGED_USERS)
+#include "chrome/browser/managed_mode/managed_user_settings_service.h"
+#include "chrome/browser/managed_mode/managed_user_settings_service_factory.h"
+#endif
+
using base::Time;
using content::BrowserThread;
using content::DownloadManagerDelegate;
@@ -332,6 +337,14 @@ void TestingProfile::Init() {
DesktopNotificationServiceFactory::GetInstance()->SetTestingFactory(
this, CreateTestDesktopNotificationService);
#endif
+
+#if defined(ENABLE_MANAGED_USERS)
+ ManagedUserSettingsService* settings_service =
+ ManagedUserSettingsServiceFactory::GetForProfile(this);
+ TestingPrefStore* store = new TestingPrefStore();
+ settings_service->Init(store);
+ store->SetInitializationCompleted();
+#endif
}
void TestingProfile::FinishInit() {