Refactor proxy handling for ChromeOS to not go through the CrosSettings interface.

The ProxyCrosSettingsProvider was not a real SignedSettings handler since the
network manager was introduced and was only used to parse the data for the UI.
However this does not go well with the unification of the SignedSettings
handling and belongs to the presentation layer. Therefore we extract the
parsing functionality in a helper class and move some of the logic up the
UI handling layer.

BUG=chromium-os:14054
TEST=Proxy UI should still be working (automation tests).

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@109886 0039d316-1c4b-4281-b951-d872f2087c98
parent 4ae8796f
......@@ -26,7 +26,7 @@
#include "chrome/browser/chromeos/login/webui_login_display.h"
#include "chrome/browser/chromeos/login/wizard_controller.h"
#include "chrome/browser/chromeos/options/take_photo_dialog.h"
#include "chrome/browser/chromeos/proxy_cros_settings_provider.h"
#include "chrome/browser/chromeos/proxy_cros_settings_parser.h"
#include "chrome/browser/chromeos/system/timezone_settings.h"
#include "chrome/browser/policy/browser_policy_connector.h"
#include "chrome/browser/policy/cloud_policy_cache_base.h"
......@@ -67,20 +67,23 @@ DictionaryValue* GetNetworkInfoDict(const chromeos::Network* network) {
return item;
}
Value* GetProxySetting(Browser* browser, const std::string& setting_name) {
chromeos::ProxyCrosSettingsProvider settings_provider(browser->profile());
base::Value* GetProxySetting(Browser* browser,
const std::string& setting_name) {
std::string setting_path = "cros.session.proxy.";
setting_path.append(setting_name);
if (setting_name == "ignorelist") {
Value* value;
if (settings_provider.Get(setting_path, &value))
base::Value* value;
if (chromeos::proxy_cros_settings_parser::GetProxyPrefValue(
browser->profile(), setting_path, &value)) {
return value;
}
} else {
Value* setting;
if (settings_provider.Get(setting_path, &setting)) {
base::Value* setting;
if (chromeos::proxy_cros_settings_parser::GetProxyPrefValue(
browser->profile(), setting_path, &setting)) {
DictionaryValue* setting_dict = static_cast<DictionaryValue*>(setting);
Value* value;
base::Value* value;
bool found = setting_dict->Remove("value", &value);
delete setting;
if (found)
......@@ -457,7 +460,7 @@ void TestingAutomationProvider::GetNetworkInfo(DictionaryValue* args,
remembered_wifi.begin(); iter != remembered_wifi.end();
++iter) {
const chromeos::WifiNetwork* wifi = *iter;
items->Append(Value::CreateStringValue(wifi->service_path()));
items->Append(base::Value::CreateStringValue(wifi->service_path()));
}
return_value->Set("remembered_wifi", items);
......@@ -516,10 +519,9 @@ void TestingAutomationProvider::GetProxySettings(Browser* browser,
"socks", "socksport", "ignorelist" };
scoped_ptr<DictionaryValue> return_value(new DictionaryValue);
chromeos::ProxyCrosSettingsProvider settings_provider(browser->profile());
for (size_t i = 0; i < arraysize(settings); ++i) {
Value* setting = GetProxySetting(browser, settings[i]);
base::Value* setting = GetProxySetting(browser, settings[i]);
if (setting)
return_value->Set(settings[i], setting);
}
......@@ -532,7 +534,7 @@ void TestingAutomationProvider::SetProxySettings(Browser* browser,
IPC::Message* reply_message) {
AutomationJSONReply reply(this, reply_message);
std::string key;
Value* value;
base::Value* value;
if (!args->GetString("key", &key) || !args->Get("value", &value)) {
reply.SendError("Invalid or missing args.");
return;
......@@ -542,8 +544,8 @@ void TestingAutomationProvider::SetProxySettings(Browser* browser,
setting_path.append(key);
// ProxyCrosSettingsProvider will own the Value* passed to Set().
chromeos::ProxyCrosSettingsProvider(browser->profile()).Set(setting_path,
value->DeepCopy());
chromeos::proxy_cros_settings_parser::SetProxyPrefValue(
browser->profile(), setting_path, value);
reply.SendSuccess(NULL);
}
......
......@@ -29,6 +29,28 @@ namespace chromeos {
namespace {
// Shoud we try to push this to base?
// Helper comparator functor for the find_if call in |findIfEqual|
template <class T>
class EqualsComparator{
public:
explicit EqualsComparator(const T& key) : key_(key) { }
bool operator() (const T& element) {
return element.Equals(key_);
}
private:
const T& key_;
};
// Tiny STL helper function to allow using the find_if syntax on objects that
// doesn't use the operator== but implement the Equals function which is the
// quasi standard with the coding style we have.
template<class InputIterator, class T>
InputIterator findIfEqual(InputIterator first, InputIterator last,
const T& key) {
return std::find_if(first, last, EqualsComparator<T>(key));
}
const char* ModeToString(ProxyConfigServiceImpl::ProxyConfig::Mode mode) {
switch (mode) {
case ProxyConfigServiceImpl::ProxyConfig::MODE_DIRECT:
......@@ -471,6 +493,22 @@ bool ProxyConfigServiceImpl::UISetProxyConfigBypassRules(
return true;
}
void ProxyConfigServiceImpl::AddNotificationCallback(base::Closure callback) {
std::vector<base::Closure>::iterator iter =
findIfEqual(callbacks_.begin(), callbacks_.end(), callback);
if (iter == callbacks_.end())
callbacks_.push_back(callback);
}
void ProxyConfigServiceImpl::RemoveNotificationCallback(
base::Closure callback) {
std::vector<base::Closure>::iterator iter =
findIfEqual(callbacks_.begin(), callbacks_.end(), callback);
if (iter != callbacks_.end())
callbacks_.erase(iter);
}
void ProxyConfigServiceImpl::OnProxyConfigChanged(
ProxyPrefs::ConfigState config_state,
const net::ProxyConfig& config) {
......@@ -762,6 +800,16 @@ void ProxyConfigServiceImpl::OnUISetCurrentNetwork(const Network* network) {
<< ", " << ModeToString(current_ui_config_.mode)
<< ", " << ConfigStateToString(current_ui_config_.state)
<< ", modifiable:" << current_ui_config_.user_modifiable;
// Notify whoever is interested in this change.
std::vector<base::Closure>::iterator iter = callbacks_.begin();
while (iter != callbacks_.end()) {
if (iter->is_null()) {
iter = callbacks_.erase(iter);
} else {
iter->Run();
++iter;
}
}
}
void ProxyConfigServiceImpl::ResetUICache() {
......
......@@ -182,6 +182,15 @@ class ProxyConfigServiceImpl
// Only valid for MODE_SINGLE_PROXY or MODE_PROXY_PER_SCHEME.
bool UISetProxyConfigBypassRules(const net::ProxyBypassRules& bypass_rules);
// Add/Remove callback functions for notification when network to be viewed is
// changed by the UI.
void AddNotificationCallback(base::Closure callback);
void RemoveNotificationCallback(base::Closure callback);
// PrefProxyConfigTrackerImpl implementation.
virtual void OnProxyConfigChanged(ProxyPrefs::ConfigState config_state,
const net::ProxyConfig& config) OVERRIDE;
// Implementation for SignedSettings::Delegate
virtual void OnSettingsOpCompleted(SignedSettings::ReturnCode code,
std::string value) OVERRIDE;
......@@ -193,10 +202,6 @@ class ProxyConfigServiceImpl
virtual void OnNetworkChanged(NetworkLibrary* cros,
const Network* network) OVERRIDE;
// PrefProxyConfigTrackerImpl implementation.
virtual void OnProxyConfigChanged(ProxyPrefs::ConfigState config_state,
const net::ProxyConfig& config) OVERRIDE;
// Register UseShardProxies preference.
static void RegisterPrefs(PrefService* pref_service);
......@@ -293,6 +298,10 @@ class ProxyConfigServiceImpl
// Operation to retrieve proxy setting from device.
scoped_refptr<SignedSettings> retrieve_property_op_;
// Callbacks for notification when network to be viewed has been changed from
// the UI.
std::vector<base::Closure> callbacks_;
DISALLOW_COPY_AND_ASSIGN(ProxyConfigServiceImpl);
};
......
// 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_CHROMEOS_PROXY_CROS_SETTINGS_PARSER_H_
#define CHROME_BROWSER_CHROMEOS_PROXY_CROS_SETTINGS_PARSER_H_
#pragma once
#include <string>
class Profile;
namespace base {
class Value;
}
namespace chromeos {
extern const char kProxyPacUrl[];
extern const char kProxySingleHttp[];
extern const char kProxySingleHttpPort[];
extern const char kProxyHttpUrl[];
extern const char kProxyHttpPort[];
extern const char kProxyHttpsUrl[];
extern const char kProxyHttpsPort[];
extern const char kProxyType[];
extern const char kProxySingle[];
extern const char kProxyFtpUrl[];
extern const char kProxyFtpPort[];
extern const char kProxySocks[];
extern const char kProxySocksPort[];
extern const char kProxyIgnoreList[];
extern const char* const kProxySettings[];
extern const size_t kProxySettingsCount;
// This namespace defines two helper functions for parsing Proxy configuration
// to and from the ProxyConfigServiceImpl and the UI that exposes them to the
// user.
namespace proxy_cros_settings_parser {
// Returns true if the supplied |path| is a proxy preference name.
bool IsProxyPref(const std::string& path);
// Sets a value in the current proxy configuration on the specified profile.
void SetProxyPrefValue(Profile* profile,
const std::string& path,
const base::Value* in_value);
// Gets a value from the current proxy configuration on the specified profile.
bool GetProxyPrefValue(Profile* profile,
const std::string& path,
base::Value** out_value);
} // namespace proxy_cros_settings_parser
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_PROXY_CROS_SETTINGS_PARSER_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.
#ifndef CHROME_BROWSER_CHROMEOS_PROXY_CROS_SETTINGS_PROVIDER_H_
#define CHROME_BROWSER_CHROMEOS_PROXY_CROS_SETTINGS_PROVIDER_H_
#pragma once
#include "base/memory/singleton.h"
#include "base/values.h"
#include "chrome/browser/chromeos/cros_settings_provider.h"
#include "chrome/browser/chromeos/proxy_config_service_impl.h"
class Profile;
namespace chromeos {
class ProxyCrosSettingsProvider : public CrosSettingsProvider {
public:
explicit ProxyCrosSettingsProvider(Profile* profile);
// CrosSettingsProvider implementation.
virtual bool Get(const std::string& path, Value** out_value) const OVERRIDE;
virtual bool HandlesSetting(const std::string& path) const OVERRIDE;
// Set the current network whose proxy settings will be displayed and possibly
// edited on.
void SetCurrentNetwork(const std::string& network);
// Make the active network the current one whose proxy settings will be
// displayed and possibly edited on.
void MakeActiveNetworkCurrent();
private:
// CrosSettingsProvider implementation.
virtual void DoSet(const std::string& path, Value* value) OVERRIDE;
chromeos::ProxyConfigServiceImpl* GetConfigService() const;
net::ProxyServer CreateProxyServerFromHost(
const std::string& host,
const ProxyConfigServiceImpl::ProxyConfig::ManualProxy& proxy,
net::ProxyServer::Scheme scheme) const;
net::ProxyServer CreateProxyServerFromPort(
uint16 port,
const ProxyConfigServiceImpl::ProxyConfig::ManualProxy& proxy,
net::ProxyServer::Scheme scheme) const;
net::ProxyServer CreateProxyServer(
std::string host,
uint16 port,
net::ProxyServer::Scheme scheme) const;
Value* CreateServerHostValue(
const ProxyConfigServiceImpl::ProxyConfig::ManualProxy& proxy) const;
Value* CreateServerPortValue(
const ProxyConfigServiceImpl::ProxyConfig::ManualProxy& proxy) const;
Profile* profile_; // Weak ptr.
DISALLOW_COPY_AND_ASSIGN(ProxyCrosSettingsProvider);
};
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_PROXY_CROS_SETTINGS_PROVIDER_H_
......@@ -8,6 +8,7 @@
#include "base/message_loop.h"
#include "base/values.h"
#include "chrome/browser/chromeos/cros_settings.h"
#include "chrome/browser/chromeos/proxy_config_service_impl.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/chrome_url_data_manager.h"
#include "chrome/browser/ui/webui/options/chromeos/core_chromeos_options_handler.h"
......@@ -65,8 +66,7 @@ namespace chromeos {
ProxySettingsUI::ProxySettingsUI(TabContents* contents)
: ChromeWebUI(contents),
proxy_settings_(NULL),
proxy_handler_(new ProxyHandler(GetProfile())) {
proxy_handler_(new ProxyHandler()) {
// |localized_strings| will be owned by ProxySettingsHTMLSource.
DictionaryValue* localized_strings = new DictionaryValue();
......@@ -101,23 +101,11 @@ void ProxySettingsUI::InitializeHandlers() {
for (iter = handlers_.begin() + 1; iter != handlers_.end(); ++iter) {
(static_cast<OptionsPageUIHandler*>(*iter))->Initialize();
}
if (proxy_settings()) {
proxy_settings()->MakeActiveNetworkCurrent();
PrefProxyConfigTracker* proxy_tracker = GetProfile()->GetProxyConfigTracker();
proxy_tracker->UIMakeActiveNetworkCurrent();
std::string network_name;
GetProfile()->GetProxyConfigTracker()->UIGetCurrentNetworkName(
&network_name);
proxy_tracker->UIGetCurrentNetworkName(&network_name);
proxy_handler_->SetNetworkName(network_name);
}
}
chromeos::ProxyCrosSettingsProvider* ProxySettingsUI::proxy_settings() {
if (!proxy_settings_) {
proxy_settings_ = static_cast<chromeos::ProxyCrosSettingsProvider*>(
chromeos::CrosSettings::Get()->GetProvider("cros.session.proxy"));
if (!proxy_settings_)
NOTREACHED() << "Error getting access to proxy cros settings provider";
}
return proxy_settings_;
}
} // namespace chromeos
......@@ -6,7 +6,6 @@
#define CHROME_BROWSER_UI_WEBUI_CHROMEOS_PROXY_SETTINGS_UI_H_
#pragma once
#include "chrome/browser/chromeos/proxy_cros_settings_provider.h"
#include "chrome/browser/ui/webui/chrome_web_ui.h"
#include "chrome/browser/ui/webui/options/options_ui.h"
......@@ -26,9 +25,6 @@ class ProxySettingsUI : public ChromeWebUI,
// Overridden from OptionsPageUIHandlerHost:
virtual void InitializeHandlers() OVERRIDE;
chromeos::ProxyCrosSettingsProvider* proxy_settings();
chromeos::ProxyCrosSettingsProvider* proxy_settings_; // Weak ptr.
chromeos::ProxyHandler* proxy_handler_; // Weak ptr.
DISALLOW_COPY_AND_ASSIGN(ProxySettingsUI);
......
......@@ -6,31 +6,58 @@
#include <string>
#include "base/bind.h"
#include "base/string_number_conversions.h"
#include "base/string_util.h"
#include "chrome/browser/chromeos/cros_settings.h"
#include "chrome/browser/chromeos/proxy_config_service_impl.h"
#include "chrome/browser/chromeos/proxy_cros_settings_parser.h"
#include "chrome/browser/prefs/pref_set_observer.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/pref_names.h"
#include "content/browser/user_metrics.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_source.h"
namespace chromeos {
CoreChromeOSOptionsHandler::CoreChromeOSOptionsHandler()
: handling_change_(false) {
: handling_change_(false),
pointer_factory_(this) {
}
CoreChromeOSOptionsHandler::~CoreChromeOSOptionsHandler() {}
CoreChromeOSOptionsHandler::~CoreChromeOSOptionsHandler() {
PrefProxyConfigTracker* proxy_tracker =
Profile::FromWebUI(web_ui_)->GetProxyConfigTracker();
proxy_tracker->RemoveNotificationCallback(
base::Bind(&CoreChromeOSOptionsHandler::NotifyProxyPrefsChanged,
pointer_factory_.GetWeakPtr()));
}
void CoreChromeOSOptionsHandler::Initialize() {
proxy_prefs_.reset(PrefSetObserver::CreateProxyPrefSetObserver(
Profile::FromWebUI(web_ui_)->GetPrefs(), this));
// Observe the chromeos::ProxyConfigServiceImpl for changes from the UI.
PrefProxyConfigTracker* proxy_tracker =
Profile::FromWebUI(web_ui_)->GetProxyConfigTracker();
proxy_tracker->AddNotificationCallback(
base::Bind(&CoreChromeOSOptionsHandler::NotifyProxyPrefsChanged,
pointer_factory_.GetWeakPtr()));
}
Value* CoreChromeOSOptionsHandler::FetchPref(const std::string& pref_name) {
base::Value* CoreChromeOSOptionsHandler::FetchPref(
const std::string& pref_name) {
if (proxy_cros_settings_parser::IsProxyPref(pref_name)) {
base::Value *value = NULL;
proxy_cros_settings_parser::GetProxyPrefValue(Profile::FromWebUI(web_ui_),
pref_name, &value);
if (!value)
return base::Value::CreateNullValue();
return value;
}
if (!CrosSettings::IsCrosSettings(pref_name)) {
// Specially handle kUseSharedProxies because kProxy controls it to
// determine if it's managed by policy/extension.
......@@ -39,7 +66,7 @@ Value* CoreChromeOSOptionsHandler::FetchPref(const std::string& pref_name) {
const PrefService::Preference* pref =
pref_service->FindPreference(prefs::kUseSharedProxies);
if (!pref)
return Value::CreateNullValue();
return base::Value::CreateNullValue();
const PrefService::Preference* controlling_pref =
pref_service->FindPreference(prefs::kProxy);
return CreateValueForPref(pref, controlling_pref);
......@@ -47,27 +74,36 @@ Value* CoreChromeOSOptionsHandler::FetchPref(const std::string& pref_name) {
return ::CoreOptionsHandler::FetchPref(pref_name);
}
Value* pref_value = NULL;
base::Value* pref_value = NULL;
CrosSettings::Get()->Get(pref_name, &pref_value);
return pref_value ? pref_value : Value::CreateNullValue();
return pref_value ? pref_value : base::Value::CreateNullValue();
}
void CoreChromeOSOptionsHandler::ObservePref(const std::string& pref_name) {
if (proxy_cros_settings_parser::IsProxyPref(pref_name)) {
// We observe those all the time.
return;
}
if (!CrosSettings::IsCrosSettings(pref_name))
return ::CoreOptionsHandler::ObservePref(pref_name);
// TODO(xiyuan): Change this when CrosSettings supports observers.
CrosSettings::Get()->AddSettingsObserver(pref_name.c_str(), this);
}
void CoreChromeOSOptionsHandler::SetPref(const std::string& pref_name,
const Value* value,
const base::Value* value,
const std::string& metric) {
if (proxy_cros_settings_parser::IsProxyPref(pref_name)) {
proxy_cros_settings_parser::SetProxyPrefValue(Profile::FromWebUI(web_ui_),
pref_name, value);
ProcessUserMetric(value, metric);
return;
}
if (!CrosSettings::IsCrosSettings(pref_name))
return ::CoreOptionsHandler::SetPref(pref_name, value, metric);
handling_change_ = true;
// CrosSettings takes ownership of its value so we need to copy it.
Value* pref_value = value->DeepCopy();
base::Value* pref_value = value->DeepCopy();
CrosSettings::Get()->Set(pref_name, pref_value);
handling_change_ = false;
......@@ -75,6 +111,8 @@ void CoreChromeOSOptionsHandler::SetPref(const std::string& pref_name,
}
void CoreChromeOSOptionsHandler::StopObservingPref(const std::string& path) {
if (proxy_cros_settings_parser::IsProxyPref(path))
return; // We unregister those in the destructor.
// Unregister this instance from observing prefs of chrome os settings.
if (CrosSettings::IsCrosSettings(path))
CrosSettings::Get()->RemoveSettingsObserver(path.c_str(), this);
......@@ -112,7 +150,7 @@ void CoreChromeOSOptionsHandler::NotifySettingsChanged(
const std::string* setting_name) {
DCHECK(web_ui_);
DCHECK(CrosSettings::Get()->IsCrosSettings(*setting_name));
Value* value = NULL;
base::Value* value = NULL;
if (!CrosSettings::Get()->Get(*setting_name, &value)) {
NOTREACHED();
if (value)
......@@ -124,7 +162,7 @@ void CoreChromeOSOptionsHandler::NotifySettingsChanged(
iter != pref_callback_map_.end(); ++iter) {
const std::wstring& callback_function = iter->second;
ListValue result_value;
result_value.Append(Value::CreateStringValue(setting_name->c_str()));
result_value.Append(base::Value::CreateStringValue(setting_name->c_str()));
result_value.Append(value->DeepCopy());
web_ui_->CallJavascriptFunction(WideToASCII(callback_function),
result_value);
......@@ -133,4 +171,26 @@ void CoreChromeOSOptionsHandler::NotifySettingsChanged(
delete value;
}
void CoreChromeOSOptionsHandler::NotifyProxyPrefsChanged() {
DCHECK(web_ui_);
for (size_t i = 0; i < kProxySettingsCount; ++i) {
base::Value* value = NULL;
proxy_cros_settings_parser::GetProxyPrefValue(
Profile::FromWebUI(web_ui_), kProxySettings[i], &value);
DCHECK(value);
PreferenceCallbackMap::const_iterator iter =
pref_callback_map_.find(kProxySettings[i]);
for (; iter != pref_callback_map_.end(); ++iter) {
const std::wstring& callback_function = iter->second;
ListValue result_value;
result_value.Append(base::Value::CreateStringValue(kProxySettings[i]));
result_value.Append(value->DeepCopy());
web_ui_->CallJavascriptFunction(WideToASCII(callback_function),
result_value);
}
if (value)
delete value;
}
}
} // namespace chromeos
......@@ -6,6 +6,7 @@
#define CHROME_BROWSER_UI_WEBUI_OPTIONS_CHROMEOS_CORE_CHROMEOS_OPTIONS_HANDLER_H_
#pragma once
#include "base/memory/weak_ptr.h"
#include "chrome/browser/ui/webui/options/core_options_handler.h"
class PrefSetObserver;
......@@ -21,10 +22,10 @@ class CoreChromeOSOptionsHandler : public CoreOptionsHandler {
protected:
// ::CoreOptionsHandler overrides
virtual void Initialize();
virtual Value* FetchPref(const std::string& pref_name);
virtual base::Value* FetchPref(const std::string& pref_name);
virtual void ObservePref(const std::string& pref_name);
virtual void SetPref(const std::string& pref_name,
const Value* value,
const base::Value* value,
const std::string& metric);
virtual void StopObservingPref(const std::string& path);
......@@ -36,12 +37,14 @@ class CoreChromeOSOptionsHandler : public CoreOptionsHandler {
private:
// Notifies registered JS callbacks on ChromeOS setting change.
void NotifySettingsChanged(const std::string* setting_name);
void NotifyProxyPrefsChanged();
// Keeps the track of change caused by the handler to make sure
// it does not signal itself again.
bool handling_change_;
scoped_ptr<PrefSetObserver> proxy_prefs_;
base::WeakPtrFactory<CoreChromeOSOptionsHandler> pointer_factory_;
};
} // namespace chromeos
......
......@@ -28,9 +28,11 @@
#include "chrome/browser/chromeos/cros_settings.h"
#include "chrome/browser/chromeos/mobile_config.h"
#include "chrome/browser/chromeos/options/network_config_view.h"
#include "chrome/browser/chromeos/proxy_config_service_impl.h"
#include "chrome/browser/chromeos/sim_dialog_delegate.h"
#include "chrome/browser/chromeos/status/network_menu_icon.h"
#include "chrome/browser/chromeos/user_cros_settings_provider.h"
#include "chrome/browser/net/pref_proxy_config_tracker.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
......@@ -53,8 +55,7 @@
static const char kOtherNetworksFakePath[] = "?";
InternetOptionsHandler::InternetOptionsHandler()
: chromeos::CrosOptionsPageUIHandler(NULL),
proxy_settings_(NULL) {
: chromeos::CrosOptionsPageUIHandler(NULL) {
registrar_.Add(this, chrome::NOTIFICATION_REQUIRE_PIN_SETTING_CHANGE_ENDED,
content::NotificationService::AllSources());
registrar_.Add(this, chrome::NOTIFICATION_ENTER_PIN_ENDED,
......@@ -689,8 +690,12 @@ void InternetOptionsHandler::SetIPConfigCallback(const ListValue* args) {
void InternetOptionsHandler::PopulateDictionaryDetails(
const chromeos::Network* network) {
DCHECK(network);
if (proxy_settings())
proxy_settings()->SetCurrentNetwork(network->service_path());
if (web_ui_) {
Profile::FromWebUI(web_ui_)->GetProxyConfigTracker()->UISetCurrentNetwork(
network->service_path());
}
DictionaryValue dictionary;
std::string hardware_address;
chromeos::NetworkIPConfigVector ipconfigs = cros_->GetIPConfigs(
......@@ -774,16 +779,6 @@ void InternetOptionsHandler::PopulateDictionaryDetails(
"options.InternetOptions.showDetailedInfo", dictionary);
}
chromeos::ProxyCrosSettingsProvider* InternetOptionsHandler::proxy_settings() {
if (!proxy_settings_) {
proxy_settings_ = static_cast<chromeos::ProxyCrosSettingsProvider*>(
chromeos::CrosSettings::Get()->GetProvider("cros.session.proxy"));
if (!proxy_settings_)
NOTREACHED() << "Error getting access to proxy cros settings provider";
}
return proxy_settings_;
}
void InternetOptionsHandler::PopulateWifiDetails(
const chromeos::WifiNetwork* wifi,
DictionaryValue* dictionary) {
......
......@@ -8,7 +8,6 @@
#include <string>
#include "chrome/browser/chromeos/cros/network_library.h"
#include "chrome/browser/chromeos/proxy_cros_settings_provider.h"
#include "chrome/browser/ui/webui/options/chromeos/cros_options_page_ui_handler.h"
#include "content/public/browser/notification_registrar.h"
#include "ui/gfx/native_widget_types.h"
......@@ -139,15 +138,11 @@ class InternetOptionsHandler
// case of cellular networks, network technology and roaming status.
void MonitorNetworks();
chromeos::ProxyCrosSettingsProvider* proxy_settings();
// Convenience pointer to netwrok library (will not change).
chromeos::NetworkLibrary* cros_;
content::NotificationRegistrar registrar_;
chromeos::ProxyCrosSettingsProvider* proxy_settings_;
DISALLOW_COPY_AND_ASSIGN(InternetOptionsHandler);
};
......
......@@ -10,7 +10,6 @@
#include "base/time.h"
#include "base/utf_string_conversions.h"
#include "base/values.h"
#include "chrome/browser/chromeos/proxy_cros_settings_provider.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
#include "grit/locale_settings.h"
......@@ -20,8 +19,7 @@
namespace chromeos {
ProxyHandler::ProxyHandler(Profile* profile)
: CrosOptionsPageUIHandler(new ProxyCrosSettingsProvider(profile)) {
ProxyHandler::ProxyHandler() {
}
ProxyHandler::~ProxyHandler() {
......
......@@ -5,14 +5,14 @@
#ifndef CHROME_BROWSER_UI_WEBUI_OPTIONS_CHROMEOS_PROXY_HANDLER_H_
#define CHROME_BROWSER_UI_WEBUI_OPTIONS_CHROMEOS_PROXY_HANDLER_H_
#include "chrome/browser/ui/webui/options/chromeos/cros_options_page_ui_handler.h"
#include "chrome/browser/ui/webui/options/options_ui.h"
namespace chromeos {
// ChromeOS proxy options page UI handler.
class ProxyHandler : public CrosOptionsPageUIHandler {
class ProxyHandler : public OptionsPageUIHandler {
public:
explicit ProxyHandler(Profile* profile);
explicit ProxyHandler();
virtual ~ProxyHandler();
// OptionsPageUIHandler implementation.
......
......@@ -162,13 +162,13 @@ void CoreOptionsHandler::HandleInitialize(const ListValue* args) {
handlers_host_->InitializeHandlers();
}
Value* CoreOptionsHandler::FetchPref(const std::string& pref_name) {
base::Value* CoreOptionsHandler::FetchPref(const std::string& pref_name) {
PrefService* pref_service = Profile::FromWebUI(web_ui_)->GetPrefs();
const PrefService::Preference* pref =
pref_service->FindPreference(pref_name.c_str());
if (!pref)
return Value::CreateNullValue();
return base::Value::CreateNullValue();
return CreateValueForPref(pref, NULL);
}
......@@ -178,15 +178,15 @@ void CoreOptionsHandler::ObservePref(const std::string& pref_name) {
}
void CoreOptionsHandler::SetPref(const std::string& pref_name,
const Value* value,
const base::Value* value,
const std::string& metric) {
PrefService* pref_service = Profile::FromWebUI(web_ui_)->GetPrefs();
switch (value->GetType()) {
case Value::TYPE_BOOLEAN:
case Value::TYPE_INTEGER:
case Value::TYPE_DOUBLE:
case Value::TYPE_STRING:
case base::Value::TYPE_BOOLEAN:
case base::Value::TYPE_INTEGER:
case base::Value::TYPE_DOUBLE:
case base::Value::TYPE_STRING:
pref_service->Set(pref_name.c_str(), *value);
break;
......@@ -210,13 +210,13 @@ void CoreOptionsHandler::ClearPref(const std::string& pref_name,
UserMetrics::RecordComputedAction(metric);
}
void CoreOptionsHandler::ProcessUserMetric(const Value* value,
void CoreOptionsHandler::ProcessUserMetric(const base::Value* value,
const std::string& metric) {
if (metric.empty())
return;
std::string metric_string = metric;
if (value->IsType(Value::TYPE_BOOLEAN)) {
if (value->IsType(base::Value::TYPE_BOOLEAN)) {
bool bool_value;
CHECK(value->GetAsBoolean(&bool_value));
metric_string += bool_value ? "_Enable" : "_Disable";
......@@ -243,7 +243,7 @@ void CoreOptionsHandler::NotifyPrefChanged(
iter != range.second; ++iter) {
const std::wstring& callback_function = iter->second;
ListValue result_value;
result_value.Append(Value::CreateStringValue(pref_name.c_str()));
result_value.Append(base::Value::CreateStringValue(pref_name.c_str()));
result_value.Append(CreateValueForPref(pref, controlling_pref));
web_ui_->CallJavascriptFunction(WideToASCII(callback_function),
result_value);
......@@ -276,8 +276,8 @@ void CoreOptionsHandler::HandleFetchPrefs(const ListValue* args) {
DCHECK_GE(static_cast<int>(args->GetSize()), 2);
// Get callback JS function name.
Value* callback;
if (!args->Get(0, &callback) || !callback->IsType(Value::TYPE_STRING))
base::Value* callback;
if (!args->Get(0, &callback) || !callback->IsType(base::Value::TYPE_STRING))
return;
string16 callback_function;
......@@ -286,13 +286,13 @@ void CoreOptionsHandler::HandleFetchPrefs(const ListValue* args) {
// Get the list of name for prefs to build the response dictionary.
DictionaryValue result_value;
Value* list_member;
base::Value* list_member;
for (size_t i = 1; i < args->GetSize(); i++) {
if (!args->Get(i, &list_member))
break;
if (!list_member->IsType(Value::TYPE_STRING))
if (!list_member->IsType(base::Value::TYPE_STRING))
continue;
std::string pref_name;
......@@ -317,13 +317,13 @@ void CoreOptionsHandler::HandleObservePrefs(const ListValue* args) {
// Get all other parameters - pref identifiers.
for (size_t i = 1; i < args->GetSize(); i++) {
Value* list_member;
base::Value* list_member;
if (!args->Get(i, &list_member))
break;
// Just ignore bad pref identifiers for now.
std::string pref_name;
if (!list_member->IsType(Value::TYPE_STRING) ||
if (!list_member->IsType(base::Value::TYPE_STRING) ||
!list_member->GetAsString(&pref_name))
continue;
......@@ -367,11 +367,11 @@ void CoreOptionsHandler::HandleSetPref(const ListValue* args, PrefType type) {
if (!args->GetString(0, &pref_name))
return;
Value* value;
base::Value* value;
if (!args->Get(1, &value))
return;
scoped_ptr<Value> temp_value;
scoped_ptr<base::Value> temp_value;
switch (type) {
case TYPE_BOOLEAN:
......@@ -382,7 +382,7 @@ void CoreOptionsHandler::HandleSetPref(const ListValue* args, PrefType type) {
double double_value;
CHECK(value->GetAsDouble(&double_value));
int int_value = static_cast<int>(double_value);
temp_value.reset(Value::CreateIntegerValue(int_value));
temp_value.reset(base::Value::CreateIntegerValue(int_value));
value = temp_value.get();
break;
}
......@@ -396,7 +396,7 @@ void CoreOptionsHandler::HandleSetPref(const ListValue* args, PrefType type) {
std::string original;
CHECK(value->GetAsString(&original));
GURL fixed = URLFixerUpper::FixupURL(original, std::string());
temp_value.reset(Value::CreateStringValue(fixed.spec()));
temp_value.reset(base::Value::CreateStringValue(fixed.spec()));
value = temp_value.get();
break;
}
......@@ -443,8 +443,9 @@ void CoreOptionsHandler::HandleUserMetricsAction(const ListValue* args) {
}
void CoreOptionsHandler::UpdateClearPluginLSOData() {
scoped_ptr<Value> enabled(
Value::CreateBooleanValue(clear_plugin_lso_data_enabled_.GetValue()));
scoped_ptr<base::Value> enabled(
base::Value::CreateBooleanValue(
clear_plugin_lso_data_enabled_.GetValue()));
web_ui_->CallJavascriptFunction(
"OptionsPage.setClearPluginLSODataEnabled", *enabled);
}
......@@ -47,14 +47,14 @@ class CoreOptionsHandler : public OptionsPageUIHandler {
protected:
// Fetches a pref value of given |pref_name|.
// Note that caller owns the returned Value.
virtual Value* FetchPref(const std::string& pref_name);
virtual base::Value* FetchPref(const std::string& pref_name);
// Observes a pref of given |pref_name|.
virtual void ObservePref(const std::string& pref_name);
// Sets a pref |value| to given |pref_name|.
virtual void SetPref(const std::string& pref_name,
const Value* value,
const base::Value* value,
const std::string& metric);
// Clears pref value for given |pref_name|.
......@@ -64,7 +64,7 @@ class CoreOptionsHandler : public OptionsPageUIHandler {
virtual void StopObservingPref(const std::string& path);
// Records a user metric action for the given value.
void ProcessUserMetric(const Value* value,
void ProcessUserMetric(const base::Value* value,
const std::string& metric);
// Notifies registered JS callbacks on change in |pref_name| preference.
......
......@@ -253,7 +253,7 @@ OptionsUI::OptionsUI(TabContents* contents)
AddOptionsPageUIHandler(localized_strings,
new chromeos::VirtualKeyboardManagerHandler());
AddOptionsPageUIHandler(localized_strings,
new chromeos::ProxyHandler(GetProfile()));
new chromeos::ProxyHandler());
AddOptionsPageUIHandler(localized_strings,
new chromeos::ChangePictureOptionsHandler());
AddOptionsPageUIHandler(localized_strings,
......
......@@ -720,8 +720,8 @@
'browser/chromeos/prerender_condition_network.h',
'browser/chromeos/proxy_config_service_impl.cc',
'browser/chromeos/proxy_config_service_impl.h',
'browser/chromeos/proxy_cros_settings_provider.cc',
'browser/chromeos/proxy_cros_settings_provider.h',
'browser/chromeos/proxy_cros_settings_parser.cc',
'browser/chromeos/proxy_cros_settings_parser.h',
'browser/chromeos/setting_level_bubble.cc',
'browser/chromeos/setting_level_bubble.h',
'browser/chromeos/setting_level_bubble_view.cc',
......
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