OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "extensions/renderer/api/display_source/wifi_display/wifi_display_sessi on.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "base/timer/timer.h" | |
9 #include "content/public/common/service_registry.h" | |
10 #include "content/public/renderer/render_frame.h" | |
11 | |
12 namespace extensions { | |
13 | |
14 using api::display_source::ErrorType; | |
15 | |
16 WiFiDisplaySession::WiFiDisplaySession( | |
17 const DisplaySourceSessionParams& params) | |
18 : binding_(this), | |
19 params_(params) { | |
20 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.
| |
21 params.render_frame->GetServiceRegistry()->ConnectToRemoteService( | |
22 mojo::GetProxy(&service_)); | |
23 CHECK(service_); | |
24 WiFiDisplaySessionServiceClientPtr client_ptr; | |
25 binding_.Bind(GetProxy(&client_ptr)); | |
26 CHECK(client_ptr); | |
27 | |
28 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.
| |
29 } | |
30 | |
31 WiFiDisplaySession::~WiFiDisplaySession() { | |
32 } | |
33 | |
34 void WiFiDisplaySession::Start() { | |
35 DCHECK(state_ == DisplaySourceSession::Idle); | |
36 service_->Connect(params_.sink_id, params_.auth_method, params_.auth_data); | |
37 state_ = DisplaySourceSession::Establishing; | |
38 } | |
39 | |
40 void WiFiDisplaySession::Terminate() { | |
41 DCHECK(state_ != DisplaySourceSession::Idle); | |
42 switch (state_) { | |
43 case DisplaySourceSession::Idle: | |
44 case DisplaySourceSession::Terminating: | |
45 // Nothing to do. | |
46 return; | |
47 case DisplaySourceSession::Establishing: | |
48 case DisplaySourceSession::Established: | |
49 service_->Disconnect(); | |
50 state_ = DisplaySourceSession::Terminating; | |
51 break; | |
52 default: | |
53 NOTREACHED(); | |
54 } | |
55 } | |
56 | |
57 void WiFiDisplaySession::OnConnected( | |
58 int32_t sink_id, const mojo::String& ip_address) { | |
59 DCHECK(state_ != DisplaySourceSession::Established); | |
60 if (sink_id == params_.sink_id) { | |
61 ip_address_ = ip_address; | |
62 state_ = DisplaySourceSession::Established; | |
63 } | |
64 | |
65 if (!started_callback_.is_null()) | |
66 started_callback_.Run(sink_id); | |
67 } | |
68 | |
69 void WiFiDisplaySession::OnDisconnected(int32_t sink_id) { | |
70 DCHECK(state_ == DisplaySourceSession::Established); | |
71 if (sink_id == params_.sink_id) { | |
72 state_ = DisplaySourceSession::Idle; | |
73 } | |
74 | |
75 if (!terminated_callback_.is_null()) | |
76 terminated_callback_.Run(sink_id); | |
77 } | |
78 | |
79 void WiFiDisplaySession::OnError( | |
80 int32_t sink_id, int32_t type, const mojo::String& description) { | |
81 DCHECK(type > api::display_source::ERROR_TYPE_NONE | |
82 && type <= api::display_source::ERROR_TYPE_LAST); | |
83 if (!error_callback_.is_null()) | |
84 error_callback_.Run(sink_id, static_cast<ErrorType>(type), description); | |
85 } | |
86 | |
87 void WiFiDisplaySession::OnMessage(const mojo::String& data) { | |
88 DCHECK(state_ == DisplaySourceSession::Established); | |
89 } | |
90 | |
91 } // namespace extensions | |
OLD | NEW |