Commit 6464cc19 authored by yzshen@chromium.org's avatar yzshen@chromium.org

Fix PepperFlashSettingsManager::Core initialization.

Previously, it is possible that before the newly created Core object is added ref by PepperFlashSettingsManager, Initialize() on the IO thread has caused the ref count to drop to 0 and destroy the object.
This change makes sure that PepperFlashSettingsManager holds 1 ref before doing the initialization.

BUG=132818
TEST=None


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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@146307 0039d316-1c4b-4281-b951-d872f2087c98
parent d2fb312d
...@@ -36,6 +36,7 @@ class PepperFlashSettingsManager::Core ...@@ -36,6 +36,7 @@ class PepperFlashSettingsManager::Core
Core(PepperFlashSettingsManager* manager, Core(PepperFlashSettingsManager* manager,
content::BrowserContext* browser_context); content::BrowserContext* browser_context);
void Initialize();
// Stops sending notifications to |manager_| and sets it to NULL. // Stops sending notifications to |manager_| and sets it to NULL.
void Detach(); void Detach();
...@@ -94,9 +95,9 @@ class PepperFlashSettingsManager::Core ...@@ -94,9 +95,9 @@ class PepperFlashSettingsManager::Core
virtual ~Core(); virtual ~Core();
void Initialize();
void ConnectToChannel(bool success, const IPC::ChannelHandle& handle); void ConnectToChannel(bool success, const IPC::ChannelHandle& handle);
void InitializeOnIOThread();
void DeauthorizeContentLicensesOnIOThread(uint32 request_id); void DeauthorizeContentLicensesOnIOThread(uint32 request_id);
void GetPermissionSettingsOnIOThread( void GetPermissionSettingsOnIOThread(
uint32 request_id, uint32 request_id,
...@@ -179,15 +180,18 @@ PepperFlashSettingsManager::Core::Core(PepperFlashSettingsManager* manager, ...@@ -179,15 +180,18 @@ PepperFlashSettingsManager::Core::Core(PepperFlashSettingsManager* manager,
plugin_prefs_(PluginPrefs::GetForProfile( plugin_prefs_(PluginPrefs::GetForProfile(
Profile::FromBrowserContext(browser_context))) { Profile::FromBrowserContext(browser_context))) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
base::Bind(&Core::Initialize, this));
} }
PepperFlashSettingsManager::Core::~Core() { PepperFlashSettingsManager::Core::~Core() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
} }
void PepperFlashSettingsManager::Core::Initialize() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
base::Bind(&Core::InitializeOnIOThread, this));
}
void PepperFlashSettingsManager::Core::Detach() { void PepperFlashSettingsManager::Core::Detach() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
...@@ -272,32 +276,6 @@ void PepperFlashSettingsManager::Core::OnChannelError() { ...@@ -272,32 +276,6 @@ void PepperFlashSettingsManager::Core::OnChannelError() {
NotifyErrorFromIOThread(); NotifyErrorFromIOThread();
} }
void PepperFlashSettingsManager::Core::Initialize() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
DCHECK(!detached_);
DCHECK(!initialized_);
webkit::WebPluginInfo plugin_info;
if (!PepperFlashSettingsManager::IsPepperFlashInUse(plugin_prefs_.get(),
&plugin_info)) {
NotifyErrorFromIOThread();
return;
}
FilePath profile_path =
browser_context_path_.Append(content::kPepperDataDirname);
#if defined(OS_WIN)
plugin_data_path_ = profile_path.Append(plugin_info.name);
#else
plugin_data_path_ = profile_path.Append(UTF16ToUTF8(plugin_info.name));
#endif
helper_ = content::PepperFlashSettingsHelper::Create();
content::PepperFlashSettingsHelper::OpenChannelCallback callback =
base::Bind(&Core::ConnectToChannel, this);
helper_->OpenChannelToBroker(plugin_info.path, callback);
}
void PepperFlashSettingsManager::Core::ConnectToChannel( void PepperFlashSettingsManager::Core::ConnectToChannel(
bool success, bool success,
const IPC::ChannelHandle& handle) { const IPC::ChannelHandle& handle) {
...@@ -350,6 +328,34 @@ void PepperFlashSettingsManager::Core::ConnectToChannel( ...@@ -350,6 +328,34 @@ void PepperFlashSettingsManager::Core::ConnectToChannel(
} }
} }
void PepperFlashSettingsManager::Core::InitializeOnIOThread() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
DCHECK(!initialized_);
if (detached_)
return;
webkit::WebPluginInfo plugin_info;
if (!PepperFlashSettingsManager::IsPepperFlashInUse(plugin_prefs_.get(),
&plugin_info)) {
NotifyErrorFromIOThread();
return;
}
FilePath profile_path =
browser_context_path_.Append(content::kPepperDataDirname);
#if defined(OS_WIN)
plugin_data_path_ = profile_path.Append(plugin_info.name);
#else
plugin_data_path_ = profile_path.Append(UTF16ToUTF8(plugin_info.name));
#endif
helper_ = content::PepperFlashSettingsHelper::Create();
content::PepperFlashSettingsHelper::OpenChannelCallback callback =
base::Bind(&Core::ConnectToChannel, this);
helper_->OpenChannelToBroker(plugin_info.path, callback);
}
void PepperFlashSettingsManager::Core::DeauthorizeContentLicensesOnIOThread( void PepperFlashSettingsManager::Core::DeauthorizeContentLicensesOnIOThread(
uint32 request_id) { uint32 request_id) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
...@@ -764,8 +770,10 @@ uint32 PepperFlashSettingsManager::GetNextRequestId() { ...@@ -764,8 +770,10 @@ uint32 PepperFlashSettingsManager::GetNextRequestId() {
} }
void PepperFlashSettingsManager::EnsureCoreExists() { void PepperFlashSettingsManager::EnsureCoreExists() {
if (!core_.get()) if (!core_.get()) {
core_ = new Core(this, browser_context_); core_ = new Core(this, browser_context_);
core_->Initialize();
}
} }
void PepperFlashSettingsManager::OnError() { void PepperFlashSettingsManager::OnError() {
......
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