Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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( |
| 203 ArcBridgeService* arc_bridge_service, | |
| 203 const scoped_refptr<base::TaskRunner>& blocking_task_runner); | 204 const scoped_refptr<base::TaskRunner>& blocking_task_runner); |
| 204 ~ArcSessionImpl() override; | 205 ~ArcSessionImpl() override; |
| 205 | 206 |
| 206 // ArcSession overrides: | 207 // ArcSession overrides: |
| 207 void Start() override; | 208 void Start() override; |
| 208 void Stop() override; | 209 void Stop() override; |
| 209 void OnShutdown() override; | 210 void OnShutdown() override; |
| 210 | 211 |
| 211 private: | 212 private: |
| 212 // Creates the UNIX socket on a worker pool and then processes its file | 213 // Creates the UNIX socket on a worker pool and then processes its file |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 231 // chromeos::SessionManagerClient::Observer: | 232 // chromeos::SessionManagerClient::Observer: |
| 232 void ArcInstanceStopped(bool clean) override; | 233 void ArcInstanceStopped(bool clean) override; |
| 233 | 234 |
| 234 // Completes the termination procedure. | 235 // Completes the termination procedure. |
| 235 void OnStopped(ArcBridgeService::StopReason reason); | 236 void OnStopped(ArcBridgeService::StopReason reason); |
| 236 | 237 |
| 237 // Checks whether a function runs on the thread where the instance is | 238 // Checks whether a function runs on the thread where the instance is |
| 238 // created. | 239 // created. |
| 239 base::ThreadChecker thread_checker_; | 240 base::ThreadChecker thread_checker_; |
| 240 | 241 |
| 242 ArcBridgeService* const arc_bridge_service_; | |
|
Luis Héctor Chávez
2016/12/06 18:48:32
Please mention who owns this pointer.
hidehiko
2016/12/06 18:54:36
Done.
| |
| 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), weak_factory_(this) { | |
| 267 chromeos::SessionManagerClient* client = GetSessionManagerClient(); | 272 chromeos::SessionManagerClient* client = GetSessionManagerClient(); |
| 268 if (client == nullptr) | 273 if (client == nullptr) |
| 269 return; | 274 return; |
| 270 client->AddObserver(this); | 275 client->AddObserver(this); |
| 271 } | 276 } |
| 272 | 277 |
| 273 ArcSessionImpl::~ArcSessionImpl() { | 278 ArcSessionImpl::~ArcSessionImpl() { |
| 274 DCHECK(thread_checker_.CalledOnValidThread()); | 279 DCHECK(thread_checker_.CalledOnValidThread()); |
| 275 DCHECK(state_ == State::NOT_STARTED || state_ == State::STOPPED); | 280 DCHECK(state_ == State::NOT_STARTED || state_ == State::STOPPED); |
| 276 chromeos::SessionManagerClient* client = GetSessionManagerClient(); | 281 chromeos::SessionManagerClient* client = GetSessionManagerClient(); |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 480 mojo::edk::CreateMessagePipe(std::move(fd)); | 485 mojo::edk::CreateMessagePipe(std::move(fd)); |
| 481 if (!server_pipe.is_valid()) { | 486 if (!server_pipe.is_valid()) { |
| 482 LOG(ERROR) << "Invalid pipe"; | 487 LOG(ERROR) << "Invalid pipe"; |
| 483 StopArcInstance(); | 488 StopArcInstance(); |
| 484 return; | 489 return; |
| 485 } | 490 } |
| 486 | 491 |
| 487 mojom::ArcBridgeInstancePtr instance; | 492 mojom::ArcBridgeInstancePtr instance; |
| 488 instance.Bind(mojo::InterfacePtrInfo<mojom::ArcBridgeInstance>( | 493 instance.Bind(mojo::InterfacePtrInfo<mojom::ArcBridgeInstance>( |
| 489 std::move(server_pipe), 0u)); | 494 std::move(server_pipe), 0u)); |
| 490 arc_bridge_host_.reset(new ArcBridgeHostImpl(std::move(instance))); | 495 arc_bridge_host_ = base::MakeUnique<ArcBridgeHostImpl>( |
| 496 arc_bridge_service_, std::move(instance)); | |
| 491 | 497 |
| 492 VLOG(2) << "Mojo is connected. ARC is running."; | 498 VLOG(2) << "Mojo is connected. ARC is running."; |
| 493 state_ = State::RUNNING; | 499 state_ = State::RUNNING; |
| 494 for (auto& observer : observer_list_) | 500 for (auto& observer : observer_list_) |
| 495 observer.OnReady(); | 501 observer.OnReady(); |
| 496 } | 502 } |
| 497 | 503 |
| 498 void ArcSessionImpl::Stop() { | 504 void ArcSessionImpl::Stop() { |
| 499 DCHECK(thread_checker_.CalledOnValidThread()); | 505 DCHECK(thread_checker_.CalledOnValidThread()); |
| 500 VLOG(2) << "Stopping ARC session is requested."; | 506 VLOG(2) << "Stopping ARC session is requested."; |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 626 void ArcSession::AddObserver(Observer* observer) { | 632 void ArcSession::AddObserver(Observer* observer) { |
| 627 observer_list_.AddObserver(observer); | 633 observer_list_.AddObserver(observer); |
| 628 } | 634 } |
| 629 | 635 |
| 630 void ArcSession::RemoveObserver(Observer* observer) { | 636 void ArcSession::RemoveObserver(Observer* observer) { |
| 631 observer_list_.RemoveObserver(observer); | 637 observer_list_.RemoveObserver(observer); |
| 632 } | 638 } |
| 633 | 639 |
| 634 // static | 640 // static |
| 635 std::unique_ptr<ArcSession> ArcSession::Create( | 641 std::unique_ptr<ArcSession> ArcSession::Create( |
| 642 ArcBridgeService* arc_bridge_service, | |
| 636 const scoped_refptr<base::TaskRunner>& blocking_task_runner) { | 643 const scoped_refptr<base::TaskRunner>& blocking_task_runner) { |
| 637 return base::MakeUnique<ArcSessionImpl>(blocking_task_runner); | 644 return base::MakeUnique<ArcSessionImpl>( |
| 645 arc_bridge_service, blocking_task_runner); | |
| 638 } | 646 } |
| 639 | 647 |
| 640 } // namespace arc | 648 } // namespace arc |
| OLD | NEW |