| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/extensions/api/cast_channel/cast_channel_api.h" | 5 #include "chrome/browser/extensions/api/cast_channel/cast_channel_api.h" |
| 6 | 6 |
| 7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 11 #include "chrome/browser/extensions/api/cast_channel/cast_socket.h" | 11 #include "chrome/browser/extensions/api/cast_channel/cast_socket.h" |
| 12 #include "chrome/browser/net/chrome_net_log.h" | 12 #include "chrome/browser/net/chrome_net_log.h" |
| 13 #include "chrome/browser/profiles/profile.h" | |
| 14 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
| 15 #include "extensions/browser/event_router.h" | 14 #include "extensions/browser/event_router.h" |
| 16 #include "extensions/browser/extension_system.h" | 15 #include "extensions/browser/extension_system.h" |
| 17 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
| 18 #include "url/gurl.h" | 17 #include "url/gurl.h" |
| 19 | 18 |
| 20 namespace extensions { | 19 namespace extensions { |
| 21 | 20 |
| 22 namespace Close = cast_channel::Close; | 21 namespace Close = cast_channel::Close; |
| 23 namespace OnError = cast_channel::OnError; | 22 namespace OnError = cast_channel::OnError; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 } | 105 } |
| 107 | 106 |
| 108 CastChannelAPI::~CastChannelAPI() {} | 107 CastChannelAPI::~CastChannelAPI() {} |
| 109 | 108 |
| 110 CastChannelAsyncApiFunction::CastChannelAsyncApiFunction() | 109 CastChannelAsyncApiFunction::CastChannelAsyncApiFunction() |
| 111 : manager_(NULL), error_(cast_channel::CHANNEL_ERROR_NONE) { } | 110 : manager_(NULL), error_(cast_channel::CHANNEL_ERROR_NONE) { } |
| 112 | 111 |
| 113 CastChannelAsyncApiFunction::~CastChannelAsyncApiFunction() { } | 112 CastChannelAsyncApiFunction::~CastChannelAsyncApiFunction() { } |
| 114 | 113 |
| 115 bool CastChannelAsyncApiFunction::PrePrepare() { | 114 bool CastChannelAsyncApiFunction::PrePrepare() { |
| 116 manager_ = ApiResourceManager<CastSocket>::Get(GetProfile()); | 115 manager_ = ApiResourceManager<CastSocket>::Get(browser_context()); |
| 117 return true; | 116 return true; |
| 118 } | 117 } |
| 119 | 118 |
| 120 bool CastChannelAsyncApiFunction::Respond() { | 119 bool CastChannelAsyncApiFunction::Respond() { |
| 121 return error_ != cast_channel::CHANNEL_ERROR_NONE; | 120 return error_ != cast_channel::CHANNEL_ERROR_NONE; |
| 122 } | 121 } |
| 123 | 122 |
| 124 CastSocket* CastChannelAsyncApiFunction::GetSocketOrCompleteWithError( | 123 CastSocket* CastChannelAsyncApiFunction::GetSocketOrCompleteWithError( |
| 125 int channel_id) { | 124 int channel_id) { |
| 126 CastSocket* socket = GetSocket(channel_id); | 125 CastSocket* socket = GetSocket(channel_id); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 175 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 177 SetResult(channel_info.ToValue().release()); | 176 SetResult(channel_info.ToValue().release()); |
| 178 } | 177 } |
| 179 | 178 |
| 180 CastChannelOpenFunction::CastChannelOpenFunction() | 179 CastChannelOpenFunction::CastChannelOpenFunction() |
| 181 : new_channel_id_(0) { } | 180 : new_channel_id_(0) { } |
| 182 | 181 |
| 183 CastChannelOpenFunction::~CastChannelOpenFunction() { } | 182 CastChannelOpenFunction::~CastChannelOpenFunction() { } |
| 184 | 183 |
| 185 bool CastChannelOpenFunction::PrePrepare() { | 184 bool CastChannelOpenFunction::PrePrepare() { |
| 186 api_ = CastChannelAPI::Get(GetProfile()); | 185 api_ = CastChannelAPI::Get(browser_context()); |
| 187 return CastChannelAsyncApiFunction::PrePrepare(); | 186 return CastChannelAsyncApiFunction::PrePrepare(); |
| 188 } | 187 } |
| 189 | 188 |
| 190 bool CastChannelOpenFunction::Prepare() { | 189 bool CastChannelOpenFunction::Prepare() { |
| 191 params_ = Open::Params::Create(*args_); | 190 params_ = Open::Params::Create(*args_); |
| 192 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 191 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 193 return true; | 192 return true; |
| 194 } | 193 } |
| 195 | 194 |
| 196 void CastChannelOpenFunction::AsyncWorkStart() { | 195 void CastChannelOpenFunction::AsyncWorkStart() { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 SetResultFromError(cast_channel::CHANNEL_ERROR_SOCKET_ERROR); | 259 SetResultFromError(cast_channel::CHANNEL_ERROR_SOCKET_ERROR); |
| 261 } else { | 260 } else { |
| 262 int channel_id = params_->channel.channel_id; | 261 int channel_id = params_->channel.channel_id; |
| 263 SetResultFromSocket(channel_id); | 262 SetResultFromSocket(channel_id); |
| 264 RemoveSocket(channel_id); | 263 RemoveSocket(channel_id); |
| 265 } | 264 } |
| 266 AsyncWorkCompleted(); | 265 AsyncWorkCompleted(); |
| 267 } | 266 } |
| 268 | 267 |
| 269 } // namespace extensions | 268 } // namespace extensions |
| OLD | NEW |