diff options
author | bauerb@chromium.org <bauerb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-31 14:41:55 +0000 |
---|---|---|
committer | bauerb@chromium.org <bauerb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-31 14:41:55 +0000 |
commit | 21d3a88076587737d437cfd5d0819f0dda10c823 (patch) | |
tree | 621bbcdb56ceacdb3cb286d895fb9711000b7eb8 /chrome/browser | |
parent | cdaf13d1e037f0119bc8724d0907e31a2729b233 (diff) | |
download | chromium_src-21d3a88076587737d437cfd5d0819f0dda10c823.zip chromium_src-21d3a88076587737d437cfd5d0819f0dda10c823.tar.gz chromium_src-21d3a88076587737d437cfd5d0819f0dda10c823.tar.bz2 |
Make PolicyService per-profile.
At the moment, all the policy services are identical, but this will allow us to add different policies per profile.
BUG=128318
TEST=none
Review URL: https://chromiumcodereview.appspot.com/10444008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@139783 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/browser_process_impl.cc | 13 | ||||
-rw-r--r-- | chrome/browser/chrome_browser_main.cc | 4 | ||||
-rw-r--r-- | chrome/browser/policy/browser_policy_connector.cc | 3 | ||||
-rw-r--r-- | chrome/browser/policy/browser_policy_connector.h | 6 | ||||
-rw-r--r-- | chrome/browser/policy/configuration_policy_pref_store.cc | 10 | ||||
-rw-r--r-- | chrome/browser/policy/configuration_policy_pref_store.h | 6 | ||||
-rw-r--r-- | chrome/browser/policy/policy_map.h | 2 | ||||
-rw-r--r-- | chrome/browser/policy/policy_service.h | 2 | ||||
-rw-r--r-- | chrome/browser/prefs/pref_service.cc | 15 | ||||
-rw-r--r-- | chrome/browser/prefs/pref_service.h | 16 | ||||
-rw-r--r-- | chrome/browser/profiles/off_the_record_profile_impl.cc | 4 | ||||
-rw-r--r-- | chrome/browser/profiles/off_the_record_profile_impl.h | 1 | ||||
-rw-r--r-- | chrome/browser/profiles/profile.h | 9 | ||||
-rw-r--r-- | chrome/browser/profiles/profile_impl.cc | 23 | ||||
-rw-r--r-- | chrome/browser/profiles/profile_impl.h | 8 | ||||
-rw-r--r-- | chrome/browser/ui/webui/policy_ui.cc | 165 | ||||
-rw-r--r-- | chrome/browser/ui/webui/policy_ui.h | 26 |
17 files changed, 176 insertions, 137 deletions
diff --git a/chrome/browser/browser_process_impl.cc b/chrome/browser/browser_process_impl.cc index 7fa16cc..19b4da1 100644 --- a/chrome/browser/browser_process_impl.cc +++ b/chrome/browser/browser_process_impl.cc @@ -43,8 +43,7 @@ #include "chrome/browser/net/sdch_dictionary_fetcher.h" #include "chrome/browser/notifications/notification_ui_manager.h" #include "chrome/browser/policy/browser_policy_connector.h" -#include "chrome/browser/policy/policy_service_impl.h" -#include "chrome/browser/policy/policy_service_stub.h" +#include "chrome/browser/policy/policy_service.h" #include "chrome/browser/prefs/browser_prefs.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/prerender/prerender_tracker.h" @@ -83,6 +82,10 @@ #include "ui/base/clipboard/clipboard.h" #include "ui/base/l10n/l10n_util.h" +#if !defined(ENABLE_CONFIGURATION_POLICY) +#include "chrome/browser/policy/policy_service_stub.h" +#endif // defined(ENABLE_CONFIGURATION_POLICY) + #if defined(OS_WIN) #include "ui/views/focus/view_storage.h" #elif defined(OS_MACOSX) @@ -448,7 +451,8 @@ policy::BrowserPolicyConnector* BrowserProcessImpl::browser_policy_connector() { policy::PolicyService* BrowserProcessImpl::policy_service() { if (!policy_service_.get()) { #if defined(ENABLE_CONFIGURATION_POLICY) - policy_service_.reset(browser_policy_connector()->CreatePolicyService()); + policy_service_.reset( + browser_policy_connector()->CreatePolicyService(NULL)); #else policy_service_.reset(new policy::PolicyServiceStub()); #endif @@ -710,7 +714,8 @@ void BrowserProcessImpl::CreateLocalState() { FilePath local_state_path; PathService::Get(chrome::FILE_LOCAL_STATE, &local_state_path); local_state_.reset( - PrefService::CreatePrefService(local_state_path, NULL, false)); + PrefService::CreatePrefService(local_state_path, policy_service(), NULL, + false)); // Initialize the prefs of the local state. browser::RegisterLocalState(local_state_.get()); diff --git a/chrome/browser/chrome_browser_main.cc b/chrome/browser/chrome_browser_main.cc index fb47fd1..3b48f9c 100644 --- a/chrome/browser/chrome_browser_main.cc +++ b/chrome/browser/chrome_browser_main.cc @@ -324,7 +324,9 @@ PrefService* InitializeLocalState(const CommandLine& parsed_command_line, FilePath parent_profile = parsed_command_line.GetSwitchValuePath(switches::kParentProfile); scoped_ptr<PrefService> parent_local_state( - PrefService::CreatePrefService(parent_profile, NULL, false)); + PrefService::CreatePrefService(parent_profile, + g_browser_process->policy_service(), + NULL, false)); parent_local_state->RegisterStringPref(prefs::kApplicationLocale, std::string()); // Right now, we only inherit the locale setting from the parent profile. diff --git a/chrome/browser/policy/browser_policy_connector.cc b/chrome/browser/policy/browser_policy_connector.cc index 2b9aa22..b3bd15b 100644 --- a/chrome/browser/policy/browser_policy_connector.cc +++ b/chrome/browser/policy/browser_policy_connector.cc @@ -150,7 +150,8 @@ void BrowserPolicyConnector::Init() { #endif } -PolicyService* BrowserPolicyConnector::CreatePolicyService() const { +PolicyService* BrowserPolicyConnector::CreatePolicyService( + Profile* profile) const { // |providers| in decreasing order of priority. PolicyServiceImpl::Providers providers; if (managed_platform_provider_.get()) diff --git a/chrome/browser/policy/browser_policy_connector.h b/chrome/browser/policy/browser_policy_connector.h index 2781a63..2c52472 100644 --- a/chrome/browser/policy/browser_policy_connector.h +++ b/chrome/browser/policy/browser_policy_connector.h @@ -17,6 +17,7 @@ #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" +class Profile; class TokenService; namespace policy { @@ -45,8 +46,9 @@ class BrowserPolicyConnector : public content::NotificationObserver { // policy system running. void Init(); - // Ownership is transferred to the caller. - PolicyService* CreatePolicyService() const; + // Creates a new policy service for the given profile, or a global one if + // it is NULL. Ownership is transferred to the caller. + PolicyService* CreatePolicyService(Profile* profile) const; // Returns a weak pointer to the CloudPolicySubsystem corresponding to the // device policy managed by this policy connector, or NULL if no such diff --git a/chrome/browser/policy/configuration_policy_pref_store.cc b/chrome/browser/policy/configuration_policy_pref_store.cc index 280a29f..30bdb12 100644 --- a/chrome/browser/policy/configuration_policy_pref_store.cc +++ b/chrome/browser/policy/configuration_policy_pref_store.cc @@ -94,15 +94,17 @@ void ConfigurationPolicyPrefStore::OnPolicyServiceInitialized() { // static ConfigurationPolicyPrefStore* -ConfigurationPolicyPrefStore::CreateMandatoryPolicyPrefStore() { - return new ConfigurationPolicyPrefStore(g_browser_process->policy_service(), +ConfigurationPolicyPrefStore::CreateMandatoryPolicyPrefStore( + PolicyService* policy_service) { + return new ConfigurationPolicyPrefStore(policy_service, POLICY_LEVEL_MANDATORY); } // static ConfigurationPolicyPrefStore* -ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore() { - return new ConfigurationPolicyPrefStore(g_browser_process->policy_service(), +ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore( + PolicyService* policy_service) { + return new ConfigurationPolicyPrefStore(policy_service, POLICY_LEVEL_RECOMMENDED); } diff --git a/chrome/browser/policy/configuration_policy_pref_store.h b/chrome/browser/policy/configuration_policy_pref_store.h index f3d33a4..7b431ec 100644 --- a/chrome/browser/policy/configuration_policy_pref_store.h +++ b/chrome/browser/policy/configuration_policy_pref_store.h @@ -48,11 +48,13 @@ class ConfigurationPolicyPrefStore // Creates a ConfigurationPolicyPrefStore that only provides policies that // have POLICY_LEVEL_MANDATORY level. - static ConfigurationPolicyPrefStore* CreateMandatoryPolicyPrefStore(); + static ConfigurationPolicyPrefStore* CreateMandatoryPolicyPrefStore( + PolicyService* policy_service); // Creates a ConfigurationPolicyPrefStore that only provides policies that // have POLICY_LEVEL_RECOMMENDED level. - static ConfigurationPolicyPrefStore* CreateRecommendedPolicyPrefStore(); + static ConfigurationPolicyPrefStore* CreateRecommendedPolicyPrefStore( + PolicyService* policy_service); private: virtual ~ConfigurationPolicyPrefStore(); diff --git a/chrome/browser/policy/policy_map.h b/chrome/browser/policy/policy_map.h index a90c146..82b95cb 100644 --- a/chrome/browser/policy/policy_map.h +++ b/chrome/browser/policy/policy_map.h @@ -15,8 +15,6 @@ namespace policy { -struct PolicyDefinitionList; - // A mapping of policy names to policy values for a given policy namespace. class PolicyMap { public: diff --git a/chrome/browser/policy/policy_service.h b/chrome/browser/policy/policy_service.h index 94f57ae..93c7f91 100644 --- a/chrome/browser/policy/policy_service.h +++ b/chrome/browser/policy/policy_service.h @@ -32,6 +32,8 @@ enum PolicyDomain { // and register for notifications on policy updates. // // The PolicyService is available from BrowserProcess as a global singleton. +// There is also a PolicyService for browser-wide policies available from +// BrowserProcess as a global singleton. class PolicyService { public: class Observer { diff --git a/chrome/browser/prefs/pref_service.cc b/chrome/browser/prefs/pref_service.cc index 6427c0e..48c255b 100644 --- a/chrome/browser/prefs/pref_service.cc +++ b/chrome/browser/prefs/pref_service.cc @@ -5,7 +5,6 @@ #include "chrome/browser/prefs/pref_service.h" #include <algorithm> -#include <string> #include "base/bind.h" #include "base/command_line.h" @@ -115,9 +114,11 @@ class ReadErrorHandler : public PersistentPrefStore::ReadErrorDelegate { } // namespace // static -PrefService* PrefService::CreatePrefService(const FilePath& pref_filename, - PrefStore* extension_prefs, - bool async) { +PrefService* PrefService::CreatePrefService( + const FilePath& pref_filename, + policy::PolicyService* policy_service, + PrefStore* extension_prefs, + bool async) { using policy::ConfigurationPolicyPrefStore; #if defined(OS_LINUX) @@ -135,9 +136,11 @@ PrefService* PrefService::CreatePrefService(const FilePath& pref_filename, #if defined(ENABLE_CONFIGURATION_POLICY) ConfigurationPolicyPrefStore* managed = - ConfigurationPolicyPrefStore::CreateMandatoryPolicyPrefStore(); + ConfigurationPolicyPrefStore::CreateMandatoryPolicyPrefStore( + policy_service); ConfigurationPolicyPrefStore* recommended = - ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore(); + ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore( + policy_service); #else ConfigurationPolicyPrefStore* managed = NULL; ConfigurationPolicyPrefStore* recommended = NULL; diff --git a/chrome/browser/prefs/pref_service.h b/chrome/browser/prefs/pref_service.h index a486917..948bd34 100644 --- a/chrome/browser/prefs/pref_service.h +++ b/chrome/browser/prefs/pref_service.h @@ -19,7 +19,6 @@ #include "base/memory/scoped_ptr.h" #include "base/threading/non_thread_safe.h" #include "base/values.h" -#include "chrome/common/json_pref_store.h" class CommandLine; class DefaultPrefStore; @@ -30,20 +29,21 @@ class PrefNotifier; class PrefNotifierImpl; class PrefStore; class PrefValueStore; -class Profile; class SyncableService; namespace content { class NotificationObserver; } +namespace policy{ +class PolicyService; +} + namespace subtle { class PrefMemberBase; class ScopedUserPrefUpdateBase; }; -class PrefService; - class PrefService : public base::NonThreadSafe { public: // Enum used when registering preferences to determine if it should be synced @@ -145,13 +145,17 @@ class PrefService : public base::NonThreadSafe { // applicable PrefStores. The |pref_filename| points to the user preference // file. This is the usual way to create a new PrefService. // |extension_pref_store| is used as the source for extension-controlled - // preferences and may be NULL. The PrefService takes ownership of - // |extension_pref_store|. If |async| is true, asynchronous version is used. + // preferences and may be NULL. + // |policy_service| is used as the source for mandatory or recommended + // policies. + // The PrefService takes ownership of |extension_pref_store|. + // If |async| is true, asynchronous version is used. // Notifies using PREF_INITIALIZATION_COMPLETED in the end. Details is set to // the created PrefService or NULL if creation has failed. Note, it is // guaranteed that in asynchronous version initialization happens after this // function returned. static PrefService* CreatePrefService(const FilePath& pref_filename, + policy::PolicyService* policy_service, PrefStore* extension_pref_store, bool async); diff --git a/chrome/browser/profiles/off_the_record_profile_impl.cc b/chrome/browser/profiles/off_the_record_profile_impl.cc index a7017e5..7c92c21 100644 --- a/chrome/browser/profiles/off_the_record_profile_impl.cc +++ b/chrome/browser/profiles/off_the_record_profile_impl.cc @@ -246,6 +246,10 @@ history::ShortcutsBackend* OffTheRecordProfileImpl::GetShortcutsBackend() { return NULL; } +policy::PolicyService* OffTheRecordProfileImpl::GetPolicyService() { + return profile_->GetPolicyService(); +} + PrefService* OffTheRecordProfileImpl::GetPrefs() { return prefs_; } diff --git a/chrome/browser/profiles/off_the_record_profile_impl.h b/chrome/browser/profiles/off_the_record_profile_impl.h index 9fd2f1e..91b9059 100644 --- a/chrome/browser/profiles/off_the_record_profile_impl.h +++ b/chrome/browser/profiles/off_the_record_profile_impl.h @@ -52,6 +52,7 @@ class OffTheRecordProfileImpl : public Profile, virtual FaviconService* GetFaviconService(ServiceAccessType sat) OVERRIDE; virtual AutocompleteClassifier* GetAutocompleteClassifier() OVERRIDE; virtual history::ShortcutsBackend* GetShortcutsBackend() OVERRIDE; + virtual policy::PolicyService* GetPolicyService() OVERRIDE; virtual PrefService* GetPrefs() OVERRIDE; virtual PrefService* GetOffTheRecordPrefs() OVERRIDE; virtual net::URLRequestContextGetter* diff --git a/chrome/browser/profiles/profile.h b/chrome/browser/profiles/profile.h index 8d75eee..fb8a28b 100644 --- a/chrome/browser/profiles/profile.h +++ b/chrome/browser/profiles/profile.h @@ -74,6 +74,10 @@ namespace net { class SSLConfigService; } +namespace policy { +class PolicyService; +} + class Profile : public content::BrowserContext { public: // Profile services are accessed with the following parameter. This parameter @@ -262,10 +266,11 @@ class Profile : public content::BrowserContext { // this profile need to be sure they refcount the returned value. virtual history::ShortcutsBackend* GetShortcutsBackend() = 0; + // Returns the PolicyService that provides policies for this profile. + virtual policy::PolicyService* GetPolicyService() = 0; // Retrieves a pointer to the PrefService that manages the preferences - // for this user profile. The PrefService is lazily created the first - // time that this method is called. + // for this user profile. virtual PrefService* GetPrefs() = 0; // Retrieves a pointer to the PrefService that manages the preferences diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc index b8cf237..0612b82 100644 --- a/chrome/browser/profiles/profile_impl.cc +++ b/chrome/browser/profiles/profile_impl.cc @@ -51,6 +51,7 @@ #include "chrome/browser/net/ssl_config_service_manager.h" #include "chrome/browser/net/url_fixer_upper.h" #include "chrome/browser/plugin_prefs.h" +#include "chrome/browser/policy/policy_service.h" #include "chrome/browser/prefs/browser_prefs.h" #include "chrome/browser/prefs/scoped_user_pref_update.h" #include "chrome/browser/prerender/prerender_manager_factory.h" @@ -85,13 +86,18 @@ #include "grit/generated_resources.h" #include "ui/base/l10n/l10n_util.h" +#if defined(ENABLE_CONFIGURATION_POLICY) +#include "chrome/browser/policy/browser_policy_connector.h" +#else +#include "chrome/browser/policy/policy_service_stub.h" +#endif // defined(ENABLE_CONFIGURATION_POLICY) + #if defined(OS_WIN) #include "chrome/installer/util/install_util.h" -#elif defined(OS_CHROMEOS) -#include "chrome/browser/chromeos/enterprise_extension_observer.h" #endif #if defined(OS_CHROMEOS) +#include "chrome/browser/chromeos/enterprise_extension_observer.h" #include "chrome/browser/chromeos/locale_change_guard.h" #include "chrome/browser/chromeos/login/user_manager.h" #include "chrome/browser/chromeos/preferences.h" @@ -249,9 +255,16 @@ ProfileImpl::ProfileImpl(const FilePath& path, session_restore_enabled_ = !command_line->HasSwitch(switches::kDisableRestoreSessionState); +#if defined(ENABLE_CONFIGURATION_POLICY) + policy_service_.reset( + g_browser_process->browser_policy_connector()->CreatePolicyService(this)); +#else + policy_service_.reset(new policy::PolicyServiceStub()); +#endif if (create_mode == CREATE_MODE_ASYNCHRONOUS) { prefs_.reset(PrefService::CreatePrefService( GetPrefFilePath(), + policy_service_.get(), new ExtensionPrefStore( ExtensionPrefValueMapFactory::GetForProfile(this), false), true)); @@ -263,6 +276,7 @@ ProfileImpl::ProfileImpl(const FilePath& path, // Load prefs synchronously. prefs_.reset(PrefService::CreatePrefService( GetPrefFilePath(), + policy_service_.get(), new ExtensionPrefStore( ExtensionPrefValueMapFactory::GetForProfile(this), false), false)); @@ -673,6 +687,11 @@ bool ProfileImpl::WasCreatedByVersionOrLater(const std::string& version) { return (profile_version.CompareTo(arg_version) >= 0); } +policy::PolicyService* ProfileImpl::GetPolicyService() { + DCHECK(policy_service_.get()); // Should explicitly be initialized. + return policy_service_.get(); +} + PrefService* ProfileImpl::GetPrefs() { DCHECK(prefs_.get()); // Should explicitly be initialized. return prefs_.get(); diff --git a/chrome/browser/profiles/profile_impl.h b/chrome/browser/profiles/profile_impl.h index 8662ea0..fc48a09 100644 --- a/chrome/browser/profiles/profile_impl.h +++ b/chrome/browser/profiles/profile_impl.h @@ -89,6 +89,7 @@ class ProfileImpl : public Profile, virtual HistoryService* GetHistoryServiceWithoutCreating() OVERRIDE; virtual AutocompleteClassifier* GetAutocompleteClassifier() OVERRIDE; virtual history::ShortcutsBackend* GetShortcutsBackend() OVERRIDE; + virtual policy::PolicyService* GetPolicyService() OVERRIDE; virtual PrefService* GetPrefs() OVERRIDE; virtual PrefService* GetOffTheRecordPrefs() OVERRIDE; virtual net::URLRequestContextGetter* @@ -191,8 +192,13 @@ class ProfileImpl : public Profile, // that the declaration occurs AFTER things it depends on as destruction // happens in reverse order of declaration. + // |prefs_| depends on |policy_service_|. + // TODO(bauerb): Once |prefs_| is a ProfileKeyedService, |policy_service_| + // should become one as well. + scoped_ptr<policy::PolicyService> policy_service_; + // Keep |prefs_| on top for destruction order because |extension_prefs_|, - // |net_pref_observer_|, |web_resource_service_|, and |io_data_| store + // |net_pref_observer_|, |promo_resource_service_|, |io_data_| an others store // pointers to |prefs_| and shall be destructed first. scoped_ptr<PrefService> prefs_; scoped_ptr<PrefService> otr_prefs_; diff --git a/chrome/browser/ui/webui/policy_ui.cc b/chrome/browser/ui/webui/policy_ui.cc index 425204a..3af9974 100644 --- a/chrome/browser/ui/webui/policy_ui.cc +++ b/chrome/browser/ui/webui/policy_ui.cc @@ -83,6 +83,82 @@ ChromeWebUIDataSource* CreatePolicyUIHTMLSource() { return source; } +string16 GetPolicyScopeString(policy::PolicyScope scope) { + switch (scope) { + case policy::POLICY_SCOPE_USER: + return l10n_util::GetStringUTF16(IDS_POLICY_SCOPE_USER); + case policy::POLICY_SCOPE_MACHINE: + return l10n_util::GetStringUTF16(IDS_POLICY_SCOPE_MACHINE); + } + NOTREACHED(); + return string16(); +} + +string16 GetPolicyLevelString(policy::PolicyLevel level) { + switch (level) { + case policy::POLICY_LEVEL_RECOMMENDED: + return l10n_util::GetStringUTF16(IDS_POLICY_LEVEL_RECOMMENDED); + case policy::POLICY_LEVEL_MANDATORY: + return l10n_util::GetStringUTF16(IDS_POLICY_LEVEL_MANDATORY); + } + NOTREACHED(); + return string16(); +} + +base::DictionaryValue* GetPolicyDetails( + const policy::PolicyDefinitionList::Entry* policy_definition, + const policy::PolicyMap::Entry* policy_value, + const string16& error_message) { + base::DictionaryValue* details = new base::DictionaryValue(); + details->SetString(PolicyUIHandler::kName, + ASCIIToUTF16(policy_definition->name)); + details->SetBoolean(PolicyUIHandler::kSet, true); + details->SetString(PolicyUIHandler::kLevel, + GetPolicyLevelString(policy_value->level)); + details->SetString(PolicyUIHandler::kScope, + GetPolicyScopeString(policy_value->scope)); + details->Set(PolicyUIHandler::kValue, policy_value->value->DeepCopy()); + if (error_message.empty()) { + details->SetString(PolicyUIHandler::kStatus, + l10n_util::GetStringUTF16(IDS_OK)); + } else { + details->SetString(PolicyUIHandler::kStatus, error_message); + } + return details; +} + +base::DictionaryValue* GetPolicyErrorDetails(const std::string& policy_name, + bool is_set) { + base::DictionaryValue* details = new base::DictionaryValue(); + details->SetString(PolicyUIHandler::kName, ASCIIToUTF16(policy_name)); + details->SetBoolean(PolicyUIHandler::kSet, is_set); + details->SetString(PolicyUIHandler::kLevel, ""); + details->SetString(PolicyUIHandler::kScope, ""); + details->SetString(PolicyUIHandler::kValue, ""); + if (is_set) + details->SetString(PolicyUIHandler::kStatus, + l10n_util::GetStringUTF16(IDS_POLICY_UNKNOWN)); + else + details->SetString(PolicyUIHandler::kStatus, + l10n_util::GetStringUTF16(IDS_POLICY_NOT_SET)); + return details; +} + +string16 CreateStatusMessageString( + policy::CloudPolicySubsystem::ErrorDetails error_details) { + static int error_to_string_id[] = { + IDS_POLICY_STATUS_OK, + IDS_POLICY_STATUS_NETWORK_ERROR, + IDS_POLICY_STATUS_NETWORK_ERROR, // this is also a network error. + IDS_POLICY_STATUS_DMTOKEN_ERROR, + IDS_POLICY_STATUS_LOCAL_ERROR, + IDS_POLICY_STATUS_SIGNATURE_ERROR, + IDS_POLICY_STATUS_SERIAL_ERROR, + }; + DCHECK(static_cast<size_t>(error_details) < arraysize(error_to_string_id)); + return l10n_util::GetStringUTF16(error_to_string_id[error_details]); +} + } // namespace //////////////////////////////////////////////////////////////////////////////// @@ -92,17 +168,16 @@ ChromeWebUIDataSource* CreatePolicyUIHTMLSource() { //////////////////////////////////////////////////////////////////////////////// PolicyUIHandler::PolicyUIHandler() - : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { - g_browser_process->policy_service()->AddObserver( - policy::POLICY_DOMAIN_CHROME, "", this); -} + : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {} PolicyUIHandler::~PolicyUIHandler() { - g_browser_process->policy_service()->RemoveObserver( + GetPolicyService()->RemoveObserver( policy::POLICY_DOMAIN_CHROME, "", this); } void PolicyUIHandler::RegisterMessages() { + GetPolicyService()->AddObserver( + policy::POLICY_DOMAIN_CHROME, "", this); web_ui()->RegisterMessageCallback( "requestData", base::Bind(&PolicyUIHandler::HandleRequestData, @@ -183,7 +258,7 @@ void PolicyUIHandler::HandleFetchPolicy(const base::ListValue* args) { // Fetching policy can potentially take a while due to cloud policy fetches. // Use a WeakPtr to make sure the callback is invalidated if the tab is closed // before the fetching completes. - g_browser_process->policy_service()->RefreshPolicies( + GetPolicyService()->RefreshPolicies( base::Bind(&PolicyUIHandler::OnRefreshDone, weak_factory_.GetWeakPtr())); } @@ -193,7 +268,7 @@ void PolicyUIHandler::OnRefreshDone() { } void PolicyUIHandler::SendDataToUI() { - policy::PolicyService* service = g_browser_process->policy_service(); + policy::PolicyService* service = GetPolicyService(); bool any_policies_set = false; base::ListValue* list = GetPolicyStatusList( @@ -207,79 +282,9 @@ void PolicyUIHandler::SendDataToUI() { web_ui()->CallJavascriptFunction("Policy.returnData", results); } -// static -string16 PolicyUIHandler::GetPolicyScopeString(policy::PolicyScope scope) { - switch (scope) { - case policy::POLICY_SCOPE_USER: - return l10n_util::GetStringUTF16(IDS_POLICY_SCOPE_USER); - case policy::POLICY_SCOPE_MACHINE: - return l10n_util::GetStringUTF16(IDS_POLICY_SCOPE_MACHINE); - } - NOTREACHED(); - return string16(); -} - -// static -string16 PolicyUIHandler::GetPolicyLevelString(policy::PolicyLevel level) { - switch (level) { - case policy::POLICY_LEVEL_RECOMMENDED: - return l10n_util::GetStringUTF16(IDS_POLICY_LEVEL_RECOMMENDED); - case policy::POLICY_LEVEL_MANDATORY: - return l10n_util::GetStringUTF16(IDS_POLICY_LEVEL_MANDATORY); - } - NOTREACHED(); - return string16(); -} - -// static -base::DictionaryValue* PolicyUIHandler::GetPolicyDetails( - const policy::PolicyDefinitionList::Entry* policy_definition, - const policy::PolicyMap::Entry* policy_value, - const string16& error_message) { - base::DictionaryValue* details = new base::DictionaryValue(); - details->SetString(kName, ASCIIToUTF16(policy_definition->name)); - details->SetBoolean(kSet, true); - details->SetString(kLevel, GetPolicyLevelString(policy_value->level)); - details->SetString(kScope, GetPolicyScopeString(policy_value->scope)); - details->Set(kValue, policy_value->value->DeepCopy()); - if (error_message.empty()) - details->SetString(kStatus, l10n_util::GetStringUTF16(IDS_OK)); - else - details->SetString(kStatus, error_message); - return details; -} - -// static -base::DictionaryValue* PolicyUIHandler::GetPolicyErrorDetails( - const std::string& policy_name, - bool is_set) { - base::DictionaryValue* details = new base::DictionaryValue(); - details->SetString(kName, ASCIIToUTF16(policy_name)); - details->SetBoolean(kSet, is_set); - details->SetString(kLevel, ""); - details->SetString(kScope, ""); - details->SetString(kValue, ""); - if (is_set) - details->SetString(kStatus, l10n_util::GetStringUTF16(IDS_POLICY_UNKNOWN)); - else - details->SetString(kStatus, l10n_util::GetStringUTF16(IDS_POLICY_NOT_SET)); - return details; -} - -// static -string16 PolicyUIHandler::CreateStatusMessageString( - policy::CloudPolicySubsystem::ErrorDetails error_details) { - static int error_to_string_id[] = { - IDS_POLICY_STATUS_OK, - IDS_POLICY_STATUS_NETWORK_ERROR, - IDS_POLICY_STATUS_NETWORK_ERROR, // this is also a network error. - IDS_POLICY_STATUS_DMTOKEN_ERROR, - IDS_POLICY_STATUS_LOCAL_ERROR, - IDS_POLICY_STATUS_SIGNATURE_ERROR, - IDS_POLICY_STATUS_SERIAL_ERROR, - }; - DCHECK(static_cast<size_t>(error_details) < arraysize(error_to_string_id)); - return l10n_util::GetStringUTF16(error_to_string_id[error_details]); +policy::PolicyService* PolicyUIHandler::GetPolicyService() { + Profile* profile = Profile::FromWebUI(web_ui()); + return profile->GetPolicyService(); } base::DictionaryValue* PolicyUIHandler::GetStatusData() { diff --git a/chrome/browser/ui/webui/policy_ui.h b/chrome/browser/ui/webui/policy_ui.h index 24ba80c..f1b13d0 100644 --- a/chrome/browser/ui/webui/policy_ui.h +++ b/chrome/browser/ui/webui/policy_ui.h @@ -69,30 +69,8 @@ class PolicyUIHandler : public content::WebUIMessageHandler, // Sends policy data to UI. void SendDataToUI(); - // Converts a PolicyScope to a string16 representation. - static string16 GetPolicyScopeString(policy::PolicyScope scope); - - // Converts a PolicyLevel to a string16 representation. - static string16 GetPolicyLevelString(policy::PolicyLevel level); - - // Fills a DictionaryValue with the details of the given policy, in the - // format expected by the about:policy webui at - // src/chrome/browser/resources/policy.js - static base::DictionaryValue* GetPolicyDetails( - const policy::PolicyDefinitionList::Entry* policy_definition, - const policy::PolicyMap::Entry* policy_value, - const string16& error_message); - - // Fills a DictionaryValue with the error status of the given |policy_name|. - // If |is_set| is true, this is a policy that was set but is not recognized; - // if |is_set| is false, this is a known policy that is not configured. - static base::DictionaryValue* GetPolicyErrorDetails( - const std::string& policy_name, - bool is_set); - - // Returns a status message based on |error_details|. - static string16 CreateStatusMessageString( - policy::CloudPolicySubsystem::ErrorDetails error_details); + // Returns the policy service to use. + policy::PolicyService* GetPolicyService(); // Returns a DictionaryValue pointer containing information about the status // of the policy system. The caller acquires ownership of the returned |