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

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: Fix nit and rebase from master 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/unpacked_installer.h" 34 #include "chrome/browser/extensions/unpacked_installer.h"
32 #include "chrome/browser/extensions/updater/manifest_fetch_data.h" 35 #include "chrome/browser/extensions/updater/manifest_fetch_data.h"
33 #include "chrome/browser/extensions/user_script_master.h"
34 #include "chrome/browser/profiles/profile.h" 36 #include "chrome/browser/profiles/profile.h"
35 #include "chrome/browser/profiles/profile_manager.h" 37 #include "chrome/browser/profiles/profile_manager.h"
36 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" 38 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h"
37 #include "chrome/common/chrome_switches.h" 39 #include "chrome/common/chrome_switches.h"
38 #include "chrome/common/chrome_version_info.h" 40 #include "chrome/common/chrome_version_info.h"
39 #include "chrome/common/extensions/extension_constants.h" 41 #include "chrome/common/extensions/extension_constants.h"
40 #include "chrome/common/extensions/extension_file_util.h" 42 #include "chrome/common/extensions/extension_file_util.h"
41 #include "chrome/common/extensions/features/feature_channel.h" 43 #include "chrome/common/extensions/features/feature_channel.h"
42 #include "chrome/common/extensions/manifest_url_handler.h" 44 #include "chrome/common/extensions/manifest_url_handler.h"
43 #include "content/public/browser/browser_thread.h" 45 #include "content/public/browser/browser_thread.h"
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 } // namespace 300 } // namespace
299 301
300 void ExtensionSystemImpl::Shared::Init(bool extensions_enabled) { 302 void ExtensionSystemImpl::Shared::Init(bool extensions_enabled) {
301 const CommandLine* command_line = CommandLine::ForCurrentProcess(); 303 const CommandLine* command_line = CommandLine::ForCurrentProcess();
302 304
303 navigation_observer_.reset(new NavigationObserver(profile_)); 305 navigation_observer_.reset(new NavigationObserver(profile_));
304 306
305 bool allow_noisy_errors = !command_line->HasSwitch(switches::kNoErrorDialogs); 307 bool allow_noisy_errors = !command_line->HasSwitch(switches::kNoErrorDialogs);
306 ExtensionErrorReporter::Init(allow_noisy_errors); 308 ExtensionErrorReporter::Init(allow_noisy_errors);
307 309
308 user_script_master_.reset(new UserScriptMaster(profile_)); 310 shared_user_script_master_.reset(new SharedUserScriptMaster(profile_));
309 311
310 // ExtensionService depends on RuntimeData. 312 // ExtensionService depends on RuntimeData.
311 runtime_data_.reset(new RuntimeData(ExtensionRegistry::Get(profile_))); 313 runtime_data_.reset(new RuntimeData(ExtensionRegistry::Get(profile_)));
312 314
313 bool autoupdate_enabled = !profile_->IsGuestSession(); 315 bool autoupdate_enabled = !profile_->IsGuestSession();
314 #if defined(OS_CHROMEOS) 316 #if defined(OS_CHROMEOS)
315 if (!extensions_enabled) 317 if (!extensions_enabled)
316 autoupdate_enabled = false; 318 autoupdate_enabled = false;
317 #endif 319 #endif
318 extension_service_.reset(new ExtensionService( 320 extension_service_.reset(new ExtensionService(
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 } 434 }
433 435
434 RuntimeData* ExtensionSystemImpl::Shared::runtime_data() { 436 RuntimeData* ExtensionSystemImpl::Shared::runtime_data() {
435 return runtime_data_.get(); 437 return runtime_data_.get();
436 } 438 }
437 439
438 ManagementPolicy* ExtensionSystemImpl::Shared::management_policy() { 440 ManagementPolicy* ExtensionSystemImpl::Shared::management_policy() {
439 return management_policy_.get(); 441 return management_policy_.get();
440 } 442 }
441 443
442 UserScriptMaster* ExtensionSystemImpl::Shared::user_script_master() { 444 SharedUserScriptMaster*
443 return user_script_master_.get(); 445 ExtensionSystemImpl::Shared::shared_user_script_master() {
446 return shared_user_script_master_.get();
444 } 447 }
445 448
446 InfoMap* ExtensionSystemImpl::Shared::info_map() { 449 InfoMap* ExtensionSystemImpl::Shared::info_map() {
447 if (!extension_info_map_.get()) 450 if (!extension_info_map_.get())
448 extension_info_map_ = new InfoMap(); 451 extension_info_map_ = new InfoMap();
449 return extension_info_map_.get(); 452 return extension_info_map_.get();
450 } 453 }
451 454
452 LazyBackgroundTaskQueue* 455 LazyBackgroundTaskQueue*
453 ExtensionSystemImpl::Shared::lazy_background_task_queue() { 456 ExtensionSystemImpl::Shared::lazy_background_task_queue() {
(...skipping 21 matching lines...) Expand all
475 } 478 }
476 479
477 QuotaService* ExtensionSystemImpl::Shared::quota_service() { 480 QuotaService* ExtensionSystemImpl::Shared::quota_service() {
478 return quota_service_.get(); 481 return quota_service_.get();
479 } 482 }
480 483
481 ContentVerifier* ExtensionSystemImpl::Shared::content_verifier() { 484 ContentVerifier* ExtensionSystemImpl::Shared::content_verifier() {
482 return content_verifier_.get(); 485 return content_verifier_.get();
483 } 486 }
484 487
488 DeclarativeUserScriptMaster*
489 ExtensionSystemImpl::Shared::GetDeclarativeUserScriptMasterByExtension(
490 const ExtensionId& extension_id) {
491 DCHECK(ready().is_signaled());
492 DeclarativeUserScriptMaster* master = NULL;
493 for (ScopedVector<DeclarativeUserScriptMaster>::iterator it =
494 declarative_user_script_masters_.begin();
495 it != declarative_user_script_masters_.end();
496 ++it) {
497 if ((*it)->extension_id() == extension_id) {
498 master = *it;
499 break;
500 }
501 }
502 if (!master) {
503 master = new DeclarativeUserScriptMaster(profile_, extension_id);
504 declarative_user_script_masters_.push_back(master);
505 }
506 return master;
507 }
508
485 // 509 //
486 // ExtensionSystemImpl 510 // ExtensionSystemImpl
487 // 511 //
488 512
489 ExtensionSystemImpl::ExtensionSystemImpl(Profile* profile) 513 ExtensionSystemImpl::ExtensionSystemImpl(Profile* profile)
490 : profile_(profile) { 514 : profile_(profile) {
491 shared_ = ExtensionSystemSharedFactory::GetForBrowserContext(profile); 515 shared_ = ExtensionSystemSharedFactory::GetForBrowserContext(profile);
492 516
493 if (profile->IsOffTheRecord()) { 517 if (profile->IsOffTheRecord()) {
494 process_manager_.reset(ProcessManager::Create(profile)); 518 process_manager_.reset(ProcessManager::Create(profile));
495 } else { 519 } else {
496 shared_->InitPrefs(); 520 shared_->InitPrefs();
497 } 521 }
498 } 522 }
499 523
500 ExtensionSystemImpl::~ExtensionSystemImpl() { 524 ExtensionSystemImpl::~ExtensionSystemImpl() {
501 } 525 }
502 526
503 void ExtensionSystemImpl::Shutdown() { 527 void ExtensionSystemImpl::Shutdown() {
504 process_manager_.reset(); 528 process_manager_.reset();
505 } 529 }
506 530
507 void ExtensionSystemImpl::InitForRegularProfile(bool extensions_enabled) { 531 void ExtensionSystemImpl::InitForRegularProfile(bool extensions_enabled) {
508 DCHECK(!profile_->IsOffTheRecord()); 532 DCHECK(!profile_->IsOffTheRecord());
509 if (user_script_master() || extension_service()) 533 if (shared_user_script_master() || extension_service())
510 return; // Already initialized. 534 return; // Already initialized.
511 535
512 // The InfoMap needs to be created before the ProcessManager. 536 // The InfoMap needs to be created before the ProcessManager.
513 shared_->info_map(); 537 shared_->info_map();
514 538
515 process_manager_.reset(ProcessManager::Create(profile_)); 539 process_manager_.reset(ProcessManager::Create(profile_));
516 540
517 shared_->Init(extensions_enabled); 541 shared_->Init(extensions_enabled);
518 } 542 }
519 543
520 ExtensionService* ExtensionSystemImpl::extension_service() { 544 ExtensionService* ExtensionSystemImpl::extension_service() {
521 return shared_->extension_service(); 545 return shared_->extension_service();
522 } 546 }
523 547
524 RuntimeData* ExtensionSystemImpl::runtime_data() { 548 RuntimeData* ExtensionSystemImpl::runtime_data() {
525 return shared_->runtime_data(); 549 return shared_->runtime_data();
526 } 550 }
527 551
528 ManagementPolicy* ExtensionSystemImpl::management_policy() { 552 ManagementPolicy* ExtensionSystemImpl::management_policy() {
529 return shared_->management_policy(); 553 return shared_->management_policy();
530 } 554 }
531 555
532 UserScriptMaster* ExtensionSystemImpl::user_script_master() { 556 SharedUserScriptMaster* ExtensionSystemImpl::shared_user_script_master() {
533 return shared_->user_script_master(); 557 return shared_->shared_user_script_master();
534 } 558 }
535 559
536 ProcessManager* ExtensionSystemImpl::process_manager() { 560 ProcessManager* ExtensionSystemImpl::process_manager() {
537 return process_manager_.get(); 561 return process_manager_.get();
538 } 562 }
539 563
540 StateStore* ExtensionSystemImpl::state_store() { 564 StateStore* ExtensionSystemImpl::state_store() {
541 return shared_->state_store(); 565 return shared_->state_store();
542 } 566 }
543 567
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 ContentVerifier* ExtensionSystemImpl::content_verifier() { 606 ContentVerifier* ExtensionSystemImpl::content_verifier() {
583 return shared_->content_verifier(); 607 return shared_->content_verifier();
584 } 608 }
585 609
586 scoped_ptr<ExtensionSet> ExtensionSystemImpl::GetDependentExtensions( 610 scoped_ptr<ExtensionSet> ExtensionSystemImpl::GetDependentExtensions(
587 const Extension* extension) { 611 const Extension* extension) {
588 return extension_service()->shared_module_service()->GetDependentExtensions( 612 return extension_service()->shared_module_service()->GetDependentExtensions(
589 extension); 613 extension);
590 } 614 }
591 615
616 DeclarativeUserScriptMaster*
617 ExtensionSystemImpl::GetDeclarativeUserScriptMasterByExtension(
618 const ExtensionId& extension_id) {
619 return shared_->GetDeclarativeUserScriptMasterByExtension(extension_id);
620 }
621
592 void ExtensionSystemImpl::RegisterExtensionWithRequestContexts( 622 void ExtensionSystemImpl::RegisterExtensionWithRequestContexts(
593 const Extension* extension) { 623 const Extension* extension) {
594 base::Time install_time; 624 base::Time install_time;
595 if (extension->location() != Manifest::COMPONENT) { 625 if (extension->location() != Manifest::COMPONENT) {
596 install_time = ExtensionPrefs::Get(profile_)-> 626 install_time = ExtensionPrefs::Get(profile_)->
597 GetInstallTime(extension->id()); 627 GetInstallTime(extension->id());
598 } 628 }
599 bool incognito_enabled = util::IsIncognitoEnabled(extension->id(), profile_); 629 bool incognito_enabled = util::IsIncognitoEnabled(extension->id(), profile_);
600 630
601 bool notifications_disabled = false; 631 bool notifications_disabled = false;
(...skipping 18 matching lines...) Expand all
620 void ExtensionSystemImpl::UnregisterExtensionWithRequestContexts( 650 void ExtensionSystemImpl::UnregisterExtensionWithRequestContexts(
621 const std::string& extension_id, 651 const std::string& extension_id,
622 const UnloadedExtensionInfo::Reason reason) { 652 const UnloadedExtensionInfo::Reason reason) {
623 BrowserThread::PostTask( 653 BrowserThread::PostTask(
624 BrowserThread::IO, 654 BrowserThread::IO,
625 FROM_HERE, 655 FROM_HERE,
626 base::Bind(&InfoMap::RemoveExtension, info_map(), extension_id, reason)); 656 base::Bind(&InfoMap::RemoveExtension, info_map(), extension_id, reason));
627 } 657 }
628 658
629 } // namespace extensions 659 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_system_impl.h ('k') | chrome/browser/extensions/shared_user_script_master.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698