OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/extensions/updater/extension_cache_impl.h" | 5 #include "chrome/browser/extensions/updater/extension_cache_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/singleton.h" | 8 #include "base/memory/singleton.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/sequenced_task_runner.h" | 10 #include "base/sequenced_task_runner.h" |
11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
12 #include "base/threading/sequenced_worker_pool.h" | 12 #include "base/threading/sequenced_worker_pool.h" |
13 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
14 #include "chrome/browser/extensions/crx_installer.h" | 14 #include "chrome/browser/extensions/crx_installer.h" |
15 #include "chrome/browser/extensions/updater/local_extension_cache.h" | 15 #include "chrome/browser/extensions/updater/local_extension_cache.h" |
16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
17 #include "content/public/browser/notification_details.h" | 17 #include "content/public/browser/notification_details.h" |
18 #include "content/public/browser/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
19 #include "content/public/browser/notification_source.h" | 19 #include "content/public/browser/notification_source.h" |
20 | 20 |
21 namespace extensions { | 21 namespace extensions { |
22 namespace { | 22 namespace { |
23 | 23 |
24 // Temporary workaround for M41, this extension should not be cached. | |
25 // TODO: Implement id/hash-based map instead of id/version. | |
Dmitry Polukhin
2015/01/15 09:40:38
Please use TODO(ginkage)... as in style guide and
| |
26 const char kBlacklistedExt[] = "lccekmodgklaepjeofjdjpbminllajkg"; | |
Dmitry Polukhin
2015/01/15 09:40:38
This constant already exists kHotwordSharedModuleI
| |
27 | |
24 #if defined(OS_CHROMEOS) | 28 #if defined(OS_CHROMEOS) |
25 const char kLocalCacheDir[] = "/var/cache/external_cache"; | 29 const char kLocalCacheDir[] = "/var/cache/external_cache"; |
26 #else | 30 #else |
27 #error Please define kLocalCacheDir suitable for target OS | 31 #error Please define kLocalCacheDir suitable for target OS |
28 #endif// Directory where the extensions are cached. | 32 #endif// Directory where the extensions are cached. |
29 | 33 |
30 // Maximum size of local cache on disk. | 34 // Maximum size of local cache on disk. |
31 size_t kMaxCacheSize = 100 * 1024 * 1024; | 35 size_t kMaxCacheSize = 100 * 1024 * 1024; |
32 | 36 |
33 // Maximum age of unused extensions in cache. | 37 // Maximum age of unused extensions in cache. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
65 } | 69 } |
66 | 70 |
67 void ExtensionCacheImpl::Shutdown(const base::Closure& callback) { | 71 void ExtensionCacheImpl::Shutdown(const base::Closure& callback) { |
68 if (cache_) | 72 if (cache_) |
69 cache_->Shutdown(callback); | 73 cache_->Shutdown(callback); |
70 else | 74 else |
71 callback.Run(); | 75 callback.Run(); |
72 } | 76 } |
73 | 77 |
74 void ExtensionCacheImpl::AllowCaching(const std::string& id) { | 78 void ExtensionCacheImpl::AllowCaching(const std::string& id) { |
79 if (id == kBlacklistedExt) | |
80 return; | |
75 allowed_extensions_.insert(id); | 81 allowed_extensions_.insert(id); |
76 } | 82 } |
77 | 83 |
78 bool ExtensionCacheImpl::GetExtension(const std::string& id, | 84 bool ExtensionCacheImpl::GetExtension(const std::string& id, |
79 base::FilePath* file_path, | 85 base::FilePath* file_path, |
80 std::string* version) { | 86 std::string* version) { |
81 if (cache_) | 87 if (cache_ && id != kBlacklistedExt) |
Dmitry Polukhin
2015/01/15 09:40:38
I would check if caching allowed like this 'Contai
ginkage
2015/01/15 15:02:24
I'm not really sure: I've added this check for cas
Dmitry Polukhin
2015/01/15 15:07:48
Yes, check in GetExtension required to recover if
| |
82 return cache_->GetExtension(id, file_path, version); | 88 return cache_->GetExtension(id, file_path, version); |
83 else | 89 else |
84 return false; | 90 return false; |
85 } | 91 } |
86 | 92 |
87 void ExtensionCacheImpl::PutExtension(const std::string& id, | 93 void ExtensionCacheImpl::PutExtension(const std::string& id, |
88 const base::FilePath& file_path, | 94 const base::FilePath& file_path, |
89 const std::string& version, | 95 const std::string& version, |
90 const PutExtensionCallback& callback) { | 96 const PutExtensionCallback& callback) { |
91 if (cache_ && ContainsKey(allowed_extensions_, id)) | 97 if (cache_ && ContainsKey(allowed_extensions_, id)) |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
126 cache_->RemoveExtension(installer->expected_id()); | 132 cache_->RemoveExtension(installer->expected_id()); |
127 break; | 133 break; |
128 } | 134 } |
129 | 135 |
130 default: | 136 default: |
131 NOTREACHED(); | 137 NOTREACHED(); |
132 } | 138 } |
133 } | 139 } |
134 | 140 |
135 } // namespace extensions | 141 } // namespace extensions |
OLD | NEW |