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

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

Issue 420543002: Declarative content scripts: Browser-side: per-extension shared memory regions (lazily loaded) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: DCHECK xtn system ready; keep all added_scripts_; careful changed_extensions_ management Created 6 years, 4 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 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/extension_system_impl.h" 5 #include "chrome/browser/extensions/extension_system_impl.h"
6 6
7 #include "base/base_switches.h" 7 #include "base/base_switches.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
12 #include "base/metrics/field_trial.h" 12 #include "base/metrics/field_trial.h"
13 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
14 #include "base/strings/string_tokenizer.h" 14 #include "base/strings/string_tokenizer.h"
15 #include "base/strings/string_util.h"
15 #include "chrome/browser/browser_process.h" 16 #include "chrome/browser/browser_process.h"
16 #include "chrome/browser/content_settings/cookie_settings.h" 17 #include "chrome/browser/content_settings/cookie_settings.h"
17 #include "chrome/browser/extensions/blacklist.h" 18 #include "chrome/browser/extensions/blacklist.h"
18 #include "chrome/browser/extensions/component_loader.h" 19 #include "chrome/browser/extensions/component_loader.h"
20 #include "chrome/browser/extensions/declarative_user_script_master.h"
19 #include "chrome/browser/extensions/error_console/error_console.h" 21 #include "chrome/browser/extensions/error_console/error_console.h"
20 #include "chrome/browser/extensions/extension_error_reporter.h" 22 #include "chrome/browser/extensions/extension_error_reporter.h"
21 #include "chrome/browser/extensions/extension_service.h" 23 #include "chrome/browser/extensions/extension_service.h"
22 #include "chrome/browser/extensions/extension_system_factory.h" 24 #include "chrome/browser/extensions/extension_system_factory.h"
23 #include "chrome/browser/extensions/extension_util.h" 25 #include "chrome/browser/extensions/extension_util.h"
24 #include "chrome/browser/extensions/extension_warning_badge_service.h" 26 #include "chrome/browser/extensions/extension_warning_badge_service.h"
25 #include "chrome/browser/extensions/extension_warning_set.h" 27 #include "chrome/browser/extensions/extension_warning_set.h"
26 #include "chrome/browser/extensions/install_verifier.h" 28 #include "chrome/browser/extensions/install_verifier.h"
27 #include "chrome/browser/extensions/navigation_observer.h" 29 #include "chrome/browser/extensions/navigation_observer.h"
28 #include "chrome/browser/extensions/shared_module_service.h" 30 #include "chrome/browser/extensions/shared_module_service.h"
31 #include "chrome/browser/extensions/shared_user_script_master.h"
29 #include "chrome/browser/extensions/standard_management_policy_provider.h" 32 #include "chrome/browser/extensions/standard_management_policy_provider.h"
30 #include "chrome/browser/extensions/state_store_notification_observer.h" 33 #include "chrome/browser/extensions/state_store_notification_observer.h"
31 #include "chrome/browser/extensions/updater/manifest_fetch_data.h" 34 #include "chrome/browser/extensions/updater/manifest_fetch_data.h"
32 #include "chrome/browser/extensions/user_script_master.h"
33 #include "chrome/browser/profiles/profile.h" 35 #include "chrome/browser/profiles/profile.h"
34 #include "chrome/browser/profiles/profile_manager.h" 36 #include "chrome/browser/profiles/profile_manager.h"
35 #include "chrome/common/chrome_switches.h" 37 #include "chrome/common/chrome_switches.h"
36 #include "chrome/common/chrome_version_info.h" 38 #include "chrome/common/chrome_version_info.h"
37 #include "chrome/common/extensions/extension_constants.h" 39 #include "chrome/common/extensions/extension_constants.h"
38 #include "chrome/common/extensions/extension_file_util.h" 40 #include "chrome/common/extensions/extension_file_util.h"
39 #include "chrome/common/extensions/features/feature_channel.h" 41 #include "chrome/common/extensions/features/feature_channel.h"
40 #include "chrome/common/extensions/manifest_url_handler.h" 42 #include "chrome/common/extensions/manifest_url_handler.h"
41 #include "content/public/browser/browser_thread.h" 43 #include "content/public/browser/browser_thread.h"
42 #include "content/public/browser/url_data_source.h" 44 #include "content/public/browser/url_data_source.h"
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 } // namespace 311 } // namespace
310 312
311 void ExtensionSystemImpl::Shared::Init(bool extensions_enabled) { 313 void ExtensionSystemImpl::Shared::Init(bool extensions_enabled) {
312 const CommandLine* command_line = CommandLine::ForCurrentProcess(); 314 const CommandLine* command_line = CommandLine::ForCurrentProcess();
313 315
314 navigation_observer_.reset(new NavigationObserver(profile_)); 316 navigation_observer_.reset(new NavigationObserver(profile_));
315 317
316 bool allow_noisy_errors = !command_line->HasSwitch(switches::kNoErrorDialogs); 318 bool allow_noisy_errors = !command_line->HasSwitch(switches::kNoErrorDialogs);
317 ExtensionErrorReporter::Init(allow_noisy_errors); 319 ExtensionErrorReporter::Init(allow_noisy_errors);
318 320
319 user_script_master_.reset(new UserScriptMaster(profile_)); 321 shared_user_script_master_.reset(new SharedUserScriptMaster(profile_));
320 322
321 // ExtensionService depends on RuntimeData. 323 // ExtensionService depends on RuntimeData.
322 runtime_data_.reset(new RuntimeData(ExtensionRegistry::Get(profile_))); 324 runtime_data_.reset(new RuntimeData(ExtensionRegistry::Get(profile_)));
323 325
324 bool autoupdate_enabled = !profile_->IsGuestSession(); 326 bool autoupdate_enabled = !profile_->IsGuestSession();
325 #if defined(OS_CHROMEOS) 327 #if defined(OS_CHROMEOS)
326 if (!extensions_enabled) 328 if (!extensions_enabled)
327 autoupdate_enabled = false; 329 autoupdate_enabled = false;
328 #endif 330 #endif
329 extension_service_.reset(new ExtensionService( 331 extension_service_.reset(new ExtensionService(
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 } 451 }
450 452
451 RuntimeData* ExtensionSystemImpl::Shared::runtime_data() { 453 RuntimeData* ExtensionSystemImpl::Shared::runtime_data() {
452 return runtime_data_.get(); 454 return runtime_data_.get();
453 } 455 }
454 456
455 ManagementPolicy* ExtensionSystemImpl::Shared::management_policy() { 457 ManagementPolicy* ExtensionSystemImpl::Shared::management_policy() {
456 return management_policy_.get(); 458 return management_policy_.get();
457 } 459 }
458 460
459 UserScriptMaster* ExtensionSystemImpl::Shared::user_script_master() { 461 SharedUserScriptMaster*
460 return user_script_master_.get(); 462 ExtensionSystemImpl::Shared::shared_user_script_master() {
463 return shared_user_script_master_.get();
461 } 464 }
462 465
463 InfoMap* ExtensionSystemImpl::Shared::info_map() { 466 InfoMap* ExtensionSystemImpl::Shared::info_map() {
464 if (!extension_info_map_.get()) 467 if (!extension_info_map_.get())
465 extension_info_map_ = new InfoMap(); 468 extension_info_map_ = new InfoMap();
466 return extension_info_map_.get(); 469 return extension_info_map_.get();
467 } 470 }
468 471
469 LazyBackgroundTaskQueue* 472 LazyBackgroundTaskQueue*
470 ExtensionSystemImpl::Shared::lazy_background_task_queue() { 473 ExtensionSystemImpl::Shared::lazy_background_task_queue() {
(...skipping 21 matching lines...) Expand all
492 } 495 }
493 496
494 QuotaService* ExtensionSystemImpl::Shared::quota_service() { 497 QuotaService* ExtensionSystemImpl::Shared::quota_service() {
495 return quota_service_.get(); 498 return quota_service_.get();
496 } 499 }
497 500
498 ContentVerifier* ExtensionSystemImpl::Shared::content_verifier() { 501 ContentVerifier* ExtensionSystemImpl::Shared::content_verifier() {
499 return content_verifier_.get(); 502 return content_verifier_.get();
500 } 503 }
501 504
505 DeclarativeUserScriptMaster*
506 ExtensionSystemImpl::Shared::GetDeclarativeUserScriptMasterByExtension(
507 const ExtensionId& extension_id) {
508 DCHECK(ready().is_signaled());
509 DeclarativeUserScriptMaster* master = NULL;
510 for (ScopedVector<DeclarativeUserScriptMaster>::iterator it =
511 declarative_user_script_masters_.begin();
512 it != declarative_user_script_masters_.end(); ++it) {
513 if ((*it)->extension_id() == extension_id) {
514 master = *it;
515 break;
516 }
517 }
518 if (!master) {
519 master = new DeclarativeUserScriptMaster(profile_, extension_id);
520 declarative_user_script_masters_.push_back(master);
521 }
522 return master;
523 }
524
502 // 525 //
503 // ExtensionSystemImpl 526 // ExtensionSystemImpl
504 // 527 //
505 528
506 ExtensionSystemImpl::ExtensionSystemImpl(Profile* profile) 529 ExtensionSystemImpl::ExtensionSystemImpl(Profile* profile)
507 : profile_(profile) { 530 : profile_(profile) {
508 shared_ = ExtensionSystemSharedFactory::GetForBrowserContext(profile); 531 shared_ = ExtensionSystemSharedFactory::GetForBrowserContext(profile);
509 532
510 if (profile->IsOffTheRecord()) { 533 if (profile->IsOffTheRecord()) {
511 process_manager_.reset(ProcessManager::Create(profile)); 534 process_manager_.reset(ProcessManager::Create(profile));
512 } else { 535 } else {
513 shared_->InitPrefs(); 536 shared_->InitPrefs();
514 } 537 }
515 } 538 }
516 539
517 ExtensionSystemImpl::~ExtensionSystemImpl() { 540 ExtensionSystemImpl::~ExtensionSystemImpl() {
518 } 541 }
519 542
520 void ExtensionSystemImpl::Shutdown() { 543 void ExtensionSystemImpl::Shutdown() {
521 process_manager_.reset(); 544 process_manager_.reset();
522 } 545 }
523 546
524 void ExtensionSystemImpl::InitForRegularProfile(bool extensions_enabled) { 547 void ExtensionSystemImpl::InitForRegularProfile(bool extensions_enabled) {
525 DCHECK(!profile_->IsOffTheRecord()); 548 DCHECK(!profile_->IsOffTheRecord());
526 if (user_script_master() || extension_service()) 549 if (shared_user_script_master() || extension_service())
527 return; // Already initialized. 550 return; // Already initialized.
528 551
529 // The InfoMap needs to be created before the ProcessManager. 552 // The InfoMap needs to be created before the ProcessManager.
530 shared_->info_map(); 553 shared_->info_map();
531 554
532 process_manager_.reset(ProcessManager::Create(profile_)); 555 process_manager_.reset(ProcessManager::Create(profile_));
533 556
534 shared_->Init(extensions_enabled); 557 shared_->Init(extensions_enabled);
535 } 558 }
536 559
537 ExtensionService* ExtensionSystemImpl::extension_service() { 560 ExtensionService* ExtensionSystemImpl::extension_service() {
538 return shared_->extension_service(); 561 return shared_->extension_service();
539 } 562 }
540 563
541 RuntimeData* ExtensionSystemImpl::runtime_data() { 564 RuntimeData* ExtensionSystemImpl::runtime_data() {
542 return shared_->runtime_data(); 565 return shared_->runtime_data();
543 } 566 }
544 567
545 ManagementPolicy* ExtensionSystemImpl::management_policy() { 568 ManagementPolicy* ExtensionSystemImpl::management_policy() {
546 return shared_->management_policy(); 569 return shared_->management_policy();
547 } 570 }
548 571
549 UserScriptMaster* ExtensionSystemImpl::user_script_master() { 572 SharedUserScriptMaster* ExtensionSystemImpl::shared_user_script_master() {
550 return shared_->user_script_master(); 573 return shared_->shared_user_script_master();
551 } 574 }
552 575
553 ProcessManager* ExtensionSystemImpl::process_manager() { 576 ProcessManager* ExtensionSystemImpl::process_manager() {
554 return process_manager_.get(); 577 return process_manager_.get();
555 } 578 }
556 579
557 StateStore* ExtensionSystemImpl::state_store() { 580 StateStore* ExtensionSystemImpl::state_store() {
558 return shared_->state_store(); 581 return shared_->state_store();
559 } 582 }
560 583
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 ContentVerifier* ExtensionSystemImpl::content_verifier() { 622 ContentVerifier* ExtensionSystemImpl::content_verifier() {
600 return shared_->content_verifier(); 623 return shared_->content_verifier();
601 } 624 }
602 625
603 scoped_ptr<ExtensionSet> ExtensionSystemImpl::GetDependentExtensions( 626 scoped_ptr<ExtensionSet> ExtensionSystemImpl::GetDependentExtensions(
604 const Extension* extension) { 627 const Extension* extension) {
605 return extension_service()->shared_module_service()->GetDependentExtensions( 628 return extension_service()->shared_module_service()->GetDependentExtensions(
606 extension); 629 extension);
607 } 630 }
608 631
632 DeclarativeUserScriptMaster*
633 ExtensionSystemImpl::GetDeclarativeUserScriptMasterByExtension(
634 const ExtensionId& extension_id) {
635 return shared_->GetDeclarativeUserScriptMasterByExtension(extension_id);
636 }
637
609 void ExtensionSystemImpl::RegisterExtensionWithRequestContexts( 638 void ExtensionSystemImpl::RegisterExtensionWithRequestContexts(
610 const Extension* extension) { 639 const Extension* extension) {
611 base::Time install_time; 640 base::Time install_time;
612 if (extension->location() != Manifest::COMPONENT) { 641 if (extension->location() != Manifest::COMPONENT) {
613 install_time = ExtensionPrefs::Get(profile_)-> 642 install_time = ExtensionPrefs::Get(profile_)->
614 GetInstallTime(extension->id()); 643 GetInstallTime(extension->id());
615 } 644 }
616 bool incognito_enabled = util::IsIncognitoEnabled(extension->id(), profile_); 645 bool incognito_enabled = util::IsIncognitoEnabled(extension->id(), profile_);
617 646
618 bool notifications_disabled = false; 647 bool notifications_disabled = false;
(...skipping 18 matching lines...) Expand all
637 void ExtensionSystemImpl::UnregisterExtensionWithRequestContexts( 666 void ExtensionSystemImpl::UnregisterExtensionWithRequestContexts(
638 const std::string& extension_id, 667 const std::string& extension_id,
639 const UnloadedExtensionInfo::Reason reason) { 668 const UnloadedExtensionInfo::Reason reason) {
640 BrowserThread::PostTask( 669 BrowserThread::PostTask(
641 BrowserThread::IO, 670 BrowserThread::IO,
642 FROM_HERE, 671 FROM_HERE,
643 base::Bind(&InfoMap::RemoveExtension, info_map(), extension_id, reason)); 672 base::Bind(&InfoMap::RemoveExtension, info_map(), extension_id, reason));
644 } 673 }
645 674
646 } // namespace extensions 675 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698