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

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

Issue 2820823005: Revert of Stop passing raw pointers to base::Value API in c/b/ui (Closed)
Patch Set: Created 3 years, 8 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/core_options_handler.h" 5 #include "chrome/browser/ui/webui/options/core_options_handler.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/bind_helpers.h" 13 #include "base/bind_helpers.h"
14 #include "base/json/json_reader.h" 14 #include "base/json/json_reader.h"
15 #include "base/memory/ptr_util.h"
16 #include "base/metrics/user_metrics.h" 15 #include "base/metrics/user_metrics.h"
17 #include "base/strings/string16.h" 16 #include "base/strings/string16.h"
18 #include "base/strings/string_number_conversions.h" 17 #include "base/strings/string_number_conversions.h"
19 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
20 #include "base/values.h" 19 #include "base/values.h"
21 #include "build/build_config.h" 20 #include "build/build_config.h"
22 #include "chrome/browser/browser_process.h" 21 #include "chrome/browser/browser_process.h"
23 #include "chrome/browser/chrome_notification_types.h" 22 #include "chrome/browser/chrome_notification_types.h"
24 #include "chrome/browser/extensions/extension_service.h" 23 #include "chrome/browser/extensions/extension_service.h"
25 #include "chrome/browser/extensions/extension_util.h" 24 #include "chrome/browser/extensions/extension_util.h"
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 void CoreOptionsHandler::HandleInitialize(const base::ListValue* args) { 245 void CoreOptionsHandler::HandleInitialize(const base::ListValue* args) {
247 DCHECK(handlers_host_); 246 DCHECK(handlers_host_);
248 handlers_host_->InitializeHandlers(); 247 handlers_host_->InitializeHandlers();
249 } 248 }
250 249
251 void CoreOptionsHandler::OnFinishedLoading(const base::ListValue* args) { 250 void CoreOptionsHandler::OnFinishedLoading(const base::ListValue* args) {
252 DCHECK(handlers_host_); 251 DCHECK(handlers_host_);
253 handlers_host_->OnFinishedLoading(); 252 handlers_host_->OnFinishedLoading();
254 } 253 }
255 254
256 std::unique_ptr<base::Value> CoreOptionsHandler::FetchPref( 255 base::Value* CoreOptionsHandler::FetchPref(const std::string& pref_name) {
257 const std::string& pref_name) {
258 return CreateValueForPref(pref_name, std::string()); 256 return CreateValueForPref(pref_name, std::string());
259 } 257 }
260 258
261 void CoreOptionsHandler::ObservePref(const std::string& pref_name) { 259 void CoreOptionsHandler::ObservePref(const std::string& pref_name) {
262 if (g_browser_process->local_state()->FindPreference(pref_name)) { 260 if (g_browser_process->local_state()->FindPreference(pref_name)) {
263 local_state_registrar_.Add( 261 local_state_registrar_.Add(
264 pref_name, 262 pref_name,
265 base::Bind(&CoreOptionsHandler::OnPreferenceChanged, 263 base::Bind(&CoreOptionsHandler::OnPreferenceChanged,
266 base::Unretained(this), 264 base::Unretained(this),
267 local_state_registrar_.prefs())); 265 local_state_registrar_.prefs()));
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 base::ListValue result_value; 357 base::ListValue result_value;
360 result_value.AppendString(name); 358 result_value.AppendString(name);
361 result_value.Append(std::move(value)); 359 result_value.Append(std::move(value));
362 for (PreferenceCallbackMap::const_iterator iter = range.first; 360 for (PreferenceCallbackMap::const_iterator iter = range.first;
363 iter != range.second; ++iter) { 361 iter != range.second; ++iter) {
364 const std::string& callback_function = iter->second; 362 const std::string& callback_function = iter->second;
365 web_ui()->CallJavascriptFunctionUnsafe(callback_function, result_value); 363 web_ui()->CallJavascriptFunctionUnsafe(callback_function, result_value);
366 } 364 }
367 } 365 }
368 366
369 std::unique_ptr<base::Value> CoreOptionsHandler::CreateValueForPref( 367 base::Value* CoreOptionsHandler::CreateValueForPref(
370 const std::string& pref_name, 368 const std::string& pref_name,
371 const std::string& controlling_pref_name) { 369 const std::string& controlling_pref_name) {
372 const PrefService* pref_service = FindServiceForPref(pref_name); 370 const PrefService* pref_service = FindServiceForPref(pref_name);
373 const PrefService::Preference* pref = 371 const PrefService::Preference* pref =
374 pref_service->FindPreference(pref_name); 372 pref_service->FindPreference(pref_name);
375 if (!pref) { 373 if (!pref) {
376 NOTREACHED(); 374 NOTREACHED();
377 return base::MakeUnique<base::Value>(); 375 return new base::Value();
378 } 376 }
379 const PrefService::Preference* controlling_pref = 377 const PrefService::Preference* controlling_pref =
380 pref_service->FindPreference(controlling_pref_name); 378 pref_service->FindPreference(controlling_pref_name);
381 if (!controlling_pref) 379 if (!controlling_pref)
382 controlling_pref = pref; 380 controlling_pref = pref;
383 381
384 auto dict = base::MakeUnique<base::DictionaryValue>(); 382 base::DictionaryValue* dict = new base::DictionaryValue;
385 dict->Set("value", base::MakeUnique<base::Value>(*pref->GetValue())); 383 dict->Set("value", pref->GetValue()->DeepCopy());
386 if (controlling_pref->IsManaged()) { 384 if (controlling_pref->IsManaged()) {
387 dict->SetString("controlledBy", "policy"); 385 dict->SetString("controlledBy", "policy");
388 } else if (controlling_pref->IsExtensionControlled() && 386 } else if (controlling_pref->IsExtensionControlled() &&
389 CanSetExtensionControlledPrefValue(controlling_pref)) { 387 CanSetExtensionControlledPrefValue(controlling_pref)) {
390 Profile* profile = Profile::FromWebUI(web_ui()); 388 Profile* profile = Profile::FromWebUI(web_ui());
391 ExtensionPrefValueMap* extension_pref_value_map = 389 ExtensionPrefValueMap* extension_pref_value_map =
392 ExtensionPrefValueMapFactory::GetForBrowserContext(profile); 390 ExtensionPrefValueMapFactory::GetForBrowserContext(profile);
393 std::string extension_id = 391 std::string extension_id =
394 extension_pref_value_map->GetExtensionControllingPref( 392 extension_pref_value_map->GetExtensionControllingPref(
395 controlling_pref->name()); 393 controlling_pref->name());
396 394
397 const extensions::Extension* extension = 395 const extensions::Extension* extension =
398 extensions::ExtensionRegistry::Get(profile)->GetExtensionById( 396 extensions::ExtensionRegistry::Get(profile)->GetExtensionById(
399 extension_id, extensions::ExtensionRegistry::EVERYTHING); 397 extension_id, extensions::ExtensionRegistry::EVERYTHING);
400 if (extension) { 398 if (extension) {
401 dict->SetString("controlledBy", "extension"); 399 dict->SetString("controlledBy", "extension");
402 dict->Set("extension", extensions::util::GetExtensionInfo(extension)); 400 dict->Set("extension",
401 extensions::util::GetExtensionInfo(extension).release());
403 } 402 }
404 } else if (controlling_pref->IsRecommended()) { 403 } else if (controlling_pref->IsRecommended()) {
405 dict->SetString("controlledBy", "recommended"); 404 dict->SetString("controlledBy", "recommended");
406 } 405 }
407 406
408 const base::Value* recommended_value = 407 const base::Value* recommended_value =
409 controlling_pref->GetRecommendedValue(); 408 controlling_pref->GetRecommendedValue();
410 if (recommended_value) 409 if (recommended_value)
411 dict->Set("recommendedValue", 410 dict->Set("recommendedValue", recommended_value->DeepCopy());
412 base::MakeUnique<base::Value>(*recommended_value));
413 dict->SetBoolean("disabled", !controlling_pref->IsUserModifiable()); 411 dict->SetBoolean("disabled", !controlling_pref->IsUserModifiable());
414 return std::move(dict); 412 return dict;
415 } 413 }
416 414
417 PrefService* CoreOptionsHandler::FindServiceForPref( 415 PrefService* CoreOptionsHandler::FindServiceForPref(
418 const std::string& pref_name) { 416 const std::string& pref_name) {
419 // Proxy is a peculiar case: on ChromeOS, settings exist in both user 417 // Proxy is a peculiar case: on ChromeOS, settings exist in both user
420 // prefs and local state, but chrome://settings should affect only user prefs. 418 // prefs and local state, but chrome://settings should affect only user prefs.
421 // Elsewhere the proxy settings are stored in local state. 419 // Elsewhere the proxy settings are stored in local state.
422 // See http://crbug.com/157147 420 // See http://crbug.com/157147
423 PrefService* user_prefs = Profile::FromWebUI(web_ui())->GetPrefs(); 421 PrefService* user_prefs = Profile::FromWebUI(web_ui())->GetPrefs();
424 if (pref_name == proxy_config::prefs::kProxy) 422 if (pref_name == proxy_config::prefs::kProxy)
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 plugin_status_pref_setter_.IsPepperFlashSettingsEnabled()); 654 plugin_status_pref_setter_.IsPepperFlashSettingsEnabled());
657 web_ui()->CallJavascriptFunctionUnsafe( 655 web_ui()->CallJavascriptFunctionUnsafe(
658 "options.OptionsPage.setPepperFlashSettingsEnabled", enabled); 656 "options.OptionsPage.setPepperFlashSettingsEnabled", enabled);
659 } 657 }
660 658
661 bool CoreOptionsHandler::IsUserUnsupervised(const base::Value* to_value) { 659 bool CoreOptionsHandler::IsUserUnsupervised(const base::Value* to_value) {
662 return !Profile::FromWebUI(web_ui())->IsSupervised(); 660 return !Profile::FromWebUI(web_ui())->IsSupervised();
663 } 661 }
664 662
665 } // namespace options 663 } // namespace options
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/options/core_options_handler.h ('k') | chrome/browser/ui/webui/options/handler_options_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698