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

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

Issue 741453002: Make sure that Content Handled application can be connected multiple times. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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"
8 #include "mojo/services/public/interfaces/network/network_service.mojom.h"
7 #include "sky/viewer/document_view.h" 9 #include "sky/viewer/document_view.h"
8 10
9 namespace sky { 11 namespace sky {
10 12
13 namespace {
14
15 class EmptyServiceProvider : public mojo::InterfaceImpl<mojo::ServiceProvider> {
Aaron Boodman 2014/11/18 23:46:15 unused?
qsr 2014/11/19 13:42:38 Seems so.
16 private:
17 void ConnectToService(const mojo::String& service_name,
18 mojo::ScopedMessagePipeHandle client_handle) override {}
19 };
20
21 } // namespace
22
23 class SkyApplication : public mojo::Application {
24 public:
25 SkyApplication(scoped_refptr<base::MessageLoopProxy> compositor_thread,
26 mojo::ShellPtr shell,
27 mojo::URLResponsePtr response)
28 : compositor_thread_(compositor_thread),
29 url_(response->url),
30 shell_(shell.Pass()),
31 initial_response_(response.Pass()),
32 nb_views_(0) {
Aaron Boodman 2014/11/18 23:46:15 view_count_ ? or num_views_
qsr 2014/11/19 13:42:38 Done.
33 shell_.set_client(this);
34 shell_->ConnectToApplication("mojo:network_service",
35 mojo::GetProxy(&network_service_app_));
Aaron Boodman 2014/11/18 23:46:15 Just make network_service_app a local. You don't n
qsr 2014/11/19 13:42:38 I was not sure of what will happen when I close th
36 mojo::MessagePipe pipe;
37 network_service_app_->ConnectToService(mojo::NetworkService::Name_,
Aaron Boodman 2014/11/18 23:46:15 Use mojo/public/cpp/application/connect.h
qsr 2014/11/19 13:42:38 Done.
38 pipe.handle0.Pass());
39 network_service_.Bind(pipe.handle1.Pass());
40 }
41
42 void Initialize(mojo::Array<mojo::String> args) override {}
43
44 void AcceptConnection(const mojo::String& requestor_url,
45 mojo::ServiceProviderPtr provider) override {
46 ++nb_views_;
47 if (initial_response_) {
48 OnResponseReceived(nullptr, provider.Pass(), initial_response_.Pass());
49 } else {
50 mojo::URLLoaderPtr* loader = new mojo::URLLoaderPtr;
Aaron Boodman 2014/11/18 23:46:15 What happens if this is a normal URLLoaderPtr, and
qsr 2014/11/19 13:42:38 The issue is we then do: loader->Start(..., loade
Aaron Boodman 2014/11/19 15:58:15 I pinged jyasskin, my go-to C++ expert. He says yo
qsr 2014/11/19 16:37:22 Done.
51 network_service_->CreateURLLoader(mojo::GetProxy(loader));
52 mojo::URLRequestPtr request(mojo::URLRequest::New());
53 request->url = url_;
54 request->auto_follow_redirects = true;
55 (*loader)->Start(request.Pass(),
56 base::Bind(&SkyApplication::OnResponseReceived,
57 base::Unretained(this), base::Owned(loader),
58 base::Passed(&provider)));
59 }
60 }
61
62 private:
63 void OnViewDestroyed() {
64 --nb_views_;
65 if (nb_views_ == 0) {
66 delete this;
67 }
68 }
69
70 void OnResponseReceived(mojo::URLLoaderPtr* loader,
Aaron Boodman 2014/11/18 23:46:15 Doesn't loader leak? You may have to keep the loa
qsr 2014/11/19 13:42:38 Unless I'm misunderstanding base::Owned, I don't t
Aaron Boodman 2014/11/19 15:58:15 OK, just scary-looking. See above comment.
qsr 2014/11/19 16:37:22 Yes, that's for sure. The response owns the body.
71 mojo::ServiceProviderPtr provider,
72 mojo::URLResponsePtr response) {
73 new DocumentView(
74 base::Bind(&SkyApplication::OnViewDestroyed, base::Unretained(this)),
75 provider.Pass(), response.Pass(), shell_.get(), compositor_thread_);
76 }
77
78 scoped_refptr<base::MessageLoopProxy> compositor_thread_;
79 mojo::String url_;
80 mojo::ShellPtr shell_;
81 mojo::ServiceProviderPtr network_service_app_;
Aaron Boodman 2014/11/18 23:46:15 You don't need to keep this alive. Just make it a
qsr 2014/11/19 13:42:38 Done.
82 mojo::NetworkServicePtr network_service_;
83 mojo::URLResponsePtr initial_response_;
84 uint32_t nb_views_;
85 };
86
11 ContentHandlerImpl::ContentHandlerImpl( 87 ContentHandlerImpl::ContentHandlerImpl(
12 scoped_refptr<base::MessageLoopProxy> compositor_thread) 88 scoped_refptr<base::MessageLoopProxy> compositor_thread)
13 : compositor_thread_(compositor_thread) { 89 : compositor_thread_(compositor_thread) {
14 } 90 }
15 91
16 ContentHandlerImpl::~ContentHandlerImpl() { 92 ContentHandlerImpl::~ContentHandlerImpl() {
17 } 93 }
18 94
19 void ContentHandlerImpl::StartApplication(mojo::ShellPtr shell, 95 void ContentHandlerImpl::StartApplication(mojo::ShellPtr shell,
20 mojo::URLResponsePtr response) { 96 mojo::URLResponsePtr response) {
21 new DocumentView(response.Pass(), shell.Pass(), compositor_thread_); 97 new SkyApplication(compositor_thread_, shell.Pass(), response.Pass());
22 } 98 }
23 99
24 } // namespace sky 100 } // namespace sky
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698