summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/net/chrome_network_delegate.cc7
-rw-r--r--chrome/browser/net/chrome_network_delegate.h1
-rw-r--r--chrome/browser/profiles/profile_manager.cc80
-rw-r--r--chrome/browser/profiles/profile_manager.h6
-rw-r--r--chrome/browser/task_manager/task_manager.cc55
-rw-r--r--chrome/browser/task_manager/task_manager.h25
-rw-r--r--chrome/browser/ui/views/about_ipc_dialog.cc1
-rw-r--r--net/base/network_delegate.cc6
-rw-r--r--net/base/network_delegate.h4
-rw-r--r--net/http/http_cache.cc4
-rw-r--r--net/http/http_cache.h1
-rw-r--r--net/http/http_network_layer.cc10
-rw-r--r--net/http/http_network_layer.h7
-rw-r--r--net/http/http_network_layer_unittest.cc4
-rw-r--r--net/http/http_transaction_factory.h4
-rw-r--r--net/http/http_transaction_unittest.cc2
-rw-r--r--net/http/http_transaction_unittest.h3
-rw-r--r--net/net.gyp3
-rw-r--r--net/proxy/network_delegate_error_observer_unittest.cc6
-rw-r--r--net/url_request/url_request_job.cc25
-rw-r--r--net/url_request/url_request_job.h8
-rw-r--r--net/url_request/url_request_job_tracker.cc62
-rw-r--r--net/url_request/url_request_job_tracker.h105
-rw-r--r--net/url_request/url_request_job_tracker_unittest.cc229
-rw-r--r--net/url_request/url_request_test_util.cc9
-rw-r--r--net/url_request/url_request_test_util.h1
-rw-r--r--net/url_request/url_request_unittest.cc20
27 files changed, 89 insertions, 599 deletions
diff --git a/chrome/browser/net/chrome_network_delegate.cc b/chrome/browser/net/chrome_network_delegate.cc
index e223828..0058ca5 100644
--- a/chrome/browser/net/chrome_network_delegate.cc
+++ b/chrome/browser/net/chrome_network_delegate.cc
@@ -5,10 +5,12 @@
#include "chrome/browser/net/chrome_network_delegate.h"
#include "base/logging.h"
+#include "chrome/browser/custom_handlers/protocol_handler_registry.h"
#include "chrome/browser/extensions/extension_event_router_forwarder.h"
#include "chrome/browser/extensions/extension_proxy_api.h"
#include "chrome/browser/extensions/extension_webrequest_api.h"
#include "chrome/browser/prefs/pref_member.h"
+#include "chrome/browser/task_manager/task_manager.h"
#include "chrome/common/pref_names.h"
#include "content/browser/browser_thread.h"
#include "net/base/host_port_pair.h"
@@ -98,6 +100,11 @@ void ChromeNetworkDelegate::OnResponseStarted(net::URLRequest* request) {
ForwardProxyErrors(request, event_router_.get(), profile_id_);
}
+void ChromeNetworkDelegate::OnRawBytesRead(const net::URLRequest& request,
+ int bytes_read) {
+ TaskManager::GetInstance()->model()->NotifyBytesRead(request, bytes_read);
+}
+
void ChromeNetworkDelegate::OnCompleted(net::URLRequest* request) {
if (request->status().status() == net::URLRequestStatus::SUCCESS) {
bool is_redirect = request->response_headers() &&
diff --git a/chrome/browser/net/chrome_network_delegate.h b/chrome/browser/net/chrome_network_delegate.h
index ad6fd3c..797ab35 100644
--- a/chrome/browser/net/chrome_network_delegate.h
+++ b/chrome/browser/net/chrome_network_delegate.h
@@ -51,6 +51,7 @@ class ChromeNetworkDelegate : public net::NetworkDelegate {
virtual void OnBeforeRedirect(net::URLRequest* request,
const GURL& new_location);
virtual void OnResponseStarted(net::URLRequest* request);
+ virtual void OnRawBytesRead(const net::URLRequest& request, int bytes_read);
virtual void OnCompleted(net::URLRequest* request);
virtual void OnURLRequestDestroyed(net::URLRequest* request);
virtual void OnHttpTransactionDestroyed(uint64 request_id);
diff --git a/chrome/browser/profiles/profile_manager.cc b/chrome/browser/profiles/profile_manager.cc
index dbd03de..c30950a 100644
--- a/chrome/browser/profiles/profile_manager.cc
+++ b/chrome/browser/profiles/profile_manager.cc
@@ -32,45 +32,12 @@
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h"
#include "net/url_request/url_request_job.h"
-#include "net/url_request/url_request_job_tracker.h"
#if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/cros/cros_library.h"
#include "chrome/browser/chromeos/cros/cryptohome_library.h"
#endif
-namespace {
-
-void SuspendURLRequestJobs() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- for (net::URLRequestJobTracker::JobIterator i =
- net::g_url_request_job_tracker.begin();
- i != net::g_url_request_job_tracker.end(); ++i)
- (*i)->Kill();
-}
-
-void SuspendRequestContext(
- net::URLRequestContextGetter* request_context_getter) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
-
- scoped_refptr<net::URLRequestContext> request_context =
- request_context_getter->GetURLRequestContext();
-
- request_context->http_transaction_factory()->Suspend(true);
-}
-
-void ResumeRequestContext(
- net::URLRequestContextGetter* request_context_getter) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
-
- scoped_refptr<net::URLRequestContext> request_context =
- request_context_getter->GetURLRequestContext();
- request_context->http_transaction_factory()->Suspend(false);
-}
-
-} // namespace
-
-
bool ProfileManagerObserver::DeleteAfterCreation() {
return false;
}
@@ -111,7 +78,6 @@ Profile* ProfileManager::GetDefaultProfile() {
}
ProfileManager::ProfileManager() : logged_in_(false) {
- base::SystemMonitor::Get()->AddObserver(this);
BrowserList::AddObserver(this);
#if defined(OS_CHROMEOS)
registrar_.Add(
@@ -122,9 +88,6 @@ ProfileManager::ProfileManager() : logged_in_(false) {
}
ProfileManager::~ProfileManager() {
- base::SystemMonitor* system_monitor = base::SystemMonitor::Get();
- if (system_monitor)
- system_monitor->RemoveObserver(this);
BrowserList::RemoveObserver(this);
}
@@ -347,49 +310,6 @@ Profile* ProfileManager::GetProfileByPath(const FilePath& path) const {
return (iter == profiles_info_.end()) ? NULL : iter->second->profile.get();
}
-void ProfileManager::OnSuspend() {
- DCHECK(CalledOnValidThread());
-
- bool posted = BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- NewRunnableFunction(&SuspendURLRequestJobs));
- DCHECK(posted);
-
- scoped_refptr<net::URLRequestContextGetter> request_context;
- std::vector<Profile*> profiles(GetLoadedProfiles());
- for (size_t i = 0; i < profiles.size(); ++i) {
- request_context = profiles[i]->GetRequestContext();
- posted = BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- NewRunnableFunction(&SuspendRequestContext, request_context));
- DCHECK(posted);
- request_context = profiles[i]->GetRequestContextForMedia();
- posted = BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- NewRunnableFunction(&SuspendRequestContext, request_context));
- DCHECK(posted);
- }
-}
-
-void ProfileManager::OnResume() {
- DCHECK(CalledOnValidThread());
-
- scoped_refptr<net::URLRequestContextGetter> request_context;
- std::vector<Profile*> profiles(GetLoadedProfiles());
- for (size_t i = 0; i < profiles.size(); ++i) {
- request_context = profiles[i]->GetRequestContext();
- bool posted = BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- NewRunnableFunction(&ResumeRequestContext, request_context));
- DCHECK(posted);
- request_context = profiles[i]->GetRequestContextForMedia();
- posted = BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- NewRunnableFunction(&ResumeRequestContext, request_context));
- DCHECK(posted);
- }
-}
-
void ProfileManager::Observe(
NotificationType type,
const NotificationSource& source,
diff --git a/chrome/browser/profiles/profile_manager.h b/chrome/browser/profiles/profile_manager.h
index de656d6..d06f700 100644
--- a/chrome/browser/profiles/profile_manager.h
+++ b/chrome/browser/profiles/profile_manager.h
@@ -17,7 +17,6 @@
#include "base/memory/linked_ptr.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop.h"
-#include "base/system_monitor/system_monitor.h"
#include "base/threading/non_thread_safe.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser_list.h"
@@ -39,7 +38,6 @@ class ProfileManagerObserver {
};
class ProfileManager : public base::NonThreadSafe,
- public base::SystemMonitor::PowerObserver,
public BrowserList::Observer,
public NotificationObserver,
public Profile::Delegate {
@@ -97,10 +95,6 @@ class ProfileManager : public base::NonThreadSafe,
// related with the creation order.
std::vector<Profile*> GetLoadedProfiles() const;
- // PowerObserver notifications
- virtual void OnSuspend();
- virtual void OnResume();
-
// NotificationObserver implementation.
virtual void Observe(NotificationType type,
const NotificationSource& source,
diff --git a/chrome/browser/task_manager/task_manager.cc b/chrome/browser/task_manager/task_manager.cc
index 15282d2..68e5bfc 100644
--- a/chrome/browser/task_manager/task_manager.cc
+++ b/chrome/browser/task_manager/task_manager.cc
@@ -34,8 +34,6 @@
#include "grit/app_resources.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
-#include "net/url_request/url_request.h"
-#include "net/url_request/url_request_job.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "unicode/coll.h"
@@ -500,13 +498,6 @@ void TaskManagerModel::StartUpdating() {
}
update_state_ = TASK_PENDING;
- // Register jobs notifications so we can compute network usage (it must be
- // done from the IO thread).
- BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- NewRunnableMethod(
- this, &TaskManagerModel::RegisterForJobDoneNotifications));
-
// Notify resource providers that we are updating.
for (ResourceProviderList::iterator iter = providers_.begin();
iter != providers_.end(); ++iter) {
@@ -531,12 +522,6 @@ void TaskManagerModel::StopUpdating() {
(*iter)->StopUpdating();
}
- // Unregister jobs notification (must be done from the IO thread).
- BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- NewRunnableMethod(
- this, &TaskManagerModel::UnregisterForJobDoneNotifications));
-
// Must clear the resources before the next attempt to start updating.
Clear();
}
@@ -549,14 +534,6 @@ void TaskManagerModel::AddResourceProvider(
providers_.push_back(provider);
}
-void TaskManagerModel::RegisterForJobDoneNotifications() {
- net::g_url_request_job_tracker.AddObserver(this);
-}
-
-void TaskManagerModel::UnregisterForJobDoneNotifications() {
- net::g_url_request_job_tracker.RemoveObserver(this);
-}
-
void TaskManagerModel::AddResource(TaskManager::Resource* resource) {
base::ProcessHandle process = resource->GetProcess();
@@ -836,41 +813,21 @@ void TaskManagerModel::BytesRead(BytesReadParam param) {
}
-// In order to retrieve the network usage, we register for net::URLRequestJob
-// notifications. Every time we get notified some bytes were read we bump a
-// counter of read bytes for the associated resource. When the timer ticks,
-// we'll compute the actual network usage (see the Refresh method).
-void TaskManagerModel::OnJobAdded(net::URLRequestJob* job) {
-}
-
-void TaskManagerModel::OnJobRemoved(net::URLRequestJob* job) {
-}
-
-void TaskManagerModel::OnJobDone(net::URLRequestJob* job,
- const net::URLRequestStatus& status) {
-}
-
-void TaskManagerModel::OnJobRedirect(net::URLRequestJob* job,
- const GURL& location,
- int status_code) {
-}
-
-void TaskManagerModel::OnBytesRead(net::URLRequestJob* job, const char* buf,
- int byte_count) {
+void TaskManagerModel::NotifyBytesRead(const net::URLRequest& request,
+ int byte_count) {
// Only net::URLRequestJob instances created by the ResourceDispatcherHost
// have a render view associated. All other jobs will have -1 returned for
// the render process child and routing ids - the jobs may still match a
// resource based on their origin id, otherwise BytesRead() will attribute
// the activity to the Browser resource.
int render_process_host_child_id = -1, routing_id = -1;
- ResourceDispatcherHost::RenderViewForRequest(job->request(),
+ ResourceDispatcherHost::RenderViewForRequest(&request,
&render_process_host_child_id,
&routing_id);
// Get the origin PID of the request's originator. This will only be set for
// plugins - for renderer or browser initiated requests it will be zero.
- int origin_pid =
- chrome_browser_net::GetOriginPIDForRequest(job->request());
+ int origin_pid = chrome_browser_net::GetOriginPIDForRequest(&request);
// This happens in the IO thread, post it to the UI thread.
BrowserThread::PostTask(
@@ -879,8 +836,8 @@ void TaskManagerModel::OnBytesRead(net::URLRequestJob* job, const char* buf,
this,
&TaskManagerModel::BytesRead,
BytesReadParam(origin_pid,
- render_process_host_child_id,
- routing_id, byte_count)));
+ render_process_host_child_id,
+ routing_id, byte_count)));
}
bool TaskManagerModel::GetProcessMetricsForRow(
diff --git a/chrome/browser/task_manager/task_manager.h b/chrome/browser/task_manager/task_manager.h
index 2b8d0a2..bfe7174 100644
--- a/chrome/browser/task_manager/task_manager.h
+++ b/chrome/browser/task_manager/task_manager.h
@@ -20,7 +20,6 @@
#include "base/string16.h"
#include "base/timer.h"
#include "chrome/browser/renderer_host/web_cache_manager.h"
-#include "net/url_request/url_request_job_tracker.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebCache.h"
class Extension;
@@ -31,6 +30,9 @@ class TaskManagerModel;
namespace base {
class ProcessMetrics;
}
+namespace net {
+class URLRequest;
+}
// This class is a singleton.
class TaskManager {
@@ -214,8 +216,7 @@ class TaskManagerModelObserver {
};
// The model that the TaskManager is using.
-class TaskManagerModel : public net::URLRequestJobTracker::JobObserver,
- public base::RefCountedThreadSafe<TaskManagerModel> {
+class TaskManagerModel : public base::RefCountedThreadSafe<TaskManagerModel> {
public:
explicit TaskManagerModel(TaskManager* task_manager);
@@ -297,18 +298,6 @@ class TaskManagerModel : public net::URLRequestJobTracker::JobObserver,
// Returns Extension of given resource or NULL if not applicable.
const Extension* GetResourceExtension(int index) const;
- // JobObserver methods:
- virtual void OnJobAdded(net::URLRequestJob* job);
- virtual void OnJobRemoved(net::URLRequestJob* job);
- virtual void OnJobDone(net::URLRequestJob* job,
- const net::URLRequestStatus& status);
- virtual void OnJobRedirect(net::URLRequestJob* job,
- const GURL& location,
- int status_code);
- virtual void OnBytesRead(net::URLRequestJob* job,
- const char* buf,
- int byte_count);
-
void AddResource(TaskManager::Resource* resource);
void RemoveResource(TaskManager::Resource* resource);
@@ -329,6 +318,8 @@ class TaskManagerModel : public net::URLRequestJobTracker::JobObserver,
size_t v8_memory_allocated,
size_t v8_memory_used);
+ void NotifyBytesRead(const net::URLRequest& request, int bytes_read);
+
private:
friend class base::RefCountedThreadSafe<TaskManagerModel>;
FRIEND_TEST_ALL_PREFIXES(TaskManagerTest, RefreshCalled);
@@ -379,10 +370,6 @@ class TaskManagerModel : public net::URLRequestJobTracker::JobObserver,
void AddItem(TaskManager::Resource* resource, bool notify_table);
void RemoveItem(TaskManager::Resource* resource);
- // Register for network usage updates
- void RegisterForJobDoneNotifications();
- void UnregisterForJobDoneNotifications();
-
// Returns the network usage (in bytes per seconds) for the specified
// resource. That's the value retrieved at the last timer's tick.
int64 GetNetworkUsageForResource(TaskManager::Resource* resource) const;
diff --git a/chrome/browser/ui/views/about_ipc_dialog.cc b/chrome/browser/ui/views/about_ipc_dialog.cc
index 9b7cf3a..fd446f3 100644
--- a/chrome/browser/ui/views/about_ipc_dialog.cc
+++ b/chrome/browser/ui/views/about_ipc_dialog.cc
@@ -29,7 +29,6 @@
#include "content/common/plugin_messages.h"
#include "net/url_request/url_request.h"
#include "net/url_request/url_request_job.h"
-#include "net/url_request/url_request_job_tracker.h"
#include "views/controls/button/text_button.h"
#include "views/controls/native/native_view_host.h"
#include "views/layout/grid_layout.h"
diff --git a/net/base/network_delegate.cc b/net/base/network_delegate.cc
index 248ef45..a236c5d 100644
--- a/net/base/network_delegate.cc
+++ b/net/base/network_delegate.cc
@@ -40,6 +40,12 @@ void NetworkDelegate::NotifyResponseStarted(URLRequest* request) {
OnResponseStarted(request);
}
+void NetworkDelegate::NotifyRawBytesRead(const URLRequest& request,
+ int bytes_read) {
+ DCHECK(CalledOnValidThread());
+ OnRawBytesRead(request, bytes_read);
+}
+
void NetworkDelegate::NotifyBeforeRedirect(URLRequest* request,
const GURL& new_location) {
DCHECK(CalledOnValidThread());
diff --git a/net/base/network_delegate.h b/net/base/network_delegate.h
index 977df2f..741b7f2 100644
--- a/net/base/network_delegate.h
+++ b/net/base/network_delegate.h
@@ -49,6 +49,7 @@ class NetworkDelegate : public base::NonThreadSafe {
void NotifyBeforeRedirect(URLRequest* request,
const GURL& new_location);
void NotifyResponseStarted(URLRequest* request);
+ void NotifyRawBytesRead(const URLRequest& request, int bytes_read);
void NotifyCompleted(URLRequest* request);
void NotifyURLRequestDestroyed(URLRequest* request);
void NotifyHttpTransactionDestroyed(uint64 request_id);
@@ -89,6 +90,9 @@ class NetworkDelegate : public base::NonThreadSafe {
// This corresponds to URLRequestDelegate::OnResponseStarted.
virtual void OnResponseStarted(URLRequest* request) = 0;
+ // Called every time we read raw bytes.
+ virtual void OnRawBytesRead(const URLRequest& request, int bytes_read) = 0;
+
// Indicates that the URL request has been completed or failed.
virtual void OnCompleted(URLRequest* request) = 0;
diff --git a/net/http/http_cache.cc b/net/http/http_cache.cc
index 3943619..fbc6461 100644
--- a/net/http/http_cache.cc
+++ b/net/http/http_cache.cc
@@ -478,10 +478,6 @@ HttpNetworkSession* HttpCache::GetSession() {
return network->GetSession();
}
-void HttpCache::Suspend(bool suspend) {
- network_layer_->Suspend(suspend);
-}
-
//-----------------------------------------------------------------------------
int HttpCache::CreateBackend(disk_cache::Backend** backend,
diff --git a/net/http/http_cache.h b/net/http/http_cache.h
index 5728dbd..3fbb5e1 100644
--- a/net/http/http_cache.h
+++ b/net/http/http_cache.h
@@ -183,7 +183,6 @@ class NET_API HttpCache : public HttpTransactionFactory,
virtual int CreateTransaction(scoped_ptr<HttpTransaction>* trans);
virtual HttpCache* GetCache();
virtual HttpNetworkSession* GetSession();
- virtual void Suspend(bool suspend);
protected:
// Disk cache entry data indices.
diff --git a/net/http/http_network_layer.cc b/net/http/http_network_layer.cc
index ce3fab8..68bc5f8 100644
--- a/net/http/http_network_layer.cc
+++ b/net/http/http_network_layer.cc
@@ -152,11 +152,15 @@ HttpNetworkSession* HttpNetworkLayer::GetSession() {
return session_;
}
-void HttpNetworkLayer::Suspend(bool suspend) {
- suspended_ = suspend;
+void HttpNetworkLayer::OnSuspend() {
+ suspended_ = true;
- if (suspend && session_)
+ if (session_)
session_->CloseIdleConnections();
}
+void HttpNetworkLayer::OnResume() {
+ suspended_ = false;
+}
+
} // namespace net
diff --git a/net/http/http_network_layer.h b/net/http/http_network_layer.h
index 35652c3..448ae8d 100644
--- a/net/http/http_network_layer.h
+++ b/net/http/http_network_layer.h
@@ -10,6 +10,7 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
+#include "base/system_monitor/system_monitor.h"
#include "base/threading/non_thread_safe.h"
#include "net/base/net_api.h"
#include "net/http/http_transaction_factory.h"
@@ -31,6 +32,7 @@ class SSLConfigService;
class SSLHostInfoFactory;
class NET_API HttpNetworkLayer : public HttpTransactionFactory,
+ public base::SystemMonitor::PowerObserver,
NON_EXPORTED_BASE(public base::NonThreadSafe) {
public:
// Construct a HttpNetworkLayer with an existing HttpNetworkSession which
@@ -60,7 +62,10 @@ class NET_API HttpNetworkLayer : public HttpTransactionFactory,
virtual int CreateTransaction(scoped_ptr<HttpTransaction>* trans);
virtual HttpCache* GetCache();
virtual HttpNetworkSession* GetSession();
- virtual void Suspend(bool suspend);
+
+ // base::SystemMonitor::PowerObserver methods:
+ virtual void OnSuspend();
+ virtual void OnResume();
private:
const scoped_refptr<HttpNetworkSession> session_;
diff --git a/net/http/http_network_layer_unittest.cc b/net/http/http_network_layer_unittest.cc
index 3bd6db8..3c356e8 100644
--- a/net/http/http_network_layer_unittest.cc
+++ b/net/http/http_network_layer_unittest.cc
@@ -57,14 +57,14 @@ TEST_F(HttpNetworkLayerTest, Suspend) {
trans.reset();
- factory_->Suspend(true);
+ factory_->OnSuspend();
rv = factory_->CreateTransaction(&trans);
EXPECT_EQ(ERR_NETWORK_IO_SUSPENDED, rv);
ASSERT_TRUE(trans == NULL);
- factory_->Suspend(false);
+ factory_->OnResume();
rv = factory_->CreateTransaction(&trans);
EXPECT_EQ(OK, rv);
diff --git a/net/http/http_transaction_factory.h b/net/http/http_transaction_factory.h
index aef7e03..2dcb9f8 100644
--- a/net/http/http_transaction_factory.h
+++ b/net/http/http_transaction_factory.h
@@ -30,10 +30,6 @@ class NET_API HttpTransactionFactory {
// Returns the associated HttpNetworkSession used by new transactions.
virtual HttpNetworkSession* GetSession() = 0;
-
- // Suspends the creation of new transactions. If |suspend| is false, creation
- // of new transactions is resumed.
- virtual void Suspend(bool suspend) = 0;
};
} // namespace net
diff --git a/net/http/http_transaction_unittest.cc b/net/http/http_transaction_unittest.cc
index c900247..cec930d 100644
--- a/net/http/http_transaction_unittest.cc
+++ b/net/http/http_transaction_unittest.cc
@@ -339,8 +339,6 @@ net::HttpNetworkSession* MockNetworkLayer::GetSession() {
return NULL;
}
-void MockNetworkLayer::Suspend(bool suspend) {}
-
//-----------------------------------------------------------------------------
// helpers
diff --git a/net/http/http_transaction_unittest.h b/net/http/http_transaction_unittest.h
index 0a11bb5..589133c 100644
--- a/net/http/http_transaction_unittest.h
+++ b/net/http/http_transaction_unittest.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -204,7 +204,6 @@ class MockNetworkLayer : public net::HttpTransactionFactory {
virtual int CreateTransaction(scoped_ptr<net::HttpTransaction>* trans);
virtual net::HttpCache* GetCache();
virtual net::HttpNetworkSession* GetSession();
- virtual void Suspend(bool suspend);
private:
int transaction_count_;
diff --git a/net/net.gyp b/net/net.gyp
index 2c90ed6..9169f97 100644
--- a/net/net.gyp
+++ b/net/net.gyp
@@ -608,8 +608,6 @@
'url_request/url_request_job_factory.h',
'url_request/url_request_job_manager.cc',
'url_request/url_request_job_manager.h',
- 'url_request/url_request_job_tracker.cc',
- 'url_request/url_request_job_tracker.h',
'url_request/url_request_netlog_params.cc',
'url_request/url_request_netlog_params.h',
'url_request/url_request_redirect_job.cc',
@@ -979,7 +977,6 @@
'tools/dump_cache/url_utilities_unittest.cc',
'udp/udp_socket_unittest.cc',
'url_request/url_request_job_factory_unittest.cc',
- 'url_request/url_request_job_tracker_unittest.cc',
'url_request/url_request_throttler_unittest.cc',
'url_request/url_request_unittest.cc',
'url_request/view_cache_helper_unittest.cc',
diff --git a/net/proxy/network_delegate_error_observer_unittest.cc b/net/proxy/network_delegate_error_observer_unittest.cc
index f76f2d0..0239b53 100644
--- a/net/proxy/network_delegate_error_observer_unittest.cc
+++ b/net/proxy/network_delegate_error_observer_unittest.cc
@@ -15,6 +15,7 @@ DISABLE_RUNNABLE_METHOD_REFCOUNT(net::NetworkDelegateErrorObserver);
namespace net {
namespace {
+
class TestNetworkDelegate : public net::NetworkDelegate {
public:
TestNetworkDelegate() : got_pac_error_(false) {}
@@ -40,13 +41,16 @@ class TestNetworkDelegate : public net::NetworkDelegate {
virtual void OnBeforeRedirect(URLRequest* request,
const GURL& new_location) {}
virtual void OnResponseStarted(URLRequest* request) {}
+ virtual void OnRawBytesRead(const URLRequest& request,
+ int bytes_read) {}
virtual void OnCompleted(URLRequest* request) {}
virtual void OnURLRequestDestroyed(URLRequest* request) {}
virtual void OnHttpTransactionDestroyed(uint64 request_id) {}
virtual URLRequestJob* OnMaybeCreateURLRequestJob(URLRequest* request) {
return NULL;
}
- virtual void OnPACScriptError(int line_number, const string16& error) {
+ virtual void OnPACScriptError(int line_number,
+ const string16& error) {
got_pac_error_ = true;
}
diff --git a/net/url_request/url_request_job.cc b/net/url_request/url_request_job.cc
index 3073414..331b968 100644
--- a/net/url_request/url_request_job.cc
+++ b/net/url_request/url_request_job.cc
@@ -17,7 +17,6 @@
#include "net/http/http_response_headers.h"
#include "net/url_request/url_request.h"
#include "net/url_request/url_request_context.h"
-#include "net/url_request/url_request_job_tracker.h"
namespace net {
@@ -33,14 +32,15 @@ URLRequestJob::URLRequestJob(URLRequest* request)
expected_content_size_(-1),
deferred_redirect_status_code_(-1),
ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {
- g_url_request_job_tracker.AddNewJob(this);
+ base::SystemMonitor* system_monitor = base::SystemMonitor::Get();
+ if (system_monitor)
+ base::SystemMonitor::Get()->AddObserver(this);
}
void URLRequestJob::SetUpload(UploadData* upload) {
}
-void URLRequestJob::SetExtraRequestHeaders(
- const HttpRequestHeaders& headers) {
+void URLRequestJob::SetExtraRequestHeaders(const HttpRequestHeaders& headers) {
}
void URLRequestJob::Kill() {
@@ -203,8 +203,14 @@ HostPortPair URLRequestJob::GetSocketAddress() const {
return HostPortPair();
}
+void URLRequestJob::OnSuspend() {
+ Kill();
+}
+
URLRequestJob::~URLRequestJob() {
- g_url_request_job_tracker.RemoveJob(this);
+ base::SystemMonitor* system_monitor = base::SystemMonitor::Get();
+ if (system_monitor)
+ base::SystemMonitor::Get()->RemoveObserver(this);
}
void URLRequestJob::NotifyHeadersComplete() {
@@ -362,8 +368,6 @@ void URLRequestJob::NotifyDone(const URLRequestStatus &status) {
request_->set_status(status);
}
- g_url_request_job_tracker.OnJobDone(this, status);
-
if (request_ && request_->context() &&
request_->context()->network_delegate()) {
request_->context()->network_delegate()->NotifyCompleted(request_);
@@ -578,8 +582,6 @@ bool URLRequestJob::ReadRawDataHelper(IOBuffer* buf, int buf_size,
}
void URLRequestJob::FollowRedirect(const GURL& location, int http_status_code) {
- g_url_request_job_tracker.OnJobRedirect(this, location, http_status_code);
-
int rv = request_->Redirect(location, http_status_code);
if (rv != OK)
NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv));
@@ -596,8 +598,9 @@ void URLRequestJob::OnRawReadComplete(int bytes_read) {
void URLRequestJob::RecordBytesRead(int bytes_read) {
filter_input_byte_count_ += bytes_read;
UpdatePacketReadTimes(); // Facilitate stats recording if it is active.
- g_url_request_job_tracker.OnBytesRead(this, raw_read_buffer_->data(),
- bytes_read);
+ const URLRequestContext* context = request_->context();
+ if (context && context->network_delegate())
+ context->network_delegate()->NotifyRawBytesRead(*request_, bytes_read);
}
bool URLRequestJob::FilterHasData() {
diff --git a/net/url_request/url_request_job.h b/net/url_request/url_request_job.h
index d4330c2..d2261ca 100644
--- a/net/url_request/url_request_job.h
+++ b/net/url_request/url_request_job.h
@@ -12,6 +12,7 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/string16.h"
+#include "base/system_monitor/system_monitor.h"
#include "base/task.h"
#include "base/time.h"
#include "googleurl/src/gurl.h"
@@ -31,7 +32,8 @@ class UploadData;
class URLRequestStatus;
class X509Certificate;
-class NET_API URLRequestJob : public base::RefCounted<URLRequestJob> {
+class NET_API URLRequestJob : public base::RefCounted<URLRequestJob>,
+ public base::SystemMonitor::PowerObserver {
public:
explicit URLRequestJob(URLRequest* request);
@@ -180,6 +182,10 @@ class NET_API URLRequestJob : public base::RefCounted<URLRequestJob> {
// See url_request.h for details.
virtual HostPortPair GetSocketAddress() const;
+ // base::SystemMonitor::PowerObserver methods:
+ // We invoke URLRequestJob::Kill on suspend (crbug.com/4606).
+ virtual void OnSuspend();
+
protected:
friend class base::RefCounted<URLRequestJob>;
virtual ~URLRequestJob();
diff --git a/net/url_request/url_request_job_tracker.cc b/net/url_request/url_request_job_tracker.cc
deleted file mode 100644
index 632d0a3..0000000
--- a/net/url_request/url_request_job_tracker.cc
+++ /dev/null
@@ -1,62 +0,0 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "net/url_request/url_request_job_tracker.h"
-
-#include <algorithm>
-
-#include "base/logging.h"
-#include "net/url_request/url_request_job.h"
-
-namespace net {
-
-URLRequestJobTracker g_url_request_job_tracker;
-
-URLRequestJobTracker::URLRequestJobTracker() {
-}
-
-URLRequestJobTracker::~URLRequestJobTracker() {
- DLOG_IF(WARNING, !active_jobs_.empty()) <<
- "Leaking " << active_jobs_.size() << " URLRequestJob object(s), this "
- "could be because the URLRequest forgot to free it (bad), or if the "
- "program was terminated while a request was active (normal).";
-}
-
-void URLRequestJobTracker::AddNewJob(URLRequestJob* job) {
- active_jobs_.push_back(job);
- FOR_EACH_OBSERVER(JobObserver, observers_, OnJobAdded(job));
-}
-
-void URLRequestJobTracker::RemoveJob(URLRequestJob* job) {
- JobList::iterator iter = std::find(active_jobs_.begin(), active_jobs_.end(),
- job);
- if (iter == active_jobs_.end()) {
- NOTREACHED() << "Removing a non-active job";
- return;
- }
- active_jobs_.erase(iter);
-
- FOR_EACH_OBSERVER(JobObserver, observers_, OnJobRemoved(job));
-}
-
-void URLRequestJobTracker::OnJobDone(URLRequestJob* job,
- const URLRequestStatus& status) {
- FOR_EACH_OBSERVER(JobObserver, observers_, OnJobDone(job, status));
-}
-
-void URLRequestJobTracker::OnJobRedirect(URLRequestJob* job,
- const GURL& location,
- int status_code) {
- FOR_EACH_OBSERVER(JobObserver, observers_,
- OnJobRedirect(job, location, status_code));
-}
-
-void URLRequestJobTracker::OnBytesRead(URLRequestJob* job,
- const char* buf,
- int byte_count) {
- FOR_EACH_OBSERVER(JobObserver, observers_,
- OnBytesRead(job, buf, byte_count));
-}
-
-} // namespace net
diff --git a/net/url_request/url_request_job_tracker.h b/net/url_request/url_request_job_tracker.h
deleted file mode 100644
index cb691ce..0000000
--- a/net/url_request/url_request_job_tracker.h
+++ /dev/null
@@ -1,105 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef NET_URL_REQUEST_URL_REQUEST_JOB_TRACKER_H_
-#define NET_URL_REQUEST_URL_REQUEST_JOB_TRACKER_H_
-#pragma once
-
-#include <vector>
-
-#include "base/observer_list.h"
-#include "net/base/net_api.h"
-#include "net/url_request/url_request_status.h"
-
-class GURL;
-
-namespace net {
-class URLRequestJob;
-
-// This class maintains a list of active URLRequestJobs for debugging purposes.
-// This allows us to warn on leaked jobs and also allows an observer to track
-// what is happening, for example, for the network status monitor.
-//
-// NOTE: URLRequest is single-threaded, so this class should only be used
-// onthe same thread where all of the application's URLRequest calls are
-// made.
-//
-class NET_API URLRequestJobTracker {
- public:
- typedef std::vector<URLRequestJob*> JobList;
- typedef JobList::const_iterator JobIterator;
-
- // The observer's methods are called on the thread that called AddObserver.
- class JobObserver {
- public:
- virtual ~JobObserver() {}
-
- // Called after the given job has been added to the list
- virtual void OnJobAdded(URLRequestJob* job) = 0;
-
- // Called after the given job has been removed from the list
- virtual void OnJobRemoved(URLRequestJob* job) = 0;
-
- // Called when the given job has completed, before notifying the request
- virtual void OnJobDone(URLRequestJob* job,
- const URLRequestStatus& status) = 0;
-
- // Called when the given job is about to follow a redirect to the given
- // new URL. The redirect type is given in status_code
- virtual void OnJobRedirect(URLRequestJob* job, const GURL& location,
- int status_code) = 0;
-
- // Called when a new chunk of unfiltered bytes has been read for
- // the given job. |byte_count| is the number of bytes for that
- // read event only. |buf| is a pointer to the data buffer that
- // contains those bytes. The data in |buf| is only valid for the
- // duration of the OnBytesRead callback.
- virtual void OnBytesRead(URLRequestJob* job, const char* buf,
- int byte_count) = 0;
- };
-
- URLRequestJobTracker();
- ~URLRequestJobTracker();
-
- // adds or removes an observer from the list. note, these methods should
- // only be called on the same thread where URLRequest objects are used.
- void AddObserver(JobObserver* observer) {
- observers_.AddObserver(observer);
- }
- void RemoveObserver(JobObserver* observer) {
- observers_.RemoveObserver(observer);
- }
-
- // adds or removes the job from the active list, should be called by the
- // job constructor and destructor. Note: don't use "AddJob" since that
- // is #defined by windows.h :(
- void AddNewJob(URLRequestJob* job);
- void RemoveJob(URLRequestJob* job);
-
- // Job status change notifications
- void OnJobDone(URLRequestJob* job, const URLRequestStatus& status);
- void OnJobRedirect(URLRequestJob* job, const GURL& location,
- int status_code);
-
- // Bytes read notifications.
- void OnBytesRead(URLRequestJob* job, const char* buf, int byte_count);
-
- // allows iteration over all active jobs
- JobIterator begin() const {
- return active_jobs_.begin();
- }
- JobIterator end() const {
- return active_jobs_.end();
- }
-
- private:
- ObserverList<JobObserver> observers_;
- JobList active_jobs_;
-};
-
-NET_API extern URLRequestJobTracker g_url_request_job_tracker;
-
-} // namespace net
-
-#endif // NET_URL_REQUEST_URL_REQUEST_JOB_TRACKER_H_
diff --git a/net/url_request/url_request_job_tracker_unittest.cc b/net/url_request/url_request_job_tracker_unittest.cc
deleted file mode 100644
index d29f2d3..0000000
--- a/net/url_request/url_request_job_tracker_unittest.cc
+++ /dev/null
@@ -1,229 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include <string.h>
-#include <algorithm>
-#include <string>
-#include <vector>
-#include "base/message_loop.h"
-#include "googleurl/src/gurl.h"
-#include "net/base/filter.h"
-#include "net/base/io_buffer.h"
-#include "net/url_request/url_request.h"
-#include "net/url_request/url_request_job.h"
-#include "net/url_request/url_request_job_tracker.h"
-#include "net/url_request/url_request_status.h"
-#include "net/url_request/url_request_test_util.h"
-#include "testing/gmock/include/gmock/gmock.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "testing/platform_test.h"
-
-using testing::Eq;
-using testing::InSequence;
-using testing::NotNull;
-using testing::StrictMock;
-
-namespace net {
-namespace {
-
-const char kBasic[] = "Hello\n";
-
-// The above string "Hello\n", gzip compressed.
-const unsigned char kCompressed[] = {
- 0x1f, 0x8b, 0x08, 0x08, 0x38, 0x18, 0x2e, 0x4c, 0x00, 0x03, 0x63,
- 0x6f, 0x6d, 0x70, 0x72, 0x65, 0x73, 0x73, 0x65, 0x64, 0x2e, 0x68,
- 0x74, 0x6d, 0x6c, 0x00, 0xf3, 0x48, 0xcd, 0xc9, 0xc9, 0xe7, 0x02,
- 0x00, 0x16, 0x35, 0x96, 0x31, 0x06, 0x00, 0x00, 0x00
-};
-
-bool GetResponseBody(const GURL& url, std::string* out_body) {
- if (url.spec() == "test:basic") {
- *out_body = kBasic;
- } else if (url.spec() == "test:compressed") {
- out_body->assign(reinterpret_cast<const char*>(kCompressed),
- sizeof(kCompressed));
- } else {
- return false;
- }
-
- return true;
-}
-
-class MockJobObserver : public URLRequestJobTracker::JobObserver {
- public:
- MOCK_METHOD1(OnJobAdded, void(URLRequestJob* job));
- MOCK_METHOD1(OnJobRemoved, void(URLRequestJob* job));
- MOCK_METHOD2(OnJobDone, void(URLRequestJob* job,
- const URLRequestStatus& status));
- MOCK_METHOD3(OnJobRedirect, void(URLRequestJob* job,
- const GURL& location,
- int status_code));
- MOCK_METHOD3(OnBytesRead, void(URLRequestJob* job,
- const char* buf,
- int byte_count));
-};
-
-// A URLRequestJob that returns static content for given URLs. We do
-// not use URLRequestTestJob here because URLRequestTestJob fakes
-// async operations by calling ReadRawData synchronously in an async
-// callback. This test requires a URLRequestJob that returns false for
-// async reads, in order to exercise the real async read codepath.
-class URLRequestJobTrackerTestJob : public URLRequestJob {
- public:
- URLRequestJobTrackerTestJob(URLRequest* request, bool async_reads)
- : URLRequestJob(request), async_reads_(async_reads) {}
-
- void Start() {
- ASSERT_TRUE(GetResponseBody(request_->url(), &response_data_));
-
- // 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, &URLRequestJobTrackerTestJob::NotifyHeadersComplete));
- }
-
- bool ReadRawData(IOBuffer* buf, int buf_size,
- int *bytes_read) {
- const size_t bytes_to_read = std::min(
- response_data_.size(), static_cast<size_t>(buf_size));
-
- // Regardless of whether we're performing a sync or async read,
- // copy the data into the caller's buffer now. That way we don't
- // have to hold on to the buffers in the async case.
- memcpy(buf->data(), response_data_.data(), bytes_to_read);
- response_data_.erase(0, bytes_to_read);
-
- if (async_reads_) {
- SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0));
- MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(
- this, &URLRequestJobTrackerTestJob::OnReadCompleted,
- bytes_to_read));
- } else {
- SetStatus(URLRequestStatus());
- *bytes_read = bytes_to_read;
- }
- return !async_reads_;
- }
-
- void OnReadCompleted(int status) {
- if (status == 0) {
- NotifyDone(URLRequestStatus());
- } else if (status > 0) {
- SetStatus(URLRequestStatus());
- } else {
- ASSERT_FALSE(true) << "Unexpected OnReadCompleted callback.";
- }
-
- NotifyReadComplete(status);
- }
-
- Filter* SetupFilter() const {
- return request_->url().spec() == "test:compressed"
- ? Filter::GZipFactory() : NULL;
- }
-
- // The data to send, will be set in Start().
- std::string response_data_;
-
- // Should reads be synchronous or asynchronous?
- const bool async_reads_;
-};
-
-// Google Mock Matcher to check two URLRequestStatus instances for
-// equality.
-MATCHER_P(StatusEq, other, "") {
- return (arg.status() == other.status() &&
- arg.os_error() == other.os_error());
-}
-
-// Google Mock Matcher to check that two blocks of memory are equal.
-MATCHER_P2(MemEq, other, len, "") {
- return memcmp(arg, other, len) == 0;
-}
-
-class URLRequestJobTrackerTest : public PlatformTest {
- protected:
- static void SetUpTestCase() {
- URLRequest::RegisterProtocolFactory("test", &Factory);
- }
-
- virtual void SetUp() {
- g_async_reads = true;
- }
-
- void AssertJobTrackerCallbacks(const char* url) {
- InSequence seq;
- testing::StrictMock<MockJobObserver> observer;
-
- const GURL gurl(url);
- std::string body;
- ASSERT_TRUE(GetResponseBody(gurl, &body));
-
- // We expect to receive one call for each method on the JobObserver,
- // in the following order:
- EXPECT_CALL(observer, OnJobAdded(NotNull()));
- EXPECT_CALL(observer, OnBytesRead(NotNull(),
- MemEq(body.data(), body.size()),
- Eq(static_cast<int>(body.size()))));
- EXPECT_CALL(observer, OnJobDone(NotNull(),
- StatusEq(URLRequestStatus())));
- EXPECT_CALL(observer, OnJobRemoved(NotNull()));
-
- // Attach our observer and perform the resource fetch.
- g_url_request_job_tracker.AddObserver(&observer);
- Fetch(gurl);
- g_url_request_job_tracker.RemoveObserver(&observer);
- }
-
- void Fetch(const GURL& url) {
- TestDelegate d;
- {
- URLRequest request(url, &d);
- request.Start();
- MessageLoop::current()->RunAllPending();
- }
-
- // A few sanity checks to make sure that the delegate also
- // receives the expected callbacks.
- EXPECT_EQ(1, d.response_started_count());
- EXPECT_FALSE(d.received_data_before_response());
- EXPECT_STREQ(kBasic, d.data_received().c_str());
- }
-
- static URLRequest::ProtocolFactory Factory;
- static bool g_async_reads;
-};
-
-// static
-URLRequestJob* URLRequestJobTrackerTest::Factory(
- URLRequest* request,
- const std::string& scheme) {
- return new URLRequestJobTrackerTestJob(request, g_async_reads);
-}
-
-// static
-bool URLRequestJobTrackerTest::g_async_reads = true;
-
-TEST_F(URLRequestJobTrackerTest, BasicAsync) {
- g_async_reads = true;
- AssertJobTrackerCallbacks("test:basic");
-}
-
-TEST_F(URLRequestJobTrackerTest, BasicSync) {
- g_async_reads = false;
- AssertJobTrackerCallbacks("test:basic");
-}
-
-TEST_F(URLRequestJobTrackerTest, CompressedAsync) {
- g_async_reads = true;
- AssertJobTrackerCallbacks("test:compressed");
-}
-
-TEST_F(URLRequestJobTrackerTest, CompressedSync) {
- g_async_reads = false;
- AssertJobTrackerCallbacks("test:compressed");
-}
-
-} // namespace
-} // namespace net
diff --git a/net/url_request/url_request_test_util.cc b/net/url_request/url_request_test_util.cc
index c9e2fe4..67d685e 100644
--- a/net/url_request/url_request_test_util.cc
+++ b/net/url_request/url_request_test_util.cc
@@ -252,7 +252,7 @@ TestNetworkDelegate::~TestNetworkDelegate() {}
int TestNetworkDelegate::OnBeforeURLRequest(
net::URLRequest* request,
net::CompletionCallback* callback,
- GURL* new_url) {
+ GURL* new_url ) {
created_requests_++;
return net::OK;
}
@@ -281,6 +281,10 @@ void TestNetworkDelegate::OnResponseStarted(net::URLRequest* request) {
}
}
+void TestNetworkDelegate::OnRawBytesRead(const net::URLRequest& request,
+ int bytes_read) {
+}
+
void TestNetworkDelegate::OnCompleted(net::URLRequest* request) {
if (request->status().status() == net::URLRequestStatus::FAILED) {
error_count_++;
@@ -288,7 +292,8 @@ void TestNetworkDelegate::OnCompleted(net::URLRequest* request) {
}
}
-void TestNetworkDelegate::OnURLRequestDestroyed(net::URLRequest* request) {
+void TestNetworkDelegate::OnURLRequestDestroyed(
+ net::URLRequest* request) {
destroyed_requests_++;
}
diff --git a/net/url_request/url_request_test_util.h b/net/url_request/url_request_test_util.h
index c4371c7..772abc6 100644
--- a/net/url_request/url_request_test_util.h
+++ b/net/url_request/url_request_test_util.h
@@ -194,6 +194,7 @@ class TestNetworkDelegate : public net::NetworkDelegate {
virtual void OnBeforeRedirect(net::URLRequest* request,
const GURL& new_location);
virtual void OnResponseStarted(net::URLRequest* request);
+ virtual void OnRawBytesRead(const net::URLRequest& request, int bytes_read);
virtual void OnCompleted(net::URLRequest* request);
virtual void OnURLRequestDestroyed(net::URLRequest* request);
virtual void OnHttpTransactionDestroyed(uint64 request_id);
diff --git a/net/url_request/url_request_unittest.cc b/net/url_request/url_request_unittest.cc
index 31bea3b..ebabe8d 100644
--- a/net/url_request/url_request_unittest.cc
+++ b/net/url_request/url_request_unittest.cc
@@ -12,6 +12,7 @@
#include <algorithm>
#include <string>
+#include "base/compiler_specific.h"
#include "base/file_util.h"
#include "base/format_macros.h"
#include "base/message_loop.h"
@@ -50,13 +51,6 @@
using base::Time;
-// We don't need a refcount because we are guaranteed the test will not proceed
-// until its task is run.
-namespace net {
-class BlockingNetworkDelegate;
-} // namespace net
-DISABLE_RUNNABLE_METHOD_REFCOUNT(net::BlockingNetworkDelegate);
-
namespace net {
namespace {
@@ -126,7 +120,9 @@ void CheckSSLInfo(const SSLInfo& ssl_info) {
// them.
class BlockingNetworkDelegate : public TestNetworkDelegate {
public:
- BlockingNetworkDelegate() : callback_retval_(net::OK) {}
+ BlockingNetworkDelegate()
+ : callback_retval_(net::OK),
+ ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {}
void set_callback_retval(int retval) { callback_retval_ = retval; }
void set_redirect_url(const GURL& url) { redirect_url_ = url; }
@@ -145,9 +141,10 @@ class BlockingNetworkDelegate : public TestNetworkDelegate {
if (!redirect_url_.is_empty())
*new_url = redirect_url_;
- MessageLoop::current()->PostTask(FROM_HERE,
- NewRunnableMethod(this, &BlockingNetworkDelegate::DoCallback,
- callback));
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ method_factory_.NewRunnableMethod(&BlockingNetworkDelegate::DoCallback,
+ callback));
return net::ERR_IO_PENDING;
}
@@ -157,6 +154,7 @@ class BlockingNetworkDelegate : public TestNetworkDelegate {
int callback_retval_;
GURL redirect_url_;
+ ScopedRunnableMethodFactory<BlockingNetworkDelegate> method_factory_;
};
// Inherit PlatformTest since we require the autorelease pool on Mac OS X.f