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

Side by Side Diff: extensions/browser/api/cast_channel/cast_channel_api.cc

Issue 690383002: cast channel error cleanup (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Code review changes. Created 6 years, 1 month 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/browser/api/cast_channel/cast_channel_api.h" 5 #include "extensions/browser/api/cast_channel/cast_channel_api.h"
6 6
7 #include <limits> 7 #include <limits>
8 #include <string> 8 #include <string>
9 9
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 VLOG(1) << "Sending message " << ParamToString(message_info) 166 VLOG(1) << "Sending message " << ParamToString(message_info)
167 << " to channel " << ParamToString(channel_info); 167 << " to channel " << ParamToString(channel_info);
168 scoped_ptr<Event> event(new Event(OnMessage::kEventName, results.Pass())); 168 scoped_ptr<Event> event(new Event(OnMessage::kEventName, results.Pass()));
169 extensions::EventRouter::Get(browser_context_) 169 extensions::EventRouter::Get(browser_context_)
170 ->DispatchEventToExtension(socket->owner_extension_id(), event.Pass()); 170 ->DispatchEventToExtension(socket->owner_extension_id(), event.Pass());
171 } 171 }
172 172
173 CastChannelAPI::~CastChannelAPI() {} 173 CastChannelAPI::~CastChannelAPI() {}
174 174
175 CastChannelAsyncApiFunction::CastChannelAsyncApiFunction() 175 CastChannelAsyncApiFunction::CastChannelAsyncApiFunction()
176 : manager_(NULL), error_(cast_channel::CHANNEL_ERROR_NONE) { } 176 : manager_(NULL), is_channel_error_(false) {
177 }
177 178
178 CastChannelAsyncApiFunction::~CastChannelAsyncApiFunction() { } 179 CastChannelAsyncApiFunction::~CastChannelAsyncApiFunction() { }
179 180
180 bool CastChannelAsyncApiFunction::PrePrepare() { 181 bool CastChannelAsyncApiFunction::PrePrepare() {
181 manager_ = ApiResourceManager<CastSocket>::Get(browser_context()); 182 manager_ = ApiResourceManager<CastSocket>::Get(browser_context());
182 return true; 183 return true;
183 } 184 }
184 185
185 bool CastChannelAsyncApiFunction::Respond() { 186 bool CastChannelAsyncApiFunction::Respond() {
186 return error_ == cast_channel::CHANNEL_ERROR_NONE; 187 return !is_channel_error_ && GetError().empty();
187 } 188 }
188 189
189 CastSocket* CastChannelAsyncApiFunction::GetSocketOrCompleteWithError( 190 CastSocket* CastChannelAsyncApiFunction::GetSocketOrCompleteWithError(
190 int channel_id) { 191 int channel_id) {
191 CastSocket* socket = GetSocket(channel_id); 192 CastSocket* socket = GetSocket(channel_id);
192 if (!socket) { 193 if (!socket) {
193 SetResultFromError(channel_id, 194 SetResultFromError(channel_id,
194 cast_channel::CHANNEL_ERROR_INVALID_CHANNEL_ID); 195 cast_channel::CHANNEL_ERROR_INVALID_CHANNEL_ID);
195 AsyncWorkCompleted(); 196 AsyncWorkCompleted();
196 } 197 }
(...skipping 27 matching lines...) Expand all
224 ChannelError error) { 225 ChannelError error) {
225 ChannelInfo channel_info; 226 ChannelInfo channel_info;
226 channel_info.channel_id = channel_id; 227 channel_info.channel_id = channel_id;
227 channel_info.url = ""; 228 channel_info.url = "";
228 channel_info.ready_state = cast_channel::READY_STATE_CLOSED; 229 channel_info.ready_state = cast_channel::READY_STATE_CLOSED;
229 channel_info.error_state = error; 230 channel_info.error_state = error;
230 channel_info.connect_info.ip_address = ""; 231 channel_info.connect_info.ip_address = "";
231 channel_info.connect_info.port = 0; 232 channel_info.connect_info.port = 0;
232 channel_info.connect_info.auth = cast_channel::CHANNEL_AUTH_TYPE_SSL; 233 channel_info.connect_info.auth = cast_channel::CHANNEL_AUTH_TYPE_SSL;
233 SetResultFromChannelInfo(channel_info); 234 SetResultFromChannelInfo(channel_info);
234 error_ = error; 235 is_channel_error_ = true;
mark a. foltz 2014/11/01 19:29:39 It might be a good idea to set an error message si
vadimgo 2014/11/03 21:22:45 Done. Also uncovered an issue with my changes in S
235 } 236 }
236 237
237 CastSocket* CastChannelAsyncApiFunction::GetSocket(int channel_id) { 238 CastSocket* CastChannelAsyncApiFunction::GetSocket(int channel_id) {
238 DCHECK_CURRENTLY_ON(BrowserThread::IO); 239 DCHECK_CURRENTLY_ON(BrowserThread::IO);
239 DCHECK(manager_); 240 DCHECK(manager_);
240 return manager_->Get(extension_->id(), channel_id); 241 return manager_->Get(extension_->id(), channel_id);
241 } 242 }
242 243
243 void CastChannelAsyncApiFunction::SetResultFromChannelInfo( 244 void CastChannelAsyncApiFunction::SetResultFromChannelInfo(
244 const ChannelInfo& channel_info) { 245 const ChannelInfo& channel_info) {
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 std::string& signature = params_->signature; 529 std::string& signature = params_->signature;
529 if (signature.empty() || keys.empty() || 530 if (signature.empty() || keys.empty() ||
530 !cast_channel::SetTrustedCertificateAuthorities(keys, signature)) { 531 !cast_channel::SetTrustedCertificateAuthorities(keys, signature)) {
531 SetError("Unable to set authority keys."); 532 SetError("Unable to set authority keys.");
532 } 533 }
533 534
534 AsyncWorkCompleted(); 535 AsyncWorkCompleted();
535 } 536 }
536 537
537 } // namespace extensions 538 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/api/cast_channel/cast_channel_api.h ('k') | extensions/browser/api/cast_channel/cast_channel_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698