mirroring_service.cc 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright 2018 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "components/mirroring/service/mirroring_service.h"
  5. #include "base/bind.h"
  6. #include "base/callback.h"
  7. #include "components/mirroring/service/session.h"
  8. #include "services/viz/public/cpp/gpu/gpu.h"
  9. namespace mirroring {
  10. MirroringService::MirroringService(
  11. mojo::PendingReceiver<mojom::MirroringService> receiver,
  12. scoped_refptr<base::SingleThreadTaskRunner> io_task_runner)
  13. : receiver_(this, std::move(receiver)),
  14. io_task_runner_(std::move(io_task_runner)) {
  15. receiver_.set_disconnect_handler(
  16. base::BindOnce(&MirroringService::OnDisconnect, base::Unretained(this)));
  17. }
  18. MirroringService::~MirroringService() = default;
  19. void MirroringService::Start(
  20. mojom::SessionParametersPtr params,
  21. const gfx::Size& max_resolution,
  22. mojo::PendingRemote<mojom::SessionObserver> observer,
  23. mojo::PendingRemote<mojom::ResourceProvider> resource_provider,
  24. mojo::PendingRemote<mojom::CastMessageChannel> outbound_channel,
  25. mojo::PendingReceiver<mojom::CastMessageChannel> inbound_channel) {
  26. session_.reset(); // Stops the current session if active.
  27. session_ = std::make_unique<Session>(
  28. std::move(params), max_resolution, std::move(observer),
  29. std::move(resource_provider), std::move(outbound_channel),
  30. std::move(inbound_channel), io_task_runner_);
  31. // We could put a waitable event here and wait till initialization completed
  32. // before exiting Start(). But that would actually be just waste of effort,
  33. // because Session will not send anything over the channels until
  34. // initialization is completed, hence no outer calls to the session
  35. // will be made.
  36. session_->AsyncInitialize(Session::AsyncInitializeDoneCB());
  37. }
  38. void MirroringService::OnDisconnect() {
  39. session_.reset();
  40. }
  41. } // namespace mirroring