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/extension_service.h" | 5 #include "chrome/browser/extensions/extension_service.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 profile_(profile), | 362 profile_(profile), |
363 system_(extensions::ExtensionSystem::Get(profile)), | 363 system_(extensions::ExtensionSystem::Get(profile)), |
364 extension_prefs_(extension_prefs), | 364 extension_prefs_(extension_prefs), |
365 settings_frontend_(extensions::SettingsFrontend::Create(profile)), | 365 settings_frontend_(extensions::SettingsFrontend::Create(profile)), |
366 pending_extension_manager_(*ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 366 pending_extension_manager_(*ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
367 install_directory_(install_directory), | 367 install_directory_(install_directory), |
368 extensions_enabled_(extensions_enabled), | 368 extensions_enabled_(extensions_enabled), |
369 show_extensions_prompts_(true), | 369 show_extensions_prompts_(true), |
370 install_updates_when_idle_(true), | 370 install_updates_when_idle_(true), |
371 ready_(false), | 371 ready_(false), |
| 372 external_update_check_has_run_(false), |
372 toolbar_model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 373 toolbar_model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
373 menu_manager_(profile), | 374 menu_manager_(profile), |
374 app_notification_manager_( | 375 app_notification_manager_( |
375 new extensions::AppNotificationManager(profile)), | 376 new extensions::AppNotificationManager(profile)), |
376 event_routers_initialized_(false), | 377 event_routers_initialized_(false), |
377 update_once_all_providers_are_ready_(false), | 378 update_once_all_providers_are_ready_(false), |
378 browser_terminating_(false), | 379 browser_terminating_(false), |
379 app_sync_bundle_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 380 app_sync_bundle_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
380 extension_sync_bundle_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 381 extension_sync_bundle_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
381 app_shortcut_manager_(profile) { | 382 app_shortcut_manager_(profile) { |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 // extension service since this can interfere with the main browser process | 605 // extension service since this can interfere with the main browser process |
605 // that is already running an extension service for this profile. | 606 // that is already running an extension service for this profile. |
606 // TODO(aa): can we start up even less of ExtensionService? | 607 // TODO(aa): can we start up even less of ExtensionService? |
607 // http://crbug.com/107636 | 608 // http://crbug.com/107636 |
608 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kImport) && | 609 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kImport) && |
609 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kImportFromFile)) { | 610 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kImportFromFile)) { |
610 if (g_browser_process->profile_manager() && | 611 if (g_browser_process->profile_manager() && |
611 g_browser_process->profile_manager()->will_import()) { | 612 g_browser_process->profile_manager()->will_import()) { |
612 RegisterForImportFinished(); | 613 RegisterForImportFinished(); |
613 } else { | 614 } else { |
614 // TODO(erikkay) this should probably be deferred to a future point | 615 // For newly created profiles, check for external updates immediately. |
615 // rather than running immediately at startup. | 616 // Otherwise delay the check until onload fires for the main frame, to |
616 CheckForExternalUpdates(); | 617 // speed up startup. |
| 618 bool is_new_profile = |
| 619 profile_->GetPrefs()->GetInitializationStatus() == |
| 620 PrefService::INITIALIZATION_STATUS_CREATED_NEW_PROFILE; |
| 621 if (is_new_profile) |
| 622 CheckForExternalUpdates(); |
617 | 623 |
618 // TODO(erikkay) this should probably be deferred as well. | 624 // Hook onload for the first frame to perform delayed startup actions. |
619 GarbageCollectExtensions(); | 625 // TODO(jeremy):If a generic mechanism is introduced to perform actions |
| 626 // delayed until after startup finishes, use that rather than listening |
| 627 // on the event ourselves. |
| 628 registrar_.Add(this, |
| 629 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
| 630 content::NotificationService::AllSources()); |
620 } | 631 } |
621 } | 632 } |
622 } | 633 } |
623 | 634 |
624 bool ExtensionService::UpdateExtension(const std::string& id, | 635 bool ExtensionService::UpdateExtension(const std::string& id, |
625 const FilePath& extension_path, | 636 const FilePath& extension_path, |
626 const GURL& download_url, | 637 const GURL& download_url, |
627 CrxInstaller** out_crx_installer) { | 638 CrxInstaller** out_crx_installer) { |
628 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 639 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
629 if (browser_terminating_) { | 640 if (browser_terminating_) { |
(...skipping 1094 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1724 // are typically part of some larger client application package. To support | 1735 // are typically part of some larger client application package. To support |
1725 // these, the extension will register its location in the the preferences file | 1736 // these, the extension will register its location in the the preferences file |
1726 // (and also, on Windows, in the registry) and this code will periodically | 1737 // (and also, on Windows, in the registry) and this code will periodically |
1727 // check that location for a .crx file, which it will then install locally if | 1738 // check that location for a .crx file, which it will then install locally if |
1728 // a new version is available. | 1739 // a new version is available. |
1729 // Errors are reported through ExtensionErrorReporter. Succcess is not | 1740 // Errors are reported through ExtensionErrorReporter. Succcess is not |
1730 // reported. | 1741 // reported. |
1731 void ExtensionService::CheckForExternalUpdates() { | 1742 void ExtensionService::CheckForExternalUpdates() { |
1732 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1743 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1733 | 1744 |
| 1745 // In the case of a new profile, this function is called at init time and then |
| 1746 // again when the first frame loads. Short-circuit subsequent calls. |
| 1747 if (external_update_check_has_run_) |
| 1748 return; |
| 1749 external_update_check_has_run_ = true; |
| 1750 |
1734 // Note that this installation is intentionally silent (since it didn't | 1751 // Note that this installation is intentionally silent (since it didn't |
1735 // go through the front-end). Extensions that are registered in this | 1752 // go through the front-end). Extensions that are registered in this |
1736 // way are effectively considered 'pre-bundled', and so implicitly | 1753 // way are effectively considered 'pre-bundled', and so implicitly |
1737 // trusted. In general, if something has HKLM or filesystem access, | 1754 // trusted. In general, if something has HKLM or filesystem access, |
1738 // they could install an extension manually themselves anyway. | 1755 // they could install an extension manually themselves anyway. |
1739 | 1756 |
1740 // Ask each external extension provider to give us a call back for each | 1757 // Ask each external extension provider to give us a call back for each |
1741 // extension they know about. See OnExternalExtension(File|UpdateUrl)Found. | 1758 // extension they know about. See OnExternalExtension(File|UpdateUrl)Found. |
1742 extensions::ProviderCollection::const_iterator i; | 1759 extensions::ProviderCollection::const_iterator i; |
1743 for (i = external_extension_providers_.begin(); | 1760 for (i = external_extension_providers_.begin(); |
(...skipping 937 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2681 // that other handlers of this notification will still have | 2698 // that other handlers of this notification will still have |
2682 // access to the Extension and ExtensionHost. | 2699 // access to the Extension and ExtensionHost. |
2683 MessageLoop::current()->PostTask( | 2700 MessageLoop::current()->PostTask( |
2684 FROM_HERE, | 2701 FROM_HERE, |
2685 base::Bind( | 2702 base::Bind( |
2686 &ExtensionService::TrackTerminatedExtension, | 2703 &ExtensionService::TrackTerminatedExtension, |
2687 AsWeakPtr(), | 2704 AsWeakPtr(), |
2688 host->extension())); | 2705 host->extension())); |
2689 break; | 2706 break; |
2690 } | 2707 } |
| 2708 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: |
| 2709 registrar_.Remove( |
| 2710 this, |
| 2711 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
| 2712 content::NotificationService::AllSources()); |
| 2713 |
| 2714 CheckForExternalUpdates(); |
| 2715 GarbageCollectExtensions(); |
| 2716 break; |
| 2717 |
2691 case content::NOTIFICATION_RENDERER_PROCESS_CREATED: { | 2718 case content::NOTIFICATION_RENDERER_PROCESS_CREATED: { |
2692 content::RenderProcessHost* process = | 2719 content::RenderProcessHost* process = |
2693 content::Source<content::RenderProcessHost>(source).ptr(); | 2720 content::Source<content::RenderProcessHost>(source).ptr(); |
2694 Profile* host_profile = | 2721 Profile* host_profile = |
2695 Profile::FromBrowserContext(process->GetBrowserContext()); | 2722 Profile::FromBrowserContext(process->GetBrowserContext()); |
2696 if (!profile_->IsSameProfile(host_profile->GetOriginalProfile())) | 2723 if (!profile_->IsSameProfile(host_profile->GetOriginalProfile())) |
2697 break; | 2724 break; |
2698 | 2725 |
2699 // Extensions need to know the channel for API restrictions. | 2726 // Extensions need to know the channel for API restrictions. |
2700 process->Send(new ExtensionMsg_SetChannel( | 2727 process->Send(new ExtensionMsg_SetChannel( |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3031 extension_id, kOnUpdateAvailableEvent); | 3058 extension_id, kOnUpdateAvailableEvent); |
3032 } else { | 3059 } else { |
3033 // Delay installation if the extension is not idle. | 3060 // Delay installation if the extension is not idle. |
3034 return !IsExtensionIdle(extension_id); | 3061 return !IsExtensionIdle(extension_id); |
3035 } | 3062 } |
3036 } | 3063 } |
3037 | 3064 |
3038 void ExtensionService::OnBlacklistUpdated() { | 3065 void ExtensionService::OnBlacklistUpdated() { |
3039 CheckManagementPolicy(); | 3066 CheckManagementPolicy(); |
3040 } | 3067 } |
OLD | NEW |