diff options
author | kalman@chromium.org <kalman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-08-11 19:58:08 +0000 |
---|---|---|
committer | kalman@chromium.org <kalman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-08-11 19:58:08 +0000 |
commit | 29381875a9ed3653afc67a6d82d5b1c932bbc8ef (patch) | |
tree | e402c748cd6261d8041927d1482a982ffb8559ab | |
parent | c4719b629a473d43e6508ef259ae8ff8fefe89d6 (diff) | |
download | chromium_src-29381875a9ed3653afc67a6d82d5b1c932bbc8ef.zip chromium_src-29381875a9ed3653afc67a6d82d5b1c932bbc8ef.tar.gz chromium_src-29381875a9ed3653afc67a6d82d5b1c932bbc8ef.tar.bz2 |
Merge 282109 "Monitor Profile destruction from ChromeExtensionMe..."
> Monitor Profile destruction from ChromeExtensionMessageFilter.
>
> BUG=391861
> R=asargent@chromium.org
> TBR=jochen@chromium.org
>
> Review URL: https://codereview.chromium.org/377833009
TBR=kalman@chromium.org
Review URL: https://codereview.chromium.org/463613002
git-svn-id: svn://svn.chromium.org/chrome/branches/2062/src@288773 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/renderer_host/chrome_extension_message_filter.cc | 61 | ||||
-rw-r--r-- | chrome/browser/renderer_host/chrome_extension_message_filter.h | 17 |
2 files changed, 66 insertions, 12 deletions
diff --git a/chrome/browser/renderer_host/chrome_extension_message_filter.cc b/chrome/browser/renderer_host/chrome_extension_message_filter.cc index 6a358ee..a6865c8 100644 --- a/chrome/browser/renderer_host/chrome_extension_message_filter.cc +++ b/chrome/browser/renderer_host/chrome_extension_message_filter.cc @@ -9,6 +9,7 @@ #include "base/files/file_path.h" #include "base/strings/utf_string_conversions.h" #include "chrome/browser/browser_process.h" +#include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/extensions/activity_log/activity_action_constants.h" #include "chrome/browser/extensions/activity_log/activity_actions.h" #include "chrome/browser/extensions/activity_log/activity_log.h" @@ -18,6 +19,7 @@ #include "chrome/browser/profiles/profile_manager.h" #include "chrome/common/extensions/api/i18n/default_locale_handler.h" #include "chrome/common/render_messages.h" +#include "content/public/browser/notification_service.h" #include "content/public/browser/render_process_host.h" #include "extensions/browser/extension_system.h" #include "extensions/common/constants.h" @@ -71,9 +73,14 @@ ChromeExtensionMessageFilter::ChromeExtensionMessageFilter( profile_(profile), extension_info_map_( extensions::ExtensionSystem::Get(profile)->info_map()) { + DCHECK_CURRENTLY_ON(BrowserThread::UI); + notification_registrar_.Add(this, + chrome::NOTIFICATION_PROFILE_DESTROYED, + content::Source<Profile>(profile)); } ChromeExtensionMessageFilter::~ChromeExtensionMessageFilter() { + DCHECK_CURRENTLY_ON(BrowserThread::UI); } bool ChromeExtensionMessageFilter::OnMessageReceived( @@ -115,6 +122,14 @@ void ChromeExtensionMessageFilter::OverrideThreadForMessage( } } +void ChromeExtensionMessageFilter::OnDestruct() const { + if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { + delete this; + } else { + BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this); + } +} + void ChromeExtensionMessageFilter::OnCanTriggerClipboardRead( const GURL& origin, bool* allowed) { *allowed = extension_info_map_->SecurityOriginHasAPIPermission( @@ -154,10 +169,17 @@ void ChromeExtensionMessageFilter::OpenChannelToExtensionOnUIThread( const std::string& channel_name, bool include_tls_channel_id) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - extensions::MessageService::Get(profile_)->OpenChannelToExtension( - source_process_id, source_routing_id, receiver_port_id, - info.source_id, info.target_id, info.source_url, channel_name, - include_tls_channel_id); + if (profile_) { + extensions::MessageService::Get(profile_) + ->OpenChannelToExtension(source_process_id, + source_routing_id, + receiver_port_id, + info.source_id, + info.target_id, + info.source_url, + channel_name, + include_tls_channel_id); + } } void ChromeExtensionMessageFilter::OnOpenChannelToNativeApp( @@ -181,9 +203,14 @@ void ChromeExtensionMessageFilter::OpenChannelToNativeAppOnUIThread( const std::string& source_extension_id, const std::string& native_app_name) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - extensions::MessageService::Get(profile_)->OpenChannelToNativeApp( - render_process_id_, source_routing_id, receiver_port_id, - source_extension_id, native_app_name); + if (profile_) { + extensions::MessageService::Get(profile_) + ->OpenChannelToNativeApp(render_process_id_, + source_routing_id, + receiver_port_id, + source_extension_id, + native_app_name); + } } void ChromeExtensionMessageFilter::OnOpenChannelToTab( @@ -206,9 +233,15 @@ void ChromeExtensionMessageFilter::OpenChannelToTabOnUIThread( const std::string& extension_id, const std::string& channel_name) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - extensions::MessageService::Get(profile_)->OpenChannelToTab( - source_process_id, source_routing_id, receiver_port_id, - tab_id, extension_id, channel_name); + if (profile_) { + extensions::MessageService::Get(profile_) + ->OpenChannelToTab(source_process_id, + source_routing_id, + receiver_port_id, + tab_id, + extension_id, + channel_name); + } } void ChromeExtensionMessageFilter::OnGetExtMessageBundle( @@ -298,3 +331,11 @@ void ChromeExtensionMessageFilter::OnAddEventToExtensionActivityLog( } AddActionToExtensionActivityLog(profile_, action); } + +void ChromeExtensionMessageFilter::Observe( + int type, + const content::NotificationSource& source, + const content::NotificationDetails& details) { + DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); + profile_ = NULL; +} diff --git a/chrome/browser/renderer_host/chrome_extension_message_filter.h b/chrome/browser/renderer_host/chrome_extension_message_filter.h index 57cd927..4a3f341 100644 --- a/chrome/browser/renderer_host/chrome_extension_message_filter.h +++ b/chrome/browser/renderer_host/chrome_extension_message_filter.h @@ -9,6 +9,8 @@ #include "base/sequenced_task_runner_helpers.h" #include "content/public/browser/browser_message_filter.h" +#include "content/public/browser/notification_observer.h" +#include "content/public/browser/notification_registrar.h" class GURL; class Profile; @@ -26,7 +28,8 @@ class InfoMap; // This class filters out incoming Chrome-specific IPC messages from the // extension process on the IPC thread. -class ChromeExtensionMessageFilter : public content::BrowserMessageFilter { +class ChromeExtensionMessageFilter : public content::BrowserMessageFilter, + public content::NotificationObserver { public: ChromeExtensionMessageFilter(int render_process_id, Profile* profile); @@ -35,6 +38,7 @@ class ChromeExtensionMessageFilter : public content::BrowserMessageFilter { virtual void OverrideThreadForMessage( const IPC::Message& message, content::BrowserThread::ID* thread) OVERRIDE; + virtual void OnDestruct() const OVERRIDE; private: friend class content::BrowserThread; @@ -97,14 +101,23 @@ class ChromeExtensionMessageFilter : public content::BrowserMessageFilter { const std::string& extension_id, const ExtensionHostMsg_APIActionOrEvent_Params& params); + // content::NotificationObserver implementation. + virtual void Observe(int type, + const content::NotificationSource& source, + const content::NotificationDetails& details) OVERRIDE; + const int render_process_id_; // The Profile associated with our renderer process. This should only be - // accessed on the UI thread! + // accessed on the UI thread! Furthermore since this class is refcounted it + // may outlive |profile_|, so make sure to NULL check if in doubt; async + // calls and the like. Profile* profile_; scoped_refptr<extensions::InfoMap> extension_info_map_; + content::NotificationRegistrar notification_registrar_; + DISALLOW_COPY_AND_ASSIGN(ChromeExtensionMessageFilter); }; |