Update V8 to version 4.6.52.
[chromium-blink-merge.git] / components / nacl / renderer / manifest_downloader.cc
bloba3721ff06bb08633d4453ae307f39c86f8207d96
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 "components/nacl/renderer/manifest_downloader.h"
7 #include "base/callback.h"
8 #include "components/nacl/renderer/histogram.h"
9 #include "components/nacl/renderer/nexe_load_manager.h"
10 #include "net/base/net_errors.h"
11 #include "third_party/WebKit/public/platform/WebURLError.h"
12 #include "third_party/WebKit/public/platform/WebURLLoader.h"
13 #include "third_party/WebKit/public/platform/WebURLResponse.h"
15 namespace nacl {
17 ManifestDownloader::ManifestDownloader(
18 scoped_ptr<blink::WebURLLoader> url_loader,
19 bool is_installed,
20 Callback cb)
21 : url_loader_(url_loader.Pass()),
22 is_installed_(is_installed),
23 cb_(cb),
24 status_code_(-1),
25 pp_nacl_error_(PP_NACL_ERROR_LOAD_SUCCESS) {
26 CHECK(!cb.is_null());
29 ManifestDownloader::~ManifestDownloader() { }
31 void ManifestDownloader::Load(const blink::WebURLRequest& request) {
32 url_loader_->loadAsynchronously(request, this);
35 void ManifestDownloader::didReceiveResponse(
36 blink::WebURLLoader* loader,
37 const blink::WebURLResponse& response) {
38 if (response.httpStatusCode() != 200)
39 pp_nacl_error_ = PP_NACL_ERROR_MANIFEST_LOAD_URL;
40 status_code_ = response.httpStatusCode();
43 void ManifestDownloader::didReceiveData(
44 blink::WebURLLoader* loader,
45 const char* data,
46 int data_length,
47 int encoded_data_length) {
48 if (buffer_.size() + data_length > kNaClManifestMaxFileBytes) {
49 pp_nacl_error_ = PP_NACL_ERROR_MANIFEST_TOO_LARGE;
50 buffer_.clear();
53 if (pp_nacl_error_ == PP_NACL_ERROR_LOAD_SUCCESS)
54 buffer_.append(data, data_length);
57 void ManifestDownloader::Close() {
58 // We log the status code here instead of in didReceiveResponse so that we
59 // always log a histogram value, even when we never receive a status code.
60 HistogramHTTPStatusCode(
61 is_installed_ ? "NaCl.HttpStatusCodeClass.Manifest.InstalledApp" :
62 "NaCl.HttpStatusCodeClass.Manifest.NotInstalledApp",
63 status_code_);
65 cb_.Run(pp_nacl_error_, buffer_);
66 delete this;
69 void ManifestDownloader::didFinishLoading(
70 blink::WebURLLoader* loader,
71 double finish_time,
72 int64_t total_encoded_data_length) {
73 Close();
76 void ManifestDownloader::didFail(
77 blink::WebURLLoader* loader,
78 const blink::WebURLError& error) {
79 // TODO(teravest): Find a place to share this code with PepperURLLoaderHost.
80 pp_nacl_error_ = PP_NACL_ERROR_MANIFEST_LOAD_URL;
81 if (error.domain.equals(blink::WebString::fromUTF8(net::kErrorDomain))) {
82 switch (error.reason) {
83 case net::ERR_ACCESS_DENIED:
84 case net::ERR_NETWORK_ACCESS_DENIED:
85 pp_nacl_error_ = PP_NACL_ERROR_MANIFEST_NOACCESS_URL;
86 break;
88 } else {
89 // It's a WebKit error.
90 pp_nacl_error_ = PP_NACL_ERROR_MANIFEST_NOACCESS_URL;
93 Close();
96 } // namespace nacl