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

Side by Side Diff: sky/viewer/content_handler_impl.cc

Issue 845593003: Pass ServiceProvider and ServiceProvider& params in Connect (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: use nullptr instead of ServiceProviderPtr(), fix ShellImpl Created 5 years, 11 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/engine/v8_inspector/inspector_backend_mojo.cc ('k') | sky/viewer/document_view.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 "sky/viewer/content_handler_impl.h" 5 #include "sky/viewer/content_handler_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "mojo/public/cpp/application/connect.h" 8 #include "mojo/public/cpp/application/connect.h"
9 #include "mojo/services/network/public/interfaces/network_service.mojom.h" 9 #include "mojo/services/network/public/interfaces/network_service.mojom.h"
10 #include "sky/viewer/document_view.h" 10 #include "sky/viewer/document_view.h"
11 11
12 namespace sky { 12 namespace sky {
13 13
14 class SkyApplication : public mojo::Application { 14 class SkyApplication : public mojo::Application {
15 public: 15 public:
16 SkyApplication(mojo::ShellPtr shell, 16 SkyApplication(mojo::ShellPtr shell,
17 mojo::URLResponsePtr response) 17 mojo::URLResponsePtr response)
18 : url_(response->url), 18 : url_(response->url),
19 shell_(shell.Pass()), 19 shell_(shell.Pass()),
20 initial_response_(response.Pass()) { 20 initial_response_(response.Pass()) {
21 shell_.set_client(this); 21 shell_.set_client(this);
22 mojo::ServiceProviderPtr service_provider; 22 mojo::ServiceProviderPtr service_provider;
23 shell_->ConnectToApplication("mojo:network_service", 23 shell_->ConnectToApplication("mojo:network_service",
24 mojo::GetProxy(&service_provider)); 24 mojo::GetProxy(&service_provider), nullptr);
25 mojo::ConnectToService(service_provider.get(), &network_service_); 25 mojo::ConnectToService(service_provider.get(), &network_service_);
26 } 26 }
27 27
28 void Initialize(mojo::Array<mojo::String> args) override {} 28 void Initialize(mojo::Array<mojo::String> args) override {}
29 29
30 void AcceptConnection(const mojo::String& requestor_url, 30 void AcceptConnection(const mojo::String& requestor_url,
31 mojo::ServiceProviderPtr provider) override { 31 mojo::InterfaceRequest<mojo::ServiceProvider> services,
32 mojo::ServiceProviderPtr exposed_services) override {
32 if (initial_response_) { 33 if (initial_response_) {
33 OnResponseReceived(mojo::URLLoaderPtr(), provider.Pass(), 34 OnResponseReceived(mojo::URLLoaderPtr(), services.Pass(),
34 initial_response_.Pass()); 35 exposed_services.Pass(), initial_response_.Pass());
35 } else { 36 } else {
36 mojo::URLLoaderPtr loader; 37 mojo::URLLoaderPtr loader;
37 network_service_->CreateURLLoader(mojo::GetProxy(&loader)); 38 network_service_->CreateURLLoader(mojo::GetProxy(&loader));
38 mojo::URLRequestPtr request(mojo::URLRequest::New()); 39 mojo::URLRequestPtr request(mojo::URLRequest::New());
39 request->url = url_; 40 request->url = url_;
40 request->auto_follow_redirects = true; 41 request->auto_follow_redirects = true;
41 42
42 // |loader| will be pass to the OnResponseReceived method through a 43 // |loader| will be pass to the OnResponseReceived method through a
43 // callback. Because order of evaluation is undefined, a reference to the 44 // callback. Because order of evaluation is undefined, a reference to the
44 // raw pointer is needed. 45 // raw pointer is needed.
45 mojo::URLLoader* raw_loader = loader.get(); 46 mojo::URLLoader* raw_loader = loader.get();
46 raw_loader->Start( 47 raw_loader->Start(
47 request.Pass(), 48 request.Pass(),
48 base::Bind(&SkyApplication::OnResponseReceived, 49 base::Bind(&SkyApplication::OnResponseReceived,
49 base::Unretained(this), base::Passed(&loader), 50 base::Unretained(this), base::Passed(&loader),
50 base::Passed(&provider))); 51 base::Passed(&services), base::Passed(&exposed_services)));
51 } 52 }
52 } 53 }
53 54
54 private: 55 private:
55 void OnResponseReceived(mojo::URLLoaderPtr loader, 56 void OnResponseReceived(
56 mojo::ServiceProviderPtr provider, 57 mojo::URLLoaderPtr loader,
57 mojo::URLResponsePtr response) { 58 mojo::InterfaceRequest<mojo::ServiceProvider> services,
58 new DocumentView(provider.Pass(), response.Pass(), shell_.get()); 59 mojo::ServiceProviderPtr exposed_services,
60 mojo::URLResponsePtr response) {
61 new DocumentView(services.Pass(), exposed_services.Pass(), response.Pass(),
62 shell_.get());
59 } 63 }
60 64
61 mojo::String url_; 65 mojo::String url_;
62 mojo::ShellPtr shell_; 66 mojo::ShellPtr shell_;
63 mojo::NetworkServicePtr network_service_; 67 mojo::NetworkServicePtr network_service_;
64 mojo::URLResponsePtr initial_response_; 68 mojo::URLResponsePtr initial_response_;
65 }; 69 };
66 70
67 ContentHandlerImpl::ContentHandlerImpl() { 71 ContentHandlerImpl::ContentHandlerImpl() {
68 } 72 }
69 73
70 ContentHandlerImpl::~ContentHandlerImpl() { 74 ContentHandlerImpl::~ContentHandlerImpl() {
71 } 75 }
72 76
73 void ContentHandlerImpl::StartApplication(mojo::ShellPtr shell, 77 void ContentHandlerImpl::StartApplication(mojo::ShellPtr shell,
74 mojo::URLResponsePtr response) { 78 mojo::URLResponsePtr response) {
75 new SkyApplication(shell.Pass(), response.Pass()); 79 new SkyApplication(shell.Pass(), response.Pass());
76 } 80 }
77 81
78 } // namespace sky 82 } // namespace sky
OLDNEW
« no previous file with comments | « sky/engine/v8_inspector/inspector_backend_mojo.cc ('k') | sky/viewer/document_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698