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

Side by Side Diff: chrome/browser/extensions/api/settings_private/settings_private_api.cc

Issue 1287913005: Refactor prefs.js for MD-Settings (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update after meeting 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/settings_private/settings_private_api.h" 5 #include "chrome/browser/extensions/api/settings_private/settings_private_api.h"
6 6
7 #include "base/values.h" 7 #include "base/values.h"
8 #include "chrome/browser/extensions/api/settings_private/settings_private_delega te.h" 8 #include "chrome/browser/extensions/api/settings_private/settings_private_delega te.h"
9 #include "chrome/browser/extensions/api/settings_private/settings_private_delega te_factory.h" 9 #include "chrome/browser/extensions/api/settings_private/settings_private_delega te_factory.h"
10 #include "chrome/browser/extensions/chrome_extension_function.h" 10 #include "chrome/browser/extensions/chrome_extension_function.h"
(...skipping 11 matching lines...) Expand all
22 } 22 }
23 23
24 ExtensionFunction::ResponseAction SettingsPrivateSetPrefFunction::Run() { 24 ExtensionFunction::ResponseAction SettingsPrivateSetPrefFunction::Run() {
25 scoped_ptr<api::settings_private::SetPref::Params> parameters = 25 scoped_ptr<api::settings_private::SetPref::Params> parameters =
26 api::settings_private::SetPref::Params::Create(*args_); 26 api::settings_private::SetPref::Params::Create(*args_);
27 EXTENSION_FUNCTION_VALIDATE(parameters.get()); 27 EXTENSION_FUNCTION_VALIDATE(parameters.get());
28 28
29 SettingsPrivateDelegate* delegate = 29 SettingsPrivateDelegate* delegate =
30 SettingsPrivateDelegateFactory::GetForBrowserContext(browser_context()); 30 SettingsPrivateDelegateFactory::GetForBrowserContext(browser_context());
31 31
32 return RespondNow(OneArgument(new base::FundamentalValue( 32 PrefsUtil::SetPrefResult result =
33 delegate->SetPref(parameters->name, parameters->value.get())))); 33 delegate->SetPref(parameters->name, parameters->value.get());
34 switch (result) {
35 case PrefsUtil::SUCCESS:
36 return RespondNow(OneArgument(new base::FundamentalValue(true)));
37 case PrefsUtil::PREF_NOT_MODIFIABLE:
38 // Not an error, but return false to indicate setting the pref failed.
39 return RespondNow(OneArgument(new base::FundamentalValue(false)));
40 default:
41 // Indicates a problem with the function call.
42 return RespondNow(Error("Error setting pref *", parameters->name));
stevenjb 2015/08/26 17:32:18 Since we went to the trouble to define the differe
michaelpg 2015/08/26 23:32:15 Done.
43 }
34 } 44 }
35 45
36 46
37 //////////////////////////////////////////////////////////////////////////////// 47 ////////////////////////////////////////////////////////////////////////////////
38 // SettingsPrivateGetAllPrefsFunction 48 // SettingsPrivateGetAllPrefsFunction
39 //////////////////////////////////////////////////////////////////////////////// 49 ////////////////////////////////////////////////////////////////////////////////
40 50
41 SettingsPrivateGetAllPrefsFunction::~SettingsPrivateGetAllPrefsFunction() { 51 SettingsPrivateGetAllPrefsFunction::~SettingsPrivateGetAllPrefsFunction() {
42 } 52 }
43 53
(...skipping 20 matching lines...) Expand all
64 SettingsPrivateDelegateFactory::GetForBrowserContext(browser_context()); 74 SettingsPrivateDelegateFactory::GetForBrowserContext(browser_context());
65 75
66 scoped_ptr<base::Value> value = delegate->GetPref(parameters->name); 76 scoped_ptr<base::Value> value = delegate->GetPref(parameters->name);
67 if (value->IsType(base::Value::TYPE_NULL)) 77 if (value->IsType(base::Value::TYPE_NULL))
68 return RespondNow(Error("Pref * does not exist", parameters->name)); 78 return RespondNow(Error("Pref * does not exist", parameters->name));
69 else 79 else
70 return RespondNow(OneArgument(value.release())); 80 return RespondNow(OneArgument(value.release()));
71 } 81 }
72 82
73 } // namespace extensions 83 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698