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

Side by Side Diff: chrome/browser/chromeos/policy/app_pack_updater.cc

Issue 16392011: Move FileEnumerator to its own file, do some refactoring. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix incorrect includes Created 7 years, 6 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 | Annotate | Revision Log
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/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/location.h" 11 #include "base/location.h"
11 #include "base/stl_util.h" 12 #include "base/stl_util.h"
12 #include "base/string_util.h" 13 #include "base/string_util.h"
13 #include "base/values.h" 14 #include "base/values.h"
14 #include "base/version.h" 15 #include "base/version.h"
15 #include "chrome/browser/browser_process.h" 16 #include "chrome/browser/browser_process.h"
16 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" 17 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h"
17 #include "chrome/browser/chromeos/settings/cros_settings.h" 18 #include "chrome/browser/chromeos/settings/cros_settings.h"
18 #include "chrome/browser/chromeos/settings/cros_settings_names.h" 19 #include "chrome/browser/chromeos/settings/cros_settings_names.h"
19 #include "chrome/browser/extensions/crx_installer.h" 20 #include "chrome/browser/extensions/crx_installer.h"
20 #include "chrome/browser/extensions/external_loader.h" 21 #include "chrome/browser/extensions/external_loader.h"
21 #include "chrome/browser/extensions/external_provider_impl.h" 22 #include "chrome/browser/extensions/external_provider_impl.h"
22 #include "chrome/browser/extensions/updater/extension_downloader.h" 23 #include "chrome/browser/extensions/updater/extension_downloader.h"
23 #include "chrome/common/chrome_notification_types.h" 24 #include "chrome/common/chrome_notification_types.h"
24 #include "chrome/common/extensions/extension.h" 25 #include "chrome/common/extensions/extension.h"
25 #include "chrome/common/extensions/extension_constants.h" 26 #include "chrome/common/extensions/extension_constants.h"
26 #include "content/public/browser/browser_thread.h" 27 #include "content/public/browser/browser_thread.h"
27 #include "content/public/browser/notification_details.h" 28 #include "content/public/browser/notification_details.h"
28 #include "content/public/browser/notification_service.h" 29 #include "content/public/browser/notification_service.h"
29 #include "content/public/browser/notification_source.h" 30 #include "content/public/browser/notification_source.h"
30 31
31 using content::BrowserThread; 32 using content::BrowserThread;
32 using file_util::FileEnumerator;
33 33
34 namespace policy { 34 namespace policy {
35 35
36 namespace { 36 namespace {
37 37
38 // Directory where the AppPack extensions are cached. 38 // Directory where the AppPack extensions are cached.
39 const char kAppPackCacheDir[] = "/var/cache/app_pack"; 39 const char kAppPackCacheDir[] = "/var/cache/app_pack";
40 40
41 // File name extension for CRX files (not case sensitive). 41 // File name extension for CRX files (not case sensitive).
42 const char kCRXFileExtension[] = ".crx"; 42 const char kCRXFileExtension[] = ".crx";
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 if (!file_util::DirectoryExists(dir)) { 243 if (!file_util::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 = FileEnumerator::FILES | FileEnumerator::DIRECTORIES | 253 int types = base::FileEnumerator::FILES | base::FileEnumerator::DIRECTORIES |
254 FileEnumerator::SHOW_SYM_LINKS; 254 base::FileEnumerator::SHOW_SYM_LINKS;
255 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 FileEnumerator::FindInfo info; 259 base::FileEnumerator::FileInfo info = enumerator.GetInfo();
260 enumerator.GetFindInfo(&info);
261 std::string basename = path.BaseName().value(); 260 std::string basename = path.BaseName().value();
262 261
263 if (FileEnumerator::IsDirectory(info) || 262 if (info.IsDirectory() || file_util::IsLink(info.GetName())) {
264 file_util::IsLink(FileEnumerator::GetFilename(info))) {
265 LOG(ERROR) << "Erasing bad file in AppPack directory: " << basename; 263 LOG(ERROR) << "Erasing bad file in AppPack directory: " << basename;
266 file_util::Delete(path, true /* recursive */); 264 file_util::Delete(path, true /* recursive */);
267 continue; 265 continue;
268 } 266 }
269 267
270 // crx files in the cache are named <extension-id>-<version>.crx. 268 // crx files in the cache are named <extension-id>-<version>.crx.
271 std::string id; 269 std::string id;
272 std::string version; 270 std::string version;
273 271
274 if (EndsWith(basename, kCRXFileExtension, false /* case-sensitive */)) { 272 if (EndsWith(basename, kCRXFileExtension, false /* case-sensitive */)) {
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 void AppPackUpdater::SetScreenSaverPath(const base::FilePath& path) { 558 void AppPackUpdater::SetScreenSaverPath(const base::FilePath& path) {
561 // Don't invoke the callback if the path isn't changing. 559 // Don't invoke the callback if the path isn't changing.
562 if (path != screen_saver_path_) { 560 if (path != screen_saver_path_) {
563 screen_saver_path_ = path; 561 screen_saver_path_ = path;
564 if (!screen_saver_update_callback_.is_null()) 562 if (!screen_saver_update_callback_.is_null())
565 screen_saver_update_callback_.Run(screen_saver_path_); 563 screen_saver_update_callback_.Run(screen_saver_path_);
566 } 564 }
567 } 565 }
568 566
569 } // namespace policy 567 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698