1 // Copyright (c) 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_assets_manager.h" 6 7 #include "base/memory/singleton.h" 8 #include "extensions/common/extension.h" 9 #include "extensions/common/file_util.h" 10 11 #if defined(OS_CHROMEOS) 12 #include "chrome/browser/extensions/extension_assets_manager_chromeos.h" 13 #endif 14 15 namespace extensions { 16 namespace { 17 18 class ExtensionAssetsManagerImpl : public ExtensionAssetsManager { 19 public: 20 static ExtensionAssetsManagerImpl* GetInstance() { 21 return Singleton<ExtensionAssetsManagerImpl>::get(); 22 } 23 24 // Override from ExtensionAssetsManager. 25 virtual void InstallExtension(const Extension* extension, 26 const base::FilePath& unpacked_extension_root, 27 const base::FilePath& local_install_dir, 28 Profile* profile, 29 InstallExtensionCallback callback) OVERRIDE { 30 callback.Run(file_util::InstallExtension( 31 unpacked_extension_root, 32 extension->id(), 33 extension->VersionString(), 34 local_install_dir)); 35 } 36 37 virtual void UninstallExtension( 38 const std::string& id, 39 Profile* profile, 40 const base::FilePath& local_install_dir, 41 const base::FilePath& extension_root) OVERRIDE { 42 file_util::UninstallExtension(local_install_dir, id); 43 } 44 45 private: 46 friend struct DefaultSingletonTraits<ExtensionAssetsManagerImpl>; 47 48 ExtensionAssetsManagerImpl() {} 49 virtual ~ExtensionAssetsManagerImpl() {} 50 51 DISALLOW_COPY_AND_ASSIGN(ExtensionAssetsManagerImpl); 52 }; 53 54 } // namespace 55 56 // static 57 ExtensionAssetsManager* ExtensionAssetsManager::GetInstance() { 58 #if defined(OS_CHROMEOS) 59 return ExtensionAssetsManagerChromeOS::GetInstance(); 60 #else 61 // If not Chrome OS, use trivial implementation that doesn't share anything. 62 return ExtensionAssetsManagerImpl::GetInstance(); 63 #endif // OS_CHROMEOS 64 } 65 66 } // namespace extensions 67