Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(155)

Side by Side Diff: chrome/browser/ui/webui/options/chromeos/core_chromeos_options_handler.cc

Issue 1296663003: Componentize proxy code from chrome/browser/net (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: updating for win p/f Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/webui/options/chromeos/core_chromeos_options_handler .h" 5 #include "chrome/browser/ui/webui/options/chromeos/core_chromeos_options_handler .h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "ash/session/session_state_delegate.h" 9 #include "ash/session/session_state_delegate.h"
10 #include "ash/shell.h" 10 #include "ash/shell.h"
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/prefs/pref_change_registrar.h" 12 #include "base/prefs/pref_change_registrar.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "base/sys_info.h" 16 #include "base/sys_info.h"
17 #include "chrome/browser/browser_process.h" 17 #include "chrome/browser/browser_process.h"
18 #include "chrome/browser/chrome_notification_types.h" 18 #include "chrome/browser/chrome_notification_types.h"
19 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" 19 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h"
20 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact ory.h" 20 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact ory.h"
21 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" 21 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
22 #include "chrome/browser/chromeos/profiles/profile_helper.h" 22 #include "chrome/browser/chromeos/profiles/profile_helper.h"
23 #include "chrome/browser/chromeos/proxy_cros_settings_parser.h" 23 #include "chrome/browser/chromeos/proxy_cros_settings_parser.h"
24 #include "chrome/browser/chromeos/settings/cros_settings.h" 24 #include "chrome/browser/chromeos/settings/cros_settings.h"
25 #include "chrome/browser/profiles/profile.h" 25 #include "chrome/browser/profiles/profile.h"
26 #include "chrome/browser/ui/webui/chromeos/ui_account_tweaks.h" 26 #include "chrome/browser/ui/webui/chromeos/ui_account_tweaks.h"
27 #include "chrome/browser/ui/webui/options/chromeos/accounts_options_handler.h" 27 #include "chrome/browser/ui/webui/options/chromeos/accounts_options_handler.h"
28 #include "chrome/common/pref_names.h" 28 #include "chrome/common/pref_names.h"
29 #include "chrome/grit/generated_resources.h" 29 #include "chrome/grit/generated_resources.h"
30 #include "components/proxy_config/proxy_config_pref_names.h"
30 #include "components/user_manager/user_manager.h" 31 #include "components/user_manager/user_manager.h"
31 #include "content/public/browser/notification_service.h" 32 #include "content/public/browser/notification_service.h"
32 #include "content/public/browser/user_metrics.h" 33 #include "content/public/browser/user_metrics.h"
33 #include "content/public/browser/web_ui.h" 34 #include "content/public/browser/web_ui.h"
34 #include "ui/base/l10n/l10n_util.h" 35 #include "ui/base/l10n/l10n_util.h"
35 36
36 namespace chromeos { 37 namespace chromeos {
37 namespace options { 38 namespace options {
38 39
39 namespace { 40 namespace {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 proxy_config_service_.UpdateFromPrefs(); 134 proxy_config_service_.UpdateFromPrefs();
134 135
135 CoreOptionsHandler::InitializeHandler(); 136 CoreOptionsHandler::InitializeHandler();
136 137
137 PrefService* profile_prefs = NULL; 138 PrefService* profile_prefs = NULL;
138 Profile* profile = Profile::FromWebUI(web_ui()); 139 Profile* profile = Profile::FromWebUI(web_ui());
139 if (!ProfileHelper::IsSigninProfile(profile)) { 140 if (!ProfileHelper::IsSigninProfile(profile)) {
140 profile_prefs = profile->GetPrefs(); 141 profile_prefs = profile->GetPrefs();
141 ObservePref(prefs::kOpenNetworkConfiguration); 142 ObservePref(prefs::kOpenNetworkConfiguration);
142 } 143 }
143 ObservePref(prefs::kProxy); 144 ObservePref(proxy_config::prefs::kProxy);
144 ObservePref(prefs::kDeviceOpenNetworkConfiguration); 145 ObservePref(prefs::kDeviceOpenNetworkConfiguration);
145 proxy_config_service_.SetPrefs(profile_prefs, 146 proxy_config_service_.SetPrefs(profile_prefs,
146 g_browser_process->local_state()); 147 g_browser_process->local_state());
147 } 148 }
148 149
149 void CoreChromeOSOptionsHandler::Observe( 150 void CoreChromeOSOptionsHandler::Observe(
150 int type, 151 int type,
151 const content::NotificationSource& source, 152 const content::NotificationSource& source,
152 const content::NotificationDetails& details) { 153 const content::NotificationDetails& details) {
153 // The only expected notification for now is this one. 154 // The only expected notification for now is this one.
(...skipping 20 matching lines...) Expand all
174 proxy_cros_settings_parser::GetProxyPrefValue( 175 proxy_cros_settings_parser::GetProxyPrefValue(
175 proxy_config_service_, pref_name, &value); 176 proxy_config_service_, pref_name, &value);
176 if (!value) 177 if (!value)
177 return base::Value::CreateNullValue().release(); 178 return base::Value::CreateNullValue().release();
178 179
179 return value; 180 return value;
180 } 181 }
181 182
182 Profile* profile = Profile::FromWebUI(web_ui()); 183 Profile* profile = Profile::FromWebUI(web_ui());
183 if (!CrosSettings::IsCrosSettings(pref_name)) { 184 if (!CrosSettings::IsCrosSettings(pref_name)) {
184 std::string controlling_pref = 185 std::string controlling_pref = pref_name == prefs::kUseSharedProxies
185 pref_name == prefs::kUseSharedProxies ? prefs::kProxy : std::string(); 186 ? proxy_config::prefs::kProxy
187 : std::string();
186 base::Value* value = CreateValueForPref(pref_name, controlling_pref); 188 base::Value* value = CreateValueForPref(pref_name, controlling_pref);
187 if (!IsSettingShared(pref_name) || !IsSecondaryUser(profile)) 189 if (!IsSettingShared(pref_name) || !IsSecondaryUser(profile))
188 return value; 190 return value;
189 base::DictionaryValue* dict; 191 base::DictionaryValue* dict;
190 if (!value->GetAsDictionary(&dict) || dict->HasKey("controlledBy")) 192 if (!value->GetAsDictionary(&dict) || dict->HasKey("controlledBy"))
191 return value; 193 return value;
192 Profile* primary_profile = ProfileHelper::Get()->GetProfileByUser( 194 Profile* primary_profile = ProfileHelper::Get()->GetProfileByUser(
193 user_manager::UserManager::Get()->GetPrimaryUser()); 195 user_manager::UserManager::Get()->GetPrimaryUser());
194 if (!primary_profile) 196 if (!primary_profile)
195 return value; 197 return value;
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 NotifyProxyPrefsChanged(); 379 NotifyProxyPrefsChanged();
378 } 380 }
379 381
380 void CoreChromeOSOptionsHandler::OnPreferenceChanged( 382 void CoreChromeOSOptionsHandler::OnPreferenceChanged(
381 PrefService* service, 383 PrefService* service,
382 const std::string& pref_name) { 384 const std::string& pref_name) {
383 // Redetermine the current proxy settings and notify the UI if any of these 385 // Redetermine the current proxy settings and notify the UI if any of these
384 // preferences change. 386 // preferences change.
385 if (pref_name == prefs::kOpenNetworkConfiguration || 387 if (pref_name == prefs::kOpenNetworkConfiguration ||
386 pref_name == prefs::kDeviceOpenNetworkConfiguration || 388 pref_name == prefs::kDeviceOpenNetworkConfiguration ||
387 pref_name == prefs::kProxy) { 389 pref_name == proxy_config::prefs::kProxy) {
388 NotifyProxyPrefsChanged(); 390 NotifyProxyPrefsChanged();
389 return; 391 return;
390 } 392 }
391 if (pref_name == prefs::kUseSharedProxies) { 393 if (pref_name == prefs::kUseSharedProxies) {
392 // kProxy controls kUseSharedProxies and decides if it's managed by 394 // kProxy controls kUseSharedProxies and decides if it's managed by
393 // policy/extension. 395 // policy/extension.
394 NotifyPrefChanged(prefs::kUseSharedProxies, prefs::kProxy); 396 NotifyPrefChanged(prefs::kUseSharedProxies, proxy_config::prefs::kProxy);
395 return; 397 return;
396 } 398 }
397 ::options::CoreOptionsHandler::OnPreferenceChanged(service, pref_name); 399 ::options::CoreOptionsHandler::OnPreferenceChanged(service, pref_name);
398 } 400 }
399 401
400 void CoreChromeOSOptionsHandler::NotifySettingsChanged( 402 void CoreChromeOSOptionsHandler::NotifySettingsChanged(
401 const std::string& setting_name) { 403 const std::string& setting_name) {
402 DCHECK(CrosSettings::Get()->IsCrosSettings(setting_name)); 404 DCHECK(CrosSettings::Get()->IsCrosSettings(setting_name));
403 scoped_ptr<base::Value> value(FetchPref(setting_name)); 405 scoped_ptr<base::Value> value(FetchPref(setting_name));
404 if (!value.get()) 406 if (!value.get())
405 NOTREACHED(); 407 NOTREACHED();
406 DispatchPrefChangeNotification(setting_name, value.Pass()); 408 DispatchPrefChangeNotification(setting_name, value.Pass());
407 } 409 }
408 410
409 void CoreChromeOSOptionsHandler::NotifyProxyPrefsChanged() { 411 void CoreChromeOSOptionsHandler::NotifyProxyPrefsChanged() {
410 proxy_config_service_.UpdateFromPrefs(); 412 proxy_config_service_.UpdateFromPrefs();
411 for (size_t i = 0; i < kProxySettingsCount; ++i) { 413 for (size_t i = 0; i < kProxySettingsCount; ++i) {
412 base::Value* value = NULL; 414 base::Value* value = NULL;
413 proxy_cros_settings_parser::GetProxyPrefValue( 415 proxy_cros_settings_parser::GetProxyPrefValue(
414 proxy_config_service_, kProxySettings[i], &value); 416 proxy_config_service_, kProxySettings[i], &value);
415 DCHECK(value); 417 DCHECK(value);
416 scoped_ptr<base::Value> ptr(value); 418 scoped_ptr<base::Value> ptr(value);
417 DispatchPrefChangeNotification(kProxySettings[i], ptr.Pass()); 419 DispatchPrefChangeNotification(kProxySettings[i], ptr.Pass());
418 } 420 }
419 } 421 }
420 422
421 } // namespace options 423 } // namespace options
422 } // namespace chromeos 424 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/options/browser_options_handler.cc ('k') | chrome/browser/ui/webui/options/core_options_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698