15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved. 25d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// found in the LICENSE file. 45d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/extensions/updater/extension_cache_fake.h" 65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/bind.h" 85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/stl_util.h" 95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "content/public/browser/browser_thread.h" 105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace extensions { 125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)ExtensionCacheFake::ExtensionCacheFake() { 145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ExtensionCache::SetForTesting(this); 155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)ExtensionCacheFake::~ExtensionCacheFake() { 185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ExtensionCache::SetForTesting(NULL); 195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void ExtensionCacheFake::Start(const base::Closure& callback) { 225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) content::BrowserThread::PostTask( 235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) content::BrowserThread::UI, 245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) FROM_HERE, 255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) callback); 265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void ExtensionCacheFake::Shutdown(const base::Closure& callback) { 295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) content::BrowserThread::PostTask( 305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) content::BrowserThread::UI, 315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) FROM_HERE, 325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) callback); 335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void ExtensionCacheFake::AllowCaching(const std::string& id) { 365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) allowed_extensions_.insert(id); 375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool ExtensionCacheFake::GetExtension(const std::string& id, 405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::FilePath* file_path, 415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::string* version) { 425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Map::iterator it = cache_.find(id); 435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (it == cache_.end()) { 445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return false; 455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } else { 465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (version) 475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) *version = it->second.first; 485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (file_path) 495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) *file_path = it->second.second; 505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return true; 515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void ExtensionCacheFake::PutExtension(const std::string& id, 555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const base::FilePath& file_path, 565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& version, 575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const PutExtensionCallback& callback) { 585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (ContainsKey(allowed_extensions_, id)) { 595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) cache_[id].first = version; 605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) cache_[id].second = file_path; 615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) content::BrowserThread::PostTask( 625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) content::BrowserThread::UI, 635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) FROM_HERE, 645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::Bind(callback, file_path, false)); 655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } else { 665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) callback.Run(file_path, true); 675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} // namespace extensions 71