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

Side by Side Diff: sky/viewer/platform/weburlloader_impl.cc

Issue 935633003: Don't depend on /net for error codes in sky viewer. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 10 months 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
« no previous file with comments | « sky/viewer/platform/platform_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "sky/viewer/platform/weburlloader_impl.h" 5 #include "sky/viewer/platform/weburlloader_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/thread_task_runner_handle.h" 10 #include "base/thread_task_runner_handle.h"
11 #include "mojo/common/common_type_converters.h" 11 #include "mojo/common/common_type_converters.h"
12 #include "mojo/services/network/public/interfaces/network_service.mojom.h" 12 #include "mojo/services/network/public/interfaces/network_service.mojom.h"
13 #include "net/base/net_errors.h"
14 #include "sky/engine/public/platform/WebURLError.h" 13 #include "sky/engine/public/platform/WebURLError.h"
15 #include "sky/engine/public/platform/WebURLLoadTiming.h" 14 #include "sky/engine/public/platform/WebURLLoadTiming.h"
16 #include "sky/engine/public/platform/WebURLLoaderClient.h" 15 #include "sky/engine/public/platform/WebURLLoaderClient.h"
17 #include "sky/engine/public/platform/WebURLResponse.h" 16 #include "sky/engine/public/platform/WebURLResponse.h"
18 #include "sky/viewer/converters/url_request_types.h" 17 #include "sky/viewer/converters/url_request_types.h"
19 18
20 namespace sky { 19 namespace sky {
21 namespace { 20 namespace {
22 21
22 // This corresponds to ERR_ABORTED in net/base/net_error_list.h.
23 // TODO(ppi): declare an enum in the network service mojom so that the clients
24 // don't need to hard-code these values.
25 const int32_t kNetErrorAborted = -3;
26
27 const char kErrorDomain[] = "net";
abarth-chromium 2015/02/17 17:58:50 Can we declare these values in a header that's sha
ppi 2015/02/17 18:08:02 Done.
28
23 static blink::WebURLResponse::HTTPVersion StatusLineToHTTPVersion( 29 static blink::WebURLResponse::HTTPVersion StatusLineToHTTPVersion(
24 const mojo::String& status_line) { 30 const mojo::String& status_line) {
25 if (status_line.is_null()) 31 if (status_line.is_null())
26 return blink::WebURLResponse::HTTP_0_9; 32 return blink::WebURLResponse::HTTP_0_9;
27 33
28 if (StartsWithASCII(status_line, "HTTP/1.0", true)) 34 if (StartsWithASCII(status_line, "HTTP/1.0", true))
29 return blink::WebURLResponse::HTTP_1_0; 35 return blink::WebURLResponse::HTTP_1_0;
30 36
31 if (StartsWithASCII(status_line, "HTTP/1.1", true)) 37 if (StartsWithASCII(status_line, "HTTP/1.1", true))
32 return blink::WebURLResponse::HTTP_1_1; 38 return blink::WebURLResponse::HTTP_1_1;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 weak_factory_.GetWeakPtr())); 96 weak_factory_.GetWeakPtr()));
91 } 97 }
92 98
93 void WebURLLoaderImpl::cancel() { 99 void WebURLLoaderImpl::cancel() {
94 url_loader_.reset(); 100 url_loader_.reset();
95 response_body_stream_.reset(); 101 response_body_stream_.reset();
96 102
97 mojo::URLResponsePtr failed_response(mojo::URLResponse::New()); 103 mojo::URLResponsePtr failed_response(mojo::URLResponse::New());
98 failed_response->url = mojo::String::From(url_); 104 failed_response->url = mojo::String::From(url_);
99 failed_response->error = mojo::NetworkError::New(); 105 failed_response->error = mojo::NetworkError::New();
100 failed_response->error->code = net::ERR_ABORTED; 106 failed_response->error->code = kNetErrorAborted;
101 107
102 base::ThreadTaskRunnerHandle::Get()->PostTask( 108 base::ThreadTaskRunnerHandle::Get()->PostTask(
103 FROM_HERE, 109 FROM_HERE,
104 base::Bind(&WebURLLoaderImpl::OnReceivedResponse, 110 base::Bind(&WebURLLoaderImpl::OnReceivedResponse,
105 weak_factory_.GetWeakPtr(), 111 weak_factory_.GetWeakPtr(),
106 base::Passed(&failed_response))); 112 base::Passed(&failed_response)));
107 } 113 }
108 114
109 void WebURLLoaderImpl::OnReceivedResponse(mojo::URLResponsePtr url_response) { 115 void WebURLLoaderImpl::OnReceivedResponse(mojo::URLResponsePtr url_response) {
110 url_ = GURL(url_response->url); 116 url_ = GURL(url_response->url);
(...skipping 11 matching lines...) Expand all
122 return; 128 return;
123 129
124 // Start streaming data 130 // Start streaming data
125 response_body_stream_ = url_response->body.Pass(); 131 response_body_stream_ = url_response->body.Pass();
126 ReadMore(); 132 ReadMore();
127 } 133 }
128 } 134 }
129 135
130 void WebURLLoaderImpl::OnReceivedError(mojo::URLResponsePtr url_response) { 136 void WebURLLoaderImpl::OnReceivedError(mojo::URLResponsePtr url_response) {
131 blink::WebURLError web_error; 137 blink::WebURLError web_error;
132 web_error.domain = blink::WebString::fromUTF8(net::kErrorDomain); 138 web_error.domain = blink::WebString::fromUTF8(kErrorDomain);
133 web_error.reason = url_response->error->code; 139 web_error.reason = url_response->error->code;
134 web_error.unreachableURL = GURL(url_response->url); 140 web_error.unreachableURL = GURL(url_response->url);
135 web_error.staleCopyInCache = false; 141 web_error.staleCopyInCache = false;
136 web_error.isCancellation = 142 web_error.isCancellation =
137 url_response->error->code == net::ERR_ABORTED ? true : false; 143 url_response->error->code == kNetErrorAborted ? true : false;
138 144
139 client_->didFail(this, web_error); 145 client_->didFail(this, web_error);
140 } 146 }
141 147
142 void WebURLLoaderImpl::OnReceivedRedirect(mojo::URLResponsePtr url_response) { 148 void WebURLLoaderImpl::OnReceivedRedirect(mojo::URLResponsePtr url_response) {
143 blink::WebURLRequest new_request; 149 blink::WebURLRequest new_request;
144 new_request.initialize(); 150 new_request.initialize();
145 new_request.setURL(GURL(url_response->redirect_url)); 151 new_request.setURL(GURL(url_response->redirect_url));
146 new_request.setHTTPMethod( 152 new_request.setHTTPMethod(
147 blink::WebString::fromUTF8(url_response->redirect_method)); 153 blink::WebString::fromUTF8(url_response->redirect_method));
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 MOJO_DEADLINE_INDEFINITE, 192 MOJO_DEADLINE_INDEFINITE,
187 base::Bind(&WebURLLoaderImpl::OnResponseBodyStreamReady, 193 base::Bind(&WebURLLoaderImpl::OnResponseBodyStreamReady,
188 weak_factory_.GetWeakPtr())); 194 weak_factory_.GetWeakPtr()));
189 } 195 }
190 196
191 void WebURLLoaderImpl::OnResponseBodyStreamReady(MojoResult result) { 197 void WebURLLoaderImpl::OnResponseBodyStreamReady(MojoResult result) {
192 ReadMore(); 198 ReadMore();
193 } 199 }
194 200
195 } // namespace sky 201 } // namespace sky
OLDNEW
« no previous file with comments | « sky/viewer/platform/platform_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698