1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#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);
}
}
} // namespace extensions
|