0

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.

BUG=242941

Review URL: https://chromiumcodereview.appspot.com/20065004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@221580 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
jackhou@chromium.org
2013-09-06 05:28:17 +00:00
parent c9513b9d4d
commit 1af4296236
4 changed files with 11 additions and 13 deletions

@ -6,23 +6,25 @@
#define CHROME_BROWSER_WEB_APPLICATIONS_APP_SHIM_HOST_MANAGER_MAC_H_
#include "apps/app_shim/extension_app_shim_handler_mac.h"
#include "base/memory/weak_ptr.h"
#include "base/memory/ref_counted.h"
#include "ipc/ipc_channel_factory.h"
// The AppShimHostManager receives connections from app shims on a UNIX
// socket (|factory_|) and creates a helper object to manage the connection.
class AppShimHostManager
: public IPC::ChannelFactory::Delegate,
public base::SupportsWeakPtr<AppShimHostManager> {
public base::RefCountedThreadSafe<AppShimHostManager> {
public:
AppShimHostManager();
virtual ~AppShimHostManager();
apps::ExtensionAppShimHandler* extension_app_shim_handler() {
return &extension_app_shim_handler_;
}
private:
friend class base::RefCountedThreadSafe<AppShimHostManager>;
virtual ~AppShimHostManager();
// IPC::ChannelFactory::Delegate implementation.
virtual void OnClientConnected(const IPC::ChannelHandle& handle) OVERRIDE;
virtual void OnListenError() OVERRIDE;

@ -31,8 +31,7 @@ AppShimHostManager::AppShimHostManager() {
apps::AppShimHandler::SetDefaultHandler(&extension_app_shim_handler_);
BrowserThread::PostTask(
BrowserThread::FILE, FROM_HERE,
base::Bind(&AppShimHostManager::InitOnFileThread,
base::Unretained(this)));
base::Bind(&AppShimHostManager::InitOnFileThread, this));
}
AppShimHostManager::~AppShimHostManager() {
@ -52,8 +51,7 @@ void AppShimHostManager::InitOnFileThread() {
factory_.reset(new IPC::ChannelFactory(socket_path, this));
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::Bind(&AppShimHostManager::ListenOnIOThread,
base::Unretained(this)));
base::Bind(&AppShimHostManager::ListenOnIOThread, this));
}
void AppShimHostManager::ListenOnIOThread() {

@ -5,12 +5,11 @@
#ifndef 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/memory/scoped_ptr.h"
#include "chrome/browser/browser_process_platform_part_base.h"
class AppShimHostManager;
namespace apps {
class ExtensionAppShimHandler;
}
@ -29,7 +28,7 @@ class BrowserProcessPlatformPart : public BrowserProcessPlatformPartBase {
private:
// Hosts the IPC channel factory that App Shims connect to on Mac.
scoped_ptr<AppShimHostManager> app_shim_host_manager_;
scoped_refptr<AppShimHostManager> app_shim_host_manager_;
DISALLOW_COPY_AND_ASSIGN(BrowserProcessPlatformPart);
};

@ -4,7 +4,6 @@
#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/ui/app_list/app_list_service.h"
@ -15,7 +14,7 @@ BrowserProcessPlatformPart::~BrowserProcessPlatformPart() {
}
void BrowserProcessPlatformPart::StartTearDown() {
app_shim_host_manager_.reset();
app_shim_host_manager_ = NULL;
}
void BrowserProcessPlatformPart::AttemptExit() {
@ -26,7 +25,7 @@ void BrowserProcessPlatformPart::AttemptExit() {
}
void BrowserProcessPlatformPart::PreMainMessageLoopRun() {
app_shim_host_manager_.reset(new AppShimHostManager);
app_shim_host_manager_ = new AppShimHostManager;
AppListService::InitAll(NULL);
}