This source file includes following definitions.
- Start
- Shutdown
- AllowCaching
- GetExtension
- PutExtension
#include "chrome/browser/extensions/updater/extension_cache_fake.h"
#include "base/bind.h"
#include "base/stl_util.h"
#include "content/public/browser/browser_thread.h"
namespace extensions {
ExtensionCacheFake::ExtensionCacheFake() {
ExtensionCache::SetForTesting(this);
}
ExtensionCacheFake::~ExtensionCacheFake() {
ExtensionCache::SetForTesting(NULL);
}
void ExtensionCacheFake::Start(const base::Closure& callback) {
content::BrowserThread::PostTask(
content::BrowserThread::UI,
FROM_HERE,
callback);
}
void ExtensionCacheFake::Shutdown(const base::Closure& callback) {
content::BrowserThread::PostTask(
content::BrowserThread::UI,
FROM_HERE,
callback);
}
void ExtensionCacheFake::AllowCaching(const std::string& id) {
allowed_extensions_.insert(id);
}
bool ExtensionCacheFake::GetExtension(const std::string& id,
base::FilePath* file_path,
std::string* version) {
Map::iterator it = cache_.find(id);
if (it == cache_.end()) {
return false;
} else {
if (version)
*version = it->second.first;
if (file_path)
*file_path = it->second.second;
return true;
}
}
void ExtensionCacheFake::PutExtension(const std::string& id,
const base::FilePath& file_path,
const std::string& version,
const PutExtensionCallback& callback) {
if (ContainsKey(allowed_extensions_, id)) {
cache_[id].first = version;
cache_[id].second = file_path;
content::BrowserThread::PostTask(
content::BrowserThread::UI,
FROM_HERE,
base::Bind(callback, file_path, false));
} else {
callback.Run(file_path, true);
}
}
}