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

Side by Side Diff: chrome/browser/extensions/api/preference/preference_api.cc

Issue 2624583002: Remove redundant c_str() calls. (Closed)
Patch Set: Created 3 years, 11 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/extensions/api/preference/preference_api.h" 5 #include "chrome/browser/extensions/api/preference/preference_api.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <map> 9 #include <map>
10 #include <memory> 10 #include <memory>
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 bool incognito = (pref_service != profile_->GetPrefs()); 376 bool incognito = (pref_service != profile_->GetPrefs());
377 377
378 std::string event_name; 378 std::string event_name;
379 APIPermission::ID permission = APIPermission::kInvalid; 379 APIPermission::ID permission = APIPermission::kInvalid;
380 bool rv = PrefMapping::GetInstance()->FindEventForBrowserPref( 380 bool rv = PrefMapping::GetInstance()->FindEventForBrowserPref(
381 browser_pref, &event_name, &permission); 381 browser_pref, &event_name, &permission);
382 DCHECK(rv); 382 DCHECK(rv);
383 383
384 base::ListValue args; 384 base::ListValue args;
385 const PrefService::Preference* pref = 385 const PrefService::Preference* pref =
386 pref_service->FindPreference(browser_pref.c_str()); 386 pref_service->FindPreference(browser_pref);
387 CHECK(pref); 387 CHECK(pref);
388 PrefTransformerInterface* transformer = 388 PrefTransformerInterface* transformer =
389 PrefMapping::GetInstance()->FindTransformerForBrowserPref(browser_pref); 389 PrefMapping::GetInstance()->FindTransformerForBrowserPref(browser_pref);
390 base::Value* transformed_value = 390 base::Value* transformed_value =
391 transformer->BrowserToExtensionPref(pref->GetValue()); 391 transformer->BrowserToExtensionPref(pref->GetValue());
392 if (!transformed_value) { 392 if (!transformed_value) {
393 LOG(ERROR) << ErrorUtils::FormatErrorMessage(kConversionErrorMessage, 393 LOG(ERROR) << ErrorUtils::FormatErrorMessage(kConversionErrorMessage,
394 pref->name()); 394 pref->name());
395 return; 395 return;
396 } 396 }
(...skipping 23 matching lines...) Expand all
420 browser_pref); 420 browser_pref);
421 } 421 }
422 422
423 void PreferenceAPIBase::SetExtensionControlledPref( 423 void PreferenceAPIBase::SetExtensionControlledPref(
424 const std::string& extension_id, 424 const std::string& extension_id,
425 const std::string& pref_key, 425 const std::string& pref_key,
426 ExtensionPrefsScope scope, 426 ExtensionPrefsScope scope,
427 base::Value* value) { 427 base::Value* value) {
428 #ifndef NDEBUG 428 #ifndef NDEBUG
429 const PrefService::Preference* pref = 429 const PrefService::Preference* pref =
430 extension_prefs()->pref_service()->FindPreference(pref_key.c_str()); 430 extension_prefs()->pref_service()->FindPreference(pref_key);
431 DCHECK(pref) << "Extension controlled preference key " << pref_key 431 DCHECK(pref) << "Extension controlled preference key " << pref_key
432 << " not registered."; 432 << " not registered.";
433 DCHECK_EQ(pref->GetType(), value->GetType()) 433 DCHECK_EQ(pref->GetType(), value->GetType())
434 << "Extension controlled preference " << pref_key << " has wrong type."; 434 << "Extension controlled preference " << pref_key << " has wrong type.";
435 #endif 435 #endif
436 436
437 std::string scope_string; 437 std::string scope_string;
438 // ScopeToPrefName() returns false if the scope is not persisted. 438 // ScopeToPrefName() returns false if the scope is not persisted.
439 if (pref_names::ScopeToPrefName(scope, &scope_string)) { 439 if (pref_names::ScopeToPrefName(scope, &scope_string)) {
440 // Also store in persisted Preferences file to recover after a 440 // Also store in persisted Preferences file to recover after a
441 // browser restart. 441 // browser restart.
442 ExtensionPrefs::ScopedDictionaryUpdate update(extension_prefs(), 442 ExtensionPrefs::ScopedDictionaryUpdate update(extension_prefs(),
443 extension_id, 443 extension_id,
444 scope_string); 444 scope_string);
445 base::DictionaryValue* preference = update.Get(); 445 base::DictionaryValue* preference = update.Get();
446 if (!preference) 446 if (!preference)
447 preference = update.Create(); 447 preference = update.Create();
448 preference->SetWithoutPathExpansion(pref_key, value->DeepCopy()); 448 preference->SetWithoutPathExpansion(pref_key, value->DeepCopy());
449 } 449 }
450 extension_pref_value_map()->SetExtensionPref( 450 extension_pref_value_map()->SetExtensionPref(
451 extension_id, pref_key, scope, value); 451 extension_id, pref_key, scope, value);
452 } 452 }
453 453
454 void PreferenceAPIBase::RemoveExtensionControlledPref( 454 void PreferenceAPIBase::RemoveExtensionControlledPref(
455 const std::string& extension_id, 455 const std::string& extension_id,
456 const std::string& pref_key, 456 const std::string& pref_key,
457 ExtensionPrefsScope scope) { 457 ExtensionPrefsScope scope) {
458 DCHECK(extension_prefs()->pref_service()->FindPreference(pref_key.c_str())) 458 DCHECK(extension_prefs()->pref_service()->FindPreference(pref_key))
459 << "Extension controlled preference key " << pref_key 459 << "Extension controlled preference key " << pref_key
460 << " not registered."; 460 << " not registered.";
461 461
462 std::string scope_string; 462 std::string scope_string;
463 if (pref_names::ScopeToPrefName(scope, &scope_string)) { 463 if (pref_names::ScopeToPrefName(scope, &scope_string)) {
464 ExtensionPrefs::ScopedDictionaryUpdate update(extension_prefs(), 464 ExtensionPrefs::ScopedDictionaryUpdate update(extension_prefs(),
465 extension_id, 465 extension_id,
466 scope_string); 466 scope_string);
467 base::DictionaryValue* preference = update.Get(); 467 base::DictionaryValue* preference = update.Get();
468 if (preference) 468 if (preference)
469 preference->RemoveWithoutPathExpansion(pref_key, NULL); 469 preference->RemoveWithoutPathExpansion(pref_key, NULL);
470 } 470 }
471 extension_pref_value_map()->RemoveExtensionPref( 471 extension_pref_value_map()->RemoveExtensionPref(
472 extension_id, pref_key, scope); 472 extension_id, pref_key, scope);
473 } 473 }
474 474
475 bool PreferenceAPIBase::CanExtensionControlPref( 475 bool PreferenceAPIBase::CanExtensionControlPref(
476 const std::string& extension_id, 476 const std::string& extension_id,
477 const std::string& pref_key, 477 const std::string& pref_key,
478 bool incognito) { 478 bool incognito) {
479 DCHECK(extension_prefs()->pref_service()->FindPreference(pref_key.c_str())) 479 DCHECK(extension_prefs()->pref_service()->FindPreference(pref_key))
480 << "Extension controlled preference key " << pref_key 480 << "Extension controlled preference key " << pref_key
481 << " not registered."; 481 << " not registered.";
482 482
483 return extension_pref_value_map()->CanExtensionControlPref( 483 return extension_pref_value_map()->CanExtensionControlPref(
484 extension_id, pref_key, incognito); 484 extension_id, pref_key, incognito);
485 } 485 }
486 486
487 bool PreferenceAPIBase::DoesExtensionControlPref( 487 bool PreferenceAPIBase::DoesExtensionControlPref(
488 const std::string& extension_id, 488 const std::string& extension_id,
489 const std::string& pref_key, 489 const std::string& pref_key,
490 bool* from_incognito) { 490 bool* from_incognito) {
491 DCHECK(extension_prefs()->pref_service()->FindPreference(pref_key.c_str())) 491 DCHECK(extension_prefs()->pref_service()->FindPreference(pref_key))
492 << "Extension controlled preference key " << pref_key 492 << "Extension controlled preference key " << pref_key
493 << " not registered."; 493 << " not registered.";
494 494
495 return extension_pref_value_map()->DoesExtensionControlPref( 495 return extension_pref_value_map()->DoesExtensionControlPref(
496 extension_id, pref_key, from_incognito); 496 extension_id, pref_key, from_incognito);
497 } 497 }
498 498
499 PreferenceAPI::PreferenceAPI(content::BrowserContext* context) 499 PreferenceAPI::PreferenceAPI(content::BrowserContext* context)
500 : profile_(Profile::FromBrowserContext(context)) { 500 : profile_(Profile::FromBrowserContext(context)) {
501 for (size_t i = 0; i < arraysize(kPrefMapping); ++i) { 501 for (size_t i = 0; i < arraysize(kPrefMapping); ++i) {
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 EXTENSION_FUNCTION_VALIDATE( 612 EXTENSION_FUNCTION_VALIDATE(
613 PrefMapping::GetInstance()->FindBrowserPrefForExtensionPref( 613 PrefMapping::GetInstance()->FindBrowserPrefForExtensionPref(
614 pref_key, &browser_pref, &read_permission, &write_permission)); 614 pref_key, &browser_pref, &read_permission, &write_permission));
615 if (!extension()->permissions_data()->HasAPIPermission(read_permission)) 615 if (!extension()->permissions_data()->HasAPIPermission(read_permission))
616 return RespondNow(Error(keys::kPermissionErrorMessage, pref_key)); 616 return RespondNow(Error(keys::kPermissionErrorMessage, pref_key));
617 617
618 Profile* profile = Profile::FromBrowserContext(browser_context()); 618 Profile* profile = Profile::FromBrowserContext(browser_context());
619 PrefService* prefs = 619 PrefService* prefs =
620 incognito ? profile->GetOffTheRecordPrefs() : profile->GetPrefs(); 620 incognito ? profile->GetOffTheRecordPrefs() : profile->GetPrefs();
621 const PrefService::Preference* pref = 621 const PrefService::Preference* pref =
622 prefs->FindPreference(browser_pref.c_str()); 622 prefs->FindPreference(browser_pref);
623 CHECK(pref); 623 CHECK(pref);
624 624
625 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue); 625 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue);
626 626
627 // Retrieve level of control. 627 // Retrieve level of control.
628 std::string level_of_control = helpers::GetLevelOfControl( 628 std::string level_of_control = helpers::GetLevelOfControl(
629 profile, extension_id(), browser_pref, incognito); 629 profile, extension_id(), browser_pref, incognito);
630 result->SetString(keys::kLevelOfControl, level_of_control); 630 result->SetString(keys::kLevelOfControl, level_of_control);
631 631
632 // Retrieve pref value. 632 // Retrieve pref value.
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 APIPermission::ID read_permission = APIPermission::kInvalid; 700 APIPermission::ID read_permission = APIPermission::kInvalid;
701 APIPermission::ID write_permission = APIPermission::kInvalid; 701 APIPermission::ID write_permission = APIPermission::kInvalid;
702 EXTENSION_FUNCTION_VALIDATE( 702 EXTENSION_FUNCTION_VALIDATE(
703 PrefMapping::GetInstance()->FindBrowserPrefForExtensionPref( 703 PrefMapping::GetInstance()->FindBrowserPrefForExtensionPref(
704 pref_key, &browser_pref, &read_permission, &write_permission)); 704 pref_key, &browser_pref, &read_permission, &write_permission));
705 if (!extension()->permissions_data()->HasAPIPermission(write_permission)) 705 if (!extension()->permissions_data()->HasAPIPermission(write_permission))
706 return RespondNow(Error(keys::kPermissionErrorMessage, pref_key)); 706 return RespondNow(Error(keys::kPermissionErrorMessage, pref_key));
707 707
708 ExtensionPrefs* prefs = ExtensionPrefs::Get(browser_context()); 708 ExtensionPrefs* prefs = ExtensionPrefs::Get(browser_context());
709 const PrefService::Preference* pref = 709 const PrefService::Preference* pref =
710 prefs->pref_service()->FindPreference(browser_pref.c_str()); 710 prefs->pref_service()->FindPreference(browser_pref);
711 CHECK(pref); 711 CHECK(pref);
712 712
713 // Validate new value. 713 // Validate new value.
714 PrefTransformerInterface* transformer = 714 PrefTransformerInterface* transformer =
715 PrefMapping::GetInstance()->FindTransformerForBrowserPref(browser_pref); 715 PrefMapping::GetInstance()->FindTransformerForBrowserPref(browser_pref);
716 std::string error; 716 std::string error;
717 bool bad_message = false; 717 bool bad_message = false;
718 std::unique_ptr<base::Value> browser_pref_value( 718 std::unique_ptr<base::Value> browser_pref_value(
719 transformer->ExtensionToBrowserPref(value, &error, &bad_message)); 719 transformer->ExtensionToBrowserPref(value, &error, &bad_message));
720 if (!browser_pref_value) { 720 if (!browser_pref_value) {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 pref_key, &browser_pref, &read_permission, &write_permission)); 774 pref_key, &browser_pref, &read_permission, &write_permission));
775 if (!extension()->permissions_data()->HasAPIPermission(write_permission)) 775 if (!extension()->permissions_data()->HasAPIPermission(write_permission))
776 return RespondNow(Error(keys::kPermissionErrorMessage, pref_key)); 776 return RespondNow(Error(keys::kPermissionErrorMessage, pref_key));
777 777
778 PreferenceAPI::Get(browser_context()) 778 PreferenceAPI::Get(browser_context())
779 ->RemoveExtensionControlledPref(extension_id(), browser_pref, scope); 779 ->RemoveExtensionControlledPref(extension_id(), browser_pref, scope);
780 return RespondNow(NoArguments()); 780 return RespondNow(NoArguments());
781 } 781 }
782 782
783 } // namespace extensions 783 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698