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

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

Issue 2038613003: Revert of ExtensionFunction: don't pass ownership of base::Value by raw pointer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 <utility>
8
9 #include "base/memory/ptr_util.h"
10 #include "base/values.h" 7 #include "base/values.h"
11 #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"
12 #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"
13 #include "chrome/browser/extensions/chrome_extension_function.h" 10 #include "chrome/browser/extensions/chrome_extension_function.h"
14 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h" 12 #include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h"
16 #include "chrome/common/extensions/api/settings_private.h" 13 #include "chrome/common/extensions/api/settings_private.h"
17 #include "content/public/common/page_zoom.h" 14 #include "content/public/common/page_zoom.h"
18 #include "extensions/browser/extension_function_registry.h" 15 #include "extensions/browser/extension_function_registry.h"
19 16
(...skipping 17 matching lines...) Expand all
37 34
38 SettingsPrivateDelegate* delegate = 35 SettingsPrivateDelegate* delegate =
39 SettingsPrivateDelegateFactory::GetForBrowserContext(browser_context()); 36 SettingsPrivateDelegateFactory::GetForBrowserContext(browser_context());
40 if (delegate == nullptr) 37 if (delegate == nullptr)
41 return RespondNow(Error(kDelegateIsNull)); 38 return RespondNow(Error(kDelegateIsNull));
42 39
43 PrefsUtil::SetPrefResult result = 40 PrefsUtil::SetPrefResult result =
44 delegate->SetPref(parameters->name, parameters->value.get()); 41 delegate->SetPref(parameters->name, parameters->value.get());
45 switch (result) { 42 switch (result) {
46 case PrefsUtil::SUCCESS: 43 case PrefsUtil::SUCCESS:
47 return RespondNow( 44 return RespondNow(OneArgument(new base::FundamentalValue(true)));
48 OneArgument(base::MakeUnique<base::FundamentalValue>(true)));
49 case PrefsUtil::PREF_NOT_MODIFIABLE: 45 case PrefsUtil::PREF_NOT_MODIFIABLE:
50 // Not an error, but return false to indicate setting the pref failed. 46 // Not an error, but return false to indicate setting the pref failed.
51 return RespondNow( 47 return RespondNow(OneArgument(new base::FundamentalValue(false)));
52 OneArgument(base::MakeUnique<base::FundamentalValue>(false)));
53 case PrefsUtil::PREF_NOT_FOUND: 48 case PrefsUtil::PREF_NOT_FOUND:
54 return RespondNow(Error("Pref not found: *", parameters->name)); 49 return RespondNow(Error("Pref not found: *", parameters->name));
55 case PrefsUtil::PREF_TYPE_MISMATCH: 50 case PrefsUtil::PREF_TYPE_MISMATCH:
56 return RespondNow(Error("Incorrect type used for value of pref *", 51 return RespondNow(Error("Incorrect type used for value of pref *",
57 parameters->name)); 52 parameters->name));
58 case PrefsUtil::PREF_TYPE_UNSUPPORTED: 53 case PrefsUtil::PREF_TYPE_UNSUPPORTED:
59 return RespondNow(Error("Unsupported type used for value of pref *", 54 return RespondNow(Error("Unsupported type used for value of pref *",
60 parameters->name)); 55 parameters->name));
61 } 56 }
62 NOTREACHED(); 57 NOTREACHED();
63 return RespondNow( 58 return RespondNow(OneArgument(new base::FundamentalValue(false)));
64 OneArgument(base::MakeUnique<base::FundamentalValue>(false)));
65 } 59 }
66 60
67 //////////////////////////////////////////////////////////////////////////////// 61 ////////////////////////////////////////////////////////////////////////////////
68 // SettingsPrivateGetAllPrefsFunction 62 // SettingsPrivateGetAllPrefsFunction
69 //////////////////////////////////////////////////////////////////////////////// 63 ////////////////////////////////////////////////////////////////////////////////
70 64
71 SettingsPrivateGetAllPrefsFunction::~SettingsPrivateGetAllPrefsFunction() { 65 SettingsPrivateGetAllPrefsFunction::~SettingsPrivateGetAllPrefsFunction() {
72 } 66 }
73 67
74 ExtensionFunction::ResponseAction SettingsPrivateGetAllPrefsFunction::Run() { 68 ExtensionFunction::ResponseAction SettingsPrivateGetAllPrefsFunction::Run() {
75 SettingsPrivateDelegate* delegate = 69 SettingsPrivateDelegate* delegate =
76 SettingsPrivateDelegateFactory::GetForBrowserContext(browser_context()); 70 SettingsPrivateDelegateFactory::GetForBrowserContext(browser_context());
77 71
78 if (delegate == nullptr) 72 if (delegate == nullptr)
79 return RespondNow(Error(kDelegateIsNull)); 73 return RespondNow(Error(kDelegateIsNull));
80 else 74 else
81 return RespondNow(OneArgument(delegate->GetAllPrefs())); 75 return RespondNow(OneArgument(delegate->GetAllPrefs().release()));
82 } 76 }
83 77
84 //////////////////////////////////////////////////////////////////////////////// 78 ////////////////////////////////////////////////////////////////////////////////
85 // SettingsPrivateGetPrefFunction 79 // SettingsPrivateGetPrefFunction
86 //////////////////////////////////////////////////////////////////////////////// 80 ////////////////////////////////////////////////////////////////////////////////
87 81
88 SettingsPrivateGetPrefFunction::~SettingsPrivateGetPrefFunction() { 82 SettingsPrivateGetPrefFunction::~SettingsPrivateGetPrefFunction() {
89 } 83 }
90 84
91 ExtensionFunction::ResponseAction SettingsPrivateGetPrefFunction::Run() { 85 ExtensionFunction::ResponseAction SettingsPrivateGetPrefFunction::Run() {
92 std::unique_ptr<api::settings_private::GetPref::Params> parameters = 86 std::unique_ptr<api::settings_private::GetPref::Params> parameters =
93 api::settings_private::GetPref::Params::Create(*args_); 87 api::settings_private::GetPref::Params::Create(*args_);
94 EXTENSION_FUNCTION_VALIDATE(parameters.get()); 88 EXTENSION_FUNCTION_VALIDATE(parameters.get());
95 89
96 SettingsPrivateDelegate* delegate = 90 SettingsPrivateDelegate* delegate =
97 SettingsPrivateDelegateFactory::GetForBrowserContext(browser_context()); 91 SettingsPrivateDelegateFactory::GetForBrowserContext(browser_context());
98 if (delegate == nullptr) 92 if (delegate == nullptr)
99 return RespondNow(Error(kDelegateIsNull)); 93 return RespondNow(Error(kDelegateIsNull));
100 94
101 std::unique_ptr<base::Value> value = delegate->GetPref(parameters->name); 95 std::unique_ptr<base::Value> value = delegate->GetPref(parameters->name);
102 if (value->IsType(base::Value::TYPE_NULL)) 96 if (value->IsType(base::Value::TYPE_NULL))
103 return RespondNow(Error("Pref * does not exist", parameters->name)); 97 return RespondNow(Error("Pref * does not exist", parameters->name));
104 else 98 else
105 return RespondNow(OneArgument(std::move(value))); 99 return RespondNow(OneArgument(value.release()));
106 } 100 }
107 101
108 //////////////////////////////////////////////////////////////////////////////// 102 ////////////////////////////////////////////////////////////////////////////////
109 // SettingsPrivateGetDefaultZoomPercentFunction 103 // SettingsPrivateGetDefaultZoomPercentFunction
110 //////////////////////////////////////////////////////////////////////////////// 104 ////////////////////////////////////////////////////////////////////////////////
111 105
112 SettingsPrivateGetDefaultZoomPercentFunction:: 106 SettingsPrivateGetDefaultZoomPercentFunction::
113 ~SettingsPrivateGetDefaultZoomPercentFunction() { 107 ~SettingsPrivateGetDefaultZoomPercentFunction() {
114 } 108 }
115 109
116 ExtensionFunction::ResponseAction 110 ExtensionFunction::ResponseAction
117 SettingsPrivateGetDefaultZoomPercentFunction::Run() { 111 SettingsPrivateGetDefaultZoomPercentFunction::Run() {
118 SettingsPrivateDelegate* delegate = 112 SettingsPrivateDelegate* delegate =
119 SettingsPrivateDelegateFactory::GetForBrowserContext(browser_context()); 113 SettingsPrivateDelegateFactory::GetForBrowserContext(browser_context());
120 114
121 if (delegate == nullptr) 115 if (delegate == nullptr)
122 return RespondNow(Error(kDelegateIsNull)); 116 return RespondNow(Error(kDelegateIsNull));
123 else 117 else
124 return RespondNow(OneArgument(delegate->GetDefaultZoomPercent())); 118 return RespondNow(OneArgument(delegate->GetDefaultZoomPercent().release()));
125 } 119 }
126 120
127 //////////////////////////////////////////////////////////////////////////////// 121 ////////////////////////////////////////////////////////////////////////////////
128 // SettingsPrivateSetDefaultZoomPercentFunction 122 // SettingsPrivateSetDefaultZoomPercentFunction
129 //////////////////////////////////////////////////////////////////////////////// 123 ////////////////////////////////////////////////////////////////////////////////
130 124
131 SettingsPrivateSetDefaultZoomPercentFunction:: 125 SettingsPrivateSetDefaultZoomPercentFunction::
132 ~SettingsPrivateSetDefaultZoomPercentFunction() { 126 ~SettingsPrivateSetDefaultZoomPercentFunction() {
133 } 127 }
134 128
135 ExtensionFunction::ResponseAction 129 ExtensionFunction::ResponseAction
136 SettingsPrivateSetDefaultZoomPercentFunction::Run() { 130 SettingsPrivateSetDefaultZoomPercentFunction::Run() {
137 std::unique_ptr<api::settings_private::SetDefaultZoomPercent::Params> 131 std::unique_ptr<api::settings_private::SetDefaultZoomPercent::Params>
138 parameters = 132 parameters =
139 api::settings_private::SetDefaultZoomPercent::Params::Create(*args_); 133 api::settings_private::SetDefaultZoomPercent::Params::Create(*args_);
140 EXTENSION_FUNCTION_VALIDATE(parameters.get()); 134 EXTENSION_FUNCTION_VALIDATE(parameters.get());
141 135
142 SettingsPrivateDelegate* delegate = 136 SettingsPrivateDelegate* delegate =
143 SettingsPrivateDelegateFactory::GetForBrowserContext(browser_context()); 137 SettingsPrivateDelegateFactory::GetForBrowserContext(browser_context());
144 if (delegate == nullptr) 138 if (delegate == nullptr)
145 return RespondNow(Error(kDelegateIsNull)); 139 return RespondNow(Error(kDelegateIsNull));
146 140
147 delegate->SetDefaultZoomPercent(parameters->percent); 141 delegate->SetDefaultZoomPercent(parameters->percent);
148 return RespondNow( 142 return RespondNow(OneArgument(new base::FundamentalValue(true)));
149 OneArgument(base::MakeUnique<base::FundamentalValue>(true)));
150 } 143 }
151 144
152 } // namespace extensions 145 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698