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

Side by Side Diff: content/renderer/fetchers/resource_fetcher_impl.h

Issue 532773002: Implement ManifestFetcher, helper to fetch Web Manifests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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 // 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 #ifndef CONTENT_RENDERER_FETCHERS_RESOURCE_FETCHER_H_ 5 #ifndef CONTENT_RENDERER_FETCHERS_RESOURCE_FETCHER_H_
6 #define CONTENT_RENDERER_FETCHERS_RESOURCE_FETCHER_H_ 6 #define CONTENT_RENDERER_FETCHERS_RESOURCE_FETCHER_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/timer/timer.h" 14 #include "base/timer/timer.h"
15 #include "content/public/renderer/resource_fetcher.h" 15 #include "content/public/renderer/resource_fetcher.h"
16 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h" 16 #include "content/renderer/fetchers/web_url_loader_client_impl.h"
17 #include "third_party/WebKit/public/platform/WebURLRequest.h" 17 #include "third_party/WebKit/public/platform/WebURLRequest.h"
18 #include "third_party/WebKit/public/platform/WebURLResponse.h" 18 #include "third_party/WebKit/public/platform/WebURLResponse.h"
19 19
20 class GURL; 20 class GURL;
21 21
22 namespace blink { 22 namespace blink {
23 class WebFrame; 23 class WebFrame;
24 class WebURLLoader; 24 class WebURLLoader;
25 struct WebURLError; 25 struct WebURLError;
26 } 26 }
27 27
28 namespace content { 28 namespace content {
29 29
30 class ResourceFetcherImpl : public ResourceFetcher, 30 class ResourceFetcherImpl : public ResourceFetcher,
31 public blink::WebURLLoaderClient { 31 public WebURLLoaderClientImpl {
32 public: 32 public:
33 // ResourceFetcher implementation: 33 // ResourceFetcher implementation:
34 virtual void SetMethod(const std::string& method) OVERRIDE; 34 virtual void SetMethod(const std::string& method) OVERRIDE;
35 virtual void SetBody(const std::string& body) OVERRIDE; 35 virtual void SetBody(const std::string& body) OVERRIDE;
36 virtual void SetHeader(const std::string& header, 36 virtual void SetHeader(const std::string& header,
37 const std::string& value) OVERRIDE; 37 const std::string& value) OVERRIDE;
38 virtual void Start(blink::WebFrame* frame, 38 virtual void Start(blink::WebFrame* frame,
39 blink::WebURLRequest::RequestContext request_context, 39 blink::WebURLRequest::RequestContext request_context,
40 blink::WebURLRequest::FrameType frame_type, 40 blink::WebURLRequest::FrameType frame_type,
41 LoaderType loader_type,
41 const Callback& callback) OVERRIDE; 42 const Callback& callback) OVERRIDE;
42 virtual void SetTimeout(const base::TimeDelta& timeout) OVERRIDE; 43 virtual void SetTimeout(const base::TimeDelta& timeout) OVERRIDE;
43 44
44 private: 45 private:
45 friend class ResourceFetcher; 46 friend class ResourceFetcher;
46 47
47 explicit ResourceFetcherImpl(const GURL& url); 48 explicit ResourceFetcherImpl(const GURL& url);
48 49
49 virtual ~ResourceFetcherImpl(); 50 virtual ~ResourceFetcherImpl();
50 51
51 void RunCallback(const blink::WebURLResponse& response,
52 const std::string& data);
53
54 // Callback for timer that limits how long we wait for the server. If this 52 // Callback for timer that limits how long we wait for the server. If this
55 // timer fires and the request hasn't completed, we kill the request. 53 // timer fires and the request hasn't completed, we kill the request.
56 void TimeoutFired(); 54 void TimeoutFired();
57 55
58 // WebURLLoaderClient methods: 56 // WebURLLoaderClientImpl methods:
59 virtual void willSendRequest( 57 virtual void OnLoadComplete() OVERRIDE;
60 blink::WebURLLoader* loader, blink::WebURLRequest& new_request, 58 virtual void Cancel() OVERRIDE;
61 const blink::WebURLResponse& redirect_response);
62 virtual void didSendData(
63 blink::WebURLLoader* loader, unsigned long long bytes_sent,
64 unsigned long long total_bytes_to_be_sent);
65 virtual void didReceiveResponse(
66 blink::WebURLLoader* loader, const blink::WebURLResponse& response);
67 virtual void didReceiveCachedMetadata(
68 blink::WebURLLoader* loader, const char* data, int data_length);
69
70 virtual void didReceiveData(
71 blink::WebURLLoader* loader, const char* data, int data_length,
72 int encoded_data_length);
73 virtual void didFinishLoading(
74 blink::WebURLLoader* loader, double finishTime,
75 int64_t total_encoded_data_length);
76 virtual void didFail(
77 blink::WebURLLoader* loader, const blink::WebURLError& error);
78 59
79 scoped_ptr<blink::WebURLLoader> loader_; 60 scoped_ptr<blink::WebURLLoader> loader_;
80 61
81 // Request to send. Released once Start() is called. 62 // Request to send. Released once Start() is called.
82 blink::WebURLRequest request_; 63 blink::WebURLRequest request_;
83 64
84 // Set to true once the request is complete.
85 bool completed_;
86
87 // Buffer to hold the content from the server.
88 std::string data_;
89
90 // A copy of the original resource response.
91 blink::WebURLResponse response_;
92
93 // Callback when we're done. 65 // Callback when we're done.
94 Callback callback_; 66 Callback callback_;
95 67
96 // Buffer to hold metadata from the cache.
97 std::string metadata_;
98
99 // Limit how long to wait for the server. 68 // Limit how long to wait for the server.
100 base::OneShotTimer<ResourceFetcherImpl> timeout_timer_; 69 base::OneShotTimer<ResourceFetcherImpl> timeout_timer_;
101 70
102 DISALLOW_COPY_AND_ASSIGN(ResourceFetcherImpl); 71 DISALLOW_COPY_AND_ASSIGN(ResourceFetcherImpl);
103 }; 72 };
104 73
105 } // namespace content 74 } // namespace content
106 75
107 #endif // CONTENT_RENDERER_FETCHERS_RESOURCE_FETCHER_H_ 76 #endif // CONTENT_RENDERER_FETCHERS_RESOURCE_FETCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698