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

Side by Side Diff: components/arc/arc_session.cc

Issue 2552213002: Remove explicit singletonness of ArcBridgeService part 1. (Closed)
Patch Set: git cl format Created 4 years 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 | « components/arc/arc_session.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/arc/arc_session.h" 5 #include "components/arc/arc_session.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <grp.h> 8 #include <grp.h>
9 #include <poll.h> 9 #include <poll.h>
10 #include <unistd.h> 10 #include <unistd.h>
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 // The instance has started. Waiting for it to connect to the IPC bridge. 192 // The instance has started. Waiting for it to connect to the IPC bridge.
193 CONNECTING_MOJO, 193 CONNECTING_MOJO,
194 194
195 // The instance is fully set up. 195 // The instance is fully set up.
196 RUNNING, 196 RUNNING,
197 197
198 // ARC is terminated. 198 // ARC is terminated.
199 STOPPED, 199 STOPPED,
200 }; 200 };
201 201
202 explicit ArcSessionImpl( 202 ArcSessionImpl(ArcBridgeService* arc_bridge_service,
203 const scoped_refptr<base::TaskRunner>& blocking_task_runner); 203 const scoped_refptr<base::TaskRunner>& blocking_task_runner);
204 ~ArcSessionImpl() override; 204 ~ArcSessionImpl() override;
205 205
206 // ArcSession overrides: 206 // ArcSession overrides:
207 void Start() override; 207 void Start() override;
208 void Stop() override; 208 void Stop() override;
209 void OnShutdown() override; 209 void OnShutdown() override;
210 210
211 private: 211 private:
212 // Creates the UNIX socket on a worker pool and then processes its file 212 // Creates the UNIX socket on a worker pool and then processes its file
213 // descriptor. 213 // descriptor.
(...skipping 17 matching lines...) Expand all
231 // chromeos::SessionManagerClient::Observer: 231 // chromeos::SessionManagerClient::Observer:
232 void ArcInstanceStopped(bool clean) override; 232 void ArcInstanceStopped(bool clean) override;
233 233
234 // Completes the termination procedure. 234 // Completes the termination procedure.
235 void OnStopped(ArcBridgeService::StopReason reason); 235 void OnStopped(ArcBridgeService::StopReason reason);
236 236
237 // Checks whether a function runs on the thread where the instance is 237 // Checks whether a function runs on the thread where the instance is
238 // created. 238 // created.
239 base::ThreadChecker thread_checker_; 239 base::ThreadChecker thread_checker_;
240 240
241 // Owned by ArcServiceManager.
242 ArcBridgeService* const arc_bridge_service_;
243
241 // Task runner to run a blocking tasks. 244 // Task runner to run a blocking tasks.
242 scoped_refptr<base::TaskRunner> blocking_task_runner_; 245 scoped_refptr<base::TaskRunner> blocking_task_runner_;
243 246
244 // The state of the session. 247 // The state of the session.
245 State state_ = State::NOT_STARTED; 248 State state_ = State::NOT_STARTED;
246 249
247 // When Stop() is called, this flag is set. 250 // When Stop() is called, this flag is set.
248 bool stop_requested_ = false; 251 bool stop_requested_ = false;
249 252
250 // In CONNECTING_MOJO state, this is set to the write side of the pipe 253 // In CONNECTING_MOJO state, this is set to the write side of the pipe
251 // to notify cancelling of the procedure. 254 // to notify cancelling of the procedure.
252 base::ScopedFD accept_cancel_pipe_; 255 base::ScopedFD accept_cancel_pipe_;
253 256
254 // Mojo endpoint. 257 // Mojo endpoint.
255 std::unique_ptr<mojom::ArcBridgeHost> arc_bridge_host_; 258 std::unique_ptr<mojom::ArcBridgeHost> arc_bridge_host_;
256 259
257 // WeakPtrFactory to use callbacks. 260 // WeakPtrFactory to use callbacks.
258 base::WeakPtrFactory<ArcSessionImpl> weak_factory_; 261 base::WeakPtrFactory<ArcSessionImpl> weak_factory_;
259 262
260 private: 263 private:
261 DISALLOW_COPY_AND_ASSIGN(ArcSessionImpl); 264 DISALLOW_COPY_AND_ASSIGN(ArcSessionImpl);
262 }; 265 };
263 266
264 ArcSessionImpl::ArcSessionImpl( 267 ArcSessionImpl::ArcSessionImpl(
268 ArcBridgeService* arc_bridge_service,
265 const scoped_refptr<base::TaskRunner>& blocking_task_runner) 269 const scoped_refptr<base::TaskRunner>& blocking_task_runner)
266 : blocking_task_runner_(blocking_task_runner), weak_factory_(this) { 270 : arc_bridge_service_(arc_bridge_service),
271 blocking_task_runner_(blocking_task_runner),
272 weak_factory_(this) {
267 chromeos::SessionManagerClient* client = GetSessionManagerClient(); 273 chromeos::SessionManagerClient* client = GetSessionManagerClient();
268 if (client == nullptr) 274 if (client == nullptr)
269 return; 275 return;
270 client->AddObserver(this); 276 client->AddObserver(this);
271 } 277 }
272 278
273 ArcSessionImpl::~ArcSessionImpl() { 279 ArcSessionImpl::~ArcSessionImpl() {
274 DCHECK(thread_checker_.CalledOnValidThread()); 280 DCHECK(thread_checker_.CalledOnValidThread());
275 DCHECK(state_ == State::NOT_STARTED || state_ == State::STOPPED); 281 DCHECK(state_ == State::NOT_STARTED || state_ == State::STOPPED);
276 chromeos::SessionManagerClient* client = GetSessionManagerClient(); 282 chromeos::SessionManagerClient* client = GetSessionManagerClient();
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 mojo::edk::CreateMessagePipe(std::move(fd)); 486 mojo::edk::CreateMessagePipe(std::move(fd));
481 if (!server_pipe.is_valid()) { 487 if (!server_pipe.is_valid()) {
482 LOG(ERROR) << "Invalid pipe"; 488 LOG(ERROR) << "Invalid pipe";
483 StopArcInstance(); 489 StopArcInstance();
484 return; 490 return;
485 } 491 }
486 492
487 mojom::ArcBridgeInstancePtr instance; 493 mojom::ArcBridgeInstancePtr instance;
488 instance.Bind(mojo::InterfacePtrInfo<mojom::ArcBridgeInstance>( 494 instance.Bind(mojo::InterfacePtrInfo<mojom::ArcBridgeInstance>(
489 std::move(server_pipe), 0u)); 495 std::move(server_pipe), 0u));
490 arc_bridge_host_.reset(new ArcBridgeHostImpl(std::move(instance))); 496 arc_bridge_host_ = base::MakeUnique<ArcBridgeHostImpl>(arc_bridge_service_,
497 std::move(instance));
491 498
492 VLOG(2) << "Mojo is connected. ARC is running."; 499 VLOG(2) << "Mojo is connected. ARC is running.";
493 state_ = State::RUNNING; 500 state_ = State::RUNNING;
494 for (auto& observer : observer_list_) 501 for (auto& observer : observer_list_)
495 observer.OnReady(); 502 observer.OnReady();
496 } 503 }
497 504
498 void ArcSessionImpl::Stop() { 505 void ArcSessionImpl::Stop() {
499 DCHECK(thread_checker_.CalledOnValidThread()); 506 DCHECK(thread_checker_.CalledOnValidThread());
500 VLOG(2) << "Stopping ARC session is requested."; 507 VLOG(2) << "Stopping ARC session is requested.";
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 void ArcSession::AddObserver(Observer* observer) { 633 void ArcSession::AddObserver(Observer* observer) {
627 observer_list_.AddObserver(observer); 634 observer_list_.AddObserver(observer);
628 } 635 }
629 636
630 void ArcSession::RemoveObserver(Observer* observer) { 637 void ArcSession::RemoveObserver(Observer* observer) {
631 observer_list_.RemoveObserver(observer); 638 observer_list_.RemoveObserver(observer);
632 } 639 }
633 640
634 // static 641 // static
635 std::unique_ptr<ArcSession> ArcSession::Create( 642 std::unique_ptr<ArcSession> ArcSession::Create(
643 ArcBridgeService* arc_bridge_service,
636 const scoped_refptr<base::TaskRunner>& blocking_task_runner) { 644 const scoped_refptr<base::TaskRunner>& blocking_task_runner) {
637 return base::MakeUnique<ArcSessionImpl>(blocking_task_runner); 645 return base::MakeUnique<ArcSessionImpl>(arc_bridge_service,
646 blocking_task_runner);
638 } 647 }
639 648
640 } // namespace arc 649 } // namespace arc
OLDNEW
« no previous file with comments | « components/arc/arc_session.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698