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

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: Address Adam comment. 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"
18 #include "sky/viewer/platform/net_constants.h"
19 19
20 namespace sky { 20 namespace sky {
21 namespace { 21 namespace {
22 22
23 static blink::WebURLResponse::HTTPVersion StatusLineToHTTPVersion( 23 static blink::WebURLResponse::HTTPVersion StatusLineToHTTPVersion(
24 const mojo::String& status_line) { 24 const mojo::String& status_line) {
25 if (status_line.is_null()) 25 if (status_line.is_null())
26 return blink::WebURLResponse::HTTP_0_9; 26 return blink::WebURLResponse::HTTP_0_9;
27 27
28 if (StartsWithASCII(status_line, "HTTP/1.0", true)) 28 if (StartsWithASCII(status_line, "HTTP/1.0", true))
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 weak_factory_.GetWeakPtr())); 90 weak_factory_.GetWeakPtr()));
91 } 91 }
92 92
93 void WebURLLoaderImpl::cancel() { 93 void WebURLLoaderImpl::cancel() {
94 url_loader_.reset(); 94 url_loader_.reset();
95 response_body_stream_.reset(); 95 response_body_stream_.reset();
96 96
97 mojo::URLResponsePtr failed_response(mojo::URLResponse::New()); 97 mojo::URLResponsePtr failed_response(mojo::URLResponse::New());
98 failed_response->url = mojo::String::From(url_); 98 failed_response->url = mojo::String::From(url_);
99 failed_response->error = mojo::NetworkError::New(); 99 failed_response->error = mojo::NetworkError::New();
100 failed_response->error->code = net::ERR_ABORTED; 100 failed_response->error->code = kNetErrorAborted;
101 101
102 base::ThreadTaskRunnerHandle::Get()->PostTask( 102 base::ThreadTaskRunnerHandle::Get()->PostTask(
103 FROM_HERE, 103 FROM_HERE,
104 base::Bind(&WebURLLoaderImpl::OnReceivedResponse, 104 base::Bind(&WebURLLoaderImpl::OnReceivedResponse,
105 weak_factory_.GetWeakPtr(), 105 weak_factory_.GetWeakPtr(),
106 base::Passed(&failed_response))); 106 base::Passed(&failed_response)));
107 } 107 }
108 108
109 void WebURLLoaderImpl::OnReceivedResponse(mojo::URLResponsePtr url_response) { 109 void WebURLLoaderImpl::OnReceivedResponse(mojo::URLResponsePtr url_response) {
110 url_ = GURL(url_response->url); 110 url_ = GURL(url_response->url);
(...skipping 11 matching lines...) Expand all
122 return; 122 return;
123 123
124 // Start streaming data 124 // Start streaming data
125 response_body_stream_ = url_response->body.Pass(); 125 response_body_stream_ = url_response->body.Pass();
126 ReadMore(); 126 ReadMore();
127 } 127 }
128 } 128 }
129 129
130 void WebURLLoaderImpl::OnReceivedError(mojo::URLResponsePtr url_response) { 130 void WebURLLoaderImpl::OnReceivedError(mojo::URLResponsePtr url_response) {
131 blink::WebURLError web_error; 131 blink::WebURLError web_error;
132 web_error.domain = blink::WebString::fromUTF8(net::kErrorDomain); 132 web_error.domain = blink::WebString::fromUTF8(kNetErrorDomain);
133 web_error.reason = url_response->error->code; 133 web_error.reason = url_response->error->code;
134 web_error.unreachableURL = GURL(url_response->url); 134 web_error.unreachableURL = GURL(url_response->url);
135 web_error.staleCopyInCache = false; 135 web_error.staleCopyInCache = false;
136 web_error.isCancellation = 136 web_error.isCancellation =
137 url_response->error->code == net::ERR_ABORTED ? true : false; 137 url_response->error->code == kNetErrorAborted ? true : false;
138 138
139 client_->didFail(this, web_error); 139 client_->didFail(this, web_error);
140 } 140 }
141 141
142 void WebURLLoaderImpl::OnReceivedRedirect(mojo::URLResponsePtr url_response) { 142 void WebURLLoaderImpl::OnReceivedRedirect(mojo::URLResponsePtr url_response) {
143 blink::WebURLRequest new_request; 143 blink::WebURLRequest new_request;
144 new_request.initialize(); 144 new_request.initialize();
145 new_request.setURL(GURL(url_response->redirect_url)); 145 new_request.setURL(GURL(url_response->redirect_url));
146 new_request.setHTTPMethod( 146 new_request.setHTTPMethod(
147 blink::WebString::fromUTF8(url_response->redirect_method)); 147 blink::WebString::fromUTF8(url_response->redirect_method));
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 MOJO_DEADLINE_INDEFINITE, 186 MOJO_DEADLINE_INDEFINITE,
187 base::Bind(&WebURLLoaderImpl::OnResponseBodyStreamReady, 187 base::Bind(&WebURLLoaderImpl::OnResponseBodyStreamReady,
188 weak_factory_.GetWeakPtr())); 188 weak_factory_.GetWeakPtr()));
189 } 189 }
190 190
191 void WebURLLoaderImpl::OnResponseBodyStreamReady(MojoResult result) { 191 void WebURLLoaderImpl::OnResponseBodyStreamReady(MojoResult result) {
192 ReadMore(); 192 ReadMore();
193 } 193 }
194 194
195 } // namespace sky 195 } // 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