Re-subimission of https://codereview.chromium.org/1041213003/
[chromium-blink-merge.git] / content / renderer / fetchers / manifest_fetcher.cc
blobba0cf3a6e346b53793d9a857842de80aa6a361a6
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.
5 #include "content/renderer/fetchers/manifest_fetcher.h"
7 #include "base/bind.h"
8 #include "base/logging.h"
9 #include "content/public/renderer/resource_fetcher.h"
10 #include "third_party/WebKit/public/platform/WebURLRequest.h"
11 #include "third_party/WebKit/public/web/WebFrame.h"
13 namespace content {
15 ManifestFetcher::ManifestFetcher(const GURL& url)
16 : completed_(false) {
17 fetcher_.reset(ResourceFetcher::Create(url));
20 ManifestFetcher::~ManifestFetcher() {
21 if (!completed_)
22 Cancel();
25 void ManifestFetcher::Start(blink::WebFrame* frame, const Callback& callback) {
26 callback_ = callback;
28 blink::WebURLLoaderOptions options;
29 options.crossOriginRequestPolicy =
30 blink::WebURLLoaderOptions::CrossOriginRequestPolicyUseAccessControl;
31 fetcher_->SetLoaderOptions(options);
33 fetcher_->Start(frame,
34 blink::WebURLRequest::RequestContextManifest,
35 blink::WebURLRequest::FrameTypeNone,
36 ResourceFetcher::FRAME_ASSOCIATED_LOADER,
37 base::Bind(&ManifestFetcher::OnLoadComplete,
38 base::Unretained(this)));
41 void ManifestFetcher::Cancel() {
42 DCHECK(!completed_);
43 fetcher_->Cancel();
46 void ManifestFetcher::OnLoadComplete(const blink::WebURLResponse& response,
47 const std::string& data) {
48 DCHECK(!completed_);
49 completed_ = true;
51 Callback callback = callback_;
52 callback.Run(response, data);
55 } // namespace content