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/updater/extension_cache.h" 6 7#include "base/memory/singleton.h" 8 9#if defined(OS_CHROMEOS) 10#include "chrome/browser/extensions/updater/extension_cache_impl.h" 11#endif // OS_CHROMEOS 12 13namespace extensions { 14namespace { 15 16#if !defined(OS_CHROMEOS) 17 18// Implementation of ExtensionCache that doesn't cache anything. 19// Real cache is used only on Chrome OS other OSes use this null implementation. 20class ExtensionCacheNullImpl : public ExtensionCache { 21 public: 22 static ExtensionCacheNullImpl* GetInstance() { 23 return Singleton<ExtensionCacheNullImpl>::get(); 24 } 25 26 // Implementation of ExtensionCache. 27 virtual void Start(const base::Closure& callback) OVERRIDE { 28 callback.Run(); 29 } 30 31 virtual void Shutdown(const base::Closure& callback) OVERRIDE { 32 callback.Run(); 33 } 34 35 virtual void AllowCaching(const std::string& id) OVERRIDE { 36 } 37 38 virtual bool GetExtension(const std::string& id, 39 base::FilePath* file_path, 40 std::string* version) OVERRIDE { 41 return false; 42 } 43 44 virtual void PutExtension(const std::string& id, 45 const base::FilePath& file_path, 46 const std::string& version, 47 const PutExtensionCallback& callback) OVERRIDE { 48 callback.Run(file_path, true); 49 } 50 51 private: 52 friend struct DefaultSingletonTraits<ExtensionCacheNullImpl>; 53 54 ExtensionCacheNullImpl() {} 55 virtual ~ExtensionCacheNullImpl() {} 56}; 57 58#endif // !OS_CHROMEOS 59 60static ExtensionCache* g_extension_cache_override = NULL; 61 62} // namespace 63 64// static 65ExtensionCache* ExtensionCache::GetInstance() { 66 if (g_extension_cache_override) { 67 return g_extension_cache_override; 68 } else { 69#if defined(OS_CHROMEOS) 70 return ExtensionCacheImpl::GetInstance(); 71#else 72 return ExtensionCacheNullImpl::GetInstance(); 73#endif 74 } 75} 76 77// static 78ExtensionCache* ExtensionCache::SetForTesting(ExtensionCache* cache) { 79 ExtensionCache* temp = g_extension_cache_override; 80 g_extension_cache_override = cache; 81 return temp; 82} 83 84} // namespace extensions 85