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

Side by Side Diff: content/common/mojo/embedded_application_runner.cc

Issue 2131493002: ShellConnection -> ServiceContext (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@st
Patch Set: . Created 4 years, 5 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "content/common/mojo/embedded_application_runner.h" 5 #include "content/common/mojo/embedded_application_runner.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/single_thread_task_runner.h" 12 #include "base/single_thread_task_runner.h"
13 #include "base/threading/thread.h" 13 #include "base/threading/thread.h"
14 #include "base/threading/thread_checker.h" 14 #include "base/threading/thread_checker.h"
15 #include "base/threading/thread_task_runner_handle.h" 15 #include "base/threading/thread_task_runner_handle.h"
16 #include "services/shell/public/cpp/shell_connection.h" 16 #include "services/shell/public/cpp/service_context.h"
17 17
18 namespace content { 18 namespace content {
19 19
20 class EmbeddedApplicationRunner::Instance 20 class EmbeddedApplicationRunner::Instance
21 : public base::RefCountedThreadSafe<Instance> { 21 : public base::RefCountedThreadSafe<Instance> {
22 public: 22 public:
23 Instance(const base::StringPiece& name, 23 Instance(const base::StringPiece& name,
24 const MojoApplicationInfo& info, 24 const MojoApplicationInfo& info,
25 const base::Closure& quit_closure) 25 const base::Closure& quit_closure)
26 : name_(name.as_string()), 26 : name_(name.as_string()),
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 private: 61 private:
62 void BindServiceRequestOnApplicationThread( 62 void BindServiceRequestOnApplicationThread(
63 shell::mojom::ServiceRequest request) { 63 shell::mojom::ServiceRequest request) {
64 DCHECK(application_task_runner_->BelongsToCurrentThread()); 64 DCHECK(application_task_runner_->BelongsToCurrentThread());
65 65
66 if (!service_) { 66 if (!service_) {
67 service_ = factory_callback_.Run( 67 service_ = factory_callback_.Run(
68 base::Bind(&Instance::Quit, base::Unretained(this))); 68 base::Bind(&Instance::Quit, base::Unretained(this)));
69 } 69 }
70 70
71 shell::ShellConnection* new_connection = 71 shell::ServiceContext* new_connection =
72 new shell::ShellConnection(service_.get(), std::move(request)); 72 new shell::ServiceContext(service_.get(), std::move(request));
73 shell_connections_.push_back(base::WrapUnique(new_connection)); 73 shell_connections_.push_back(base::WrapUnique(new_connection));
74 new_connection->SetConnectionLostClosure( 74 new_connection->SetConnectionLostClosure(
75 base::Bind(&Instance::OnStop, base::Unretained(this), 75 base::Bind(&Instance::OnStop, base::Unretained(this),
76 new_connection)); 76 new_connection));
77 } 77 }
78 78
79 private: 79 private:
80 friend class base::RefCountedThreadSafe<Instance>; 80 friend class base::RefCountedThreadSafe<Instance>;
81 81
82 ~Instance() { 82 ~Instance() {
83 // If this instance had its own thread, it MUST be explicitly destroyed by 83 // If this instance had its own thread, it MUST be explicitly destroyed by
84 // ShutDown() on the runner's thread by the time this destructor is run. 84 // ShutDown() on the runner's thread by the time this destructor is run.
85 DCHECK(!thread_); 85 DCHECK(!thread_);
86 } 86 }
87 87
88 void OnStop(shell::ShellConnection* connection) { 88 void OnStop(shell::ServiceContext* connection) {
89 DCHECK(application_task_runner_->BelongsToCurrentThread()); 89 DCHECK(application_task_runner_->BelongsToCurrentThread());
90 90
91 for (auto it = shell_connections_.begin(); it != shell_connections_.end(); 91 for (auto it = shell_connections_.begin(); it != shell_connections_.end();
92 ++it) { 92 ++it) {
93 if (it->get() == connection) { 93 if (it->get() == connection) {
94 shell_connections_.erase(it); 94 shell_connections_.erase(it);
95 break; 95 break;
96 } 96 }
97 } 97 }
98 } 98 }
(...skipping 24 matching lines...) Expand all
123 base::ThreadChecker runner_thread_checker_; 123 base::ThreadChecker runner_thread_checker_;
124 124
125 // These fields must only be accessed from the runner's thread. 125 // These fields must only be accessed from the runner's thread.
126 std::unique_ptr<base::Thread> thread_; 126 std::unique_ptr<base::Thread> thread_;
127 scoped_refptr<base::SingleThreadTaskRunner> application_task_runner_; 127 scoped_refptr<base::SingleThreadTaskRunner> application_task_runner_;
128 128
129 // These fields must only be accessed from the application thread, except in 129 // These fields must only be accessed from the application thread, except in
130 // the destructor which may run on either the runner thread or the application 130 // the destructor which may run on either the runner thread or the application
131 // thread. 131 // thread.
132 std::unique_ptr<shell::Service> service_; 132 std::unique_ptr<shell::Service> service_;
133 std::vector<std::unique_ptr<shell::ShellConnection>> shell_connections_; 133 std::vector<std::unique_ptr<shell::ServiceContext>> shell_connections_;
134 134
135 DISALLOW_COPY_AND_ASSIGN(Instance); 135 DISALLOW_COPY_AND_ASSIGN(Instance);
136 }; 136 };
137 137
138 EmbeddedApplicationRunner::EmbeddedApplicationRunner( 138 EmbeddedApplicationRunner::EmbeddedApplicationRunner(
139 const base::StringPiece& name, 139 const base::StringPiece& name,
140 const MojoApplicationInfo& info) 140 const MojoApplicationInfo& info)
141 : weak_factory_(this) { 141 : weak_factory_(this) {
142 instance_ = new Instance(name, info, 142 instance_ = new Instance(name, info,
143 base::Bind(&EmbeddedApplicationRunner::OnQuit, 143 base::Bind(&EmbeddedApplicationRunner::OnQuit,
(...skipping 13 matching lines...) Expand all
157 const base::Closure& quit_closure) { 157 const base::Closure& quit_closure) {
158 quit_closure_ = quit_closure; 158 quit_closure_ = quit_closure;
159 } 159 }
160 160
161 void EmbeddedApplicationRunner::OnQuit() { 161 void EmbeddedApplicationRunner::OnQuit() {
162 if (!quit_closure_.is_null()) 162 if (!quit_closure_.is_null())
163 quit_closure_.Run(); 163 quit_closure_.Run();
164 } 164 }
165 165
166 } // namespace content 166 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/mojo/mojo_shell_context.cc ('k') | content/common/mojo/mojo_shell_connection_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698