summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-03 20:24:50 +0000
committerwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-03 20:24:50 +0000
commitc4a1dc65ee5c402923c8e58ae29c502c58cbe0c1 (patch)
treebfcb8e3adfced68ea314365b32db1e2c13e2fa43 /chrome
parentd58df53b86f0c72ec4207455b7fb6c8a500979e9 (diff)
downloadchromium_src-c4a1dc65ee5c402923c8e58ae29c502c58cbe0c1.zip
chromium_src-c4a1dc65ee5c402923c8e58ae29c502c58cbe0c1.tar.gz
chromium_src-c4a1dc65ee5c402923c8e58ae29c502c58cbe0c1.tar.bz2
Stop using adding refcounts to some URLRequestJob subtypes.
Switch to using ScopedRunnableMethodFactory::NewRunnableMethod(). Clean up some unnecessary AddRef()/Release() pairs. BUG=63692 TEST=existing Review URL: http://codereview.chromium.org/5559003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@68206 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/net/url_request_failed_dns_job.cc13
-rw-r--r--chrome/browser/net/url_request_failed_dns_job.h8
-rw-r--r--chrome/browser/net/url_request_slow_download_job.cc20
-rw-r--r--chrome/browser/net/url_request_slow_download_job.h3
-rw-r--r--chrome/browser/net/view_http_cache_job_factory.cc36
-rw-r--r--chrome/common/net/url_request_intercept_job.cc11
-rw-r--r--chrome/common/net/url_request_intercept_job.h2
7 files changed, 52 insertions, 41 deletions
diff --git a/chrome/browser/net/url_request_failed_dns_job.cc b/chrome/browser/net/url_request_failed_dns_job.cc
index b97a6b1..7b6a16b 100644
--- a/chrome/browser/net/url_request_failed_dns_job.cc
+++ b/chrome/browser/net/url_request_failed_dns_job.cc
@@ -4,6 +4,7 @@
#include "chrome/browser/net/url_request_failed_dns_job.h"
+#include "base/compiler_specific.h"
#include "base/message_loop.h"
#include "googleurl/src/gurl.h"
#include "net/base/net_errors.h"
@@ -13,9 +14,17 @@
const char URLRequestFailedDnsJob::kTestUrl[] =
"http://url.handled.by.fake.dns/";
+URLRequestFailedDnsJob::URLRequestFailedDnsJob(net::URLRequest* request)
+ : URLRequestJob(request),
+ ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {}
+
+URLRequestFailedDnsJob::~URLRequestFailedDnsJob() {}
+
void URLRequestFailedDnsJob::Start() {
- MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(
- this, &URLRequestFailedDnsJob::StartAsync));
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ method_factory_.NewRunnableMethod(
+ &URLRequestFailedDnsJob::StartAsync));
}
/* static */
diff --git a/chrome/browser/net/url_request_failed_dns_job.h b/chrome/browser/net/url_request_failed_dns_job.h
index 14e5402..197fb2a 100644
--- a/chrome/browser/net/url_request_failed_dns_job.h
+++ b/chrome/browser/net/url_request_failed_dns_job.h
@@ -7,12 +7,12 @@
#define CHROME_BROWSER_NET_URL_REQUEST_FAILED_DNS_JOB_H_
#pragma once
+#include "base/task.h"
#include "net/url_request/url_request_job.h"
class URLRequestFailedDnsJob : public net::URLRequestJob {
public:
- explicit URLRequestFailedDnsJob(net::URLRequest* request)
- : URLRequestJob(request) { }
+ explicit URLRequestFailedDnsJob(net::URLRequest* request);
virtual void Start();
@@ -26,10 +26,12 @@ class URLRequestFailedDnsJob : public net::URLRequestJob {
static void AddUrlHandler();
private:
- ~URLRequestFailedDnsJob() {}
+ ~URLRequestFailedDnsJob();
// Simulate a DNS failure.
void StartAsync();
+
+ ScopedRunnableMethodFactory<URLRequestFailedDnsJob> method_factory_;
};
#endif // CHROME_BROWSER_NET_URL_REQUEST_FAILED_DNS_JOB_H_
diff --git a/chrome/browser/net/url_request_slow_download_job.cc b/chrome/browser/net/url_request_slow_download_job.cc
index a9cae93..7158e7c 100644
--- a/chrome/browser/net/url_request_slow_download_job.cc
+++ b/chrome/browser/net/url_request_slow_download_job.cc
@@ -4,6 +4,7 @@
#include "chrome/browser/net/url_request_slow_download_job.h"
+#include "base/compiler_specific.h"
#include "base/message_loop.h"
#include "base/string_util.h"
#include "googleurl/src/gurl.h"
@@ -26,8 +27,10 @@ std::vector<URLRequestSlowDownloadJob*>
URLRequestSlowDownloadJob::kPendingRequests;
void URLRequestSlowDownloadJob::Start() {
- MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(this,
- &URLRequestSlowDownloadJob::StartAsync));
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ method_factory_.NewRunnableMethod(
+ &URLRequestSlowDownloadJob::StartAsync));
}
/* static */
@@ -42,7 +45,8 @@ void URLRequestSlowDownloadJob::AddUrlHandler() {
}
/*static */
-URLRequestJob* URLRequestSlowDownloadJob::Factory(net::URLRequest* request,
+URLRequestJob* URLRequestSlowDownloadJob::Factory(
+ net::URLRequest* request,
const std::string& scheme) {
URLRequestSlowDownloadJob* job = new URLRequestSlowDownloadJob(request);
if (request->url().spec() != kFinishDownloadUrl)
@@ -61,11 +65,11 @@ void URLRequestSlowDownloadJob::FinishPendingRequests() {
}
URLRequestSlowDownloadJob::URLRequestSlowDownloadJob(net::URLRequest* request)
- : URLRequestJob(request),
- first_download_size_remaining_(kFirstDownloadSize),
- should_finish_download_(false),
- should_send_second_chunk_(false) {
-}
+ : URLRequestJob(request),
+ first_download_size_remaining_(kFirstDownloadSize),
+ should_finish_download_(false),
+ should_send_second_chunk_(false),
+ ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {}
void URLRequestSlowDownloadJob::StartAsync() {
if (LowerCaseEqualsASCII(kFinishDownloadUrl, request_->url().spec().c_str()))
diff --git a/chrome/browser/net/url_request_slow_download_job.h b/chrome/browser/net/url_request_slow_download_job.h
index 22da86a..2d8502c 100644
--- a/chrome/browser/net/url_request_slow_download_job.h
+++ b/chrome/browser/net/url_request_slow_download_job.h
@@ -12,6 +12,7 @@
#include <string>
#include <vector>
+#include "base/task.h"
#include "net/url_request/url_request_job.h"
class URLRequestSlowDownloadJob : public URLRequestJob {
@@ -56,6 +57,8 @@ class URLRequestSlowDownloadJob : public URLRequestJob {
int first_download_size_remaining_;
bool should_finish_download_;
bool should_send_second_chunk_;
+
+ ScopedRunnableMethodFactory<URLRequestSlowDownloadJob> method_factory_;
};
#endif // CHROME_BROWSER_NET_URL_REQUEST_SLOW_DOWNLOAD_JOB_H_
diff --git a/chrome/browser/net/view_http_cache_job_factory.cc b/chrome/browser/net/view_http_cache_job_factory.cc
index 8703877..9ec3964 100644
--- a/chrome/browser/net/view_http_cache_job_factory.cc
+++ b/chrome/browser/net/view_http_cache_job_factory.cc
@@ -4,7 +4,9 @@
#include "chrome/browser/net/view_http_cache_job_factory.h"
+#include "base/compiler_specific.h"
#include "base/message_loop.h"
+#include "base/task.h"
#include "base/string_util.h"
#include "chrome/common/url_constants.h"
#include "net/base/net_errors.h"
@@ -19,12 +21,12 @@ namespace {
class ViewHttpCacheJob : public net::URLRequestJob {
public:
explicit ViewHttpCacheJob(net::URLRequest* request)
- : URLRequestJob(request), data_offset_(0), cancel_(false), busy_(false),
+ : URLRequestJob(request), data_offset_(0),
ALLOW_THIS_IN_INITIALIZER_LIST(
- callback_(this, &ViewHttpCacheJob::OnIOComplete)) {}
+ callback_(this, &ViewHttpCacheJob::OnIOComplete)),
+ ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {}
virtual void Start();
- virtual void Kill();
virtual bool GetMimeType(std::string* mime_type) const;
virtual bool GetCharset(std::string* charset);
virtual bool ReadRawData(net::IOBuffer* buf, int buf_size, int *bytes_read);
@@ -37,18 +39,15 @@ class ViewHttpCacheJob : public net::URLRequestJob {
std::string data_;
int data_offset_;
- bool cancel_;
- bool busy_;
net::ViewCacheHelper cache_helper_;
net::CompletionCallbackImpl<ViewHttpCacheJob> callback_;
+ ScopedRunnableMethodFactory<ViewHttpCacheJob> method_factory_;
};
void ViewHttpCacheJob::Start() {
- if (!request_ || cancel_)
+ if (!request_ || is_done())
return;
- busy_ = true;
- AddRef(); // Released on OnIOComplete().
std::string cache_key =
request_->url().spec().substr(strlen(chrome::kNetworkViewCacheURL));
@@ -65,19 +64,13 @@ void ViewHttpCacheJob::Start() {
if (rv != net::ERR_IO_PENDING) {
// Start reading asynchronously so that all error reporting and data
// callbacks happen as they would for network requests.
- MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(
- this, &ViewHttpCacheJob::OnIOComplete, rv));
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ method_factory_.NewRunnableMethod(
+ &ViewHttpCacheJob::OnIOComplete, rv));
}
}
-void ViewHttpCacheJob::Kill() {
- // We don't want to delete this object while we are busy; we'll do it when it
- // is safe.
- cancel_ = true;
- if (!busy_)
- URLRequestJob::Kill();
-}
-
bool ViewHttpCacheJob::GetMimeType(std::string* mime_type) const {
mime_type->assign("text/html");
return true;
@@ -101,14 +94,7 @@ bool ViewHttpCacheJob::ReadRawData(net::IOBuffer* buf, int buf_size,
}
void ViewHttpCacheJob::OnIOComplete(int result) {
- // We may be holding the last reference to this job.
- scoped_refptr<ViewHttpCacheJob> self(this);
DCHECK_EQ(net::OK, result);
- busy_ = false;
- Release(); // Acquired on Start().
-
- if (cancel_)
- return URLRequestJob::Kill();
// Notify that the headers are complete.
NotifyHeadersComplete();
diff --git a/chrome/common/net/url_request_intercept_job.cc b/chrome/common/net/url_request_intercept_job.cc
index deadd7d..eb3b74f 100644
--- a/chrome/common/net/url_request_intercept_job.cc
+++ b/chrome/common/net/url_request_intercept_job.cc
@@ -8,6 +8,7 @@
#include "chrome/common/net/url_request_intercept_job.h"
+#include "base/compiler_specific.h"
#include "base/message_loop.h"
#include "base/string_util.h"
#include "chrome/common/chrome_plugin_lib.h"
@@ -31,7 +32,8 @@ URLRequestInterceptJob::URLRequestInterceptJob(net::URLRequest* request,
: URLRequestJob(request),
cprequest_(cprequest),
plugin_(plugin),
- read_buffer_(NULL) {
+ read_buffer_(NULL),
+ ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {
cprequest_->data = this; // see FromCPRequest().
registrar_.Add(this, NotificationType::CHROME_PLUGIN_UNLOADED,
@@ -53,8 +55,10 @@ void URLRequestInterceptJob::DetachPlugin() {
void URLRequestInterceptJob::Start() {
// Start reading asynchronously so that all error reporting and data
// callbacks happen as they would for network requests.
- MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(
- this, &URLRequestInterceptJob::StartAsync));
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ method_factory_.NewRunnableMethod(
+ &URLRequestInterceptJob::StartAsync));
}
void URLRequestInterceptJob::Kill() {
@@ -64,6 +68,7 @@ void URLRequestInterceptJob::Kill() {
DetachPlugin();
}
URLRequestJob::Kill();
+ method_factory_.RevokeAll();
}
bool URLRequestInterceptJob::ReadRawData(net::IOBuffer* dest, int dest_size,
diff --git a/chrome/common/net/url_request_intercept_job.h b/chrome/common/net/url_request_intercept_job.h
index 6d47bfc..1d84e42 100644
--- a/chrome/common/net/url_request_intercept_job.h
+++ b/chrome/common/net/url_request_intercept_job.h
@@ -9,6 +9,7 @@
#include <string>
#include "base/scoped_ptr.h"
+#include "base/task.h"
#include "net/url_request/url_request_job.h"
#include "chrome/common/chrome_plugin_api.h"
#include "chrome/common/chrome_plugin_util.h"
@@ -64,6 +65,7 @@ class URLRequestInterceptJob : public net::URLRequestJob,
ChromePluginLib* plugin_;
net::IOBuffer* read_buffer_;
int read_buffer_size_;
+ ScopedRunnableMethodFactory<URLRequestInterceptJob> method_factory_;
DISALLOW_COPY_AND_ASSIGN(URLRequestInterceptJob);
};