Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Side by Side Diff: chrome/browser/extensions/installed_loader.cc

Issue 540673002: Enable forced extension updates on NaCl arch mismatch. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/bind.h"
8 #include "base/callback.h"
9 #include "base/files/file_enumerator.h"
7 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/files/file_util.h"
8 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
9 #include "base/metrics/sparse_histogram.h" 13 #include "base/metrics/sparse_histogram.h"
10 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
11 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
12 #include "base/threading/thread_restrictions.h" 16 #include "base/threading/thread_restrictions.h"
13 #include "base/values.h" 17 #include "base/values.h"
14 #include "chrome/browser/browser_process.h" 18 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/extensions/extension_action_manager.h" 19 #include "chrome/browser/extensions/extension_action_manager.h"
16 #include "chrome/browser/extensions/extension_error_reporter.h" 20 #include "chrome/browser/extensions/extension_error_reporter.h"
17 #include "chrome/browser/extensions/extension_service.h" 21 #include "chrome/browser/extensions/extension_service.h"
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 if (reasons == Extension::DISABLE_NONE) { 153 if (reasons == Extension::DISABLE_NONE) {
150 RecordDisbleReasonHistogram(Extension::DISABLE_NONE); 154 RecordDisbleReasonHistogram(Extension::DISABLE_NONE);
151 return; 155 return;
152 } 156 }
153 for (int reason = 1; reason < Extension::DISABLE_REASON_LAST; reason <<= 1) { 157 for (int reason = 1; reason < Extension::DISABLE_REASON_LAST; reason <<= 1) {
154 if (reasons & reason) 158 if (reasons & reason)
155 RecordDisbleReasonHistogram(reason); 159 RecordDisbleReasonHistogram(reason);
156 } 160 }
157 } 161 }
158 162
163 void RespondWithPlatformSpecificResourceArchs(
164 const base::Callback<void(const std::set<std::string>&)>& callback,
165 scoped_ptr<std::set<std::string> > archs) {
166 callback.Run(*archs.get());
167 }
168
169 void CollectPlatformSpecificResourceArchsOnBlockingPool(
170 const base::FilePath& extension_path,
171 const base::Callback<void(const std::set<std::string>&)>& callback) {
172 scoped_ptr<std::set<std::string > > archs(new std::set<std::string>());
173 base::FilePath platform_specific_path = extension_path.Append(
174 kPlatformSpecificFolder);
175 if (base::PathExists(platform_specific_path)) {
176 base::FileEnumerator all_archs(platform_specific_path,
177 false,
178 base::FileEnumerator::DIRECTORIES);
179 base::FilePath arch;
180 while (!(arch = all_archs.Next()).empty()) {
181 std::string arch_name = arch.BaseName().AsUTF8Unsafe();
182 std::replace(arch_name.begin(), arch_name.end(), '_', '-');
183 archs->insert(arch_name);
184 }
185 }
186 BrowserThread::PostTask(
187 BrowserThread::UI,
188 FROM_HERE,
189 base::Bind(&RespondWithPlatformSpecificResourceArchs,
190 callback,
191 base::Passed(&archs)));
192 }
193
194 void CollectPlatformSpecificResourceArchs(scoped_refptr<Extension> extension) {
195 BrowserThread::PostBlockingPoolTask(
196 FROM_HERE,
197 base::Bind(&CollectPlatformSpecificResourceArchsOnBlockingPool,
198 extension->path(),
199 base::Bind(&Extension::SetPlatformSpecificResourceArchs,
200 extension)));
201 }
202
159 } // namespace 203 } // namespace
160 204
161 InstalledLoader::InstalledLoader(ExtensionService* extension_service) 205 InstalledLoader::InstalledLoader(ExtensionService* extension_service)
162 : extension_service_(extension_service), 206 : extension_service_(extension_service),
163 extension_registry_(ExtensionRegistry::Get(extension_service->profile())), 207 extension_registry_(ExtensionRegistry::Get(extension_service->profile())),
164 extension_prefs_(ExtensionPrefs::Get(extension_service->profile())) {} 208 extension_prefs_(ExtensionPrefs::Get(extension_service->profile())) {}
165 209
166 InstalledLoader::~InstalledLoader() { 210 InstalledLoader::~InstalledLoader() {
167 } 211 }
168 212
169 void InstalledLoader::Load(const ExtensionInfo& info, bool write_to_prefs) { 213 void InstalledLoader::Load(const ExtensionInfo& info, bool write_to_prefs) {
170 std::string error; 214 std::string error;
171 scoped_refptr<const Extension> extension(NULL); 215 scoped_refptr<Extension> extension(NULL);
172 if (info.extension_manifest) { 216 if (info.extension_manifest) {
173 extension = Extension::Create( 217 extension = Extension::Create(
174 info.extension_path, 218 info.extension_path,
175 info.extension_location, 219 info.extension_location,
176 *info.extension_manifest, 220 *info.extension_manifest,
177 GetCreationFlags(&info), 221 GetCreationFlags(&info),
178 &error); 222 &error);
179 } else { 223 } else {
180 error = errors::kManifestUnreadable; 224 error = errors::kManifestUnreadable;
181 } 225 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 error, 262 error,
219 extension_service_->profile(), 263 extension_service_->profile(),
220 false); // Be quiet. 264 false); // Be quiet.
221 return; 265 return;
222 } 266 }
223 267
224 if (write_to_prefs) 268 if (write_to_prefs)
225 extension_prefs_->UpdateManifest(extension.get()); 269 extension_prefs_->UpdateManifest(extension.get());
226 270
227 extension_service_->AddExtension(extension.get()); 271 extension_service_->AddExtension(extension.get());
272
273 CollectPlatformSpecificResourceArchs(extension);
228 } 274 }
229 275
230 void InstalledLoader::LoadAllExtensions() { 276 void InstalledLoader::LoadAllExtensions() {
231 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 277 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
232 278
233 base::TimeTicks start_time = base::TimeTicks::Now(); 279 base::TimeTicks start_time = base::TimeTicks::Now();
234 280
235 Profile* profile = extension_service_->profile(); 281 Profile* profile = extension_service_->profile();
236 scoped_ptr<ExtensionPrefs::ExtensionsInfo> extensions_info( 282 scoped_ptr<ExtensionPrefs::ExtensionsInfo> extensions_info(
237 extension_prefs_->GetInstalledExtensionsInfo()); 283 extension_prefs_->GetInstalledExtensionsInfo());
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 int InstalledLoader::GetCreationFlags(const ExtensionInfo* info) { 621 int InstalledLoader::GetCreationFlags(const ExtensionInfo* info) {
576 int flags = extension_prefs_->GetCreationFlags(info->extension_id); 622 int flags = extension_prefs_->GetCreationFlags(info->extension_id);
577 if (!Manifest::IsUnpackedLocation(info->extension_location)) 623 if (!Manifest::IsUnpackedLocation(info->extension_location))
578 flags |= Extension::REQUIRE_KEY; 624 flags |= Extension::REQUIRE_KEY;
579 if (extension_prefs_->AllowFileAccess(info->extension_id)) 625 if (extension_prefs_->AllowFileAccess(info->extension_id))
580 flags |= Extension::ALLOW_FILE_ACCESS; 626 flags |= Extension::ALLOW_FILE_ACCESS;
581 return flags; 627 return flags;
582 } 628 }
583 629
584 } // namespace extensions 630 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/updater/extension_downloader.h » ('j') | extensions/common/extension.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698