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

Side by Side Diff: Source/core/platform/network/chromium/ResourceHandle.cpp

Issue 14246006: Implementing timeout support for XHR (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@timeoutResourceHandle
Patch Set: Rebased, cancel method accepting error argument. Created 7 years, 8 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 * Copyright (C) 2013 Intel Corporation. All rights reserved.
3 * 4 *
4 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
6 * met: 7 * met:
7 * 8 *
8 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 11 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer 12 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the 13 * in the documentation and/or other materials provided with the
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 52
52 namespace WebCore { 53 namespace WebCore {
53 54
54 // ResourceHandleInternal ----------------------------------------------------- 55 // ResourceHandleInternal -----------------------------------------------------
55 ResourceHandleInternal::ResourceHandleInternal(NetworkingContext* context, const ResourceRequest& request, ResourceHandleClient* client) 56 ResourceHandleInternal::ResourceHandleInternal(NetworkingContext* context, const ResourceRequest& request, ResourceHandleClient* client)
56 : m_context(context) 57 : m_context(context)
57 , m_request(request) 58 , m_request(request)
58 , m_owner(0) 59 , m_owner(0)
59 , m_client(client) 60 , m_client(client)
60 , m_state(ConnectionStateNew) 61 , m_state(ConnectionStateNew)
62 , m_timeoutTimer(this, &ResourceHandleInternal::timerFired)
61 { 63 {
62 } 64 }
63 65
64 void ResourceHandleInternal::start() 66 void ResourceHandleInternal::start()
65 { 67 {
66 if (m_state != ConnectionStateNew) 68 if (m_state != ConnectionStateNew)
67 CRASH(); 69 CRASH();
68 m_state = ConnectionStateStarted; 70 m_state = ConnectionStateStarted;
69 71
70 m_loader = adoptPtr(Platform::current()->createURLLoader()); 72 m_loader = adoptPtr(Platform::current()->createURLLoader());
71 ASSERT(m_loader); 73 ASSERT(m_loader);
72 74
73 WrappedResourceRequest wrappedRequest(m_request); 75 WrappedResourceRequest wrappedRequest(m_request);
74 wrappedRequest.setAllowStoredCredentials(allowStoredCredentials()); 76 wrappedRequest.setAllowStoredCredentials(allowStoredCredentials());
75 m_loader->loadAsynchronously(wrappedRequest, this); 77 m_loader->loadAsynchronously(wrappedRequest, this);
78
79 if (m_request.timeoutInterval() > 0)
darin (slow to review) 2013/04/22 17:46:39 I'm also curious if we can remove ResourceRequest:
80 m_timeoutTimer.startOneShot(m_request.timeoutInterval());
76 } 81 }
77 82
78 void ResourceHandleInternal::cancel() 83 void ResourceHandleInternal::cancel(const ResourceError& error)
79 { 84 {
80 m_state = ConnectionStateCanceled; 85 m_state = ConnectionStateCanceled;
81 m_loader->cancel(); 86 m_loader->cancel();
82 87
88 if (m_client && !error.isNull()) {
89 m_client->didFail(m_owner, error);
Dominik Röttsches 2013/04/22 15:47:45 didFail() here triggers a WebCore::ResourceLoader:
90 return;
91 }
92
83 // Do not make any further calls to the client. 93 // Do not make any further calls to the client.
84 m_client = 0; 94 m_client = 0;
85 } 95 }
86 96
87 void ResourceHandleInternal::setDefersLoading(bool value) 97 void ResourceHandleInternal::setDefersLoading(bool value)
88 { 98 {
89 m_loader->setDefersLoading(value); 99 m_loader->setDefersLoading(value);
90 } 100 }
91 101
92 void ResourceHandleInternal::didChangePriority(WebURLRequest::Priority newPriori ty) 102 void ResourceHandleInternal::didChangePriority(WebURLRequest::Priority newPriori ty)
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 ASSERT(m_client); 180 ASSERT(m_client);
171 m_state = ConnectionStateFailed; 181 m_state = ConnectionStateFailed;
172 m_client->didFail(m_owner, error); 182 m_client->didFail(m_owner, error);
173 } 183 }
174 184
175 ResourceHandleInternal* ResourceHandleInternal::FromResourceHandle(ResourceHandl e* handle) 185 ResourceHandleInternal* ResourceHandleInternal::FromResourceHandle(ResourceHandl e* handle)
176 { 186 {
177 return handle->d.get(); 187 return handle->d.get();
178 } 188 }
179 189
190 void ResourceHandleInternal::timerFired(Timer<ResourceHandleInternal>* timer)
191 {
192 ASSERT_UNUSED(timer, timer == &m_timeoutTimer);
193
194 // Using values from net/base/net_error_list.h ERR_TIMED_OUT.
195 static const int timeoutError = -7;
196 static const char* const errorDomain = "net";
Dominik Röttsches 2013/04/22 15:47:45 Since the cancel() method now checks for isNull(),
197 ResourceError error(errorDomain, timeoutError, m_request.url().string(), Str ing());
198 error.setIsTimeout(true);
199 cancel(error);
200 }
201
180 // ResourceHandle ------------------------------------------------------------- 202 // ResourceHandle -------------------------------------------------------------
181 203
182 ResourceHandle::ResourceHandle(NetworkingContext* context, const ResourceRequest & request, ResourceHandleClient* client, bool defersLoading, bool shouldContentS niff) 204 ResourceHandle::ResourceHandle(NetworkingContext* context, const ResourceRequest & request, ResourceHandleClient* client, bool defersLoading, bool shouldContentS niff)
183 : d(adoptPtr(new ResourceHandleInternal(context, request, client))) 205 : d(adoptPtr(new ResourceHandleInternal(context, request, client)))
184 { 206 {
185 d->setOwner(this); 207 d->setOwner(this);
186 208
187 // FIXME: Figure out what to do with the bool params. 209 // FIXME: Figure out what to do with the bool params.
188 } 210 }
189 211
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 d->didChangePriority(static_cast<WebURLRequest::Priority>(newPriority)); 297 d->didChangePriority(static_cast<WebURLRequest::Priority>(newPriority));
276 } 298 }
277 299
278 // static 300 // static
279 void ResourceHandle::cacheMetadata(const ResourceResponse& response, const Vecto r<char>& data) 301 void ResourceHandle::cacheMetadata(const ResourceResponse& response, const Vecto r<char>& data)
280 { 302 {
281 WebKit::Platform::current()->cacheMetadata(response.url(), response.response Time(), data.data(), data.size()); 303 WebKit::Platform::current()->cacheMetadata(response.url(), response.response Time(), data.data(), data.size());
282 } 304 }
283 305
284 } // namespace WebCore 306 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698