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" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 if (version_dir.BaseName() == iter->second.BaseName()) { | 89 if (version_dir.BaseName() == iter->second.BaseName()) { |
90 known_version = true; | 90 known_version = true; |
91 break; | 91 break; |
92 } | 92 } |
93 } | 93 } |
94 if (!known_version) | 94 if (!known_version) |
95 base::DeleteFile(version_dir, true); // Recursive. | 95 base::DeleteFile(version_dir, true); // Recursive. |
96 } | 96 } |
97 } | 97 } |
98 | 98 |
| 99 void GarbageCollectExtensionsOnFileThread( |
| 100 const base::FilePath& install_directory, |
| 101 const ExtensionPathsMultimap& extension_paths) { |
| 102 DCHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 103 |
| 104 // Nothing to clean up if it doesn't exist. |
| 105 if (!base::DirectoryExists(install_directory)) |
| 106 return; |
| 107 |
| 108 base::FileEnumerator enumerator(install_directory, |
| 109 false, // Not recursive. |
| 110 base::FileEnumerator::DIRECTORIES); |
| 111 |
| 112 for (base::FilePath extension_path = enumerator.Next(); |
| 113 !extension_path.empty(); |
| 114 extension_path = enumerator.Next()) { |
| 115 CheckExtensionDirectory(extension_path, extension_paths); |
| 116 } |
| 117 } |
| 118 |
99 } // namespace | 119 } // namespace |
100 | 120 |
101 ExtensionGarbageCollector::ExtensionGarbageCollector( | 121 ExtensionGarbageCollector::ExtensionGarbageCollector( |
102 content::BrowserContext* context) | 122 content::BrowserContext* context) |
103 : context_(context), crx_installs_in_progress_(0), weak_factory_(this) { | 123 : context_(context), crx_installs_in_progress_(0), weak_factory_(this) { |
| 124 #if defined(OS_CHROMEOS) |
| 125 disable_garbage_collection_ = false; |
| 126 #endif |
104 | 127 |
105 ExtensionSystem* extension_system = ExtensionSystem::Get(context_); | 128 ExtensionSystem* extension_system = ExtensionSystem::Get(context_); |
106 DCHECK(extension_system); | 129 DCHECK(extension_system); |
107 | 130 |
108 extension_system->ready().PostDelayed( | 131 extension_system->ready().PostDelayed( |
109 FROM_HERE, | 132 FROM_HERE, |
110 base::Bind(&ExtensionGarbageCollector::GarbageCollectExtensions, | 133 base::Bind(&ExtensionGarbageCollector::GarbageCollectExtensions, |
111 weak_factory_.GetWeakPtr()), | 134 weak_factory_.GetWeakPtr()), |
112 base::TimeDelta::FromSeconds(kGarbageCollectStartupDelay)); | 135 base::TimeDelta::FromSeconds(kGarbageCollectStartupDelay)); |
113 | 136 |
(...skipping 15 matching lines...) Expand all Loading... |
129 } | 152 } |
130 | 153 |
131 void ExtensionGarbageCollector::Shutdown() { | 154 void ExtensionGarbageCollector::Shutdown() { |
132 InstallTracker::Get(context_)->RemoveObserver(this); | 155 InstallTracker::Get(context_)->RemoveObserver(this); |
133 } | 156 } |
134 | 157 |
135 void ExtensionGarbageCollector::GarbageCollectExtensionsForTest() { | 158 void ExtensionGarbageCollector::GarbageCollectExtensionsForTest() { |
136 GarbageCollectExtensions(); | 159 GarbageCollectExtensions(); |
137 } | 160 } |
138 | 161 |
139 // static | |
140 void ExtensionGarbageCollector::GarbageCollectExtensionsOnFileThread( | |
141 const base::FilePath& install_directory, | |
142 const ExtensionPathsMultimap& extension_paths) { | |
143 DCHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
144 | |
145 // Nothing to clean up if it doesn't exist. | |
146 if (!base::DirectoryExists(install_directory)) | |
147 return; | |
148 | |
149 base::FileEnumerator enumerator(install_directory, | |
150 false, // Not recursive. | |
151 base::FileEnumerator::DIRECTORIES); | |
152 | |
153 for (base::FilePath extension_path = enumerator.Next(); | |
154 !extension_path.empty(); | |
155 extension_path = enumerator.Next()) { | |
156 CheckExtensionDirectory(extension_path, extension_paths); | |
157 } | |
158 } | |
159 | |
160 void ExtensionGarbageCollector::GarbageCollectExtensions() { | 162 void ExtensionGarbageCollector::GarbageCollectExtensions() { |
161 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 163 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
162 | 164 |
| 165 #if defined(OS_CHROMEOS) |
| 166 if (disable_garbage_collection_) |
| 167 return; |
| 168 #endif |
| 169 |
163 ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(context_); | 170 ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(context_); |
164 DCHECK(extension_prefs); | 171 DCHECK(extension_prefs); |
165 | 172 |
166 if (extension_prefs->pref_service()->ReadOnly()) | 173 if (extension_prefs->pref_service()->ReadOnly()) |
167 return; | 174 return; |
168 | 175 |
169 if (crx_installs_in_progress_ > 0) { | 176 if (crx_installs_in_progress_ > 0) { |
170 // Don't garbage collect while there are installations in progress, | 177 // Don't garbage collect while there are installations in progress, |
171 // which may be using the temporary installation directory. Try to garbage | 178 // which may be using the temporary installation directory. Try to garbage |
172 // collect again later. | 179 // collect again later. |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 // accounting. | 272 // accounting. |
266 NOTREACHED(); | 273 NOTREACHED(); |
267 | 274 |
268 // Don't let the count go negative to avoid garbage collecting when | 275 // Don't let the count go negative to avoid garbage collecting when |
269 // an install is actually in progress. | 276 // an install is actually in progress. |
270 crx_installs_in_progress_ = 0; | 277 crx_installs_in_progress_ = 0; |
271 } | 278 } |
272 } | 279 } |
273 | 280 |
274 } // namespace extensions | 281 } // namespace extensions |
OLD | NEW |