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

Side by Side Diff: mojo/shell/public/cpp/lib/content_handler_factory.cc

Issue 1675153002: ApplicationImpl->ShellConnection, mojom::Application->mojom::ShellClient (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ci2
Patch Set: . Created 4 years, 10 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 <set> 5 #include <set>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 11 matching lines...) Expand all
22 namespace mojo { 22 namespace mojo {
23 23
24 namespace { 24 namespace {
25 25
26 class ApplicationThread : public base::PlatformThread::Delegate { 26 class ApplicationThread : public base::PlatformThread::Delegate {
27 public: 27 public:
28 ApplicationThread( 28 ApplicationThread(
29 scoped_refptr<base::SingleThreadTaskRunner> handler_thread, 29 scoped_refptr<base::SingleThreadTaskRunner> handler_thread,
30 const base::Callback<void(ApplicationThread*)>& termination_callback, 30 const base::Callback<void(ApplicationThread*)>& termination_callback,
31 ContentHandlerFactory::Delegate* handler_delegate, 31 ContentHandlerFactory::Delegate* handler_delegate,
32 InterfaceRequest<shell::mojom::Application> application_request, 32 InterfaceRequest<shell::mojom::ShellClient> request,
33 URLResponsePtr response, 33 URLResponsePtr response,
34 const Callback<void()>& destruct_callback) 34 const Callback<void()>& destruct_callback)
35 : handler_thread_(handler_thread), 35 : handler_thread_(handler_thread),
36 termination_callback_(termination_callback), 36 termination_callback_(termination_callback),
37 handler_delegate_(handler_delegate), 37 handler_delegate_(handler_delegate),
38 application_request_(std::move(application_request)), 38 request_(std::move(request)),
39 response_(std::move(response)), 39 response_(std::move(response)),
40 destruct_callback_(destruct_callback) {} 40 destruct_callback_(destruct_callback) {}
41 41
42 ~ApplicationThread() override { 42 ~ApplicationThread() override {
43 destruct_callback_.Run(); 43 destruct_callback_.Run();
44 } 44 }
45 45
46 private: 46 private:
47 void ThreadMain() override { 47 void ThreadMain() override {
48 handler_delegate_->RunApplication(std::move(application_request_), 48 handler_delegate_->RunApplication(std::move(request_),
49 std::move(response_)); 49 std::move(response_));
50 handler_thread_->PostTask(FROM_HERE, 50 handler_thread_->PostTask(FROM_HERE,
51 base::Bind(termination_callback_, this)); 51 base::Bind(termination_callback_, this));
52 } 52 }
53 53
54 scoped_refptr<base::SingleThreadTaskRunner> handler_thread_; 54 scoped_refptr<base::SingleThreadTaskRunner> handler_thread_;
55 base::Callback<void(ApplicationThread*)> termination_callback_; 55 base::Callback<void(ApplicationThread*)> termination_callback_;
56 ContentHandlerFactory::Delegate* handler_delegate_; 56 ContentHandlerFactory::Delegate* handler_delegate_;
57 InterfaceRequest<shell::mojom::Application> application_request_; 57 InterfaceRequest<shell::mojom::ShellClient> request_;
58 URLResponsePtr response_; 58 URLResponsePtr response_;
59 Callback<void()> destruct_callback_; 59 Callback<void()> destruct_callback_;
60 60
61 DISALLOW_COPY_AND_ASSIGN(ApplicationThread); 61 DISALLOW_COPY_AND_ASSIGN(ApplicationThread);
62 }; 62 };
63 63
64 class ContentHandlerImpl : public shell::mojom::ContentHandler { 64 class ContentHandlerImpl : public shell::mojom::ContentHandler {
65 public: 65 public:
66 ContentHandlerImpl(ContentHandlerFactory::Delegate* delegate, 66 ContentHandlerImpl(ContentHandlerFactory::Delegate* delegate,
67 InterfaceRequest<shell::mojom::ContentHandler> request) 67 InterfaceRequest<shell::mojom::ContentHandler> request)
68 : delegate_(delegate), 68 : delegate_(delegate),
69 binding_(this, std::move(request)), 69 binding_(this, std::move(request)),
70 weak_factory_(this) {} 70 weak_factory_(this) {}
71 ~ContentHandlerImpl() override { 71 ~ContentHandlerImpl() override {
72 // We're shutting down and doing cleanup. Cleanup may trigger calls back to 72 // We're shutting down and doing cleanup. Cleanup may trigger calls back to
73 // OnThreadEnd(). As we're doing the cleanup here we don't want to do it in 73 // OnThreadEnd(). As we're doing the cleanup here we don't want to do it in
74 // OnThreadEnd() as well. InvalidateWeakPtrs() ensures we don't get any 74 // OnThreadEnd() as well. InvalidateWeakPtrs() ensures we don't get any
75 // calls to OnThreadEnd(). 75 // calls to OnThreadEnd().
76 weak_factory_.InvalidateWeakPtrs(); 76 weak_factory_.InvalidateWeakPtrs();
77 for (auto thread : active_threads_) { 77 for (auto thread : active_threads_) {
78 base::PlatformThread::Join(thread.second); 78 base::PlatformThread::Join(thread.second);
79 delete thread.first; 79 delete thread.first;
80 } 80 }
81 } 81 }
82 82
83 private: 83 private:
84 // Overridden from ContentHandler: 84 // Overridden from ContentHandler:
85 void StartApplication( 85 void StartApplication(InterfaceRequest<shell::mojom::ShellClient> request,
86 InterfaceRequest<shell::mojom::Application> application_request, 86 URLResponsePtr response,
87 URLResponsePtr response, 87 const Callback<void()>& destruct_callback) override {
88 const Callback<void()>& destruct_callback) override {
89 ApplicationThread* thread = 88 ApplicationThread* thread =
90 new ApplicationThread(base::ThreadTaskRunnerHandle::Get(), 89 new ApplicationThread(base::ThreadTaskRunnerHandle::Get(),
91 base::Bind(&ContentHandlerImpl::OnThreadEnd, 90 base::Bind(&ContentHandlerImpl::OnThreadEnd,
92 weak_factory_.GetWeakPtr()), 91 weak_factory_.GetWeakPtr()),
93 delegate_, std::move(application_request), 92 delegate_, std::move(request),
94 std::move(response), destruct_callback); 93 std::move(response), destruct_callback);
95 base::PlatformThreadHandle handle; 94 base::PlatformThreadHandle handle;
96 bool launched = base::PlatformThread::Create(0, thread, &handle); 95 bool launched = base::PlatformThread::Create(0, thread, &handle);
97 DCHECK(launched); 96 DCHECK(launched);
98 active_threads_[thread] = handle; 97 active_threads_[thread] = handle;
99 } 98 }
100 99
101 void OnThreadEnd(ApplicationThread* thread) { 100 void OnThreadEnd(ApplicationThread* thread) {
102 DCHECK(active_threads_.find(thread) != active_threads_.end()); 101 DCHECK(active_threads_.find(thread) != active_threads_.end());
103 base::PlatformThreadHandle handle = active_threads_[thread]; 102 base::PlatformThreadHandle handle = active_threads_[thread];
(...skipping 13 matching lines...) Expand all
117 } // namespace 116 } // namespace
118 117
119 ContentHandlerFactory::ContentHandlerFactory(Delegate* delegate) 118 ContentHandlerFactory::ContentHandlerFactory(Delegate* delegate)
120 : delegate_(delegate) { 119 : delegate_(delegate) {
121 } 120 }
122 121
123 ContentHandlerFactory::~ContentHandlerFactory() { 122 ContentHandlerFactory::~ContentHandlerFactory() {
124 } 123 }
125 124
126 void ContentHandlerFactory::ManagedDelegate::RunApplication( 125 void ContentHandlerFactory::ManagedDelegate::RunApplication(
127 InterfaceRequest<shell::mojom::Application> application_request, 126 InterfaceRequest<shell::mojom::ShellClient> request,
128 URLResponsePtr response) { 127 URLResponsePtr response) {
129 base::MessageLoop loop(common::MessagePumpMojo::Create()); 128 base::MessageLoop loop(common::MessagePumpMojo::Create());
130 auto application = this->CreateApplication(std::move(application_request), 129 auto application =
131 std::move(response)); 130 this->CreateApplication(std::move(request), std::move(response));
132 if (application) 131 if (application)
133 loop.Run(); 132 loop.Run();
134 } 133 }
135 134
136 void ContentHandlerFactory::Create( 135 void ContentHandlerFactory::Create(
137 Connection* connection, 136 Connection* connection,
138 InterfaceRequest<shell::mojom::ContentHandler> request) { 137 InterfaceRequest<shell::mojom::ContentHandler> request) {
139 new ContentHandlerImpl(delegate_, std::move(request)); 138 new ContentHandlerImpl(delegate_, std::move(request));
140 } 139 }
141 140
142 } // namespace mojo 141 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/shell/public/cpp/lib/application_test_base.cc ('k') | mojo/shell/public/cpp/lib/shell_connection.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698