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

Side by Side Diff: components/html_viewer/html_viewer.cc

Issue 1161463004: Move URL Loader creation to a separate factory object. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "components/html_viewer/html_document.h" 12 #include "components/html_viewer/html_document.h"
13 #include "components/html_viewer/setup.h" 13 #include "components/html_viewer/setup.h"
14 #include "mojo/application/public/cpp/application_connection.h" 14 #include "mojo/application/public/cpp/application_connection.h"
15 #include "mojo/application/public/cpp/application_delegate.h" 15 #include "mojo/application/public/cpp/application_delegate.h"
16 #include "mojo/application/public/cpp/application_impl.h" 16 #include "mojo/application/public/cpp/application_impl.h"
17 #include "mojo/application/public/cpp/application_runner.h" 17 #include "mojo/application/public/cpp/application_runner.h"
18 #include "mojo/application/public/cpp/connect.h" 18 #include "mojo/application/public/cpp/connect.h"
19 #include "mojo/application/public/cpp/interface_factory_impl.h" 19 #include "mojo/application/public/cpp/interface_factory_impl.h"
20 #include "mojo/application/public/interfaces/content_handler.mojom.h" 20 #include "mojo/application/public/interfaces/content_handler.mojom.h"
21 #include "mojo/common/common_type_converters.h" 21 #include "mojo/common/common_type_converters.h"
22 #include "mojo/services/network/public/interfaces/network_service.mojom.h" 22 #include "mojo/services/network/public/interfaces/network_service.mojom.h"
23 #include "mojo/services/network/public/interfaces/url_loader_factory.mojom.h"
23 #include "third_party/WebKit/public/web/WebKit.h" 24 #include "third_party/WebKit/public/web/WebKit.h"
24 #include "third_party/mojo/src/mojo/public/c/system/main.h" 25 #include "third_party/mojo/src/mojo/public/c/system/main.h"
25 #include "third_party/mojo/src/mojo/public/cpp/bindings/strong_binding.h" 26 #include "third_party/mojo/src/mojo/public/cpp/bindings/strong_binding.h"
26 27
27 using mojo::ApplicationConnection; 28 using mojo::ApplicationConnection;
28 using mojo::Array; 29 using mojo::Array;
29 using mojo::BindToRequest; 30 using mojo::BindToRequest;
30 using mojo::ContentHandler; 31 using mojo::ContentHandler;
31 using mojo::InterfaceRequest; 32 using mojo::InterfaceRequest;
32 using mojo::ServiceProvider; 33 using mojo::ServiceProvider;
(...skipping 19 matching lines...) Expand all
52 setup_(setup) { 53 setup_(setup) {
53 } 54 }
54 55
55 ~HTMLViewerApplication() override { 56 ~HTMLViewerApplication() override {
56 } 57 }
57 58
58 void Initialize(ShellPtr shell, const String& url) override { 59 void Initialize(ShellPtr shell, const String& url) override {
59 shell_ = shell.Pass(); 60 shell_ = shell.Pass();
60 mojo::URLRequestPtr request(mojo::URLRequest::New()); 61 mojo::URLRequestPtr request(mojo::URLRequest::New());
61 request->url = mojo::String::From("mojo:network_service"); 62 request->url = mojo::String::From("mojo:network_service");
62 setup_->app()->ConnectToService(request.Pass(), &network_service_); 63 mojo::ApplicationConnection* connection =
64 setup_->app()->ConnectToApplication(request.Pass());
65 connection->ConnectToService(&network_service_);
66 connection->ConnectToService(&url_loader_factory_);
63 } 67 }
64 68
65 void AcceptConnection(const String& requestor_url, 69 void AcceptConnection(const String& requestor_url,
66 InterfaceRequest<ServiceProvider> services, 70 InterfaceRequest<ServiceProvider> services,
67 ServiceProviderPtr exposed_services, 71 ServiceProviderPtr exposed_services,
68 const String& url) override { 72 const String& url) override {
69 if (initial_response_) { 73 if (initial_response_) {
70 OnResponseReceived(URLLoaderPtr(), services.Pass(), 74 OnResponseReceived(URLLoaderPtr(), services.Pass(),
71 initial_response_.Pass()); 75 initial_response_.Pass());
72 } else { 76 } else {
73 URLLoaderPtr loader; 77 URLLoaderPtr loader;
74 network_service_->CreateURLLoader(GetProxy(&loader)); 78 url_loader_factory_->CreateURLLoader(GetProxy(&loader));
75 mojo::URLRequestPtr request(mojo::URLRequest::New()); 79 mojo::URLRequestPtr request(mojo::URLRequest::New());
76 request->url = url_; 80 request->url = url_;
77 request->auto_follow_redirects = true; 81 request->auto_follow_redirects = true;
78 82
79 // |loader| will be pass to the OnResponseReceived method through a 83 // |loader| will be pass to the OnResponseReceived method through a
80 // callback. Because order of evaluation is undefined, a reference to the 84 // callback. Because order of evaluation is undefined, a reference to the
81 // raw pointer is needed. 85 // raw pointer is needed.
82 mojo::URLLoader* raw_loader = loader.get(); 86 mojo::URLLoader* raw_loader = loader.get();
83 raw_loader->Start( 87 raw_loader->Start(
84 request.Pass(), 88 request.Pass(),
(...skipping 15 matching lines...) Expand all
100 // HTMLDocument is destroyed when the hosting view is destroyed. 104 // HTMLDocument is destroyed when the hosting view is destroyed.
101 // TODO(sky): when headless, this leaks. 105 // TODO(sky): when headless, this leaks.
102 new HTMLDocument(services.Pass(), response.Pass(), shell_.Pass(), setup_); 106 new HTMLDocument(services.Pass(), response.Pass(), shell_.Pass(), setup_);
103 } 107 }
104 108
105 scoped_ptr<mojo::AppRefCount> app_refcount_; 109 scoped_ptr<mojo::AppRefCount> app_refcount_;
106 String url_; 110 String url_;
107 mojo::StrongBinding<mojo::Application> binding_; 111 mojo::StrongBinding<mojo::Application> binding_;
108 ShellPtr shell_; 112 ShellPtr shell_;
109 mojo::NetworkServicePtr network_service_; 113 mojo::NetworkServicePtr network_service_;
114 mojo::URLLoaderFactoryPtr url_loader_factory_;
110 URLResponsePtr initial_response_; 115 URLResponsePtr initial_response_;
111 Setup* setup_; 116 Setup* setup_;
112 117
113 DISALLOW_COPY_AND_ASSIGN(HTMLViewerApplication); 118 DISALLOW_COPY_AND_ASSIGN(HTMLViewerApplication);
114 }; 119 };
115 120
116 class ContentHandlerImpl : public mojo::ContentHandler { 121 class ContentHandlerImpl : public mojo::ContentHandler {
117 public: 122 public:
118 ContentHandlerImpl(Setup* setup, 123 ContentHandlerImpl(Setup* setup,
119 mojo::InterfaceRequest<ContentHandler> request) 124 mojo::InterfaceRequest<ContentHandler> request)
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 174
170 DISALLOW_COPY_AND_ASSIGN(HTMLViewer); 175 DISALLOW_COPY_AND_ASSIGN(HTMLViewer);
171 }; 176 };
172 177
173 } // namespace html_viewer 178 } // namespace html_viewer
174 179
175 MojoResult MojoMain(MojoHandle shell_handle) { 180 MojoResult MojoMain(MojoHandle shell_handle) {
176 mojo::ApplicationRunner runner(new html_viewer::HTMLViewer); 181 mojo::ApplicationRunner runner(new html_viewer::HTMLViewer);
177 return runner.Run(shell_handle); 182 return runner.Run(shell_handle);
178 } 183 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698