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

Side by Side Diff: extensions/renderer/api/display_source/wifi_display/wifi_display_session.cc

Issue 1674583002: [chrome.displaySource] Session notification improvements (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Init sCallId Created 4 years, 10 months 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
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 "extensions/renderer/api/display_source/wifi_display/wifi_display_sessi on.h" 5 #include "extensions/renderer/api/display_source/wifi_display/wifi_display_sessi on.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/timer/timer.h" 8 #include "base/timer/timer.h"
9 #include "content/public/common/service_registry.h" 9 #include "content/public/common/service_registry.h"
10 #include "content/public/renderer/render_frame.h" 10 #include "content/public/renderer/render_frame.h"
(...skipping 24 matching lines...) Expand all
35 weak_factory_.GetWeakPtr())); 35 weak_factory_.GetWeakPtr()));
36 } 36 }
37 37
38 WiFiDisplaySession::~WiFiDisplaySession() { 38 WiFiDisplaySession::~WiFiDisplaySession() {
39 } 39 }
40 40
41 void WiFiDisplaySession::Start() { 41 void WiFiDisplaySession::Start() {
42 DCHECK(state_ == DisplaySourceSession::Idle); 42 DCHECK(state_ == DisplaySourceSession::Idle);
43 service_->Connect(params_.sink_id, params_.auth_method, params_.auth_data); 43 service_->Connect(params_.sink_id, params_.auth_method, params_.auth_data);
44 state_ = DisplaySourceSession::Establishing; 44 state_ = DisplaySourceSession::Establishing;
45 if (!started_callback_.is_null())
46 started_callback_.Run(params_.sink_id);
45 } 47 }
46 48
47 void WiFiDisplaySession::Terminate() { 49 void WiFiDisplaySession::Terminate() {
48 DCHECK(state_ != DisplaySourceSession::Idle); 50 DCHECK(state_ != DisplaySourceSession::Idle);
49 switch (state_) { 51 switch (state_) {
50 case DisplaySourceSession::Idle: 52 case DisplaySourceSession::Idle:
51 case DisplaySourceSession::Terminating: 53 case DisplaySourceSession::Terminating:
52 // Nothing to do. 54 // Nothing to do.
53 return; 55 return;
54 case DisplaySourceSession::Establishing: 56 case DisplaySourceSession::Establishing:
55 case DisplaySourceSession::Established: 57 case DisplaySourceSession::Established:
56 service_->Disconnect(); 58 service_->Disconnect();
57 state_ = DisplaySourceSession::Terminating; 59 state_ = DisplaySourceSession::Terminating;
58 break; 60 break;
59 default: 61 default:
60 NOTREACHED(); 62 NOTREACHED();
61 } 63 }
62 } 64 }
63 65
64 void WiFiDisplaySession::OnConnected( 66 void WiFiDisplaySession::OnEstablished(const mojo::String& ip_address) {
65 int32_t sink_id, const mojo::String& ip_address) { 67 DCHECK(state_ != DisplaySourceSession::Established);
66 if (sink_id == params_.sink_id) { 68 ip_address_ = ip_address;
67 DCHECK(state_ != DisplaySourceSession::Established); 69 state_ = DisplaySourceSession::Established;
68 ip_address_ = ip_address;
69 state_ = DisplaySourceSession::Established;
70 }
71
72 if (!started_callback_.is_null())
73 started_callback_.Run(sink_id);
74 } 70 }
75 71
76 void WiFiDisplaySession::OnDisconnected(int32_t sink_id) { 72 void WiFiDisplaySession::OnTerminated() {
77 if (sink_id == params_.sink_id) { 73 DCHECK(state_ != DisplaySourceSession::Idle);
78 DCHECK(state_ == DisplaySourceSession::Established || 74 state_ = DisplaySourceSession::Idle;
79 state_ == DisplaySourceSession::Terminating);
80 state_ = DisplaySourceSession::Idle;
81 }
82
83 if (!terminated_callback_.is_null()) 75 if (!terminated_callback_.is_null())
84 terminated_callback_.Run(sink_id); 76 terminated_callback_.Run(params_.sink_id);
85 } 77 }
86 78
87 void WiFiDisplaySession::OnError( 79 void WiFiDisplaySession::OnError(int32_t type,
88 int32_t sink_id, int32_t type, const mojo::String& description) { 80 const mojo::String& description) {
89 DCHECK(type > api::display_source::ERROR_TYPE_NONE 81 DCHECK(type > api::display_source::ERROR_TYPE_NONE
90 && type <= api::display_source::ERROR_TYPE_LAST); 82 && type <= api::display_source::ERROR_TYPE_LAST);
91 if (!error_callback_.is_null()) 83 if (!error_callback_.is_null())
92 error_callback_.Run(sink_id, static_cast<ErrorType>(type), description); 84 error_callback_.Run(params_.sink_id, static_cast<ErrorType>(type),
85 description);
93 } 86 }
94 87
95 void WiFiDisplaySession::OnMessage(const mojo::String& data) { 88 void WiFiDisplaySession::OnMessage(const mojo::String& data) {
96 DCHECK(state_ == DisplaySourceSession::Established); 89 DCHECK(state_ == DisplaySourceSession::Established);
97 } 90 }
98 91
99 void WiFiDisplaySession::OnConnectionError() { 92 void WiFiDisplaySession::OnConnectionError() {
100 if (!error_callback_.is_null()) { 93 if (!error_callback_.is_null()) {
101 error_callback_.Run(params_.sink_id, 94 error_callback_.Run(params_.sink_id,
102 api::display_source::ERROR_TYPE_UNKNOWN_ERROR, 95 api::display_source::ERROR_TYPE_UNKNOWN_ERROR,
103 kErrorInternal); 96 kErrorInternal);
104 } 97 }
105 98
106 if (state_ == DisplaySourceSession::Established || 99 if (state_ != DisplaySourceSession::Idle) {
107 state_ == DisplaySourceSession::Terminating) {
108 // We must explicitly notify the session termination as it will never 100 // We must explicitly notify the session termination as it will never
109 // arrive from browser process (IPC is broken). 101 // arrive from browser process (IPC is broken).
110 if (!terminated_callback_.is_null()) 102 if (!terminated_callback_.is_null())
111 terminated_callback_.Run(params_.sink_id); 103 terminated_callback_.Run(params_.sink_id);
112 } 104 }
113 } 105 }
114 106
115 } // namespace extensions 107 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698