| OLD | NEW |
| 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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 base::Value* BrowserToExtensionPref( | 193 base::Value* BrowserToExtensionPref( |
| 194 const base::Value* browser_pref) override { | 194 const base::Value* browser_pref) override { |
| 195 return InvertBooleanValue(browser_pref); | 195 return InvertBooleanValue(browser_pref); |
| 196 } | 196 } |
| 197 | 197 |
| 198 private: | 198 private: |
| 199 static base::Value* InvertBooleanValue(const base::Value* value) { | 199 static base::Value* InvertBooleanValue(const base::Value* value) { |
| 200 bool bool_value = false; | 200 bool bool_value = false; |
| 201 bool result = value->GetAsBoolean(&bool_value); | 201 bool result = value->GetAsBoolean(&bool_value); |
| 202 DCHECK(result); | 202 DCHECK(result); |
| 203 return new base::FundamentalValue(!bool_value); | 203 return new base::Value(!bool_value); |
| 204 } | 204 } |
| 205 }; | 205 }; |
| 206 | 206 |
| 207 class NetworkPredictionTransformer : public PrefTransformerInterface { | 207 class NetworkPredictionTransformer : public PrefTransformerInterface { |
| 208 public: | 208 public: |
| 209 base::Value* ExtensionToBrowserPref(const base::Value* extension_pref, | 209 base::Value* ExtensionToBrowserPref(const base::Value* extension_pref, |
| 210 std::string* error, | 210 std::string* error, |
| 211 bool* bad_message) override { | 211 bool* bad_message) override { |
| 212 bool bool_value = false; | 212 bool bool_value = false; |
| 213 const bool pref_found = extension_pref->GetAsBoolean(&bool_value); | 213 const bool pref_found = extension_pref->GetAsBoolean(&bool_value); |
| 214 DCHECK(pref_found) << "Preference not found."; | 214 DCHECK(pref_found) << "Preference not found."; |
| 215 if (bool_value) { | 215 if (bool_value) { |
| 216 return new base::FundamentalValue( | 216 return new base::Value( |
| 217 chrome_browser_net::NETWORK_PREDICTION_DEFAULT); | 217 chrome_browser_net::NETWORK_PREDICTION_DEFAULT); |
| 218 } else { | 218 } else { |
| 219 return new base::FundamentalValue( | 219 return new base::Value( |
| 220 chrome_browser_net::NETWORK_PREDICTION_NEVER); | 220 chrome_browser_net::NETWORK_PREDICTION_NEVER); |
| 221 } | 221 } |
| 222 } | 222 } |
| 223 | 223 |
| 224 base::Value* BrowserToExtensionPref( | 224 base::Value* BrowserToExtensionPref( |
| 225 const base::Value* browser_pref) override { | 225 const base::Value* browser_pref) override { |
| 226 int int_value = chrome_browser_net::NETWORK_PREDICTION_DEFAULT; | 226 int int_value = chrome_browser_net::NETWORK_PREDICTION_DEFAULT; |
| 227 const bool pref_found = browser_pref->GetAsInteger(&int_value); | 227 const bool pref_found = browser_pref->GetAsInteger(&int_value); |
| 228 DCHECK(pref_found) << "Preference not found."; | 228 DCHECK(pref_found) << "Preference not found."; |
| 229 return new base::FundamentalValue( | 229 return new base::Value( |
| 230 int_value != chrome_browser_net::NETWORK_PREDICTION_NEVER); | 230 int_value != chrome_browser_net::NETWORK_PREDICTION_NEVER); |
| 231 } | 231 } |
| 232 }; | 232 }; |
| 233 | 233 |
| 234 class PrefMapping { | 234 class PrefMapping { |
| 235 public: | 235 public: |
| 236 static PrefMapping* GetInstance() { | 236 static PrefMapping* GetInstance() { |
| 237 return base::Singleton<PrefMapping>::get(); | 237 return base::Singleton<PrefMapping>::get(); |
| 238 } | 238 } |
| 239 | 239 |
| (...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 773 pref_key, &browser_pref, &read_permission, &write_permission)); | 773 pref_key, &browser_pref, &read_permission, &write_permission)); |
| 774 if (!extension()->permissions_data()->HasAPIPermission(write_permission)) | 774 if (!extension()->permissions_data()->HasAPIPermission(write_permission)) |
| 775 return RespondNow(Error(keys::kPermissionErrorMessage, pref_key)); | 775 return RespondNow(Error(keys::kPermissionErrorMessage, pref_key)); |
| 776 | 776 |
| 777 PreferenceAPI::Get(browser_context()) | 777 PreferenceAPI::Get(browser_context()) |
| 778 ->RemoveExtensionControlledPref(extension_id(), browser_pref, scope); | 778 ->RemoveExtensionControlledPref(extension_id(), browser_pref, scope); |
| 779 return RespondNow(NoArguments()); | 779 return RespondNow(NoArguments()); |
| 780 } | 780 } |
| 781 | 781 |
| 782 } // namespace extensions | 782 } // namespace extensions |
| OLD | NEW |