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