ba8255651d8a9909d05416e220865f1d55946e59
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / updater / extension_cache_fake.cc
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_fake.h"
6
7 #include "base/bind.h"
8 #include "base/stl_util.h"
9 #include "content/public/browser/browser_thread.h"
10
11 namespace extensions {
12
13 ExtensionCacheFake::ExtensionCacheFake() {
14 }
15
16 ExtensionCacheFake::~ExtensionCacheFake() {
17 }
18
19 void ExtensionCacheFake::Start(const base::Closure& callback) {
20   content::BrowserThread::PostTask(
21       content::BrowserThread::UI,
22       FROM_HERE,
23       callback);
24 }
25
26 void ExtensionCacheFake::Shutdown(const base::Closure& callback) {
27   content::BrowserThread::PostTask(
28       content::BrowserThread::UI,
29       FROM_HERE,
30       callback);
31 }
32
33 void ExtensionCacheFake::AllowCaching(const std::string& id) {
34   allowed_extensions_.insert(id);
35 }
36
37 bool ExtensionCacheFake::GetExtension(const std::string& id,
38                                       base::FilePath* file_path,
39                                       std::string* version) {
40   Map::iterator it = cache_.find(id);
41   if (it == cache_.end()) {
42     return false;
43   } else {
44     if (version)
45       *version = it->second.first;
46     if (file_path)
47       *file_path = it->second.second;
48     return true;
49   }
50 }
51
52 void ExtensionCacheFake::PutExtension(const std::string& id,
53                                       const base::FilePath& file_path,
54                                       const std::string& version,
55                                       const PutExtensionCallback& callback) {
56   if (ContainsKey(allowed_extensions_, id)) {
57     cache_[id].first = version;
58     cache_[id].second = file_path;
59     content::BrowserThread::PostTask(
60         content::BrowserThread::UI,
61         FROM_HERE,
62         base::Bind(callback, file_path, false));
63   } else {
64     callback.Run(file_path, true);
65   }
66 }
67
68 }  // namespace extensions