| 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/sequenced_task_runner.h" | 10 #include "base/sequenced_task_runner.h" |
| 10 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 11 #include "base/threading/sequenced_worker_pool.h" | 12 #include "base/threading/sequenced_worker_pool.h" |
| 12 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
| 13 #include "chrome/browser/extensions/crx_installer.h" | 14 #include "chrome/browser/extensions/crx_installer.h" |
| 14 #include "chrome/browser/extensions/updater/local_extension_cache.h" | 15 #include "chrome/browser/extensions/updater/local_extension_cache.h" |
| 15 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 16 #include "content/public/browser/notification_details.h" | 17 #include "content/public/browser/notification_details.h" |
| 17 #include "content/public/browser/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
| 18 #include "content/public/browser/notification_source.h" | 19 #include "content/public/browser/notification_source.h" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 else | 98 else |
| 98 callback.Run(file_path, true); | 99 callback.Run(file_path, true); |
| 99 } | 100 } |
| 100 | 101 |
| 101 void ExtensionCacheImpl::OnCacheInitialized() { | 102 void ExtensionCacheImpl::OnCacheInitialized() { |
| 102 for (std::vector<base::Closure>::iterator it = init_callbacks_.begin(); | 103 for (std::vector<base::Closure>::iterator it = init_callbacks_.begin(); |
| 103 it != init_callbacks_.end(); ++it) { | 104 it != init_callbacks_.end(); ++it) { |
| 104 it->Run(); | 105 it->Run(); |
| 105 } | 106 } |
| 106 init_callbacks_.clear(); | 107 init_callbacks_.clear(); |
| 108 |
| 109 uint64 cache_size = 0; |
| 110 size_t extensions_count = 0; |
| 111 if (cache_->GetStatistics(&cache_size, &extensions_count)) { |
| 112 UMA_HISTOGRAM_COUNTS_100("Extensions.ExtensionCacheCount", |
| 113 extensions_count); |
| 114 UMA_HISTOGRAM_MEMORY_MB("Extensions.ExtensionCacheSize", |
| 115 cache_size / (1024 * 1024)); |
| 116 } |
| 107 } | 117 } |
| 108 | 118 |
| 109 void ExtensionCacheImpl::Observe(int type, | 119 void ExtensionCacheImpl::Observe(int type, |
| 110 const content::NotificationSource& source, | 120 const content::NotificationSource& source, |
| 111 const content::NotificationDetails& details) { | 121 const content::NotificationDetails& details) { |
| 112 if (!cache_) | 122 if (!cache_) |
| 113 return; | 123 return; |
| 114 | 124 |
| 115 switch (type) { | 125 switch (type) { |
| 116 case chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR: { | 126 case chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR: { |
| 117 extensions::CrxInstaller* installer = | 127 extensions::CrxInstaller* installer = |
| 118 content::Source<extensions::CrxInstaller>(source).ptr(); | 128 content::Source<extensions::CrxInstaller>(source).ptr(); |
| 119 // TODO(dpolukhin): remove extension from cache only if installation | 129 // TODO(dpolukhin): remove extension from cache only if installation |
| 120 // failed due to file corruption. | 130 // failed due to file corruption. |
| 121 cache_->RemoveExtension(installer->expected_id()); | 131 cache_->RemoveExtension(installer->expected_id()); |
| 122 break; | 132 break; |
| 123 } | 133 } |
| 124 | 134 |
| 125 default: | 135 default: |
| 126 NOTREACHED(); | 136 NOTREACHED(); |
| 127 } | 137 } |
| 128 } | 138 } |
| 129 | 139 |
| 130 } // namespace extensions | 140 } // namespace extensions |
| OLD | NEW |