OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "chrome/browser/extensions/extension_garbage_collector_chromeos.h" |
| 6 |
| 7 #include "chrome/browser/chromeos/login/users/user_manager.h" |
| 8 #include "chrome/browser/extensions/extension_assets_manager_chromeos.h" |
| 9 #include "chrome/browser/extensions/extension_service.h" |
| 10 #include "extensions/browser/extension_system.h" |
| 11 |
| 12 namespace extensions { |
| 13 |
| 14 bool ExtensionGarbageCollectorChromeOS::shared_extensions_garbage_collected_ = |
| 15 false; |
| 16 |
| 17 ExtensionGarbageCollectorChromeOS::ExtensionGarbageCollectorChromeOS( |
| 18 content::BrowserContext* context) |
| 19 : ExtensionGarbageCollector(context), |
| 20 disable_garbage_collection_(false) { |
| 21 } |
| 22 |
| 23 ExtensionGarbageCollectorChromeOS::~ExtensionGarbageCollectorChromeOS() {} |
| 24 |
| 25 // static |
| 26 ExtensionGarbageCollectorChromeOS* ExtensionGarbageCollectorChromeOS::Get( |
| 27 content::BrowserContext* context) { |
| 28 return static_cast<ExtensionGarbageCollectorChromeOS*>( |
| 29 ExtensionGarbageCollector::Get(context)); |
| 30 } |
| 31 |
| 32 // static |
| 33 void ExtensionGarbageCollectorChromeOS::ClearGarbageCollectedForTesting() { |
| 34 shared_extensions_garbage_collected_ = false; |
| 35 } |
| 36 |
| 37 void ExtensionGarbageCollectorChromeOS::GarbageCollectExtensions() { |
| 38 if (disable_garbage_collection_) |
| 39 return; |
| 40 |
| 41 // Process per-profile extensions dir. |
| 42 ExtensionGarbageCollector::GarbageCollectExtensions(); |
| 43 |
| 44 if (!shared_extensions_garbage_collected_ && |
| 45 CanGarbageCollectSharedExtensions()) { |
| 46 GarbageCollectSharedExtensions(); |
| 47 shared_extensions_garbage_collected_ = true; |
| 48 } |
| 49 } |
| 50 |
| 51 bool ExtensionGarbageCollectorChromeOS::CanGarbageCollectSharedExtensions() { |
| 52 chromeos::UserManager* user_manager = chromeos::UserManager::Get(); |
| 53 if (!user_manager) { |
| 54 NOTREACHED(); |
| 55 return false; |
| 56 } |
| 57 |
| 58 const chromeos::UserList& active_users = user_manager->GetLoggedInUsers(); |
| 59 for (size_t i = 0; i < active_users.size(); i++) { |
| 60 Profile* profile = user_manager->GetProfileByUser(active_users[i]); |
| 61 ExtensionGarbageCollectorChromeOS* gc = |
| 62 ExtensionGarbageCollectorChromeOS::Get(profile); |
| 63 if (gc->crx_installs_in_progress_ > 0) |
| 64 return false; |
| 65 } |
| 66 |
| 67 return true; |
| 68 } |
| 69 |
| 70 void ExtensionGarbageCollectorChromeOS::GarbageCollectSharedExtensions() { |
| 71 std::multimap<std::string, base::FilePath> paths; |
| 72 if (ExtensionAssetsManagerChromeOS::CleanUpSharedExtensions(&paths)) { |
| 73 ExtensionService* service = |
| 74 ExtensionSystem::Get(context_)->extension_service(); |
| 75 if (!service->GetFileTaskRunner()->PostTask( |
| 76 FROM_HERE, |
| 77 base::Bind(&GarbageCollectExtensionsOnFileThread, |
| 78 ExtensionAssetsManagerChromeOS::GetSharedInstallDir(), |
| 79 paths))) { |
| 80 NOTREACHED(); |
| 81 } |
| 82 } |
| 83 } |
| 84 |
| 85 } // namespace extensions |
OLD | NEW |