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

Side by Side Diff: mojo/examples/wget/wget.cc

Issue 324023002: Mojo: cleanup redirect handling for network service. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | mojo/services/network/url_loader_impl.h » ('j') | 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 <stdio.h> 5 #include <stdio.h>
6 6
7 #include "mojo/public/cpp/application/application.h" 7 #include "mojo/public/cpp/application/application.h"
8 #include "mojo/services/public/interfaces/network/network_service.mojom.h" 8 #include "mojo/services/public/interfaces/network/network_service.mojom.h"
9 #include "mojo/services/public/interfaces/network/url_loader.mojom.h" 9 #include "mojo/services/public/interfaces/network/url_loader.mojom.h"
10 10
11 namespace mojo { 11 namespace mojo {
12 namespace examples { 12 namespace examples {
13 13
14 class WGetApp : public Application, public URLLoaderClient { 14 class WGetApp : public Application, public URLLoaderClient {
15 public: 15 public:
16 virtual void Initialize() MOJO_OVERRIDE { 16 virtual void Initialize() MOJO_OVERRIDE {
17 ConnectTo("mojo:mojo_network_service", &network_service_); 17 ConnectTo("mojo:mojo_network_service", &network_service_);
18 Start(); 18 Start();
19 } 19 }
20 20
21 private: 21 private:
22 virtual void OnReceivedRedirect(URLResponsePtr response, 22 virtual void OnReceivedRedirect(URLResponsePtr response,
23 const String& new_url, 23 const String& new_url,
24 const String& new_method) MOJO_OVERRIDE { 24 const String& new_method) MOJO_OVERRIDE {
25 assert(false); // This should never be called. 25 PrintResponse(response);
26 } 26 }
27 27
28 virtual void OnReceivedResponse(URLResponsePtr response) MOJO_OVERRIDE { 28 virtual void OnReceivedResponse(URLResponsePtr response) MOJO_OVERRIDE {
29 PrintResponse(response); 29 PrintResponse(response);
30 PrintResponseBody(); 30 PrintResponseBody();
31 Start(); 31 Start();
32 } 32 }
33 33
34 virtual void OnReceivedError(NetworkErrorPtr error) MOJO_OVERRIDE { 34 virtual void OnReceivedError(NetworkErrorPtr error) MOJO_OVERRIDE {
35 printf("Got error: %d (%s)\n", 35 printf("Got error: %d (%s)\n",
36 error->code, error->description.get().c_str()); 36 error->code, error->description.get().c_str());
37 } 37 }
38 38
39 virtual void OnReceivedEndOfResponseBody() MOJO_OVERRIDE { 39 virtual void OnReceivedEndOfResponseBody() MOJO_OVERRIDE {
40 // Ignored. 40 // Ignored.
41 } 41 }
42 42
43 void Start() { 43 void Start() {
44 std::string url = PromptForURL(); 44 std::string url = PromptForURL();
45 printf("Loading: %s\n", url.c_str()); 45 printf("Loading: %s\n", url.c_str());
46 46
47 network_service_->CreateURLLoader(Get(&url_loader_)); 47 network_service_->CreateURLLoader(Get(&url_loader_));
48 url_loader_.set_client(this); 48 url_loader_.set_client(this);
49 49
50 URLRequestPtr request(URLRequest::New()); 50 URLRequestPtr request(URLRequest::New());
51 request->url = url; 51 request->url = url;
52 request->method = "GET"; 52 request->method = "GET";
53 request->follow_redirects = true; 53 request->auto_follow_redirects = true;
54 54
55 DataPipe data_pipe; 55 DataPipe data_pipe;
56 response_body_stream_ = data_pipe.consumer_handle.Pass(); 56 response_body_stream_ = data_pipe.consumer_handle.Pass();
57 57
58 url_loader_->Start(request.Pass(), data_pipe.producer_handle.Pass()); 58 url_loader_->Start(request.Pass(), data_pipe.producer_handle.Pass());
59 } 59 }
60 60
61 std::string PromptForURL() { 61 std::string PromptForURL() {
62 printf("Enter URL> "); 62 printf("Enter URL> ");
63 char buf[1024]; 63 char buf[1024];
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 }; 107 };
108 108
109 } // namespace examples 109 } // namespace examples
110 110
111 // static 111 // static
112 Application* Application::Create() { 112 Application* Application::Create() {
113 return new examples::WGetApp(); 113 return new examples::WGetApp();
114 } 114 }
115 115
116 } // namespace mojo 116 } // namespace mojo
OLDNEW
« no previous file with comments | « no previous file | mojo/services/network/url_loader_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698