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 void ExtensionGarbageCollectorChromeOS::GarbageCollectExtensions() { |
| 33 if (disable_garbage_collection_) |
| 34 return; |
| 35 |
| 36 // Process per-profile extensions dir. |
| 37 ExtensionGarbageCollector::GarbageCollectExtensions(); |
| 38 |
| 39 if (!shared_extensions_garbage_collected && |
| 40 CanGarbageCollectSharedExtensions()) { |
| 41 GarbageCollectSharedExtensions(); |
| 42 shared_extensions_garbage_collected = true; |
| 43 } |
| 44 } |
| 45 |
| 46 bool ExtensionGarbageCollectorChromeOS::CanGarbageCollectSharedExtensions() { |
| 47 chromeos::UserManager* user_manager = chromeos::UserManager::Get(); |
| 48 if (!user_manager) { |
| 49 NOTREACHED(); |
| 50 return false; |
| 51 } |
| 52 |
| 53 const chromeos::UserList& active_users = user_manager->GetLoggedInUsers(); |
| 54 for (size_t i = 0; i < active_users.size(); i++) { |
| 55 Profile* profile = user_manager->GetProfileByUser(active_users[i]); |
| 56 ExtensionGarbageCollectorChromeOS* gc = |
| 57 ExtensionGarbageCollectorChromeOS::Get(profile); |
| 58 if (gc->crx_installs_in_progress_ > 0) |
| 59 return false; |
| 60 } |
| 61 |
| 62 return true; |
| 63 } |
| 64 |
| 65 void ExtensionGarbageCollectorChromeOS::GarbageCollectSharedExtensions() { |
| 66 std::multimap<std::string, base::FilePath> paths; |
| 67 if (ExtensionAssetsManagerChromeOS::CleanUpSharedExtensions(&paths)) { |
| 68 ExtensionService* service = |
| 69 ExtensionSystem::Get(context_)->extension_service(); |
| 70 if (!service->GetFileTaskRunner()->PostTask( |
| 71 FROM_HERE, |
| 72 base::Bind(&GarbageCollectExtensionsOnFileThread, |
| 73 ExtensionAssetsManagerChromeOS::GetSharedInstallDir(), |
| 74 paths))) { |
| 75 NOTREACHED(); |
| 76 } |
| 77 } |
| 78 } |
| 79 |
| 80 } // namespace extensions |
OLD | NEW |