OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/installed_loader.h" | 5 #include "chrome/browser/extensions/installed_loader.h" |
6 | 6 |
7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
10 #include "base/threading/thread_restrictions.h" | 10 #include "base/threading/thread_restrictions.h" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 namespace extensions { | 81 namespace extensions { |
82 | 82 |
83 InstalledLoader::InstalledLoader(ExtensionService* extension_service) | 83 InstalledLoader::InstalledLoader(ExtensionService* extension_service) |
84 : extension_service_(extension_service), | 84 : extension_service_(extension_service), |
85 extension_prefs_(extension_service->extension_prefs()) { | 85 extension_prefs_(extension_service->extension_prefs()) { |
86 } | 86 } |
87 | 87 |
88 InstalledLoader::~InstalledLoader() { | 88 InstalledLoader::~InstalledLoader() { |
89 } | 89 } |
90 | 90 |
91 void InstalledLoader::Load(const ExtensionInfo& info, bool write_to_prefs) { | 91 scoped_refptr<const Extension> InstalledLoader::Load(const ExtensionInfo& info, |
| 92 bool write_to_prefs) { |
92 std::string error; | 93 std::string error; |
93 scoped_refptr<const Extension> extension(NULL); | 94 scoped_refptr<const Extension> extension(NULL); |
94 if (info.extension_manifest.get()) { | 95 if (info.extension_manifest.get()) { |
95 extension = Extension::Create( | 96 extension = Extension::Create( |
96 info.extension_path, | 97 info.extension_path, |
97 info.extension_location, | 98 info.extension_location, |
98 *info.extension_manifest, | 99 *info.extension_manifest, |
99 GetCreationFlags(&info), | 100 GetCreationFlags(&info), |
100 &error); | 101 &error); |
101 } else { | 102 } else { |
(...skipping 19 matching lines...) Expand all Loading... |
121 !policy->UserMayLoad(extension, NULL)) { | 122 !policy->UserMayLoad(extension, NULL)) { |
122 // The error message from UserMayInstall() often contains the extension ID | 123 // The error message from UserMayInstall() often contains the extension ID |
123 // and is therefore not well suited to this UI. | 124 // and is therefore not well suited to this UI. |
124 error = errors::kDisabledByPolicy; | 125 error = errors::kDisabledByPolicy; |
125 extension = NULL; | 126 extension = NULL; |
126 } | 127 } |
127 | 128 |
128 if (!extension) { | 129 if (!extension) { |
129 extension_service_-> | 130 extension_service_-> |
130 ReportExtensionLoadError(info.extension_path, error, false); | 131 ReportExtensionLoadError(info.extension_path, error, false); |
131 return; | 132 return scoped_refptr<const Extension>(); |
132 } | 133 } |
133 | 134 |
134 if (write_to_prefs) | 135 if (write_to_prefs) |
135 extension_prefs_->UpdateManifest(extension); | 136 extension_prefs_->UpdateManifest(extension); |
136 | 137 |
137 extension_service_->AddExtension(extension); | 138 return extension; |
138 } | 139 } |
139 | 140 |
140 void InstalledLoader::LoadAllExtensions() { | 141 void InstalledLoader::LoadAllExtensions() { |
141 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 142 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
142 | 143 |
143 base::TimeTicks start_time = base::TimeTicks::Now(); | 144 base::TimeTicks start_time = base::TimeTicks::Now(); |
144 | 145 |
145 scoped_ptr<ExtensionPrefs::ExtensionsInfo> extensions_info( | 146 scoped_ptr<ExtensionPrefs::ExtensionsInfo> extensions_info( |
146 extension_prefs_->GetInstalledExtensionsInfo()); | 147 extension_prefs_->GetInstalledExtensionsInfo()); |
147 | 148 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 continue; | 206 continue; |
206 } | 207 } |
207 | 208 |
208 extensions_info->at(i)->extension_manifest.reset( | 209 extensions_info->at(i)->extension_manifest.reset( |
209 static_cast<DictionaryValue*>( | 210 static_cast<DictionaryValue*>( |
210 extension->manifest()->value()->DeepCopy())); | 211 extension->manifest()->value()->DeepCopy())); |
211 should_write_prefs = true; | 212 should_write_prefs = true; |
212 } | 213 } |
213 } | 214 } |
214 | 215 |
| 216 std::vector<scoped_refptr<const Extension> > loaded_extensions; |
215 for (size_t i = 0; i < extensions_info->size(); ++i) { | 217 for (size_t i = 0; i < extensions_info->size(); ++i) { |
216 Load(*extensions_info->at(i), should_write_prefs); | 218 scoped_refptr<const Extension> loaded_extension = |
| 219 Load(*extensions_info->at(i), should_write_prefs); |
| 220 if (loaded_extension) |
| 221 loaded_extensions.push_back(loaded_extension); |
217 } | 222 } |
218 | 223 |
| 224 extension_service_->AddExtensions(loaded_extensions); |
219 extension_service_->OnLoadedInstalledExtensions(); | 225 extension_service_->OnLoadedInstalledExtensions(); |
220 | 226 |
221 // The histograms Extensions.ManifestReload* allow us to validate | 227 // The histograms Extensions.ManifestReload* allow us to validate |
222 // the assumption that reloading manifest is a rare event. | 228 // the assumption that reloading manifest is a rare event. |
223 UMA_HISTOGRAM_COUNTS_100("Extensions.ManifestReloadNotNeeded", | 229 UMA_HISTOGRAM_COUNTS_100("Extensions.ManifestReloadNotNeeded", |
224 reload_reason_counts[NOT_NEEDED]); | 230 reload_reason_counts[NOT_NEEDED]); |
225 UMA_HISTOGRAM_COUNTS_100("Extensions.ManifestReloadUnpackedDir", | 231 UMA_HISTOGRAM_COUNTS_100("Extensions.ManifestReloadUnpackedDir", |
226 reload_reason_counts[UNPACKED_DIR]); | 232 reload_reason_counts[UNPACKED_DIR]); |
227 UMA_HISTOGRAM_COUNTS_100("Extensions.ManifestReloadNeedsRelocalization", | 233 UMA_HISTOGRAM_COUNTS_100("Extensions.ManifestReloadNeedsRelocalization", |
228 reload_reason_counts[NEEDS_RELOCALIZATION]); | 234 reload_reason_counts[NEEDS_RELOCALIZATION]); |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 int InstalledLoader::GetCreationFlags(const ExtensionInfo* info) { | 377 int InstalledLoader::GetCreationFlags(const ExtensionInfo* info) { |
372 int flags = extension_prefs_->GetCreationFlags(info->extension_id); | 378 int flags = extension_prefs_->GetCreationFlags(info->extension_id); |
373 if (info->extension_location != Manifest::LOAD) | 379 if (info->extension_location != Manifest::LOAD) |
374 flags |= Extension::REQUIRE_KEY; | 380 flags |= Extension::REQUIRE_KEY; |
375 if (extension_prefs_->AllowFileAccess(info->extension_id)) | 381 if (extension_prefs_->AllowFileAccess(info->extension_id)) |
376 flags |= Extension::ALLOW_FILE_ACCESS; | 382 flags |= Extension::ALLOW_FILE_ACCESS; |
377 return flags; | 383 return flags; |
378 } | 384 } |
379 | 385 |
380 } // namespace extensions | 386 } // namespace extensions |
OLD | NEW |