| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/extension_garbage_collector.h" | 5 #include "chrome/browser/extensions/extension_garbage_collector.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/files/file_enumerator.h" | 9 #include "base/files/file_enumerator.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/sequenced_task_runner.h" | 13 #include "base/sequenced_task_runner.h" |
| 14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 17 #include "chrome/browser/extensions/extension_service.h" | 17 #include "chrome/browser/extensions/extension_service.h" |
| 18 #include "chrome/browser/extensions/extension_util.h" | 18 #include "chrome/browser/extensions/extension_util.h" |
| 19 #include "chrome/browser/extensions/pending_extension_manager.h" | 19 #include "chrome/browser/extensions/pending_extension_manager.h" |
| 20 #include "chrome/common/extensions/extension_file_util.h" | |
| 21 #include "chrome/common/extensions/manifest_handlers/app_isolation_info.h" | 20 #include "chrome/common/extensions/manifest_handlers/app_isolation_info.h" |
| 22 #include "content/public/browser/browser_context.h" | 21 #include "content/public/browser/browser_context.h" |
| 23 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
| 24 #include "content/public/browser/storage_partition.h" | 23 #include "content/public/browser/storage_partition.h" |
| 25 #include "extensions/browser/extension_prefs.h" | 24 #include "extensions/browser/extension_prefs.h" |
| 26 #include "extensions/browser/extension_registry.h" | 25 #include "extensions/browser/extension_registry.h" |
| 27 #include "extensions/browser/extension_system.h" | 26 #include "extensions/browser/extension_system.h" |
| 28 #include "extensions/common/extension.h" | 27 #include "extensions/common/extension.h" |
| 28 #include "extensions/common/file_util.h" |
| 29 | 29 |
| 30 namespace extensions { | 30 namespace extensions { |
| 31 | 31 |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| 34 // Wait this many seconds before trying to garbage collect extensions again. | 34 // Wait this many seconds before trying to garbage collect extensions again. |
| 35 const int kGarbageCollectRetryDelayInSeconds = 30; | 35 const int kGarbageCollectRetryDelayInSeconds = 30; |
| 36 | 36 |
| 37 // Wait this many seconds after startup to see if there are any extensions | 37 // Wait this many seconds after startup to see if there are any extensions |
| 38 // which can be garbage collected. | 38 // which can be garbage collected. |
| 39 const int kGarbageCollectStartupDelay = 30; | 39 const int kGarbageCollectStartupDelay = 30; |
| 40 | 40 |
| 41 typedef std::multimap<std::string, base::FilePath> ExtensionPathsMultimap; | 41 typedef std::multimap<std::string, base::FilePath> ExtensionPathsMultimap; |
| 42 | 42 |
| 43 void CheckExtensionDirectory(const base::FilePath& path, | 43 void CheckExtensionDirectory(const base::FilePath& path, |
| 44 const ExtensionPathsMultimap& extension_paths, | 44 const ExtensionPathsMultimap& extension_paths, |
| 45 bool clean_temp_dir) { | 45 bool clean_temp_dir) { |
| 46 base::FilePath basename = path.BaseName(); | 46 base::FilePath basename = path.BaseName(); |
| 47 // Clean up temporary files left if Chrome crashed or quit in the middle | 47 // Clean up temporary files left if Chrome crashed or quit in the middle |
| 48 // of an extension install. | 48 // of an extension install. |
| 49 if (basename.value() == extension_file_util::kTempDirectoryName) { | 49 if (basename.value() == file_util::kTempDirectoryName) { |
| 50 if (clean_temp_dir) | 50 if (clean_temp_dir) |
| 51 base::DeleteFile(path, true); // Recursive. | 51 base::DeleteFile(path, true); // Recursive. |
| 52 return; | 52 return; |
| 53 } | 53 } |
| 54 | 54 |
| 55 // Parse directory name as a potential extension ID. | 55 // Parse directory name as a potential extension ID. |
| 56 std::string extension_id; | 56 std::string extension_id; |
| 57 if (IsStringASCII(basename.value())) { | 57 if (IsStringASCII(basename.value())) { |
| 58 extension_id = base::UTF16ToASCII(basename.LossyDisplayName()); | 58 extension_id = base::UTF16ToASCII(basename.LossyDisplayName()); |
| 59 if (!Extension::IdIsValid(extension_id)) | 59 if (!Extension::IdIsValid(extension_id)) |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 | 243 |
| 244 extension_service_->OnGarbageCollectIsolatedStorageStart(); | 244 extension_service_->OnGarbageCollectIsolatedStorageStart(); |
| 245 content::BrowserContext::GarbageCollectStoragePartitions( | 245 content::BrowserContext::GarbageCollectStoragePartitions( |
| 246 context_, | 246 context_, |
| 247 active_paths.Pass(), | 247 active_paths.Pass(), |
| 248 base::Bind(&ExtensionService::OnGarbageCollectIsolatedStorageFinished, | 248 base::Bind(&ExtensionService::OnGarbageCollectIsolatedStorageFinished, |
| 249 extension_service_->AsWeakPtr())); | 249 extension_service_->AsWeakPtr())); |
| 250 } | 250 } |
| 251 | 251 |
| 252 } // namespace extensions | 252 } // namespace extensions |
| OLD | NEW |