Commit 8a16e9b9 authored by rsimha@chromium.org's avatar rsimha@chromium.org

Revert 221580 "Make AppShimHostManager a RefCountedThreadSafe."

Reason for revert: Use-after-free heap errors caught by asan.
See bug 286483.

> Make AppShimHostManager a RefCountedThreadSafe.
> 
> This prevents a crash when Chrome shuts down immediately and 
> AppShimHostManager is destructed before InitOnFileThread is run.
> Note this means AppShimHostManager can stay around longer than
> BrowserProcessPlatformPart during initialization.
> 
> Review URL: https://chromiumcodereview.appspot.com/20065004

BUG=286483,242941
TBR=jackhou@chromium.org

Review URL: https://codereview.chromium.org/24052002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@221793 0039d316-1c4b-4281-b951-d872f2087c98
parent e460a4dc
...@@ -6,25 +6,23 @@ ...@@ -6,25 +6,23 @@
#define CHROME_BROWSER_WEB_APPLICATIONS_APP_SHIM_HOST_MANAGER_MAC_H_ #define CHROME_BROWSER_WEB_APPLICATIONS_APP_SHIM_HOST_MANAGER_MAC_H_
#include "apps/app_shim/extension_app_shim_handler_mac.h" #include "apps/app_shim/extension_app_shim_handler_mac.h"
#include "base/memory/ref_counted.h" #include "base/memory/weak_ptr.h"
#include "ipc/ipc_channel_factory.h" #include "ipc/ipc_channel_factory.h"
// The AppShimHostManager receives connections from app shims on a UNIX // The AppShimHostManager receives connections from app shims on a UNIX
// socket (|factory_|) and creates a helper object to manage the connection. // socket (|factory_|) and creates a helper object to manage the connection.
class AppShimHostManager class AppShimHostManager
: public IPC::ChannelFactory::Delegate, : public IPC::ChannelFactory::Delegate,
public base::RefCountedThreadSafe<AppShimHostManager> { public base::SupportsWeakPtr<AppShimHostManager> {
public: public:
AppShimHostManager(); AppShimHostManager();
virtual ~AppShimHostManager();
apps::ExtensionAppShimHandler* extension_app_shim_handler() { apps::ExtensionAppShimHandler* extension_app_shim_handler() {
return &extension_app_shim_handler_; return &extension_app_shim_handler_;
} }
private: private:
friend class base::RefCountedThreadSafe<AppShimHostManager>;
virtual ~AppShimHostManager();
// IPC::ChannelFactory::Delegate implementation. // IPC::ChannelFactory::Delegate implementation.
virtual void OnClientConnected(const IPC::ChannelHandle& handle) OVERRIDE; virtual void OnClientConnected(const IPC::ChannelHandle& handle) OVERRIDE;
virtual void OnListenError() OVERRIDE; virtual void OnListenError() OVERRIDE;
......
...@@ -31,7 +31,8 @@ AppShimHostManager::AppShimHostManager() { ...@@ -31,7 +31,8 @@ AppShimHostManager::AppShimHostManager() {
apps::AppShimHandler::SetDefaultHandler(&extension_app_shim_handler_); apps::AppShimHandler::SetDefaultHandler(&extension_app_shim_handler_);
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::FILE, FROM_HERE, BrowserThread::FILE, FROM_HERE,
base::Bind(&AppShimHostManager::InitOnFileThread, this)); base::Bind(&AppShimHostManager::InitOnFileThread,
base::Unretained(this)));
} }
AppShimHostManager::~AppShimHostManager() { AppShimHostManager::~AppShimHostManager() {
...@@ -51,7 +52,8 @@ void AppShimHostManager::InitOnFileThread() { ...@@ -51,7 +52,8 @@ void AppShimHostManager::InitOnFileThread() {
factory_.reset(new IPC::ChannelFactory(socket_path, this)); factory_.reset(new IPC::ChannelFactory(socket_path, this));
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE, BrowserThread::IO, FROM_HERE,
base::Bind(&AppShimHostManager::ListenOnIOThread, this)); base::Bind(&AppShimHostManager::ListenOnIOThread,
base::Unretained(this)));
} }
void AppShimHostManager::ListenOnIOThread() { void AppShimHostManager::ListenOnIOThread() {
......
...@@ -5,11 +5,12 @@ ...@@ -5,11 +5,12 @@
#ifndef CHROME_BROWSER_BROWSER_PROCESS_PLATFORM_PART_MAC_H_ #ifndef CHROME_BROWSER_BROWSER_PROCESS_PLATFORM_PART_MAC_H_
#define CHROME_BROWSER_BROWSER_PROCESS_PLATFORM_PART_MAC_H_ #define CHROME_BROWSER_BROWSER_PROCESS_PLATFORM_PART_MAC_H_
#include "apps/app_shim/app_shim_host_manager_mac.h"
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "chrome/browser/browser_process_platform_part_base.h" #include "chrome/browser/browser_process_platform_part_base.h"
class AppShimHostManager;
namespace apps { namespace apps {
class ExtensionAppShimHandler; class ExtensionAppShimHandler;
} }
...@@ -28,7 +29,7 @@ class BrowserProcessPlatformPart : public BrowserProcessPlatformPartBase { ...@@ -28,7 +29,7 @@ class BrowserProcessPlatformPart : public BrowserProcessPlatformPartBase {
private: private:
// Hosts the IPC channel factory that App Shims connect to on Mac. // Hosts the IPC channel factory that App Shims connect to on Mac.
scoped_refptr<AppShimHostManager> app_shim_host_manager_; scoped_ptr<AppShimHostManager> app_shim_host_manager_;
DISALLOW_COPY_AND_ASSIGN(BrowserProcessPlatformPart); DISALLOW_COPY_AND_ASSIGN(BrowserProcessPlatformPart);
}; };
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "chrome/browser/browser_process_platform_part_mac.h" #include "chrome/browser/browser_process_platform_part_mac.h"
#include "apps/app_shim/app_shim_host_manager_mac.h"
#include "chrome/browser/chrome_browser_application_mac.h" #include "chrome/browser/chrome_browser_application_mac.h"
#include "chrome/browser/ui/app_list/app_list_service.h" #include "chrome/browser/ui/app_list/app_list_service.h"
...@@ -14,7 +15,7 @@ BrowserProcessPlatformPart::~BrowserProcessPlatformPart() { ...@@ -14,7 +15,7 @@ BrowserProcessPlatformPart::~BrowserProcessPlatformPart() {
} }
void BrowserProcessPlatformPart::StartTearDown() { void BrowserProcessPlatformPart::StartTearDown() {
app_shim_host_manager_ = NULL; app_shim_host_manager_.reset();
} }
void BrowserProcessPlatformPart::AttemptExit() { void BrowserProcessPlatformPart::AttemptExit() {
...@@ -25,7 +26,7 @@ void BrowserProcessPlatformPart::AttemptExit() { ...@@ -25,7 +26,7 @@ void BrowserProcessPlatformPart::AttemptExit() {
} }
void BrowserProcessPlatformPart::PreMainMessageLoopRun() { void BrowserProcessPlatformPart::PreMainMessageLoopRun() {
app_shim_host_manager_ = new AppShimHostManager; app_shim_host_manager_.reset(new AppShimHostManager);
AppListService::InitAll(NULL); AppListService::InitAll(NULL);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment