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

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

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

Powered by Google App Engine
This is Rietveld 408576698