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

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: 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
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),
25 mojo::ServiceProviderPtr());
25 mojo::ConnectToService(service_provider.get(), &network_service_); 26 mojo::ConnectToService(service_provider.get(), &network_service_);
26 } 27 }
27 28
28 void Initialize(mojo::Array<mojo::String> args) override {} 29 void Initialize(mojo::Array<mojo::String> args) override {}
29 30
30 void AcceptConnection(const mojo::String& requestor_url, 31 void AcceptConnection(const mojo::String& requestor_url,
31 mojo::ServiceProviderPtr provider) override { 32 mojo::InterfaceRequest<mojo::ServiceProvider> services,
33 mojo::ServiceProviderPtr exported_services) override {
32 if (initial_response_) { 34 if (initial_response_) {
33 OnResponseReceived(mojo::URLLoaderPtr(), provider.Pass(), 35 OnResponseReceived(mojo::URLLoaderPtr(), services.Pass(),
34 initial_response_.Pass()); 36 exported_services.Pass(), initial_response_.Pass());
35 } else { 37 } else {
36 mojo::URLLoaderPtr loader; 38 mojo::URLLoaderPtr loader;
37 network_service_->CreateURLLoader(mojo::GetProxy(&loader)); 39 network_service_->CreateURLLoader(mojo::GetProxy(&loader));
38 mojo::URLRequestPtr request(mojo::URLRequest::New()); 40 mojo::URLRequestPtr request(mojo::URLRequest::New());
39 request->url = url_; 41 request->url = url_;
40 request->auto_follow_redirects = true; 42 request->auto_follow_redirects = true;
41 43
42 // |loader| will be pass to the OnResponseReceived method through a 44 // |loader| will be pass to the OnResponseReceived method through a
43 // callback. Because order of evaluation is undefined, a reference to the 45 // callback. Because order of evaluation is undefined, a reference to the
44 // raw pointer is needed. 46 // raw pointer is needed.
45 mojo::URLLoader* raw_loader = loader.get(); 47 mojo::URLLoader* raw_loader = loader.get();
46 raw_loader->Start( 48 raw_loader->Start(
47 request.Pass(), 49 request.Pass(),
48 base::Bind(&SkyApplication::OnResponseReceived, 50 base::Bind(&SkyApplication::OnResponseReceived,
49 base::Unretained(this), base::Passed(&loader), 51 base::Unretained(this), base::Passed(&loader),
50 base::Passed(&provider))); 52 base::Passed(&services),
53 base::Passed(&exported_services)));
51 } 54 }
52 } 55 }
53 56
54 private: 57 private:
55 void OnResponseReceived(mojo::URLLoaderPtr loader, 58 void OnResponseReceived(
56 mojo::ServiceProviderPtr provider, 59 mojo::URLLoaderPtr loader,
57 mojo::URLResponsePtr response) { 60 mojo::InterfaceRequest<mojo::ServiceProvider> services,
58 new DocumentView(provider.Pass(), response.Pass(), shell_.get()); 61 mojo::ServiceProviderPtr exported_services,
62 mojo::URLResponsePtr response) {
63 new DocumentView(services.Pass(), exported_services.Pass(), response.Pass(),
64 shell_.get());
59 } 65 }
60 66
61 mojo::String url_; 67 mojo::String url_;
62 mojo::ShellPtr shell_; 68 mojo::ShellPtr shell_;
63 mojo::NetworkServicePtr network_service_; 69 mojo::NetworkServicePtr network_service_;
64 mojo::URLResponsePtr initial_response_; 70 mojo::URLResponsePtr initial_response_;
65 }; 71 };
66 72
67 ContentHandlerImpl::ContentHandlerImpl() { 73 ContentHandlerImpl::ContentHandlerImpl() {
68 } 74 }
69 75
70 ContentHandlerImpl::~ContentHandlerImpl() { 76 ContentHandlerImpl::~ContentHandlerImpl() {
71 } 77 }
72 78
73 void ContentHandlerImpl::StartApplication(mojo::ShellPtr shell, 79 void ContentHandlerImpl::StartApplication(mojo::ShellPtr shell,
74 mojo::URLResponsePtr response) { 80 mojo::URLResponsePtr response) {
75 new SkyApplication(shell.Pass(), response.Pass()); 81 new SkyApplication(shell.Pass(), response.Pass());
76 } 82 }
77 83
78 } // namespace sky 84 } // namespace sky
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698