Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(527)

Side by Side Diff: webkit/glue/resource_fetcher.cc

Issue 8550010: base::Bind() conversion for webkit. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "webkit/glue/resource_fetcher.h" 5 #include "webkit/glue/resource_fetcher.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 8 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" 9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h"
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKitPlatformSupport .h" 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKitPlatformSupport .h"
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h" 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h"
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoader.h" 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoader.h"
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h"
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h"
15 15
16 using base::TimeDelta; 16 using base::TimeDelta;
17 using WebKit::WebFrame; 17 using WebKit::WebFrame;
18 using WebKit::WebURLError; 18 using WebKit::WebURLError;
19 using WebKit::WebURLLoader; 19 using WebKit::WebURLLoader;
20 using WebKit::WebURLRequest; 20 using WebKit::WebURLRequest;
21 using WebKit::WebURLResponse; 21 using WebKit::WebURLResponse;
22 22
23 namespace webkit_glue { 23 namespace webkit_glue {
24 24
25 ResourceFetcher::ResourceFetcher(const GURL& url, WebFrame* frame, 25 ResourceFetcher::ResourceFetcher(const GURL& url, WebFrame* frame,
26 WebURLRequest::TargetType target_type, 26 WebURLRequest::TargetType target_type,
27 Callback* callback) 27 const Callback& callback)
28 : url_(url), 28 : url_(url),
29 target_type_(target_type), 29 target_type_(target_type),
30 completed_(false), 30 completed_(false),
31 callback_(callback) { 31 callback_(callback) {
32 // Can't do anything without a frame. However, delegate can be NULL (so we 32 // Can't do anything without a frame. However, delegate can be NULL (so we
33 // can do a http request and ignore the results). 33 // can do a http request and ignore the results).
34 DCHECK(frame); 34 DCHECK(frame);
35 Start(frame); 35 Start(frame);
36 } 36 }
37 37
(...skipping 13 matching lines...) Expand all
51 WebURLRequest request(url_); 51 WebURLRequest request(url_);
52 request.setTargetType(target_type_); 52 request.setTargetType(target_type_);
53 frame->dispatchWillSendRequest(request); 53 frame->dispatchWillSendRequest(request);
54 54
55 loader_.reset(WebKit::webKitPlatformSupport()->createURLLoader()); 55 loader_.reset(WebKit::webKitPlatformSupport()->createURLLoader());
56 loader_->loadAsynchronously(request, this); 56 loader_->loadAsynchronously(request, this);
57 } 57 }
58 58
59 void ResourceFetcher::RunCallback(const WebURLResponse& response, 59 void ResourceFetcher::RunCallback(const WebURLResponse& response,
60 const std::string& data) { 60 const std::string& data) {
61 if (!callback_.get()) 61 if (callback_.is_null())
62 return; 62 return;
63 63
64 // Take care to clear callback_ before running the callback as it may lead to 64 // Take care to clear callback_ before running the callback as it may lead to
65 // our destruction. 65 // our destruction.
awong 2011/11/21 21:46:56 Update similar to image_resource_fetcher.cc
dcheng 2011/11/21 22:04:16 Done.
66 scoped_ptr<Callback> callback; 66 Callback callback = callback_;
67 callback.swap(callback_); 67 callback_.Reset();
68 callback->Run(response, data); 68 callback.Run(response, data);
69 } 69 }
70 70
71 ///////////////////////////////////////////////////////////////////////////// 71 /////////////////////////////////////////////////////////////////////////////
72 // WebURLLoaderClient methods 72 // WebURLLoaderClient methods
73 73
74 void ResourceFetcher::willSendRequest( 74 void ResourceFetcher::willSendRequest(
75 WebURLLoader* loader, WebURLRequest& new_request, 75 WebURLLoader* loader, WebURLRequest& new_request,
76 const WebURLResponse& redirect_response) { 76 const WebURLResponse& redirect_response) {
77 } 77 }
78 78
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 118
119 // Go ahead and tell our delegate that we're done. 119 // Go ahead and tell our delegate that we're done.
120 RunCallback(WebURLResponse(), std::string()); 120 RunCallback(WebURLResponse(), std::string());
121 } 121 }
122 122
123 ///////////////////////////////////////////////////////////////////////////// 123 /////////////////////////////////////////////////////////////////////////////
124 // A resource fetcher with a timeout 124 // A resource fetcher with a timeout
125 125
126 ResourceFetcherWithTimeout::ResourceFetcherWithTimeout( 126 ResourceFetcherWithTimeout::ResourceFetcherWithTimeout(
127 const GURL& url, WebFrame* frame, WebURLRequest::TargetType target_type, 127 const GURL& url, WebFrame* frame, WebURLRequest::TargetType target_type,
128 int timeout_secs, Callback* callback) 128 int timeout_secs, const Callback& callback)
129 : ResourceFetcher(url, frame, target_type, callback) { 129 : ResourceFetcher(url, frame, target_type, callback) {
130 timeout_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(timeout_secs), this, 130 timeout_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(timeout_secs), this,
131 &ResourceFetcherWithTimeout::TimeoutFired); 131 &ResourceFetcherWithTimeout::TimeoutFired);
132 } 132 }
133 133
134 ResourceFetcherWithTimeout::~ResourceFetcherWithTimeout() { 134 ResourceFetcherWithTimeout::~ResourceFetcherWithTimeout() {
135 } 135 }
136 136
137 void ResourceFetcherWithTimeout::TimeoutFired() { 137 void ResourceFetcherWithTimeout::TimeoutFired() {
138 if (!completed_) { 138 if (!completed_) {
139 loader_->cancel(); 139 loader_->cancel();
140 didFail(NULL, WebURLError()); 140 didFail(NULL, WebURLError());
141 } 141 }
142 } 142 }
143 143
144 } // namespace webkit_glue 144 } // namespace webkit_glue
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698