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

Side by Side Diff: components/nacl/renderer/manifest_downloader.cc

Issue 2399463007: AssociatedURLLoader shouldn't derive from WebURLLoader (Closed)
Patch Set: Rebase Created 4 years, 1 month 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 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 #include "components/nacl/renderer/manifest_downloader.h" 5 #include "components/nacl/renderer/manifest_downloader.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "components/nacl/renderer/histogram.h" 10 #include "components/nacl/renderer/histogram.h"
11 #include "components/nacl/renderer/nexe_load_manager.h" 11 #include "components/nacl/renderer/nexe_load_manager.h"
12 #include "net/base/net_errors.h" 12 #include "net/base/net_errors.h"
13 #include "third_party/WebKit/public/platform/WebURLError.h" 13 #include "third_party/WebKit/public/platform/WebURLError.h"
14 #include "third_party/WebKit/public/platform/WebURLLoader.h" 14 #include "third_party/WebKit/public/platform/WebURLLoader.h"
15 #include "third_party/WebKit/public/platform/WebURLResponse.h" 15 #include "third_party/WebKit/public/platform/WebURLResponse.h"
16 #include "third_party/WebKit/public/web/WebAssociatedURLLoader.h"
16 17
17 namespace nacl { 18 namespace nacl {
18 19
19 ManifestDownloader::ManifestDownloader( 20 ManifestDownloader::ManifestDownloader(
20 std::unique_ptr<blink::WebURLLoader> url_loader, 21 std::unique_ptr<blink::WebAssociatedURLLoader> url_loader,
21 bool is_installed, 22 bool is_installed,
22 Callback cb) 23 Callback cb)
23 : url_loader_(std::move(url_loader)), 24 : url_loader_(std::move(url_loader)),
24 is_installed_(is_installed), 25 is_installed_(is_installed),
25 cb_(cb), 26 cb_(cb),
26 status_code_(-1), 27 status_code_(-1),
27 pp_nacl_error_(PP_NACL_ERROR_LOAD_SUCCESS) { 28 pp_nacl_error_(PP_NACL_ERROR_LOAD_SUCCESS) {
28 CHECK(!cb.is_null()); 29 CHECK(!cb.is_null());
29 } 30 }
30 31
31 ManifestDownloader::~ManifestDownloader() { } 32 ManifestDownloader::~ManifestDownloader() { }
32 33
33 void ManifestDownloader::Load(const blink::WebURLRequest& request) { 34 void ManifestDownloader::Load(const blink::WebURLRequest& request) {
34 url_loader_->loadAsynchronously(request, this); 35 url_loader_->loadAsynchronously(request, this);
35 } 36 }
36 37
37 void ManifestDownloader::didReceiveResponse( 38 void ManifestDownloader::didReceiveResponse(
38 blink::WebURLLoader* loader,
39 const blink::WebURLResponse& response) { 39 const blink::WebURLResponse& response) {
40 if (response.httpStatusCode() != 200) 40 if (response.httpStatusCode() != 200)
41 pp_nacl_error_ = PP_NACL_ERROR_MANIFEST_LOAD_URL; 41 pp_nacl_error_ = PP_NACL_ERROR_MANIFEST_LOAD_URL;
42 status_code_ = response.httpStatusCode(); 42 status_code_ = response.httpStatusCode();
43 } 43 }
44 44
45 void ManifestDownloader::didReceiveData(blink::WebURLLoader* loader, 45 void ManifestDownloader::didReceiveData(const char* data, int data_length) {
46 const char* data,
47 int data_length,
48 int encoded_data_length,
49 int encoded_body_length) {
50 if (buffer_.size() + data_length > kNaClManifestMaxFileBytes) { 46 if (buffer_.size() + data_length > kNaClManifestMaxFileBytes) {
51 pp_nacl_error_ = PP_NACL_ERROR_MANIFEST_TOO_LARGE; 47 pp_nacl_error_ = PP_NACL_ERROR_MANIFEST_TOO_LARGE;
52 buffer_.clear(); 48 buffer_.clear();
53 } 49 }
54 50
55 if (pp_nacl_error_ == PP_NACL_ERROR_LOAD_SUCCESS) 51 if (pp_nacl_error_ == PP_NACL_ERROR_LOAD_SUCCESS)
56 buffer_.append(data, data_length); 52 buffer_.append(data, data_length);
57 } 53 }
58 54
59 void ManifestDownloader::Close() { 55 void ManifestDownloader::Close() {
60 // We log the status code here instead of in didReceiveResponse so that we 56 // We log the status code here instead of in didReceiveResponse so that we
61 // always log a histogram value, even when we never receive a status code. 57 // always log a histogram value, even when we never receive a status code.
62 HistogramHTTPStatusCode( 58 HistogramHTTPStatusCode(
63 is_installed_ ? "NaCl.HttpStatusCodeClass.Manifest.InstalledApp" : 59 is_installed_ ? "NaCl.HttpStatusCodeClass.Manifest.InstalledApp" :
64 "NaCl.HttpStatusCodeClass.Manifest.NotInstalledApp", 60 "NaCl.HttpStatusCodeClass.Manifest.NotInstalledApp",
65 status_code_); 61 status_code_);
66 62
67 cb_.Run(pp_nacl_error_, buffer_); 63 cb_.Run(pp_nacl_error_, buffer_);
68 delete this; 64 delete this;
69 } 65 }
70 66
71 void ManifestDownloader::didFinishLoading( 67 void ManifestDownloader::didFinishLoading(double finish_time) {
72 blink::WebURLLoader* loader,
73 double finish_time,
74 int64_t total_encoded_data_length) {
75 Close(); 68 Close();
76 } 69 }
77 70
78 void ManifestDownloader::didFail( 71 void ManifestDownloader::didFail(const blink::WebURLError& error) {
79 blink::WebURLLoader* loader,
80 const blink::WebURLError& error) {
81 // TODO(teravest): Find a place to share this code with PepperURLLoaderHost. 72 // TODO(teravest): Find a place to share this code with PepperURLLoaderHost.
82 pp_nacl_error_ = PP_NACL_ERROR_MANIFEST_LOAD_URL; 73 pp_nacl_error_ = PP_NACL_ERROR_MANIFEST_LOAD_URL;
83 if (error.domain.equals(blink::WebString::fromUTF8(net::kErrorDomain))) { 74 if (error.domain.equals(blink::WebString::fromUTF8(net::kErrorDomain))) {
84 switch (error.reason) { 75 switch (error.reason) {
85 case net::ERR_ACCESS_DENIED: 76 case net::ERR_ACCESS_DENIED:
86 case net::ERR_NETWORK_ACCESS_DENIED: 77 case net::ERR_NETWORK_ACCESS_DENIED:
87 pp_nacl_error_ = PP_NACL_ERROR_MANIFEST_NOACCESS_URL; 78 pp_nacl_error_ = PP_NACL_ERROR_MANIFEST_NOACCESS_URL;
88 break; 79 break;
89 } 80 }
90 } else { 81 } else {
91 // It's a WebKit error. 82 // It's a WebKit error.
92 pp_nacl_error_ = PP_NACL_ERROR_MANIFEST_NOACCESS_URL; 83 pp_nacl_error_ = PP_NACL_ERROR_MANIFEST_NOACCESS_URL;
93 } 84 }
94 85
95 Close(); 86 Close();
96 } 87 }
97 88
98 } // namespace nacl 89 } // namespace nacl
OLDNEW
« no previous file with comments | « components/nacl/renderer/manifest_downloader.h ('k') | components/nacl/renderer/ppb_nacl_private_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698