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

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

Issue 2166513002: Create --disable-extensions-except switch (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comment added to address code review commen in patch 6 Created 4 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/extension_service.h" 5 #include "chrome/browser/extensions/extension_service.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <iterator> 10 #include <iterator>
11 #include <set> 11 #include <set>
12 12
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/location.h" 14 #include "base/location.h"
15 #include "base/metrics/histogram_macros.h" 15 #include "base/metrics/histogram_macros.h"
16 #include "base/single_thread_task_runner.h" 16 #include "base/single_thread_task_runner.h"
17 #include "base/strings/string_number_conversions.h" 17 #include "base/strings/string_number_conversions.h"
18 #include "base/strings/string_tokenizer.h"
18 #include "base/strings/stringprintf.h" 19 #include "base/strings/stringprintf.h"
19 #include "base/strings/utf_string_conversions.h" 20 #include "base/strings/utf_string_conversions.h"
20 #include "base/threading/sequenced_worker_pool.h" 21 #include "base/threading/sequenced_worker_pool.h"
21 #include "base/threading/thread_restrictions.h" 22 #include "base/threading/thread_restrictions.h"
22 #include "base/threading/thread_task_runner_handle.h" 23 #include "base/threading/thread_task_runner_handle.h"
23 #include "base/time/time.h" 24 #include "base/time/time.h"
24 #include "base/trace_event/trace_event.h" 25 #include "base/trace_event/trace_event.h"
25 #include "build/build_config.h" 26 #include "build/build_config.h"
26 #include "chrome/browser/browser_process.h" 27 #include "chrome/browser/browser_process.h"
27 #include "chrome/browser/chrome_notification_types.h" 28 #include "chrome/browser/chrome_notification_types.h"
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 294
294 ExtensionService::ExtensionService(Profile* profile, 295 ExtensionService::ExtensionService(Profile* profile,
295 const base::CommandLine* command_line, 296 const base::CommandLine* command_line,
296 const base::FilePath& install_directory, 297 const base::FilePath& install_directory,
297 extensions::ExtensionPrefs* extension_prefs, 298 extensions::ExtensionPrefs* extension_prefs,
298 extensions::Blacklist* blacklist, 299 extensions::Blacklist* blacklist,
299 bool autoupdate_enabled, 300 bool autoupdate_enabled,
300 bool extensions_enabled, 301 bool extensions_enabled,
301 extensions::OneShotEvent* ready) 302 extensions::OneShotEvent* ready)
302 : extensions::Blacklist::Observer(blacklist), 303 : extensions::Blacklist::Observer(blacklist),
304 command_line_(command_line),
303 profile_(profile), 305 profile_(profile),
304 system_(extensions::ExtensionSystem::Get(profile)), 306 system_(extensions::ExtensionSystem::Get(profile)),
305 extension_prefs_(extension_prefs), 307 extension_prefs_(extension_prefs),
306 blacklist_(blacklist), 308 blacklist_(blacklist),
307 registry_(extensions::ExtensionRegistry::Get(profile)), 309 registry_(extensions::ExtensionRegistry::Get(profile)),
308 pending_extension_manager_(profile), 310 pending_extension_manager_(profile),
309 install_directory_(install_directory), 311 install_directory_(install_directory),
310 extensions_enabled_(extensions_enabled), 312 extensions_enabled_(extensions_enabled),
311 ready_(ready), 313 ready_(ready),
312 shared_module_service_(new extensions::SharedModuleService(profile_)), 314 shared_module_service_(new extensions::SharedModuleService(profile_)),
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 if (include_disabled) { 411 if (include_disabled) {
410 // Include blacklisted and blocked extensions here because there are 412 // Include blacklisted and blocked extensions here because there are
411 // hundreds of callers of this function, and many might assume that this 413 // hundreds of callers of this function, and many might assume that this
412 // includes those that have been disabled due to blacklisting or blocking. 414 // includes those that have been disabled due to blacklisting or blocking.
413 include_mask |= ExtensionRegistry::DISABLED | 415 include_mask |= ExtensionRegistry::DISABLED |
414 ExtensionRegistry::BLACKLISTED | ExtensionRegistry::BLOCKED; 416 ExtensionRegistry::BLACKLISTED | ExtensionRegistry::BLOCKED;
415 } 417 }
416 return registry_->GetExtensionById(id, include_mask); 418 return registry_->GetExtensionById(id, include_mask);
417 } 419 }
418 420
421 void ExtensionService::LoadExtensionsFromCommandLineFlag(
Devlin 2016/08/30 14:15:39 nit: function definition order in the .cc file sho
422 const char* switch_name) {
423 if (command_line_->HasSwitch(switch_name)) {
424 base::CommandLine::StringType path_list =
425 command_line_->GetSwitchValueNative(switch_name);
426 base::StringTokenizerT<base::CommandLine::StringType,
427 base::CommandLine::StringType::const_iterator>
428 t(path_list, FILE_PATH_LITERAL(","));
429 while (t.GetNext()) {
430 std::string extension_id;
431 extensions::UnpackedInstaller::Create(this)->LoadFromCommandLine(
432 base::FilePath(t.token()), &extension_id, false /*only-allow-apps*/);
433 // Extension id is added to whitelist after its extension is loaded
434 // because code is executed asynchronously ...
catmullings 2016/08/29 22:28:01 Devlin, I didn't quite understand the asynchronous
Devlin 2016/08/30 14:15:39 So, if this code were to be executed synchronously
435 if (switch_name == switches::kDisableExtensionsExcept) {
436 disable_flag_exempted_extensions_.insert(extension_id);
437 }
Devlin 2016/08/30 14:15:39 nit: We don't have a strong stylistic rule for bra
438 }
439 }
440 }
441
419 void ExtensionService::Init() { 442 void ExtensionService::Init() {
420 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 443 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
421 TRACE_EVENT0("browser,startup", "ExtensionService::Init"); 444 TRACE_EVENT0("browser,startup", "ExtensionService::Init");
422 SCOPED_UMA_HISTOGRAM_TIMER("Extensions.ExtensionServiceInitTime"); 445 SCOPED_UMA_HISTOGRAM_TIMER("Extensions.ExtensionServiceInitTime");
423 446
424 DCHECK(!is_ready()); // Can't redo init. 447 DCHECK(!is_ready()); // Can't redo init.
425 DCHECK_EQ(registry_->enabled_extensions().size(), 0u); 448 DCHECK_EQ(registry_->enabled_extensions().size(), 0u);
426 449
427 // LoadAllExtensions() calls OnLoadedInstalledExtensions(). 450 // LoadAllExtensions() calls OnLoadedInstalledExtensions().
428 component_loader_->LoadAll(); 451 component_loader_->LoadAll();
429 extensions::InstalledLoader(this).LoadAllExtensions(); 452 extensions::InstalledLoader(this).LoadAllExtensions();
430 453 LoadExtensionsFromCommandLineFlag(switches::kDisableExtensionsExcept);
454 if (extensions_enabled_) {
Devlin 2016/08/30 14:15:39 ditto re single line ifs
455 LoadExtensionsFromCommandLineFlag(switches::kLoadExtension);
456 }
431 EnabledReloadableExtensions(); 457 EnabledReloadableExtensions();
432 MaybeFinishShutdownDelayed(); 458 MaybeFinishShutdownDelayed();
433 SetReadyAndNotifyListeners(); 459 SetReadyAndNotifyListeners();
434 460
435 // TODO(erikkay): this should probably be deferred to a future point 461 // TODO(erikkay): this should probably be deferred to a future point
436 // rather than running immediately at startup. 462 // rather than running immediately at startup.
437 CheckForExternalUpdates(); 463 CheckForExternalUpdates();
438 464
439 LoadGreylistFromPrefs(); 465 LoadGreylistFromPrefs();
440 } 466 }
(...skipping 974 matching lines...) Expand 10 before | Expand all | Expand 10 after
1415 EnableExtension(extension->id()); 1441 EnableExtension(extension->id());
1416 } 1442 }
1417 1443
1418 OnBlacklistUpdated(); 1444 OnBlacklistUpdated();
1419 } 1445 }
1420 1446
1421 void ExtensionService::AddExtension(const Extension* extension) { 1447 void ExtensionService::AddExtension(const Extension* extension) {
1422 // TODO(jstritar): We may be able to get rid of this branch by overriding the 1448 // TODO(jstritar): We may be able to get rid of this branch by overriding the
1423 // default extension state to DISABLED when the --disable-extensions flag 1449 // default extension state to DISABLED when the --disable-extensions flag
1424 // is set (http://crbug.com/29067). 1450 // is set (http://crbug.com/29067).
1425 if (!extensions_enabled() && 1451 if (!extensions_enabled() && !extension->is_theme() &&
1426 !extension->is_theme() &&
1427 extension->location() != Manifest::COMPONENT && 1452 extension->location() != Manifest::COMPONENT &&
1428 !Manifest::IsExternalLocation(extension->location())) { 1453 !Manifest::IsExternalLocation(extension->location()) &&
1454 disable_flag_exempted_extensions_.count(extension->id()) == 0) {
1429 return; 1455 return;
1430 } 1456 }
1431 1457
1432 bool is_extension_upgrade = false; 1458 bool is_extension_upgrade = false;
1433 bool is_extension_loaded = false; 1459 bool is_extension_loaded = false;
1434 const Extension* old = GetInstalledExtension(extension->id()); 1460 const Extension* old = GetInstalledExtension(extension->id());
1435 if (old) { 1461 if (old) {
1436 is_extension_loaded = true; 1462 is_extension_loaded = true;
1437 int version_compare_result = 1463 int version_compare_result =
1438 extension->version()->CompareTo(*(old->version())); 1464 extension->version()->CompareTo(*(old->version()));
(...skipping 1005 matching lines...) Expand 10 before | Expand all | Expand 10 after
2444 } 2470 }
2445 2471
2446 void ExtensionService::OnProfileDestructionStarted() { 2472 void ExtensionService::OnProfileDestructionStarted() {
2447 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs(); 2473 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs();
2448 for (ExtensionIdSet::iterator it = ids_to_unload.begin(); 2474 for (ExtensionIdSet::iterator it = ids_to_unload.begin();
2449 it != ids_to_unload.end(); 2475 it != ids_to_unload.end();
2450 ++it) { 2476 ++it) {
2451 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN); 2477 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN);
2452 } 2478 }
2453 } 2479 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698