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

Side by Side Diff: chrome/browser/extensions/api/autotest_private/autotest_private_api.cc

Issue 2811673002: Reland: Stop passing raw pointers to base::Value API in c/b/chromeos and c/b/extensions (Closed)
Patch Set: Workaround with std::move Created 3 years, 8 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 (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/autotest_private/autotest_private_api.h" 5 #include "chrome/browser/extensions/api/autotest_private/autotest_private_api.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 #include "base/values.h"
13 #include "build/build_config.h" 14 #include "build/build_config.h"
14 #include "chrome/browser/extensions/extension_action_manager.h" 15 #include "chrome/browser/extensions/extension_action_manager.h"
15 #include "chrome/browser/extensions/extension_service.h" 16 #include "chrome/browser/extensions/extension_service.h"
16 #include "chrome/browser/lifetime/application_lifetime.h" 17 #include "chrome/browser/lifetime/application_lifetime.h"
17 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/common/extensions/api/autotest_private.h" 19 #include "chrome/common/extensions/api/autotest_private.h"
19 #include "extensions/browser/extension_function_registry.h" 20 #include "extensions/browser/extension_function_registry.h"
20 #include "extensions/browser/extension_registry.h" 21 #include "extensions/browser/extension_registry.h"
21 #include "extensions/browser/extension_system.h" 22 #include "extensions/browser/extension_system.h"
22 #include "extensions/browser/extension_util.h" 23 #include "extensions/browser/extension_util.h"
(...skipping 10 matching lines...) Expand all
33 #include "chromeos/dbus/session_manager_client.h" 34 #include "chromeos/dbus/session_manager_client.h"
34 #include "components/user_manager/user.h" 35 #include "components/user_manager/user.h"
35 #include "components/user_manager/user_manager.h" 36 #include "components/user_manager/user_manager.h"
36 #include "ui/message_center/message_center.h" 37 #include "ui/message_center/message_center.h"
37 #include "ui/message_center/notification.h" 38 #include "ui/message_center/notification.h"
38 #endif 39 #endif
39 40
40 namespace extensions { 41 namespace extensions {
41 namespace { 42 namespace {
42 43
43 base::ListValue* GetHostPermissions(const Extension* ext, bool effective_perm) { 44 std::unique_ptr<base::ListValue> GetHostPermissions(const Extension* ext,
45 bool effective_perm) {
44 const PermissionsData* permissions_data = ext->permissions_data(); 46 const PermissionsData* permissions_data = ext->permissions_data();
45 const URLPatternSet& pattern_set = 47 const URLPatternSet& pattern_set =
46 effective_perm ? permissions_data->GetEffectiveHostPermissions() 48 effective_perm ? permissions_data->GetEffectiveHostPermissions()
47 : permissions_data->active_permissions().explicit_hosts(); 49 : permissions_data->active_permissions().explicit_hosts();
48 50
49 base::ListValue* permissions = new base::ListValue; 51 auto permissions = base::MakeUnique<base::ListValue>();
50 for (URLPatternSet::const_iterator perm = pattern_set.begin(); 52 for (URLPatternSet::const_iterator perm = pattern_set.begin();
51 perm != pattern_set.end(); 53 perm != pattern_set.end();
52 ++perm) { 54 ++perm) {
53 permissions->AppendString(perm->GetAsString()); 55 permissions->AppendString(perm->GetAsString());
54 } 56 }
55 57
56 return permissions; 58 return permissions;
57 } 59 }
58 60
59 base::ListValue* GetAPIPermissions(const Extension* ext) { 61 std::unique_ptr<base::ListValue> GetAPIPermissions(const Extension* ext) {
60 base::ListValue* permissions = new base::ListValue; 62 auto permissions = base::MakeUnique<base::ListValue>();
61 std::set<std::string> perm_list = 63 std::set<std::string> perm_list =
62 ext->permissions_data()->active_permissions().GetAPIsAsStrings(); 64 ext->permissions_data()->active_permissions().GetAPIsAsStrings();
63 for (std::set<std::string>::const_iterator perm = perm_list.begin(); 65 for (std::set<std::string>::const_iterator perm = perm_list.begin();
64 perm != perm_list.end(); ++perm) { 66 perm != perm_list.end(); ++perm) {
65 permissions->AppendString(*perm); 67 permissions->AppendString(*perm);
66 } 68 }
67 return permissions; 69 return permissions;
68 } 70 }
69 71
70 bool IsTestMode(content::BrowserContext* context) { 72 bool IsTestMode(content::BrowserContext* context) {
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 DVLOG(1) << "AutotestPrivateGetExtensionsInfoFunction"; 161 DVLOG(1) << "AutotestPrivateGetExtensionsInfoFunction";
160 162
161 ExtensionService* service = 163 ExtensionService* service =
162 ExtensionSystem::Get(browser_context())->extension_service(); 164 ExtensionSystem::Get(browser_context())->extension_service();
163 ExtensionRegistry* registry = ExtensionRegistry::Get(browser_context()); 165 ExtensionRegistry* registry = ExtensionRegistry::Get(browser_context());
164 const ExtensionSet& extensions = registry->enabled_extensions(); 166 const ExtensionSet& extensions = registry->enabled_extensions();
165 const ExtensionSet& disabled_extensions = registry->disabled_extensions(); 167 const ExtensionSet& disabled_extensions = registry->disabled_extensions();
166 ExtensionActionManager* extension_action_manager = 168 ExtensionActionManager* extension_action_manager =
167 ExtensionActionManager::Get(browser_context()); 169 ExtensionActionManager::Get(browser_context());
168 170
169 base::ListValue* extensions_values = new base::ListValue; 171 auto extensions_values = base::MakeUnique<base::ListValue>();
170 ExtensionList all; 172 ExtensionList all;
171 all.insert(all.end(), extensions.begin(), extensions.end()); 173 all.insert(all.end(), extensions.begin(), extensions.end());
172 all.insert(all.end(), disabled_extensions.begin(), disabled_extensions.end()); 174 all.insert(all.end(), disabled_extensions.begin(), disabled_extensions.end());
173 for (ExtensionList::const_iterator it = all.begin(); 175 for (ExtensionList::const_iterator it = all.begin();
174 it != all.end(); ++it) { 176 it != all.end(); ++it) {
175 const Extension* extension = it->get(); 177 const Extension* extension = it->get();
176 std::string id = extension->id(); 178 std::string id = extension->id();
177 std::unique_ptr<base::DictionaryValue> extension_value( 179 std::unique_ptr<base::DictionaryValue> extension_value(
178 new base::DictionaryValue); 180 new base::DictionaryValue);
179 extension_value->SetString("id", id); 181 extension_value->SetString("id", id);
(...skipping 25 matching lines...) Expand all
205 "allowedInIncognito", util::IsIncognitoEnabled(id, browser_context())); 207 "allowedInIncognito", util::IsIncognitoEnabled(id, browser_context()));
206 extension_value->SetBoolean( 208 extension_value->SetBoolean(
207 "hasPageAction", 209 "hasPageAction",
208 extension_action_manager->GetPageAction(*extension) != NULL); 210 extension_action_manager->GetPageAction(*extension) != NULL);
209 211
210 extensions_values->Append(std::move(extension_value)); 212 extensions_values->Append(std::move(extension_value));
211 } 213 }
212 214
213 std::unique_ptr<base::DictionaryValue> return_value( 215 std::unique_ptr<base::DictionaryValue> return_value(
214 new base::DictionaryValue); 216 new base::DictionaryValue);
215 return_value->Set("extensions", extensions_values); 217 return_value->Set("extensions", std::move(extensions_values));
216 return RespondNow(OneArgument(std::move(return_value))); 218 return RespondNow(OneArgument(std::move(return_value)));
217 } 219 }
218 220
219 static int AccessArray(const volatile int arr[], const volatile int *index) { 221 static int AccessArray(const volatile int arr[], const volatile int *index) {
220 return arr[*index]; 222 return arr[*index];
221 } 223 }
222 224
223 ExtensionFunction::ResponseAction 225 ExtensionFunction::ResponseAction
224 AutotestPrivateSimulateAsanMemoryBugFunction::Run() { 226 AutotestPrivateSimulateAsanMemoryBugFunction::Run() {
225 DVLOG(1) << "AutotestPrivateSimulateAsanMemoryBugFunction"; 227 DVLOG(1) << "AutotestPrivateSimulateAsanMemoryBugFunction";
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 return new AutotestPrivateAPI(); 396 return new AutotestPrivateAPI();
395 } 397 }
396 398
397 AutotestPrivateAPI::AutotestPrivateAPI() : test_mode_(false) { 399 AutotestPrivateAPI::AutotestPrivateAPI() : test_mode_(false) {
398 } 400 }
399 401
400 AutotestPrivateAPI::~AutotestPrivateAPI() { 402 AutotestPrivateAPI::~AutotestPrivateAPI() {
401 } 403 }
402 404
403 } // namespace extensions 405 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698