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

Side by Side Diff: chrome/browser/extensions/extension_garbage_collector.cc

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

Powered by Google App Engine
This is Rietveld 408576698