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

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

Issue 149172: Modify ResourceFetcher to use WebURLLoader instead of ResourceHandle.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 months 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
« no previous file with comments | « webkit/glue/resource_fetcher.h ('k') | webkit/glue/resource_fetcher_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "config.h"
6 #include "webkit/glue/resource_fetcher.h" 5 #include "webkit/glue/resource_fetcher.h"
7 6
8 #include "base/compiler_specific.h" 7 #include "base/logging.h"
8 #include "webkit/api/public/WebKit.h"
9 #include "webkit/api/public/WebKitClient.h"
10 #include "webkit/api/public/WebURLError.h"
11 #include "webkit/api/public/WebURLLoader.h"
12 #include "webkit/api/public/WebURLRequest.h"
13 #include "webkit/api/public/WebURL.h"
14 #include "webkit/glue/webframe.h"
9 15
10 MSVC_PUSH_WARNING_LEVEL(0); 16 using base::TimeDelta;
11 #include "FrameLoader.h" 17 using WebKit::WebURLError;
12 #include "FrameLoaderClient.h" 18 using WebKit::WebURLLoader;
13 #include "ResourceHandle.h" 19 using WebKit::WebURLRequest;
14 #include "ResourceRequest.h" 20 using WebKit::WebURLResponse;
15 MSVC_POP_WARNING();
16 21
17 #undef LOG 22 namespace webkit_glue {
18 #include "base/logging.h"
19 #include "webkit/glue/glue_util.h"
20 #include "net/url_request/url_request_status.h"
21 23
22 using WebCore::ResourceError; 24 ResourceFetcher::ResourceFetcher(const GURL& url, WebFrame* frame,
23 using WebCore::ResourceHandle; 25 Callback* c)
24 using WebCore::ResourceResponse; 26 : url_(url), callback_(c), completed_(false) {
brettw 2009/07/07 15:59:53 Can you put these initializers on separate lines?
darin (slow to review) 2009/07/07 16:20:52 OK
25
26 ResourceFetcher::ResourceFetcher(const GURL& url, WebCore::Frame* frame,
27 Delegate* d)
28 : url_(url), delegate_(d), completed_(false) {
29 // Can't do anything without a frame. However, delegate can be NULL (so we 27 // Can't do anything without a frame. However, delegate can be NULL (so we
30 // can do a http request and ignore the results). 28 // can do a http request and ignore the results).
31 DCHECK(frame); 29 DCHECK(frame);
32 Start(frame); 30 Start(frame);
33 } 31 }
34 32
35 ResourceFetcher::~ResourceFetcher() { 33 ResourceFetcher::~ResourceFetcher() {
36 if (!completed_ && loader_.get()) 34 if (!completed_ && loader_.get())
37 loader_->cancel(); 35 loader_->cancel();
38 loader_ = NULL;
39 } 36 }
40 37
41 void ResourceFetcher::Cancel() { 38 void ResourceFetcher::Cancel() {
42 if (!completed_) { 39 if (!completed_) {
43 loader_->cancel(); 40 loader_->cancel();
44 completed_ = true; 41 completed_ = true;
45 } 42 }
46 } 43 }
47 44
48 void ResourceFetcher::Start(WebCore::Frame* frame) { 45 void ResourceFetcher::Start(WebFrame* frame) {
49 WebCore::ResourceRequest request(webkit_glue::GURLToKURL(url_)); 46 WebURLRequest request(url_);
50 WebCore::ResourceResponse response; 47 frame->DispatchWillSendRequest(&request);
51 frame->loader()->client()->dispatchWillSendRequest(NULL, 0, request,
52 response);
53 48
54 loader_ = ResourceHandle::create(request, this, NULL, false, false); 49 loader_.reset(WebKit::webKitClient()->createURLLoader());
50 loader_->loadAsynchronously(request, this);
55 } 51 }
56 52
57 ///////////////////////////////////////////////////////////////////////////// 53 /////////////////////////////////////////////////////////////////////////////
58 // ResourceHandleClient methods 54 // WebURLLoaderClient methods
59 void ResourceFetcher::didReceiveResponse(ResourceHandle* resource_handle, 55
60 const ResourceResponse& response) { 56 void ResourceFetcher::willSendRequest(
61 ASSERT(!completed_); 57 WebURLLoader* loader, WebURLRequest& new_request,
62 // It's safe to use the ResourceResponse copy constructor 58 const WebURLResponse& redirect_response) {
63 // (xmlhttprequest.cpp uses it). 59 }
60
61 void ResourceFetcher::didSendData(
62 WebURLLoader* loader, unsigned long long bytes_sent,
63 unsigned long long total_bytes_to_be_sent) {
64 }
65
66 void ResourceFetcher::didReceiveResponse(
67 WebURLLoader* loader, const WebURLResponse& response) {
68 DCHECK(!completed_);
64 response_ = response; 69 response_ = response;
65 } 70 }
66 71
67 void ResourceFetcher::didReceiveData(ResourceHandle* resource_handle, 72 void ResourceFetcher::didReceiveData(
68 const char* data, int length, 73 WebURLLoader* loader, const char* data, int data_length,
69 int total_length) { 74 long long total_data_length) {
70 ASSERT(!completed_); 75 DCHECK(!completed_);
71 if (length <= 0) 76 DCHECK(data_length > 0);
72 return;
73 77
74 data_.append(data, length); 78 data_.append(data, data_length);
75 } 79 }
76 80
77 void ResourceFetcher::didFinishLoading(ResourceHandle* resource_handle) { 81 void ResourceFetcher::didFinishLoading(WebURLLoader* loader) {
78 ASSERT(!completed_); 82 DCHECK(!completed_);
79 completed_ = true; 83 completed_ = true;
80 84
81 if (delegate_) 85 if (callback_)
82 delegate_->OnURLFetchComplete(response_, data_); 86 callback_->Run(response_, data_);
83 } 87 }
84 88
85 void ResourceFetcher::didFail(ResourceHandle* resource_handle, 89 void ResourceFetcher::didFail(WebURLLoader* loader, const WebURLError& error) {
86 const ResourceError& error) { 90 DCHECK(!completed_);
87 ASSERT(!completed_);
88 completed_ = true; 91 completed_ = true;
89 92
90 // Go ahead and tell our delegate that we're done. Send an empty 93 // Go ahead and tell our delegate that we're done.
91 // ResourceResponse and string. 94 if (callback_)
92 if (delegate_) 95 callback_->Run(WebURLResponse(), std::string());
93 delegate_->OnURLFetchComplete(ResourceResponse(), std::string());
94 } 96 }
95 97
96 ///////////////////////////////////////////////////////////////////////////// 98 /////////////////////////////////////////////////////////////////////////////
97 // A resource fetcher with a timeout 99 // A resource fetcher with a timeout
98 100
99 ResourceFetcherWithTimeout::ResourceFetcherWithTimeout( 101 ResourceFetcherWithTimeout::ResourceFetcherWithTimeout(
100 const GURL& url, WebCore::Frame* frame, double timeout_secs, Delegate* d) 102 const GURL& url, WebFrame* frame, int timeout_secs, Callback* c)
101 : ResourceFetcher(url, frame, d) { 103 : ResourceFetcher(url, frame, c) {
102 timeout_timer_.reset(new FetchTimer(this, 104 timeout_timer_.Start(TimeDelta::FromSeconds(timeout_secs), this,
103 &ResourceFetcherWithTimeout::TimeoutFired)); 105 &ResourceFetcherWithTimeout::TimeoutFired);
104 timeout_timer_->startOneShot(timeout_secs);
105 } 106 }
106 107
107 void ResourceFetcherWithTimeout::TimeoutFired(FetchTimer* timer) { 108 void ResourceFetcherWithTimeout::TimeoutFired() {
108 if (!completed_) { 109 if (!completed_) {
109 loader_->cancel(); 110 loader_->cancel();
110 didFail(NULL, ResourceError()); 111 didFail(NULL, WebURLError());
111 } 112 }
112 } 113 }
114
115 } // namespace webkit_glue
OLDNEW
« no previous file with comments | « webkit/glue/resource_fetcher.h ('k') | webkit/glue/resource_fetcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698