| Index: chrome/browser/spellchecker/spellcheck_host_impl.cc
|
| diff --git a/chrome/browser/spellchecker/spellcheck_host_impl.cc b/chrome/browser/spellchecker/spellcheck_host_impl.cc
|
| index 946e5ab29bfd8ff7b979ed7e1107ccaf9247f08b..eda588dafe291b25dbfb3cb01aa3e9d14185d9b9 100644
|
| --- a/chrome/browser/spellchecker/spellcheck_host_impl.cc
|
| +++ b/chrome/browser/spellchecker/spellcheck_host_impl.cc
|
| @@ -6,6 +6,7 @@
|
|
|
| #include <set>
|
|
|
| +#include "base/bind.h"
|
| #include "base/file_util.h"
|
| #include "base/logging.h"
|
| #include "base/path_service.h"
|
| @@ -91,7 +92,8 @@ SpellCheckHostImpl::SpellCheckHostImpl(
|
| tried_to_download_(false),
|
| use_platform_spellchecker_(false),
|
| request_context_getter_(request_context_getter),
|
| - metrics_(metrics) {
|
| + metrics_(metrics),
|
| + weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
|
| DCHECK(profile_);
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
|
|
| @@ -100,7 +102,8 @@ SpellCheckHostImpl::SpellCheckHostImpl(
|
| custom_dictionary_file_ =
|
| personal_file_directory.Append(chrome::kCustomDictionaryFileName);
|
|
|
| - registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CREATED,
|
| + registrar_.Add(weak_ptr_factory_.GetWeakPtr(),
|
| + content::NOTIFICATION_RENDERER_PROCESS_CREATED,
|
| content::NotificationService::AllSources());
|
| }
|
|
|
| @@ -118,8 +121,8 @@ void SpellCheckHostImpl::Initialize() {
|
| use_platform_spellchecker_ = true;
|
| SpellCheckerPlatform::SetLanguage(language_);
|
| MessageLoop::current()->PostTask(FROM_HERE,
|
| - NewRunnableMethod(this,
|
| - &SpellCheckHostImpl::InformProfileOfInitialization));
|
| + base::Bind(&SpellCheckHostImpl::InformProfileOfInitialization,
|
| + weak_ptr_factory_.GetWeakPtr()));
|
| return;
|
| }
|
|
|
| @@ -128,8 +131,8 @@ void SpellCheckHostImpl::Initialize() {
|
| #endif
|
|
|
| BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
|
| - NewRunnableMethod(this,
|
| - &SpellCheckHostImpl::InitializeDictionaryLocation));
|
| + base::Bind(&SpellCheckHostImpl::InitializeDictionaryLocation,
|
| + weak_ptr_factory_.GetWeakPtr()));
|
| }
|
|
|
| void SpellCheckHostImpl::UnsetProfile() {
|
| @@ -175,8 +178,8 @@ void SpellCheckHostImpl::AddWord(const std::string& word) {
|
| if (profile_)
|
| profile_->CustomWordAddedLocally(word);
|
| BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
|
| - NewRunnableMethod(this,
|
| - &SpellCheckHostImpl::WriteWordToCustomDictionary, word));
|
| + base::Bind(&SpellCheckHostImpl::WriteWordToCustomDictionary,
|
| + weak_ptr_factory_.GetWeakPtr(), word));
|
| for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator());
|
| !i.IsAtEnd(); i.Advance()) {
|
| i.GetCurrentValue()->Send(new SpellCheckMsg_WordAdded(word));
|
| @@ -231,7 +234,8 @@ void SpellCheckHostImpl::InitializeInternal() {
|
| // We download from the ui thread because we need to know that
|
| // |request_context_getter_| is still valid before initiating the download.
|
| BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
|
| - NewRunnableMethod(this, &SpellCheckHostImpl::DownloadDictionary));
|
| + base::Bind(&SpellCheckHostImpl::DownloadDictionary,
|
| + weak_ptr_factory_.GetWeakPtr()));
|
| return;
|
| }
|
|
|
| @@ -249,9 +253,9 @@ void SpellCheckHostImpl::InitializeInternal() {
|
| }
|
|
|
| BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
|
| - NewRunnableMethod(
|
| - this,
|
| + base::Bind(
|
| &SpellCheckHostImpl::InformProfileOfInitializationWithCustomWords,
|
| + weak_ptr_factory_.GetWeakPtr(),
|
| custom_words.release()));
|
| }
|
|
|
| @@ -259,7 +263,8 @@ void SpellCheckHostImpl::InitializeOnFileThread() {
|
| DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::FILE));
|
|
|
| BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
|
| - NewRunnableMethod(this, &SpellCheckHostImpl::Initialize));
|
| + base::Bind(&SpellCheckHostImpl::Initialize,
|
| + weak_ptr_factory_.GetWeakPtr()));
|
| }
|
|
|
| void SpellCheckHostImpl::InformProfileOfInitialization() {
|
| @@ -302,7 +307,8 @@ void SpellCheckHostImpl::DownloadDictionary() {
|
| }
|
| GURL url = GURL(std::string(kDownloadServerUrl) +
|
| StringToLowerASCII(bdict_file));
|
| - fetcher_.reset(new URLFetcher(url, URLFetcher::GET, this));
|
| + fetcher_.reset(new URLFetcher(url, URLFetcher::GET,
|
| + weak_ptr_factory_.GetWeakPtr()));
|
| fetcher_->set_request_context(request_context_getter_);
|
| tried_to_download_ = true;
|
| fetcher_->Start();
|
| @@ -349,7 +355,8 @@ void SpellCheckHostImpl::OnURLFetchComplete(const URLFetcher* source,
|
|
|
| data_ = data;
|
| BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
|
| - NewRunnableMethod(this, &SpellCheckHostImpl::SaveDictionaryData));
|
| + base::Bind(&SpellCheckHostImpl::SaveDictionaryData,
|
| + weak_ptr_factory_.GetWeakPtr()));
|
| }
|
|
|
| void SpellCheckHostImpl::Observe(int type,
|
| @@ -371,8 +378,8 @@ void SpellCheckHostImpl::SaveDictionaryData() {
|
| if (!verified) {
|
| LOG(ERROR) << "Failure to verify the downloaded dictionary.";
|
| BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
|
| - NewRunnableMethod(this,
|
| - &SpellCheckHostImpl::InformProfileOfInitialization));
|
| + base::Bind(&SpellCheckHostImpl::InformProfileOfInitialization,
|
| + weak_ptr_factory_.GetWeakPtr()));
|
| return;
|
| }
|
|
|
| @@ -396,8 +403,9 @@ void SpellCheckHostImpl::SaveDictionaryData() {
|
| // To avoid trying to load a partially saved dictionary, shortcut the
|
| // Initialize() call.
|
| BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
|
| - NewRunnableMethod(this,
|
| - &SpellCheckHostImpl::InformProfileOfInitialization));
|
| + base::Bind(
|
| + &SpellCheckHostImpl::InformProfileOfInitialization,
|
| + weak_ptr_factory_.GetWeakPtr()));
|
| return;
|
| }
|
| }
|
|
|