OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_MANIFEST_FETCHER_H_ | 5 #ifndef CONTENT_RENDERER_FETCHERS_MANIFEST_FETCHER_H_ |
6 #define CONTENT_RENDERER_FETCHERS_MANIFEST_FETCHER_H_ | 6 #define CONTENT_RENDERER_FETCHERS_MANIFEST_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/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "content/common/content_export.h" |
13 #include "third_party/WebKit/public/platform/WebURLResponse.h" | 14 #include "third_party/WebKit/public/platform/WebURLResponse.h" |
14 | 15 |
15 class GURL; | 16 class GURL; |
16 | 17 |
17 namespace blink { | 18 namespace blink { |
18 class WebFrame; | 19 class WebFrame; |
19 } | 20 } |
20 | 21 |
21 namespace content { | 22 namespace content { |
22 | 23 |
23 class ResourceFetcher; | 24 class ResourceFetcher; |
24 | 25 |
25 // Helper class to download a Web Manifest. When an instance is created, the | 26 // Helper class to download a Web Manifest. When an instance is created, the |
26 // caller need to call Start() and wait for the passed callback to be executed. | 27 // caller need to call Start() and wait for the passed callback to be executed. |
27 // If the fetch fails, the callback will be called with two empty objects. | 28 // If the fetch fails, the callback will be called with two empty objects. |
28 class ManifestFetcher { | 29 class CONTENT_EXPORT ManifestFetcher { |
29 public: | 30 public: |
30 // This will be called asynchronously after the URL has been fetched, | 31 // This will be called asynchronously after the URL has been fetched, |
31 // successfully or not. If there is a failure, response and data will both be | 32 // successfully or not. If there is a failure, response and data will both be |
32 // empty. |response| and |data| are both valid until the URLFetcher instance | 33 // empty. |response| and |data| are both valid until the URLFetcher instance |
33 // is destroyed. | 34 // is destroyed. |
34 typedef base::Callback<void(const blink::WebURLResponse& response, | 35 typedef base::Callback<void(const blink::WebURLResponse& response, |
35 const std::string& data)> Callback; | 36 const std::string& data)> Callback; |
36 | 37 |
37 explicit ManifestFetcher(const GURL& url); | 38 explicit ManifestFetcher(const GURL& url); |
38 virtual ~ManifestFetcher(); | 39 virtual ~ManifestFetcher(); |
39 | 40 |
40 void Start(blink::WebFrame* frame, const Callback& callback); | 41 void Start(blink::WebFrame* frame, const Callback& callback); |
41 void Cancel(); | 42 void Cancel(); |
42 | 43 |
43 private: | 44 private: |
44 void OnLoadComplete(const blink::WebURLResponse& response, | 45 void OnLoadComplete(const blink::WebURLResponse& response, |
45 const std::string& data); | 46 const std::string& data); |
46 | 47 |
47 bool completed_; | 48 bool completed_; |
48 Callback callback_; | 49 Callback callback_; |
49 scoped_ptr<ResourceFetcher> fetcher_; | 50 scoped_ptr<ResourceFetcher> fetcher_; |
50 | 51 |
51 DISALLOW_COPY_AND_ASSIGN(ManifestFetcher); | 52 DISALLOW_COPY_AND_ASSIGN(ManifestFetcher); |
52 }; | 53 }; |
53 | 54 |
54 } // namespace content | 55 } // namespace content |
55 | 56 |
56 #endif // CONTENT_RENDERER_FETCHERS_MANIFEST_FETCHER_H_ | 57 #endif // CONTENT_RENDERER_FETCHERS_MANIFEST_FETCHER_H_ |
OLD | NEW |