summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpenghuang@chromium.org <penghuang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-12 20:29:41 +0000
committerpenghuang@chromium.org <penghuang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-12 20:29:41 +0000
commite0ab447ef3fca38572c9839efa83abce43a6aab0 (patch)
tree1674e12aef78503fbbc27f5a1dfdd9e2112e34b6
parent33a66d5daec87827d0f56d8019be8061436904cf (diff)
downloadchromium_src-e0ab447ef3fca38572c9839efa83abce43a6aab0.zip
chromium_src-e0ab447ef3fca38572c9839efa83abce43a6aab0.tar.gz
chromium_src-e0ab447ef3fca38572c9839efa83abce43a6aab0.tar.bz2
Fix a rare crash in ExtensionResourcesJob::ResolvePath.
Use PostTaskAndReplyWithReply() which guarantees task and reply closures will be deleted on the correct thread, also use WeakPtr to make the task cancelable. BUG=246977 Review URL: https://chromiumcodereview.appspot.com/16124016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@205917 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/extensions/extension_resource_protocols.cc44
1 files changed, 24 insertions, 20 deletions
diff --git a/chrome/browser/extensions/extension_resource_protocols.cc b/chrome/browser/extensions/extension_resource_protocols.cc
index 03f2a67..565b08b 100644
--- a/chrome/browser/extensions/extension_resource_protocols.cc
+++ b/chrome/browser/extensions/extension_resource_protocols.cc
@@ -5,7 +5,9 @@
#include "chrome/browser/extensions/extension_resource_protocols.h"
#include "base/files/file_path.h"
+#include "base/memory/weak_ptr.h"
#include "base/path_service.h"
+#include "base/threading/thread_checker.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/extensions/extension_file_util.h"
#include "content/public/browser/browser_thread.h"
@@ -13,12 +15,18 @@
namespace {
+base::FilePath ResolvePath(const GURL& url) {
+ base::FilePath root_path;
+ PathService::Get(chrome::DIR_RESOURCES_EXTENSION, &root_path);
+ return extension_file_util::ExtensionResourceURLToFilePath(url, root_path);
+}
+
class ExtensionResourcesJob : public net::URLRequestFileJob {
public:
ExtensionResourcesJob(net::URLRequest* request,
net::NetworkDelegate* network_delegate)
: net::URLRequestFileJob(request, network_delegate, base::FilePath()),
- thread_id_(content::BrowserThread::UI) {
+ weak_ptr_factory_(this) {
}
virtual void Start() OVERRIDE;
@@ -26,33 +34,29 @@ class ExtensionResourcesJob : public net::URLRequestFileJob {
protected:
virtual ~ExtensionResourcesJob() {}
- void ResolvePath();
- void ResolvePathDone();
+ void ResolvePathDone(const base::FilePath& resolved_path);
private:
- content::BrowserThread::ID thread_id_;
+ base::WeakPtrFactory<ExtensionResourcesJob> weak_ptr_factory_;
+
+ base::ThreadChecker thread_checker_;
+
+ DISALLOW_COPY_AND_ASSIGN(ExtensionResourcesJob);
};
void ExtensionResourcesJob::Start() {
- bool result =
- content::BrowserThread::GetCurrentThreadIdentifier(&thread_id_);
- CHECK(result) << "Can not get thread id.";
- content::BrowserThread::PostTask(
+ DCHECK(thread_checker_.CalledOnValidThread());
+ content::BrowserThread::PostTaskAndReplyWithResult(
content::BrowserThread::FILE, FROM_HERE,
- base::Bind(&ExtensionResourcesJob::ResolvePath, this));
-}
-
-void ExtensionResourcesJob::ResolvePath() {
- base::FilePath root_path;
- PathService::Get(chrome::DIR_RESOURCES_EXTENSION, &root_path);
- file_path_ = extension_file_util::ExtensionResourceURLToFilePath(
- request()->url(), root_path);
- content::BrowserThread::PostTask(
- thread_id_, FROM_HERE,
- base::Bind(&ExtensionResourcesJob::ResolvePathDone, this));
+ base::Bind(&ResolvePath, request()->url()),
+ base::Bind(&ExtensionResourcesJob::ResolvePathDone,
+ weak_ptr_factory_.GetWeakPtr()));
}
-void ExtensionResourcesJob::ResolvePathDone() {
+void ExtensionResourcesJob::ResolvePathDone(
+ const base::FilePath& resolved_path) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ file_path_ = resolved_path;
net::URLRequestFileJob::Start();
}