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 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 app_pack_updater, | 233 app_pack_updater, |
234 base::Owned(entries))); | 234 base::Owned(entries))); |
235 } | 235 } |
236 | 236 |
237 // static | 237 // static |
238 void AppPackUpdater::BlockingCheckCacheInternal( | 238 void AppPackUpdater::BlockingCheckCacheInternal( |
239 const std::set<std::string>* valid_ids, | 239 const std::set<std::string>* valid_ids, |
240 CacheEntryMap* entries) { | 240 CacheEntryMap* entries) { |
241 // Start by verifying that the cache dir exists. | 241 // Start by verifying that the cache dir exists. |
242 base::FilePath dir(kAppPackCacheDir); | 242 base::FilePath dir(kAppPackCacheDir); |
243 if (!file_util::DirectoryExists(dir)) { | 243 if (!base::DirectoryExists(dir)) { |
244 // Create it now. | 244 // Create it now. |
245 if (!file_util::CreateDirectory(dir)) | 245 if (!file_util::CreateDirectory(dir)) |
246 LOG(ERROR) << "Failed to create AppPack directory at " << dir.value(); | 246 LOG(ERROR) << "Failed to create AppPack directory at " << dir.value(); |
247 // Nothing else to do. | 247 // Nothing else to do. |
248 return; | 248 return; |
249 } | 249 } |
250 | 250 |
251 // Enumerate all the files in the cache |dir|, including directories | 251 // Enumerate all the files in the cache |dir|, including directories |
252 // and symlinks. Each unrecognized file will be erased. | 252 // and symlinks. Each unrecognized file will be erased. |
253 int types = base::FileEnumerator::FILES | base::FileEnumerator::DIRECTORIES | | 253 int types = base::FileEnumerator::FILES | base::FileEnumerator::DIRECTORIES | |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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::Delete(cached_crx_path, true /* recursive */); |
485 } | 485 } |
486 | 486 |
487 if (!file_util::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::Delete(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)) { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |