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