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