OLD | NEW |
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/chromeos/policy/app_pack_updater.h" | 5 #include "chrome/browser/chromeos/policy/app_pack_updater.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/files/file_enumerator.h" | 10 #include "base/files/file_enumerator.h" |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 base::FileEnumerator::SHOW_SYM_LINKS; | 254 base::FileEnumerator::SHOW_SYM_LINKS; |
255 base::FileEnumerator enumerator(dir, false /* recursive */, types); | 255 base::FileEnumerator enumerator(dir, false /* recursive */, types); |
256 | 256 |
257 for (base::FilePath path = enumerator.Next(); | 257 for (base::FilePath path = enumerator.Next(); |
258 !path.empty(); path = enumerator.Next()) { | 258 !path.empty(); path = enumerator.Next()) { |
259 base::FileEnumerator::FileInfo info = enumerator.GetInfo(); | 259 base::FileEnumerator::FileInfo info = enumerator.GetInfo(); |
260 std::string basename = path.BaseName().value(); | 260 std::string basename = path.BaseName().value(); |
261 | 261 |
262 if (info.IsDirectory() || file_util::IsLink(info.GetName())) { | 262 if (info.IsDirectory() || file_util::IsLink(info.GetName())) { |
263 LOG(ERROR) << "Erasing bad file in AppPack directory: " << basename; | 263 LOG(ERROR) << "Erasing bad file in AppPack directory: " << basename; |
264 base::Delete(path, true /* recursive */); | 264 base::DeleteFile(path, true /* recursive */); |
265 continue; | 265 continue; |
266 } | 266 } |
267 | 267 |
268 // crx files in the cache are named <extension-id>-<version>.crx. | 268 // crx files in the cache are named <extension-id>-<version>.crx. |
269 std::string id; | 269 std::string id; |
270 std::string version; | 270 std::string version; |
271 | 271 |
272 if (EndsWith(basename, kCRXFileExtension, false /* case-sensitive */)) { | 272 if (EndsWith(basename, kCRXFileExtension, false /* case-sensitive */)) { |
273 size_t n = basename.find('-'); | 273 size_t n = basename.find('-'); |
274 if (n != std::string::npos && n + 1 < basename.size() - 4) { | 274 if (n != std::string::npos && n + 1 < basename.size() - 4) { |
(...skipping 12 matching lines...) Expand all Loading... |
287 id.clear(); | 287 id.clear(); |
288 } | 288 } |
289 | 289 |
290 if (!Version(version).IsValid()) { | 290 if (!Version(version).IsValid()) { |
291 LOG(ERROR) << "Bad AppPack extension version in cache: " << version; | 291 LOG(ERROR) << "Bad AppPack extension version in cache: " << version; |
292 version.clear(); | 292 version.clear(); |
293 } | 293 } |
294 | 294 |
295 if (id.empty() || version.empty()) { | 295 if (id.empty() || version.empty()) { |
296 LOG(ERROR) << "Invalid file in AppPack cache, erasing: " << basename; | 296 LOG(ERROR) << "Invalid file in AppPack cache, erasing: " << basename; |
297 base::Delete(path, true /* recursive */); | 297 base::DeleteFile(path, true /* recursive */); |
298 continue; | 298 continue; |
299 } | 299 } |
300 | 300 |
301 // Enforce a lower-case id. | 301 // Enforce a lower-case id. |
302 id = StringToLowerASCII(id); | 302 id = StringToLowerASCII(id); |
303 | 303 |
304 // File seems good so far. Make sure there isn't another entry with the | 304 // File seems good so far. Make sure there isn't another entry with the |
305 // same id but a different version. | 305 // same id but a different version. |
306 | 306 |
307 if (ContainsKey(*entries, id)) { | 307 if (ContainsKey(*entries, id)) { |
308 LOG(ERROR) << "Found two AppPack files for the same extension, will " | 308 LOG(ERROR) << "Found two AppPack files for the same extension, will " |
309 "erase the oldest version"; | 309 "erase the oldest version"; |
310 CacheEntry& entry = (*entries)[id]; | 310 CacheEntry& entry = (*entries)[id]; |
311 Version vEntry(entry.cached_version); | 311 Version vEntry(entry.cached_version); |
312 Version vCurrent(version); | 312 Version vCurrent(version); |
313 DCHECK(vEntry.IsValid()); | 313 DCHECK(vEntry.IsValid()); |
314 DCHECK(vCurrent.IsValid()); | 314 DCHECK(vCurrent.IsValid()); |
315 if (vEntry.CompareTo(vCurrent) < 0) { | 315 if (vEntry.CompareTo(vCurrent) < 0) { |
316 base::Delete(base::FilePath(entry.path), true /* recursive */); | 316 base::DeleteFile(base::FilePath(entry.path), true /* recursive */); |
317 entry.path = path.value(); | 317 entry.path = path.value(); |
318 } else { | 318 } else { |
319 base::Delete(path, true /* recursive */); | 319 base::DeleteFile(path, true /* recursive */); |
320 } | 320 } |
321 continue; | 321 continue; |
322 } | 322 } |
323 | 323 |
324 // This is the only file for this |id| so far, add it. | 324 // This is the only file for this |id| so far, add it. |
325 | 325 |
326 CacheEntry& entry = (*entries)[id]; | 326 CacheEntry& entry = (*entries)[id]; |
327 entry.path = path.value(); | 327 entry.path = path.value(); |
328 entry.cached_version = version; | 328 entry.cached_version = version; |
329 } | 329 } |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 // static | 463 // static |
464 void AppPackUpdater::BlockingInstallCacheEntry( | 464 void AppPackUpdater::BlockingInstallCacheEntry( |
465 base::WeakPtr<AppPackUpdater> app_pack_updater, | 465 base::WeakPtr<AppPackUpdater> app_pack_updater, |
466 const std::string& id, | 466 const std::string& id, |
467 const base::FilePath& path, | 467 const base::FilePath& path, |
468 const std::string& version) { | 468 const std::string& version) { |
469 Version version_validator(version); | 469 Version version_validator(version); |
470 if (!version_validator.IsValid()) { | 470 if (!version_validator.IsValid()) { |
471 LOG(ERROR) << "AppPack downloaded extension " << id << " but got bad " | 471 LOG(ERROR) << "AppPack downloaded extension " << id << " but got bad " |
472 << "version: " << version; | 472 << "version: " << version; |
473 base::Delete(path, true /* recursive */); | 473 base::DeleteFile(path, true /* recursive */); |
474 return; | 474 return; |
475 } | 475 } |
476 | 476 |
477 std::string basename = id + "-" + version + kCRXFileExtension; | 477 std::string basename = id + "-" + version + kCRXFileExtension; |
478 base::FilePath cache_dir(kAppPackCacheDir); | 478 base::FilePath cache_dir(kAppPackCacheDir); |
479 base::FilePath cached_crx_path = cache_dir.Append(basename); | 479 base::FilePath cached_crx_path = cache_dir.Append(basename); |
480 | 480 |
481 if (base::PathExists(cached_crx_path)) { | 481 if (base::PathExists(cached_crx_path)) { |
482 LOG(WARNING) << "AppPack downloaded a crx whose filename will overwrite " | 482 LOG(WARNING) << "AppPack downloaded a crx whose filename will overwrite " |
483 << "an existing cached crx."; | 483 << "an existing cached crx."; |
484 base::Delete(cached_crx_path, true /* recursive */); | 484 base::DeleteFile(cached_crx_path, true /* recursive */); |
485 } | 485 } |
486 | 486 |
487 if (!base::DirectoryExists(cache_dir)) { | 487 if (!base::DirectoryExists(cache_dir)) { |
488 LOG(ERROR) << "AppPack cache directory does not exist, creating now: " | 488 LOG(ERROR) << "AppPack cache directory does not exist, creating now: " |
489 << cache_dir.value(); | 489 << cache_dir.value(); |
490 if (!file_util::CreateDirectory(cache_dir)) { | 490 if (!file_util::CreateDirectory(cache_dir)) { |
491 LOG(ERROR) << "Failed to create the AppPack cache dir!"; | 491 LOG(ERROR) << "Failed to create the AppPack cache dir!"; |
492 base::Delete(path, true /* recursive */); | 492 base::DeleteFile(path, true /* recursive */); |
493 return; | 493 return; |
494 } | 494 } |
495 } | 495 } |
496 | 496 |
497 if (!base::Move(path, cached_crx_path)) { | 497 if (!base::Move(path, cached_crx_path)) { |
498 LOG(ERROR) << "Failed to move AppPack crx from " << path.value() | 498 LOG(ERROR) << "Failed to move AppPack crx from " << path.value() |
499 << " to " << cached_crx_path.value(); | 499 << " to " << cached_crx_path.value(); |
500 base::Delete(path, true /* recursive */); | 500 base::DeleteFile(path, true /* recursive */); |
501 return; | 501 return; |
502 } | 502 } |
503 | 503 |
504 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 504 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
505 base::Bind(&AppPackUpdater::OnCacheEntryInstalled, | 505 base::Bind(&AppPackUpdater::OnCacheEntryInstalled, |
506 app_pack_updater, | 506 app_pack_updater, |
507 std::string(id), | 507 std::string(id), |
508 cached_crx_path.value(), | 508 cached_crx_path.value(), |
509 std::string(version))); | 509 std::string(version))); |
510 } | 510 } |
(...skipping 21 matching lines...) Expand all Loading... |
532 it != cached_extensions_.end(); ++it) { | 532 it != cached_extensions_.end(); ++it) { |
533 if (it->second.path == path.value()) { | 533 if (it->second.path == path.value()) { |
534 LOG(ERROR) << "AppPack extension at " << path.value() << " failed to " | 534 LOG(ERROR) << "AppPack extension at " << path.value() << " failed to " |
535 << "install, deleting it."; | 535 << "install, deleting it."; |
536 cached_extensions_.erase(it); | 536 cached_extensions_.erase(it); |
537 UpdateExtensionLoader(); | 537 UpdateExtensionLoader(); |
538 | 538 |
539 // The file will be downloaded again on the next restart. | 539 // The file will be downloaded again on the next restart. |
540 BrowserThread::PostTask( | 540 BrowserThread::PostTask( |
541 BrowserThread::FILE, FROM_HERE, | 541 BrowserThread::FILE, FROM_HERE, |
542 base::Bind(base::IgnoreResult(base::Delete), path, true)); | 542 base::Bind(base::IgnoreResult(base::DeleteFile), path, true)); |
543 | 543 |
544 // Don't try to DownloadMissingExtensions() from here, | 544 // Don't try to DownloadMissingExtensions() from here, |
545 // since it can cause a fail/retry loop. | 545 // since it can cause a fail/retry loop. |
546 break; | 546 break; |
547 } | 547 } |
548 } | 548 } |
549 } | 549 } |
550 | 550 |
551 void AppPackUpdater::PostBlockingTask(const tracked_objects::Location& location, | 551 void AppPackUpdater::PostBlockingTask(const tracked_objects::Location& location, |
552 const base::Closure& task) { | 552 const base::Closure& task) { |
553 BrowserThread::GetBlockingPool()->PostSequencedWorkerTaskWithShutdownBehavior( | 553 BrowserThread::GetBlockingPool()->PostSequencedWorkerTaskWithShutdownBehavior( |
554 worker_pool_token_, location, task, | 554 worker_pool_token_, location, task, |
555 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); | 555 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
556 } | 556 } |
557 | 557 |
558 void AppPackUpdater::SetScreenSaverPath(const base::FilePath& path) { | 558 void AppPackUpdater::SetScreenSaverPath(const base::FilePath& path) { |
559 // Don't invoke the callback if the path isn't changing. | 559 // Don't invoke the callback if the path isn't changing. |
560 if (path != screen_saver_path_) { | 560 if (path != screen_saver_path_) { |
561 screen_saver_path_ = path; | 561 screen_saver_path_ = path; |
562 if (!screen_saver_update_callback_.is_null()) | 562 if (!screen_saver_update_callback_.is_null()) |
563 screen_saver_update_callback_.Run(screen_saver_path_); | 563 screen_saver_update_callback_.Run(screen_saver_path_); |
564 } | 564 } |
565 } | 565 } |
566 | 566 |
567 } // namespace policy | 567 } // namespace policy |
OLD | NEW |