Chromium Code Reviews| Index: extensions/renderer/api/display_source/wifi_display/wifi_display_session.cc |
| diff --git a/extensions/renderer/api/display_source/wifi_display/wifi_display_session.cc b/extensions/renderer/api/display_source/wifi_display/wifi_display_session.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..fd4ccb65146f4abc438f8d794148bf1917b73b11 |
| --- /dev/null |
| +++ b/extensions/renderer/api/display_source/wifi_display/wifi_display_session.cc |
| @@ -0,0 +1,91 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "extensions/renderer/api/display_source/wifi_display/wifi_display_session.h" |
| + |
| +#include "base/logging.h" |
| +#include "base/timer/timer.h" |
| +#include "content/public/common/service_registry.h" |
| +#include "content/public/renderer/render_frame.h" |
| + |
| +namespace extensions { |
| + |
| +using api::display_source::ErrorType; |
| + |
| +WiFiDisplaySession::WiFiDisplaySession( |
| + const DisplaySourceSessionParams& params) |
| + : binding_(this), |
| + params_(params) { |
| + CHECK(params_.render_frame); |
|
Ken Rockot(use gerrit already)
2016/01/05 17:21:37
In general these CHECKs should probably just be DC
Mikhail
2016/01/11 19:39:41
Done.
|
| + params.render_frame->GetServiceRegistry()->ConnectToRemoteService( |
| + mojo::GetProxy(&service_)); |
| + CHECK(service_); |
| + WiFiDisplaySessionServiceClientPtr client_ptr; |
| + binding_.Bind(GetProxy(&client_ptr)); |
| + CHECK(client_ptr); |
| + |
| + service_->SetClient(std::move(client_ptr)); |
|
Ken Rockot(use gerrit already)
2016/01/05 17:21:37
You probably want to set a connection error handle
Mikhail
2016/01/11 19:39:41
Done.
|
| +} |
| + |
| +WiFiDisplaySession::~WiFiDisplaySession() { |
| +} |
| + |
| +void WiFiDisplaySession::Start() { |
| + DCHECK(state_ == DisplaySourceSession::Idle); |
| + service_->Connect(params_.sink_id, params_.auth_method, params_.auth_data); |
| + state_ = DisplaySourceSession::Establishing; |
| +} |
| + |
| +void WiFiDisplaySession::Terminate() { |
| + DCHECK(state_ != DisplaySourceSession::Idle); |
| + switch (state_) { |
| + case DisplaySourceSession::Idle: |
| + case DisplaySourceSession::Terminating: |
| + // Nothing to do. |
| + return; |
| + case DisplaySourceSession::Establishing: |
| + case DisplaySourceSession::Established: |
| + service_->Disconnect(); |
| + state_ = DisplaySourceSession::Terminating; |
| + break; |
| + default: |
| + NOTREACHED(); |
| + } |
| +} |
| + |
| +void WiFiDisplaySession::OnConnected( |
| + int32_t sink_id, const mojo::String& ip_address) { |
| + DCHECK(state_ != DisplaySourceSession::Established); |
| + if (sink_id == params_.sink_id) { |
| + ip_address_ = ip_address; |
| + state_ = DisplaySourceSession::Established; |
| + } |
| + |
| + if (!started_callback_.is_null()) |
| + started_callback_.Run(sink_id); |
| +} |
| + |
| +void WiFiDisplaySession::OnDisconnected(int32_t sink_id) { |
| + DCHECK(state_ == DisplaySourceSession::Established); |
| + if (sink_id == params_.sink_id) { |
| + state_ = DisplaySourceSession::Idle; |
| + } |
| + |
| + if (!terminated_callback_.is_null()) |
| + terminated_callback_.Run(sink_id); |
| +} |
| + |
| +void WiFiDisplaySession::OnError( |
| + int32_t sink_id, int32_t type, const mojo::String& description) { |
| + DCHECK(type > api::display_source::ERROR_TYPE_NONE |
| + && type <= api::display_source::ERROR_TYPE_LAST); |
| + if (!error_callback_.is_null()) |
| + error_callback_.Run(sink_id, static_cast<ErrorType>(type), description); |
| +} |
| + |
| +void WiFiDisplaySession::OnMessage(const mojo::String& data) { |
| + DCHECK(state_ == DisplaySourceSession::Established); |
| +} |
| + |
| +} // namespace extensions |