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

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

Issue 2310683002: Remove most ScopedVector usage from c/b/extensions. (Closed)
Patch Set: remove scoped_vector includes Created 4 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 (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/external_provider_impl.h" 5 #include "chrome/browser/extensions/external_provider_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <set> 9 #include <set>
10 #include <vector> 10 #include <vector>
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 void ExternalProviderImpl::SetPrefs(base::DictionaryValue* prefs) { 115 void ExternalProviderImpl::SetPrefs(base::DictionaryValue* prefs) {
116 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 116 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
117 117
118 // Check if the service is still alive. It is possible that it went 118 // Check if the service is still alive. It is possible that it went
119 // away while |loader_| was working on the FILE thread. 119 // away while |loader_| was working on the FILE thread.
120 if (!service_) return; 120 if (!service_) return;
121 121
122 prefs_.reset(prefs); 122 prefs_.reset(prefs);
123 ready_ = true; // Queries for extensions are allowed from this point. 123 ready_ = true; // Queries for extensions are allowed from this point.
124 124
125 ScopedVector<ExternalInstallInfoUpdateUrl> external_update_url_extensions; 125 std::vector<std::unique_ptr<ExternalInstallInfoUpdateUrl>>
126 ScopedVector<ExternalInstallInfoFile> external_file_extensions; 126 external_update_url_extensions;
127 std::vector<std::unique_ptr<ExternalInstallInfoFile>>
128 external_file_extensions;
127 129
128 RetrieveExtensionsFromPrefs(&external_update_url_extensions, 130 RetrieveExtensionsFromPrefs(&external_update_url_extensions,
129 &external_file_extensions); 131 &external_file_extensions);
130 for (auto* extension : external_update_url_extensions) 132 for (const auto& extension : external_update_url_extensions)
131 service_->OnExternalExtensionUpdateUrlFound(*extension, true); 133 service_->OnExternalExtensionUpdateUrlFound(*extension, true);
132 134
133 for (auto* extension : external_file_extensions) 135 for (const auto& extension : external_file_extensions)
134 service_->OnExternalExtensionFileFound(*extension); 136 service_->OnExternalExtensionFileFound(*extension);
135 137
136 service_->OnExternalProviderReady(this); 138 service_->OnExternalProviderReady(this);
137 } 139 }
138 140
139 void ExternalProviderImpl::UpdatePrefs(base::DictionaryValue* prefs) { 141 void ExternalProviderImpl::UpdatePrefs(base::DictionaryValue* prefs) {
140 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 142 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
141 // We only expect updates from windows registry. 143 // We only expect updates from windows registry.
142 CHECK(crx_location_ == Manifest::EXTERNAL_REGISTRY); 144 CHECK(crx_location_ == Manifest::EXTERNAL_REGISTRY);
143 145
144 // Check if the service is still alive. It is possible that it went 146 // Check if the service is still alive. It is possible that it went
145 // away while |loader_| was working on the FILE thread. 147 // away while |loader_| was working on the FILE thread.
146 if (!service_) 148 if (!service_)
147 return; 149 return;
148 150
149 std::set<std::string> removed_extensions; 151 std::set<std::string> removed_extensions;
150 // Find extensions that were removed by this ExternalProvider. 152 // Find extensions that were removed by this ExternalProvider.
151 for (base::DictionaryValue::Iterator i(*prefs_); !i.IsAtEnd(); i.Advance()) { 153 for (base::DictionaryValue::Iterator i(*prefs_); !i.IsAtEnd(); i.Advance()) {
152 const std::string& extension_id = i.key(); 154 const std::string& extension_id = i.key();
153 // Don't bother about invalid ids. 155 // Don't bother about invalid ids.
154 if (!crx_file::id_util::IdIsValid(extension_id)) 156 if (!crx_file::id_util::IdIsValid(extension_id))
155 continue; 157 continue;
156 if (!prefs->HasKey(extension_id)) 158 if (!prefs->HasKey(extension_id))
157 removed_extensions.insert(extension_id); 159 removed_extensions.insert(extension_id);
158 } 160 }
159 161
160 prefs_.reset(prefs); 162 prefs_.reset(prefs);
161 163
162 ScopedVector<ExternalInstallInfoUpdateUrl> external_update_url_extensions; 164 std::vector<std::unique_ptr<ExternalInstallInfoUpdateUrl>>
163 ScopedVector<ExternalInstallInfoFile> external_file_extensions; 165 external_update_url_extensions;
166 std::vector<std::unique_ptr<ExternalInstallInfoFile>>
167 external_file_extensions;
164 RetrieveExtensionsFromPrefs(&external_update_url_extensions, 168 RetrieveExtensionsFromPrefs(&external_update_url_extensions,
165 &external_file_extensions); 169 &external_file_extensions);
166 170
167 // Notify ExtensionService about completion of finding incremental updates 171 // Notify ExtensionService about completion of finding incremental updates
168 // from this provider. 172 // from this provider.
169 // Provide the list of added and removed extensions. 173 // Provide the list of added and removed extensions.
170 service_->OnExternalProviderUpdateComplete( 174 service_->OnExternalProviderUpdateComplete(
171 this, external_update_url_extensions, external_file_extensions, 175 this, external_update_url_extensions, external_file_extensions,
172 removed_extensions); 176 removed_extensions);
173 } 177 }
174 178
175 void ExternalProviderImpl::RetrieveExtensionsFromPrefs( 179 void ExternalProviderImpl::RetrieveExtensionsFromPrefs(
176 ScopedVector<ExternalInstallInfoUpdateUrl>* external_update_url_extensions, 180 std::vector<std::unique_ptr<ExternalInstallInfoUpdateUrl>>*
177 ScopedVector<ExternalInstallInfoFile>* external_file_extensions) { 181 external_update_url_extensions,
182 std::vector<std::unique_ptr<ExternalInstallInfoFile>>*
183 external_file_extensions) {
178 // Set of unsupported extensions that need to be deleted from prefs_. 184 // Set of unsupported extensions that need to be deleted from prefs_.
179 std::set<std::string> unsupported_extensions; 185 std::set<std::string> unsupported_extensions;
180 186
181 // Discover all the extensions this provider has. 187 // Discover all the extensions this provider has.
182 for (base::DictionaryValue::Iterator i(*prefs_); !i.IsAtEnd(); i.Advance()) { 188 for (base::DictionaryValue::Iterator i(*prefs_); !i.IsAtEnd(); i.Advance()) {
183 const std::string& extension_id = i.key(); 189 const std::string& extension_id = i.key();
184 const base::DictionaryValue* extension = NULL; 190 const base::DictionaryValue* extension = NULL;
185 191
186 if (!crx_file::id_util::IdIsValid(extension_id)) { 192 if (!crx_file::id_util::IdIsValid(extension_id)) {
187 LOG(WARNING) << "Malformed extension dictionary: key " 193 LOG(WARNING) << "Malformed extension dictionary: key "
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 } 350 }
345 351
346 std::unique_ptr<base::Version> version( 352 std::unique_ptr<base::Version> version(
347 new base::Version(external_version)); 353 new base::Version(external_version));
348 if (!version->IsValid()) { 354 if (!version->IsValid()) {
349 LOG(WARNING) << "Malformed extension dictionary for extension: " 355 LOG(WARNING) << "Malformed extension dictionary for extension: "
350 << extension_id.c_str() << ". Invalid version string \"" 356 << extension_id.c_str() << ". Invalid version string \""
351 << external_version << "\"."; 357 << external_version << "\".";
352 continue; 358 continue;
353 } 359 }
354 external_file_extensions->push_back(new ExternalInstallInfoFile( 360 external_file_extensions->push_back(
355 extension_id, std::move(version), path, crx_location_, creation_flags, 361 base::MakeUnique<ExternalInstallInfoFile>(
356 auto_acknowledge_, install_immediately_)); 362 extension_id, std::move(version), path, crx_location_,
363 creation_flags, auto_acknowledge_, install_immediately_));
357 } else { // if (has_external_update_url) 364 } else { // if (has_external_update_url)
358 CHECK(has_external_update_url); // Checking of keys above ensures this. 365 CHECK(has_external_update_url); // Checking of keys above ensures this.
359 if (download_location_ == Manifest::INVALID_LOCATION) { 366 if (download_location_ == Manifest::INVALID_LOCATION) {
360 LOG(WARNING) << "This provider does not support installing external " 367 LOG(WARNING) << "This provider does not support installing external "
361 << "extensions from update URLs."; 368 << "extensions from update URLs.";
362 continue; 369 continue;
363 } 370 }
364 std::unique_ptr<GURL> update_url(new GURL(external_update_url)); 371 std::unique_ptr<GURL> update_url(new GURL(external_update_url));
365 if (!update_url->is_valid()) { 372 if (!update_url->is_valid()) {
366 LOG(WARNING) << "Malformed extension dictionary for extension: " 373 LOG(WARNING) << "Malformed extension dictionary for extension: "
367 << extension_id.c_str() << ". Key " << kExternalUpdateUrl 374 << extension_id.c_str() << ". Key " << kExternalUpdateUrl
368 << " has value \"" << external_update_url 375 << " has value \"" << external_update_url
369 << "\", which is not a valid URL."; 376 << "\", which is not a valid URL.";
370 continue; 377 continue;
371 } 378 }
372 external_update_url_extensions->push_back( 379 external_update_url_extensions->push_back(
373 new ExternalInstallInfoUpdateUrl( 380 base::MakeUnique<ExternalInstallInfoUpdateUrl>(
374 extension_id, install_parameter, std::move(update_url), 381 extension_id, install_parameter, std::move(update_url),
375 download_location_, creation_flags, auto_acknowledge_)); 382 download_location_, creation_flags, auto_acknowledge_));
376 } 383 }
377 } 384 }
378 385
379 for (std::set<std::string>::iterator it = unsupported_extensions.begin(); 386 for (std::set<std::string>::iterator it = unsupported_extensions.begin();
380 it != unsupported_extensions.end(); ++it) { 387 it != unsupported_extensions.end(); ++it) {
381 // Remove extension for the list of know external extensions. The extension 388 // Remove extension for the list of know external extensions. The extension
382 // will be uninstalled later because provider doesn't provide it anymore. 389 // will be uninstalled later because provider doesn't provide it anymore.
383 prefs_->Remove(*it, NULL); 390 prefs_->Remove(*it, NULL);
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 provider_list->push_back(std::move(drive_migration_provider)); 695 provider_list->push_back(std::move(drive_migration_provider));
689 } 696 }
690 697
691 provider_list->push_back(base::MakeUnique<ExternalProviderImpl>( 698 provider_list->push_back(base::MakeUnique<ExternalProviderImpl>(
692 service, new ExternalComponentLoader(profile), profile, 699 service, new ExternalComponentLoader(profile), profile,
693 Manifest::INVALID_LOCATION, Manifest::EXTERNAL_COMPONENT, 700 Manifest::INVALID_LOCATION, Manifest::EXTERNAL_COMPONENT,
694 Extension::FROM_WEBSTORE | Extension::WAS_INSTALLED_BY_DEFAULT)); 701 Extension::FROM_WEBSTORE | Extension::WAS_INSTALLED_BY_DEFAULT));
695 } 702 }
696 703
697 } // namespace extensions 704 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/external_provider_impl.h ('k') | chrome/browser/extensions/window_open_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698