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