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 <stddef.h> | 7 #include <stddef.h> |
| 8 |
| 9 #include <memory> |
8 #include <utility> | 10 #include <utility> |
9 | 11 |
10 #include "base/bind.h" | 12 #include "base/bind.h" |
11 #include "base/files/file_enumerator.h" | 13 #include "base/files/file_enumerator.h" |
12 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
13 #include "base/location.h" | 15 #include "base/location.h" |
14 #include "base/logging.h" | 16 #include "base/logging.h" |
15 #include "base/memory/scoped_ptr.h" | |
16 #include "base/sequenced_task_runner.h" | 17 #include "base/sequenced_task_runner.h" |
17 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
18 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
19 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
20 #include "base/thread_task_runner_handle.h" | 21 #include "base/thread_task_runner_handle.h" |
21 #include "base/time/time.h" | 22 #include "base/time/time.h" |
22 #include "chrome/browser/extensions/extension_garbage_collector_factory.h" | 23 #include "chrome/browser/extensions/extension_garbage_collector_factory.h" |
23 #include "chrome/browser/extensions/extension_service.h" | 24 #include "chrome/browser/extensions/extension_service.h" |
24 #include "chrome/browser/extensions/extension_util.h" | 25 #include "chrome/browser/extensions/extension_util.h" |
25 #include "chrome/browser/extensions/install_tracker.h" | 26 #include "chrome/browser/extensions/install_tracker.h" |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 // which may be using the temporary installation directory. Try to garbage | 178 // which may be using the temporary installation directory. Try to garbage |
178 // collect again later. | 179 // collect again later. |
179 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 180 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
180 FROM_HERE, | 181 FROM_HERE, |
181 base::Bind(&ExtensionGarbageCollector::GarbageCollectExtensions, | 182 base::Bind(&ExtensionGarbageCollector::GarbageCollectExtensions, |
182 weak_factory_.GetWeakPtr()), | 183 weak_factory_.GetWeakPtr()), |
183 base::TimeDelta::FromSeconds(kGarbageCollectRetryDelayInSeconds)); | 184 base::TimeDelta::FromSeconds(kGarbageCollectRetryDelayInSeconds)); |
184 return; | 185 return; |
185 } | 186 } |
186 | 187 |
187 scoped_ptr<ExtensionPrefs::ExtensionsInfo> info( | 188 std::unique_ptr<ExtensionPrefs::ExtensionsInfo> info( |
188 extension_prefs->GetInstalledExtensionsInfo()); | 189 extension_prefs->GetInstalledExtensionsInfo()); |
189 std::multimap<std::string, base::FilePath> extension_paths; | 190 std::multimap<std::string, base::FilePath> extension_paths; |
190 for (size_t i = 0; i < info->size(); ++i) { | 191 for (size_t i = 0; i < info->size(); ++i) { |
191 extension_paths.insert( | 192 extension_paths.insert( |
192 std::make_pair(info->at(i)->extension_id, info->at(i)->extension_path)); | 193 std::make_pair(info->at(i)->extension_id, info->at(i)->extension_path)); |
193 } | 194 } |
194 | 195 |
195 info = extension_prefs->GetAllDelayedInstallInfo(); | 196 info = extension_prefs->GetAllDelayedInstallInfo(); |
196 for (size_t i = 0; i < info->size(); ++i) { | 197 for (size_t i = 0; i < info->size(); ++i) { |
197 extension_paths.insert( | 198 extension_paths.insert( |
(...skipping 13 matching lines...) Expand all Loading... |
211 | 212 |
212 void ExtensionGarbageCollector::GarbageCollectIsolatedStorageIfNeeded() { | 213 void ExtensionGarbageCollector::GarbageCollectIsolatedStorageIfNeeded() { |
213 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 214 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
214 | 215 |
215 ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(context_); | 216 ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(context_); |
216 DCHECK(extension_prefs); | 217 DCHECK(extension_prefs); |
217 if (!extension_prefs->NeedsStorageGarbageCollection()) | 218 if (!extension_prefs->NeedsStorageGarbageCollection()) |
218 return; | 219 return; |
219 extension_prefs->SetNeedsStorageGarbageCollection(false); | 220 extension_prefs->SetNeedsStorageGarbageCollection(false); |
220 | 221 |
221 scoped_ptr<base::hash_set<base::FilePath> > active_paths( | 222 std::unique_ptr<base::hash_set<base::FilePath>> active_paths( |
222 new base::hash_set<base::FilePath>()); | 223 new base::hash_set<base::FilePath>()); |
223 scoped_ptr<ExtensionSet> extensions = | 224 std::unique_ptr<ExtensionSet> extensions = |
224 ExtensionRegistry::Get(context_)->GenerateInstalledExtensionsSet(); | 225 ExtensionRegistry::Get(context_)->GenerateInstalledExtensionsSet(); |
225 for (ExtensionSet::const_iterator iter = extensions->begin(); | 226 for (ExtensionSet::const_iterator iter = extensions->begin(); |
226 iter != extensions->end(); | 227 iter != extensions->end(); |
227 ++iter) { | 228 ++iter) { |
228 if (AppIsolationInfo::HasIsolatedStorage(iter->get())) { | 229 if (AppIsolationInfo::HasIsolatedStorage(iter->get())) { |
229 active_paths->insert( | 230 active_paths->insert( |
230 content::BrowserContext::GetStoragePartitionForSite( | 231 content::BrowserContext::GetStoragePartitionForSite( |
231 context_, util::GetSiteForExtensionId((*iter)->id(), context_)) | 232 context_, util::GetSiteForExtensionId((*iter)->id(), context_)) |
232 ->GetPath()); | 233 ->GetPath()); |
233 } | 234 } |
(...skipping 22 matching lines...) Expand all Loading... |
256 // accounting. | 257 // accounting. |
257 NOTREACHED(); | 258 NOTREACHED(); |
258 | 259 |
259 // Don't let the count go negative to avoid garbage collecting when | 260 // Don't let the count go negative to avoid garbage collecting when |
260 // an install is actually in progress. | 261 // an install is actually in progress. |
261 crx_installs_in_progress_ = 0; | 262 crx_installs_in_progress_ = 0; |
262 } | 263 } |
263 } | 264 } |
264 | 265 |
265 } // namespace extensions | 266 } // namespace extensions |
OLD | NEW |