Make policy errors available to display in about:policy.

This is the continuation of http://codereview.chromium.org/7972013/

BUG=99178
TEST=Everything works as before, no visible changes yet


Review URL: http://codereview.chromium.org/8139029

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@107115 0039d316-1c4b-4281-b951-d872f2087c98
parent bbef1d39
......@@ -4384,6 +4384,49 @@ Keep your key file in a safe place. You will need it to create new versions of y
<message name="IDS_POLICY_STATUS_SERIAL_ERROR" desc="Indicates that a policy fetch failed because the serial number was invalid.">
Invalid serial number
</message>
<message name="IDS_POLICY_TYPE_ERROR" desc="The text displayed in the status column when a policy value has the wrong type.">
Expected <ph name="VALUE_TYPE">$1<ex>boolean</ex></ph> value.
</message>
<message name="IDS_POLICY_OUT_OF_RANGE_ERROR" desc="The text displayed in the status column when a policy value is out of range.">
Value is out of range <ph name="VALUE">$1<ex>10</ex></ph>.
</message>
<message name="IDS_POLICY_DEFAULT_SEARCH_DISABLED" desc="The text displayed in the status column when a policy value has been ignored because default search has been disabled.">
Ignored because default search is disabled by policy.
</message>
<message name="IDS_POLICY_NOT_SPECIFIED_ERROR" desc="The text displayed in the status column when a policy value should have been specified but wasn't.">
Must be specified.
</message>
<message name="IDS_POLICY_INVALID_SEARCH_URL_ERROR" desc="The text displayed in the status column when a the URL given for DefaultSearchProviderSearchURL is invalid.">
Invalid search URL.
</message>
<message name="IDS_POLICY_INVALID_PROXY_MODE_ERROR" desc="The text displayed in the status column when the value for ProxyMode is invalid.">
Invalid proxy mode.
</message>
<message name="IDS_POLICY_PROXY_MODE_DISABLED_ERROR" desc="The text displayed in the status column when use of a proxy is disabled but a proxy configuration is given.">
Use of a proxy is disabled but an explicit proxy configuration is specified.
</message>
<message name="IDS_POLICY_PROXY_MODE_AUTO_DETECT_ERROR" desc="The text displayed in the status column when the proxy is set to auto configured but a proxy configuration is given.">
Proxy is set to auto configured.
</message>
<message name="IDS_POLICY_PROXY_MODE_PAC_URL_ERROR" desc="The text displayed in the status column when the proxy configuration is set to use a .pac script URL but policies only for fixed proxy servers are also specified.">
Proxy configuration is set to use a .pac script URL, not fixed proxy servers.
</message>
<message name="IDS_POLICY_PROXY_MODE_FIXED_SERVERS_ERROR" desc="The text displayed in the status column when the proxy configuration is set to use fixed proxy servers but an alternate configuration is given.">
Proxy is set to use fixed proxy servers, not a .pac script URL.
</message>
<message name="IDS_POLICY_PROXY_MODE_SYSTEM_ERROR" desc="The text displayed in the status column when the proxy configuration is set to use system settings but an alternate configuration is given.">
System proxy settings are set to be used but an explicit proxy configuration is also specified.
</message>
<message name="IDS_POLICY_PROXY_BOTH_SPECIFIED_ERROR" desc="The text displayed in the status column when both fixed proxy servers and .pac url are specified.">
Both fixed proxy servers and a .pac script URL are specified.
</message>
<message name="IDS_POLICY_PROXY_NEITHER_SPECIFIED_ERROR" desc="The text displayed in the status column when neither a fixed proxy servers or a .pac url are specified.">
Neither fixed proxy servers nor a .pac script URL are specified.
</message>
<message name="IDS_POLICY_OVERRIDDEN" desc="The text displayed in the status column when the corresponding policy is being ignored because another policy is overriding it.">
Ignored because it was overridden by <ph name="POLICY_NAME">$1<ex>ProxyMode</ex></ph>.
</message>
<!-- about:flags -->
<message name="IDS_FLAGS_LONG_TITLE" desc="Long version of the title for the about:flags page.">
Careful, these experiments may bite
......
......@@ -8,6 +8,7 @@
#include "base/command_line.h"
#include "base/file_path.h"
#include "base/path_service.h"
#include "base/stl_util.h"
#include "chrome/browser/net/gaia/token_service.h"
#include "chrome/browser/policy/cloud_policy_provider.h"
#include "chrome/browser/policy/cloud_policy_provider_impl.h"
......@@ -97,6 +98,8 @@ BrowserPolicyConnector::~BrowserPolicyConnector() {
user_cloud_policy_subsystem_.reset();
user_policy_token_cache_.reset();
user_data_store_.reset();
STLDeleteElements(policy_handlers_.get());
}
ConfigurationPolicyProvider*
......@@ -308,6 +311,11 @@ const CloudPolicyDataStore*
return user_data_store_.get();
}
const ConfigurationPolicyHandler::HandlerList*
BrowserPolicyConnector::GetConfigurationPolicyHandlerList() const {
return policy_handlers_.get();
}
BrowserPolicyConnector::BrowserPolicyConnector()
: ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
managed_platform_provider_.reset(CreateManagedPlatformProvider());
......@@ -323,6 +331,7 @@ BrowserPolicyConnector::BrowserPolicyConnector()
#if defined(OS_CHROMEOS)
InitializeDevicePolicy();
#endif
policy_handlers_.reset(ConfigurationPolicyHandler::CreateHandlerList());
}
BrowserPolicyConnector::BrowserPolicyConnector(
......@@ -334,7 +343,9 @@ BrowserPolicyConnector::BrowserPolicyConnector(
recommended_platform_provider_(recommended_platform_provider),
managed_cloud_provider_(managed_cloud_provider),
recommended_cloud_provider_(recommended_cloud_provider),
ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {}
ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
policy_handlers_.reset(ConfigurationPolicyHandler::CreateHandlerList());
}
void BrowserPolicyConnector::Observe(
int type,
......
......@@ -12,6 +12,7 @@
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/policy/cloud_policy_data_store.h"
#include "chrome/browser/policy/configuration_policy_handler.h"
#include "chrome/browser/policy/enterprise_install_attributes.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
......@@ -108,6 +109,9 @@ class BrowserPolicyConnector : public content::NotificationObserver {
const CloudPolicyDataStore* GetDeviceCloudPolicyDataStore() const;
const CloudPolicyDataStore* GetUserCloudPolicyDataStore() const;
const ConfigurationPolicyHandler::HandlerList*
GetConfigurationPolicyHandlerList() const;
private:
friend class ::TestingBrowserProcess;
......@@ -170,6 +174,9 @@ class BrowserPolicyConnector : public content::NotificationObserver {
// policy authentication tokens.
TokenService* token_service_;
// List of all available handlers derived from ConfigurationPolicyHandler.
scoped_ptr<ConfigurationPolicyHandler::HandlerList> policy_handlers_;
DISALLOW_COPY_AND_ASSIGN(BrowserPolicyConnector);
};
......
......@@ -192,16 +192,6 @@ TEST_P(ConfigDirPolicyProviderValueTest, Default) {
EXPECT_TRUE(policy_map.empty());
}
TEST_P(ConfigDirPolicyProviderValueTest, NullValue) {
DictionaryValue dict;
dict.Set(GetParam().policy_key(), Value::CreateNullValue());
WriteConfigFile(dict, "empty");
ConfigDirPolicyProvider provider(GetChromePolicyDefinitionList(), test_dir());
PolicyMap policy_map;
EXPECT_TRUE(provider.Provide(&policy_map));
EXPECT_TRUE(policy_map.empty());
}
TEST_P(ConfigDirPolicyProviderValueTest, TestValue) {
DictionaryValue dict;
dict.Set(GetParam().policy_key(), GetParam().test_value()->DeepCopy());
......
This diff is collapsed.
// Copyright (c) 2011 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_CONFIGURATION_POLICY_HANDLER_H_
#define CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_HANDLER_H_
#pragma once
#include <vector>
#include "base/basictypes.h"
class PrefValueMap;
namespace policy {
class PolicyErrorMap;
class PolicyMap;
// An abstract super class that subclasses should implement to map policies to
// their corresponding preferences, and to check whether the policies are valid.
class ConfigurationPolicyHandler {
public:
typedef std::vector<ConfigurationPolicyHandler*> HandlerList;
ConfigurationPolicyHandler() {}
virtual ~ConfigurationPolicyHandler() {}
// Returns true if the policy settings handled by this
// ConfigurationPolicyHandler can be applied and false otherwise. Fills
// |errors| with error messages or warnings. |errors| may contain error
// messages even when |CheckPolicySettings()| returns true.
virtual bool CheckPolicySettings(const PolicyMap* policies,
PolicyErrorMap* errors) = 0;
// Processes the policies handled by this ConfigurationPolicyHandler and sets
// the appropriate preferences in |prefs|.
virtual void ApplyPolicySettings(const PolicyMap* policies,
PrefValueMap* prefs) = 0;
// Creates a new HandlerList with all the known handlers and returns it.
// The new list and its elements are owned by the caller.
static HandlerList* CreateHandlerList();
private:
DISALLOW_COPY_AND_ASSIGN(ConfigurationPolicyHandler);
};
} // namespace policy
#endif // CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_HANDLER_H_
......@@ -13,9 +13,9 @@
#include "chrome/browser/policy/configuration_policy_provider.h"
#include "chrome/common/pref_store.h"
namespace policy {
class PrefValueMap;
class ConfigurationPolicyPrefKeeper;
namespace policy {
// Constants for the "Proxy Server Mode" defined in the policies.
// Note that these diverge from internal presentation defined in
......@@ -47,15 +47,15 @@ class ConfigurationPolicyPrefStore
virtual ~ConfigurationPolicyPrefStore();
// PrefStore methods:
virtual void AddObserver(PrefStore::Observer* observer);
virtual void RemoveObserver(PrefStore::Observer* observer);
virtual bool IsInitializationComplete() const;
virtual void AddObserver(PrefStore::Observer* observer) OVERRIDE;
virtual void RemoveObserver(PrefStore::Observer* observer) OVERRIDE;
virtual bool IsInitializationComplete() const OVERRIDE;
virtual ReadResult GetValue(const std::string& key,
const Value** result) const;
const Value** result) const OVERRIDE;
// ConfigurationPolicyProvider::Observer methods:
virtual void OnUpdatePolicy();
virtual void OnProviderGoingAway();
virtual void OnUpdatePolicy() OVERRIDE;
virtual void OnProviderGoingAway() OVERRIDE;
// Creates a ConfigurationPolicyPrefStore that reads managed platform policy.
static ConfigurationPolicyPrefStore* CreateManagedPlatformPolicyPrefStore();
......@@ -79,6 +79,10 @@ class ConfigurationPolicyPrefStore
// sending out change notifications as appropriate.
void Refresh();
// Returns a new PrefValueMap containing the preference values that correspond
// to the policies currently provided by |provider_|.
PrefValueMap* CreatePreferencesFromPolicies();
// The policy provider from which policy settings are read.
ConfigurationPolicyProvider* provider_;
......@@ -87,7 +91,7 @@ class ConfigurationPolicyPrefStore
bool initialization_complete_;
// Current policy preferences.
scoped_ptr<ConfigurationPolicyPrefKeeper> policy_keeper_;
scoped_ptr<PrefValueMap> prefs_;
ObserverList<PrefStore::Observer, true> observers_;
......
......@@ -4,6 +4,7 @@
#ifndef CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_BACKEND_MOCK_H_
#define CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_BACKEND_MOCK_H_
#pragma once
#include "chrome/browser/policy/device_management_backend.h"
#include "testing/gmock/include/gmock/gmock.h"
......
// Copyright (c) 2011 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/policy_error_map.h"
#include <utility>
#include "base/utf_string_conversions.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
namespace policy {
struct PolicyErrorMap::PendingError {
PendingError(ConfigurationPolicyType policy,
int message_id,
const string16& replacement)
: policy(policy),
message_id(message_id),
has_replacement(true),
replacement(replacement) {}
PendingError(ConfigurationPolicyType policy, int message_id)
: policy(policy), message_id(message_id), has_replacement(false) {}
ConfigurationPolicyType policy;
int message_id;
bool has_replacement;
string16 replacement;
};
PolicyErrorMap::PolicyErrorMap() {
}
PolicyErrorMap::~PolicyErrorMap() {
}
bool PolicyErrorMap::IsReady() const {
return ui::ResourceBundle::HasSharedInstance();
}
void PolicyErrorMap::AddError(ConfigurationPolicyType policy, int message_id) {
AddError(PendingError(policy, message_id));
}
void PolicyErrorMap::AddError(ConfigurationPolicyType policy,
int message_id,
const std::string& replacement) {
AddError(PendingError(policy, message_id, ASCIIToUTF16(replacement)));
}
ListValue* PolicyErrorMap::GetErrors(ConfigurationPolicyType policy) {
CheckReadyAndConvert();
std::pair<const_iterator, const_iterator> range = map_.equal_range(policy);
if (range.first == range.second)
return NULL;
ListValue* list = new ListValue();
for (const_iterator it = range.first; it != range.second; ++it)
list->Append(Value::CreateStringValue(it->second));
return list;
}
bool PolicyErrorMap::empty() {
CheckReadyAndConvert();
return map_.empty();
}
size_t PolicyErrorMap::size() {
CheckReadyAndConvert();
return map_.size();
}
PolicyErrorMap::const_iterator PolicyErrorMap::begin() {
CheckReadyAndConvert();
return map_.begin();
}
PolicyErrorMap::const_iterator PolicyErrorMap::end() {
CheckReadyAndConvert();
return map_.end();
}
void PolicyErrorMap::Clear() {
CheckReadyAndConvert();
map_.clear();
}
void PolicyErrorMap::AddError(const PendingError& error) {
if (IsReady()) {
Convert(error);
} else {
pending_.push_back(error);
}
}
void PolicyErrorMap::Convert(const PendingError& error) {
string16 message;
if (error.has_replacement)
message = l10n_util::GetStringFUTF16(error.message_id, error.replacement);
else
message = l10n_util::GetStringUTF16(error.message_id);
map_.insert(std::make_pair(error.policy, message));
}
void PolicyErrorMap::CheckReadyAndConvert() {
DCHECK(IsReady());
for (size_t i = 0; i < pending_.size(); ++i) {
Convert(pending_[i]);
}
pending_.clear();
}
} // namespace policy
// Copyright (c) 2011 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_POLICY_ERROR_MAP_H_
#define CHROME_BROWSER_POLICY_POLICY_ERROR_MAP_H_
#pragma once
#include <map>
#include <string>
#include "base/basictypes.h"
#include "base/string16.h"
#include "base/values.h"
#include "policy/configuration_policy_type.h"
namespace policy {
// Collects error messages and their associated policies.
class PolicyErrorMap {
public:
typedef std::multimap<ConfigurationPolicyType, string16> PolicyMapType;
typedef PolicyMapType::const_iterator const_iterator;
PolicyErrorMap();
virtual ~PolicyErrorMap();
// Returns true when the errors logged are ready to be retrieved. It is always
// safe to call AddError, but the other methods are only allowed once
// IsReady is true. IsReady will be true once the UI message loop has started.
bool IsReady() const;
// Adds an entry with key |policy| and the error message corresponding to
// |message_id| in grit/generated_resources.h to the map.
void AddError(ConfigurationPolicyType policy, int message_id);
// Adds an entry with key |policy| and the error message corresponding to
// |message_id| in grit/generated_resources.h to the map and replaces the
// placeholder within the error message with |replacement_string|.
void AddError(ConfigurationPolicyType policy,
int message_id,
const std::string& replacement_string);
// Returns a list of all the error messages stored for |policy|. Returns NULL
// if there are no error messages for |policy. The caller acquires ownership
// of the returned ListValue pointer.
ListValue* GetErrors(ConfigurationPolicyType policy);
bool empty();
size_t size();
const_iterator begin();
const_iterator end();
void Clear();
private:
struct PendingError;
// Maps the error when ready, otherwise adds it to the pending errors list.
void AddError(const PendingError& error);
// Converts a PendingError into a |map_| entry.
void Convert(const PendingError& error);
// Converts all pending errors to |map_| entries.
void CheckReadyAndConvert();
std::vector<PendingError> pending_;
PolicyMapType map_;
DISALLOW_COPY_AND_ASSIGN(PolicyErrorMap);
};
} // namespace policy
#endif // CHROME_BROWSER_POLICY_POLICY_ERROR_MAP_H_
......@@ -53,7 +53,7 @@ void PolicyMap::LoadFrom(
const PolicyDefinitionList::Entry* entry;
for (entry = list->begin; entry != list->end; ++entry) {
Value* value;
if (policies->Get(entry->name, &value) && value->IsType(entry->value_type))
if (policies->Get(entry->name, &value))
Set(entry->policy_type, value->DeepCopy());
}
}
......
......@@ -4,6 +4,7 @@
#ifndef CHROME_BROWSER_POLICY_POLICY_MAP_H_
#define CHROME_BROWSER_POLICY_POLICY_MAP_H_
#pragma once
#include <map>
......
......@@ -4,6 +4,7 @@
#ifndef CHROME_BROWSER_POLICY_POLICY_PATH_PARSER_H_
#define CHROME_BROWSER_POLICY_POLICY_PATH_PARSER_H_
#pragma once
#include <string>
......
......@@ -4,6 +4,7 @@
#ifndef CHROME_BROWSER_POLICY_POLICY_STATUS_INFO_H_
#define CHROME_BROWSER_POLICY_POLICY_STATUS_INFO_H_
#pragma once
#include "base/memory/scoped_ptr.h"
#include "base/string16.h"
......
......@@ -1753,6 +1753,8 @@
'browser/policy/cloud_policy_subsystem.h',
'browser/policy/config_dir_policy_provider.cc',
'browser/policy/config_dir_policy_provider.h',
'browser/policy/configuration_policy_handler.cc',
'browser/policy/configuration_policy_handler.h',
'browser/policy/configuration_policy_loader_win.cc',
'browser/policy/configuration_policy_loader_win.h',
'browser/policy/configuration_policy_pref_store.cc',
......@@ -1786,6 +1788,8 @@
'browser/policy/file_based_policy_loader.h',
'browser/policy/file_based_policy_provider.cc',
'browser/policy/file_based_policy_provider.h',
'browser/policy/policy_error_map.cc',
'browser/policy/policy_error_map.h',
'browser/policy/policy_notifier.cc',
'browser/policy/policy_notifier.h',
'browser/policy/policy_path_parser.h',
......
......@@ -114,6 +114,11 @@ void ResourceBundle::CleanupSharedInstance() {
}
}
/* static */
bool ResourceBundle::HasSharedInstance() {
return g_shared_instance_ != NULL;
}
/* static */
ResourceBundle& ResourceBundle::GetSharedInstance() {
// Must call InitSharedInstance before this function.
......
......@@ -104,6 +104,9 @@ class UI_EXPORT ResourceBundle {
// Delete the ResourceBundle for this process if it exists.
static void CleanupSharedInstance();
// Returns true after the global resource loader instance has been created.
static bool HasSharedInstance();
// Return the global resource loader instance.
static ResourceBundle& GetSharedInstance();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment