Clean up ResolveProxyHelper

Since the ResolveProxyHelper is deleted after the callback is called,
there is no need to use weak reference.
This commit is contained in:
Cheng Zhao 2015-06-26 11:04:12 +08:00
parent 143a5e1178
commit aa20f75335
2 changed files with 10 additions and 20 deletions

View file

@ -33,17 +33,13 @@ class ResolveProxyHelper {
const GURL& url, const GURL& url,
Session::ResolveProxyCallback callback) Session::ResolveProxyCallback callback)
: callback_(callback), : callback_(callback),
original_thread_(base::ThreadTaskRunnerHandle::Get()), original_thread_(base::ThreadTaskRunnerHandle::Get()) {
weak_ptr_factory_(this) { scoped_refptr<net::URLRequestContextGetter> context_getter =
scoped_refptr<net::URLRequestContextGetter> getter = browser_context->GetRequestContext();
browser_context->GetDefaultStoragePartition(browser_context) context_getter->GetNetworkTaskRunner()->PostTask(
->GetURLRequestContext();
getter->GetNetworkTaskRunner()->PostTask(
FROM_HERE, FROM_HERE,
base::Bind(&ResolveProxyHelper::ResolveProxy, base::Bind(&ResolveProxyHelper::ResolveProxy,
weak_ptr_factory_.GetWeakPtr(), base::Unretained(this), context_getter, url));
getter, url));
} }
void OnResolveProxyCompleted(int result) { void OnResolveProxyCompleted(int result) {
@ -52,22 +48,19 @@ class ResolveProxyHelper {
proxy = proxy_info_.ToPacString(); proxy = proxy_info_.ToPacString();
original_thread_->PostTask(FROM_HERE, original_thread_->PostTask(FROM_HERE,
base::Bind(callback_, proxy)); base::Bind(callback_, proxy));
delete this; delete this;
} }
private: private:
void ResolveProxy( void ResolveProxy(scoped_refptr<net::URLRequestContextGetter> context_getter,
scoped_refptr<net::URLRequestContextGetter> getter, const GURL& url) {
const GURL& url) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO); DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
net::ProxyService* proxy_service = net::ProxyService* proxy_service =
getter->GetURLRequestContext()->proxy_service(); context_getter->GetURLRequestContext()->proxy_service();
net::CompletionCallback completion_callback = net::CompletionCallback completion_callback =
base::Bind(&ResolveProxyHelper::OnResolveProxyCompleted, base::Bind(&ResolveProxyHelper::OnResolveProxyCompleted,
weak_ptr_factory_.GetWeakPtr()); base::Unretained(this));
// Start the request. // Start the request.
int result = proxy_service->ResolveProxy( int result = proxy_service->ResolveProxy(
@ -83,13 +76,10 @@ class ResolveProxyHelper {
net::ProxyInfo proxy_info_; net::ProxyInfo proxy_info_;
net::ProxyService::PacRequest* pac_req_; net::ProxyService::PacRequest* pac_req_;
scoped_refptr<base::SingleThreadTaskRunner> original_thread_; scoped_refptr<base::SingleThreadTaskRunner> original_thread_;
base::WeakPtrFactory<ResolveProxyHelper> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(ResolveProxyHelper); DISALLOW_COPY_AND_ASSIGN(ResolveProxyHelper);
}; };
} // namespace } // namespace
Session::Session(AtomBrowserContext* browser_context) Session::Session(AtomBrowserContext* browser_context)

2
vendor/brightray vendored

@ -1 +1 @@
Subproject commit b05e019d2f66023fad1ae2f16cc765e3d62ffd5e Subproject commit b158824f01a1aee3bc2e062d2834e7ff3c91c838