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

Side by Side Diff: chrome/browser/chromeos/extensions/external_cache.cc

Issue 2765363004: Stop passing raw pointers to DictionaryValue::Set, part 2 (Closed)
Patch Set: Fix comments Created 3 years, 9 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/chromeos/extensions/external_cache.h" 5 #include "chrome/browser/chromeos/extensions/external_cache.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 258
259 if (update_url.is_valid()) 259 if (update_url.is_valid())
260 downloader_->AddPendingExtension(it.key(), update_url, false, 0); 260 downloader_->AddPendingExtension(it.key(), update_url, false, 0);
261 } 261 }
262 262
263 base::FilePath file_path; 263 base::FilePath file_path;
264 std::string version; 264 std::string version;
265 std::string hash; 265 std::string hash;
266 if (local_cache_.GetExtension(it.key(), hash, &file_path, &version)) { 266 if (local_cache_.GetExtension(it.key(), hash, &file_path, &version)) {
267 // Copy entry to don't modify it inside extensions_. 267 // Copy entry to don't modify it inside extensions_.
268 base::DictionaryValue* entry_copy = entry->DeepCopy(); 268 std::unique_ptr<base::DictionaryValue> entry_copy =
269 entry->CreateDeepCopy();
269 270
270 if (extension_urls::IsWebstoreUpdateUrl(GURL(external_update_url))) { 271 if (extension_urls::IsWebstoreUpdateUrl(GURL(external_update_url))) {
271 entry_copy->SetBoolean( 272 entry_copy->SetBoolean(
272 extensions::ExternalProviderImpl::kIsFromWebstore, true); 273 extensions::ExternalProviderImpl::kIsFromWebstore, true);
273 } 274 }
274 entry_copy->Remove(extensions::ExternalProviderImpl::kExternalUpdateUrl, 275 entry_copy->Remove(extensions::ExternalProviderImpl::kExternalUpdateUrl,
275 NULL); 276 NULL);
276 entry_copy->SetString(extensions::ExternalProviderImpl::kExternalVersion, 277 entry_copy->SetString(extensions::ExternalProviderImpl::kExternalVersion,
277 version); 278 version);
278 entry_copy->SetString(extensions::ExternalProviderImpl::kExternalCrx, 279 entry_copy->SetString(extensions::ExternalProviderImpl::kExternalCrx,
279 file_path.value()); 280 file_path.value());
280 cached_extensions_->Set(it.key(), entry_copy); 281 cached_extensions_->Set(it.key(), std::move(entry_copy));
281 } else { 282 } else {
282 bool has_external_crx = entry->HasKey( 283 bool has_external_crx = entry->HasKey(
283 extensions::ExternalProviderImpl::kExternalCrx); 284 extensions::ExternalProviderImpl::kExternalCrx);
284 bool is_already_installed = 285 bool is_already_installed =
285 !delegate_->GetInstalledExtensionVersion(it.key()).empty(); 286 !delegate_->GetInstalledExtensionVersion(it.key()).empty();
286 if (keep_if_present || has_external_crx || is_already_installed) { 287 if (keep_if_present || has_external_crx || is_already_installed) {
287 // Copy entry to don't modify it inside extensions_. 288 // Copy entry to don't modify it inside extensions_.
288 cached_extensions_->Set(it.key(), entry->DeepCopy()); 289 cached_extensions_->Set(it.key(), entry->CreateDeepCopy());
289 } 290 }
290 } 291 }
291 } 292 }
292 293
293 if (downloader_) 294 if (downloader_)
294 downloader_->StartAllPending(NULL); 295 downloader_->StartAllPending(NULL);
295 296
296 VLOG(1) << "Updated ExternalCache, there are " 297 VLOG(1) << "Updated ExternalCache, there are "
297 << cached_extensions_->size() << " extensions cached"; 298 << cached_extensions_->size() << " extensions cached";
298 299
299 UpdateExtensionLoader(); 300 UpdateExtensionLoader();
300 } 301 }
301 302
302 void ExternalCache::OnPutExtension(const std::string& id, 303 void ExternalCache::OnPutExtension(const std::string& id,
303 const base::FilePath& file_path, 304 const base::FilePath& file_path,
304 bool file_ownership_passed) { 305 bool file_ownership_passed) {
305 if (local_cache_.is_shutdown() || file_ownership_passed) { 306 if (local_cache_.is_shutdown() || file_ownership_passed) {
306 backend_task_runner_->PostTask(FROM_HERE, 307 backend_task_runner_->PostTask(FROM_HERE,
307 base::Bind(base::IgnoreResult(&base::DeleteFile), file_path, true)); 308 base::Bind(base::IgnoreResult(&base::DeleteFile), file_path, true));
308 return; 309 return;
309 } 310 }
310 311
311 VLOG(1) << "ExternalCache installed a new extension in the cache " << id; 312 VLOG(1) << "ExternalCache installed a new extension in the cache " << id;
312 313
313 base::DictionaryValue* entry = NULL; 314 base::DictionaryValue* original_entry = NULL;
314 if (!extensions_->GetDictionary(id, &entry)) { 315 if (!extensions_->GetDictionary(id, &original_entry)) {
315 LOG(ERROR) << "ExternalCache cannot find entry for extension " << id; 316 LOG(ERROR) << "ExternalCache cannot find entry for extension " << id;
316 return; 317 return;
317 } 318 }
318 319
319 // Copy entry to don't modify it inside extensions_. 320 // Copy original_entry to avoid modifying it inside extensions_.
320 entry = entry->DeepCopy(); 321 std::unique_ptr<base::DictionaryValue> entry =
322 original_entry->CreateDeepCopy();
321 323
322 std::string version; 324 std::string version;
323 std::string hash; 325 std::string hash;
324 if (!local_cache_.GetExtension(id, hash, NULL, &version)) { 326 if (!local_cache_.GetExtension(id, hash, NULL, &version)) {
325 // Copy entry to don't modify it inside extensions_. 327 // Copy entry to don't modify it inside extensions_.
326 LOG(ERROR) << "Can't find installed extension in cache " << id; 328 LOG(ERROR) << "Can't find installed extension in cache " << id;
327 return; 329 return;
328 } 330 }
329 331
330 if (flush_on_put_) { 332 if (flush_on_put_) {
331 backend_task_runner_->PostTask(FROM_HERE, 333 backend_task_runner_->PostTask(FROM_HERE,
332 base::Bind(&FlushFile, file_path)); 334 base::Bind(&FlushFile, file_path));
333 } 335 }
334 336
335 std::string update_url; 337 std::string update_url;
336 if (entry->GetString(extensions::ExternalProviderImpl::kExternalUpdateUrl, 338 if (entry->GetString(extensions::ExternalProviderImpl::kExternalUpdateUrl,
337 &update_url) && 339 &update_url) &&
338 extension_urls::IsWebstoreUpdateUrl(GURL(update_url))) { 340 extension_urls::IsWebstoreUpdateUrl(GURL(update_url))) {
339 entry->SetBoolean(extensions::ExternalProviderImpl::kIsFromWebstore, true); 341 entry->SetBoolean(extensions::ExternalProviderImpl::kIsFromWebstore, true);
340 } 342 }
341 entry->Remove(extensions::ExternalProviderImpl::kExternalUpdateUrl, NULL); 343 entry->Remove(extensions::ExternalProviderImpl::kExternalUpdateUrl, NULL);
342 entry->SetString(extensions::ExternalProviderImpl::kExternalVersion, version); 344 entry->SetString(extensions::ExternalProviderImpl::kExternalVersion, version);
343 entry->SetString(extensions::ExternalProviderImpl::kExternalCrx, 345 entry->SetString(extensions::ExternalProviderImpl::kExternalCrx,
344 file_path.value()); 346 file_path.value());
345 347
346 cached_extensions_->Set(id, entry); 348 cached_extensions_->Set(id, std::move(entry));
347 if (delegate_) 349 if (delegate_)
348 delegate_->OnExtensionLoadedInCache(id); 350 delegate_->OnExtensionLoadedInCache(id);
349 UpdateExtensionLoader(); 351 UpdateExtensionLoader();
350 } 352 }
351 353
352 void ExternalCache::OnPutExternalExtension( 354 void ExternalCache::OnPutExternalExtension(
353 const std::string& id, 355 const std::string& id,
354 const PutExternalExtensionCallback& callback, 356 const PutExternalExtensionCallback& callback,
355 const base::FilePath& file_path, 357 const base::FilePath& file_path,
356 bool file_ownership_passed) { 358 bool file_ownership_passed) {
357 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 359 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
358 OnPutExtension(id, file_path, file_ownership_passed); 360 OnPutExtension(id, file_path, file_ownership_passed);
359 callback.Run(id, !file_ownership_passed); 361 callback.Run(id, !file_ownership_passed);
360 } 362 }
361 363
362 std::string ExternalCache::Delegate::GetInstalledExtensionVersion( 364 std::string ExternalCache::Delegate::GetInstalledExtensionVersion(
363 const std::string& id) { 365 const std::string& id) {
364 return std::string(); 366 return std::string();
365 } 367 }
366 368
367 } // namespace chromeos 369 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698