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

Side by Side Diff: chrome/browser/extensions/component_loader.cc

Issue 1871713002: Convert //chrome/browser/extensions from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and fix header Created 4 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/component_loader.h" 5 #include "chrome/browser/extensions/component_loader.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 const base::FilePath& path) { 85 const base::FilePath& path) {
86 std::string raw_key; 86 std::string raw_key;
87 std::string id_input; 87 std::string id_input;
88 CHECK(manifest->GetString(manifest_keys::kPublicKey, &raw_key)); 88 CHECK(manifest->GetString(manifest_keys::kPublicKey, &raw_key));
89 CHECK(Extension::ParsePEMKeyBytes(raw_key, &id_input)); 89 CHECK(Extension::ParsePEMKeyBytes(raw_key, &id_input));
90 std::string id = crx_file::id_util::GenerateId(id_input); 90 std::string id = crx_file::id_util::GenerateId(id_input);
91 return id; 91 return id;
92 } 92 }
93 93
94 #if defined(OS_CHROMEOS) 94 #if defined(OS_CHROMEOS)
95 scoped_ptr<base::DictionaryValue> 95 std::unique_ptr<base::DictionaryValue> LoadManifestOnFileThread(
96 LoadManifestOnFileThread(
97 const base::FilePath& root_directory, 96 const base::FilePath& root_directory,
98 const base::FilePath::CharType* manifest_filename) { 97 const base::FilePath::CharType* manifest_filename) {
99 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); 98 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE);
100 std::string error; 99 std::string error;
101 scoped_ptr<base::DictionaryValue> manifest( 100 std::unique_ptr<base::DictionaryValue> manifest(
102 file_util::LoadManifest(root_directory, manifest_filename, &error)); 101 file_util::LoadManifest(root_directory, manifest_filename, &error));
103 if (!manifest) { 102 if (!manifest) {
104 LOG(ERROR) << "Can't load " 103 LOG(ERROR) << "Can't load "
105 << root_directory.Append(manifest_filename).AsUTF8Unsafe() 104 << root_directory.Append(manifest_filename).AsUTF8Unsafe()
106 << ": " << error; 105 << ": " << error;
107 return nullptr; 106 return nullptr;
108 } 107 }
109 bool localized = extension_l10n_util::LocalizeExtension( 108 bool localized = extension_l10n_util::LocalizeExtension(
110 root_directory, manifest.get(), &error); 109 root_directory, manifest.get(), &error);
111 CHECK(localized) << error; 110 CHECK(localized) << error;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 for (RegisteredComponentExtensions::iterator it = 155 for (RegisteredComponentExtensions::iterator it =
157 component_extensions_.begin(); 156 component_extensions_.begin();
158 it != component_extensions_.end(); ++it) { 157 it != component_extensions_.end(); ++it) {
159 Load(*it); 158 Load(*it);
160 } 159 }
161 } 160 }
162 161
163 base::DictionaryValue* ComponentLoader::ParseManifest( 162 base::DictionaryValue* ComponentLoader::ParseManifest(
164 const std::string& manifest_contents) const { 163 const std::string& manifest_contents) const {
165 JSONStringValueDeserializer deserializer(manifest_contents); 164 JSONStringValueDeserializer deserializer(manifest_contents);
166 scoped_ptr<base::Value> manifest = deserializer.Deserialize(NULL, NULL); 165 std::unique_ptr<base::Value> manifest = deserializer.Deserialize(NULL, NULL);
167 166
168 if (!manifest.get() || !manifest->IsType(base::Value::TYPE_DICTIONARY)) { 167 if (!manifest.get() || !manifest->IsType(base::Value::TYPE_DICTIONARY)) {
169 LOG(ERROR) << "Failed to parse extension manifest."; 168 LOG(ERROR) << "Failed to parse extension manifest.";
170 return NULL; 169 return NULL;
171 } 170 }
172 // Transfer ownership to the caller. 171 // Transfer ownership to the caller.
173 return static_cast<base::DictionaryValue*>(manifest.release()); 172 return static_cast<base::DictionaryValue*>(manifest.release());
174 } 173 }
175 174
176 void ComponentLoader::ClearAllRegistered() { 175 void ComponentLoader::ClearAllRegistered() {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 234
236 component_extensions_.push_back(info); 235 component_extensions_.push_back(info);
237 if (extension_service_->is_ready()) 236 if (extension_service_->is_ready())
238 Load(info); 237 Load(info);
239 return info.extension_id; 238 return info.extension_id;
240 } 239 }
241 240
242 std::string ComponentLoader::AddOrReplace(const base::FilePath& path) { 241 std::string ComponentLoader::AddOrReplace(const base::FilePath& path) {
243 base::FilePath absolute_path = base::MakeAbsoluteFilePath(path); 242 base::FilePath absolute_path = base::MakeAbsoluteFilePath(path);
244 std::string error; 243 std::string error;
245 scoped_ptr<base::DictionaryValue> manifest( 244 std::unique_ptr<base::DictionaryValue> manifest(
246 file_util::LoadManifest(absolute_path, &error)); 245 file_util::LoadManifest(absolute_path, &error));
247 if (!manifest) { 246 if (!manifest) {
248 LOG(ERROR) << "Could not load extension from '" << 247 LOG(ERROR) << "Could not load extension from '" <<
249 absolute_path.value() << "'. " << error; 248 absolute_path.value() << "'. " << error;
250 return std::string(); 249 return std::string();
251 } 250 }
252 Remove(GenerateId(manifest.get(), absolute_path)); 251 Remove(GenerateId(manifest.get(), absolute_path));
253 252
254 // We don't check component extensions loaded by path because this is only 253 // We don't check component extensions loaded by path because this is only
255 // used by developers for testing. 254 // used by developers for testing.
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 weak_factory_.GetWeakPtr(), 776 weak_factory_.GetWeakPtr(),
778 root_directory, 777 root_directory,
779 extension_id, 778 extension_id,
780 done_cb)); 779 done_cb));
781 } 780 }
782 781
783 void ComponentLoader::FinishAddWithManifestFile( 782 void ComponentLoader::FinishAddWithManifestFile(
784 const base::FilePath& root_directory, 783 const base::FilePath& root_directory,
785 const char* extension_id, 784 const char* extension_id,
786 const base::Closure& done_cb, 785 const base::Closure& done_cb,
787 scoped_ptr<base::DictionaryValue> manifest) { 786 std::unique_ptr<base::DictionaryValue> manifest) {
788 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 787 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
789 if (!manifest) 788 if (!manifest)
790 return; // Error already logged. 789 return; // Error already logged.
791 std::string actual_extension_id = Add( 790 std::string actual_extension_id = Add(
792 manifest.release(), 791 manifest.release(),
793 root_directory, 792 root_directory,
794 false); 793 false);
795 CHECK_EQ(extension_id, actual_extension_id); 794 CHECK_EQ(extension_id, actual_extension_id);
796 if (!done_cb.is_null()) 795 if (!done_cb.is_null())
797 done_cb.Run(); 796 done_cb.Run();
798 } 797 }
799 #endif 798 #endif
800 799
801 } // namespace extensions 800 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/component_loader.h ('k') | chrome/browser/extensions/component_loader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698