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
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/profiles/profile_helper.h"
6 #include "chrome/browser/extensions/extension_assets_manager_chromeos.h"
7 #include "chrome/browser/extensions/extension_garbage_collector_chromeos.h"
8 #include "chrome/browser/extensions/extension_service.h"
9 #include "components/user_manager/user_manager.h"
10 #include "extensions/browser/extension_system.h"
12 namespace extensions
{
14 bool ExtensionGarbageCollectorChromeOS::shared_extensions_garbage_collected_
=
17 ExtensionGarbageCollectorChromeOS::ExtensionGarbageCollectorChromeOS(
18 content::BrowserContext
* context
)
19 : ExtensionGarbageCollector(context
),
20 disable_garbage_collection_(false) {
23 ExtensionGarbageCollectorChromeOS::~ExtensionGarbageCollectorChromeOS() {}
26 ExtensionGarbageCollectorChromeOS
* ExtensionGarbageCollectorChromeOS::Get(
27 content::BrowserContext
* context
) {
28 return static_cast<ExtensionGarbageCollectorChromeOS
*>(
29 ExtensionGarbageCollector::Get(context
));
33 void ExtensionGarbageCollectorChromeOS::ClearGarbageCollectedForTesting() {
34 shared_extensions_garbage_collected_
= false;
37 void ExtensionGarbageCollectorChromeOS::GarbageCollectExtensions() {
38 if (disable_garbage_collection_
)
41 // Process per-profile extensions dir.
42 ExtensionGarbageCollector::GarbageCollectExtensions();
44 if (!shared_extensions_garbage_collected_
&&
45 CanGarbageCollectSharedExtensions()) {
46 GarbageCollectSharedExtensions();
47 shared_extensions_garbage_collected_
= true;
51 bool ExtensionGarbageCollectorChromeOS::CanGarbageCollectSharedExtensions() {
52 user_manager::UserManager
* user_manager
= user_manager::UserManager::Get();
58 const user_manager::UserList
& active_users
= user_manager
->GetLoggedInUsers();
59 for (size_t i
= 0; i
< active_users
.size(); i
++) {
61 chromeos::ProfileHelper::Get()->GetProfileByUserUnsafe(active_users
[i
]);
62 ExtensionGarbageCollectorChromeOS
* gc
=
63 ExtensionGarbageCollectorChromeOS::Get(profile
);
64 if (gc
&& gc
->crx_installs_in_progress_
> 0)
71 void ExtensionGarbageCollectorChromeOS::GarbageCollectSharedExtensions() {
72 std::multimap
<std::string
, base::FilePath
> paths
;
73 if (ExtensionAssetsManagerChromeOS::CleanUpSharedExtensions(&paths
)) {
74 ExtensionService
* service
=
75 ExtensionSystem::Get(context_
)->extension_service();
76 if (!service
->GetFileTaskRunner()->PostTask(
78 base::Bind(&GarbageCollectExtensionsOnFileThread
,
79 ExtensionAssetsManagerChromeOS::GetSharedInstallDir(),
86 } // namespace extensions