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 "chrome/common/extensions/extension_constants.h" |
16 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
17 #include "content/public/browser/notification_details.h" | 18 #include "content/public/browser/notification_details.h" |
18 #include "content/public/browser/notification_service.h" | 19 #include "content/public/browser/notification_service.h" |
19 #include "content/public/browser/notification_source.h" | 20 #include "content/public/browser/notification_source.h" |
20 | 21 |
21 namespace extensions { | 22 namespace extensions { |
22 namespace { | 23 namespace { |
23 | 24 |
24 #if defined(OS_CHROMEOS) | 25 #if defined(OS_CHROMEOS) |
25 const char kLocalCacheDir[] = "/var/cache/external_cache"; | 26 const char kLocalCacheDir[] = "/var/cache/external_cache"; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 } | 66 } |
66 | 67 |
67 void ExtensionCacheImpl::Shutdown(const base::Closure& callback) { | 68 void ExtensionCacheImpl::Shutdown(const base::Closure& callback) { |
68 if (cache_) | 69 if (cache_) |
69 cache_->Shutdown(callback); | 70 cache_->Shutdown(callback); |
70 else | 71 else |
71 callback.Run(); | 72 callback.Run(); |
72 } | 73 } |
73 | 74 |
74 void ExtensionCacheImpl::AllowCaching(const std::string& id) { | 75 void ExtensionCacheImpl::AllowCaching(const std::string& id) { |
| 76 // Temporary workaround for M41, this extension should not be cached. |
| 77 // TODO(ginkage): Implement id/hash-based map instead of id/version. |
| 78 if (id == extension_misc::kHotwordSharedModuleId) |
| 79 return; |
75 allowed_extensions_.insert(id); | 80 allowed_extensions_.insert(id); |
76 } | 81 } |
77 | 82 |
78 bool ExtensionCacheImpl::GetExtension(const std::string& id, | 83 bool ExtensionCacheImpl::GetExtension(const std::string& id, |
79 base::FilePath* file_path, | 84 base::FilePath* file_path, |
80 std::string* version) { | 85 std::string* version) { |
81 if (cache_) | 86 if (cache_ && CachingAllowed(id)) |
82 return cache_->GetExtension(id, file_path, version); | 87 return cache_->GetExtension(id, file_path, version); |
83 else | 88 else |
84 return false; | 89 return false; |
85 } | 90 } |
86 | 91 |
87 void ExtensionCacheImpl::PutExtension(const std::string& id, | 92 void ExtensionCacheImpl::PutExtension(const std::string& id, |
88 const base::FilePath& file_path, | 93 const base::FilePath& file_path, |
89 const std::string& version, | 94 const std::string& version, |
90 const PutExtensionCallback& callback) { | 95 const PutExtensionCallback& callback) { |
91 if (cache_ && ContainsKey(allowed_extensions_, id)) | 96 if (cache_ && CachingAllowed(id)) |
92 cache_->PutExtension(id, file_path, version, callback); | 97 cache_->PutExtension(id, file_path, version, callback); |
93 else | 98 else |
94 callback.Run(file_path, true); | 99 callback.Run(file_path, true); |
95 } | 100 } |
96 | 101 |
| 102 bool ExtensionCacheImpl::CachingAllowed(const std::string& id) { |
| 103 return ContainsKey(allowed_extensions_, id) && |
| 104 id != extension_misc::kHotwordSharedModuleId; |
| 105 } |
| 106 |
97 void ExtensionCacheImpl::OnCacheInitialized() { | 107 void ExtensionCacheImpl::OnCacheInitialized() { |
98 for (std::vector<base::Closure>::iterator it = init_callbacks_.begin(); | 108 for (std::vector<base::Closure>::iterator it = init_callbacks_.begin(); |
99 it != init_callbacks_.end(); ++it) { | 109 it != init_callbacks_.end(); ++it) { |
100 it->Run(); | 110 it->Run(); |
101 } | 111 } |
102 init_callbacks_.clear(); | 112 init_callbacks_.clear(); |
103 | 113 |
104 uint64 cache_size = 0; | 114 uint64 cache_size = 0; |
105 size_t extensions_count = 0; | 115 size_t extensions_count = 0; |
106 if (cache_->GetStatistics(&cache_size, &extensions_count)) { | 116 if (cache_->GetStatistics(&cache_size, &extensions_count)) { |
(...skipping 19 matching lines...) Expand all Loading... |
126 cache_->RemoveExtension(installer->expected_id()); | 136 cache_->RemoveExtension(installer->expected_id()); |
127 break; | 137 break; |
128 } | 138 } |
129 | 139 |
130 default: | 140 default: |
131 NOTREACHED(); | 141 NOTREACHED(); |
132 } | 142 } |
133 } | 143 } |
134 | 144 |
135 } // namespace extensions | 145 } // namespace extensions |
OLD | NEW |