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
3 // found in the LICENSE file.
5 #include "chrome/browser/devtools/device/webrtc/webrtc_device_provider.h"
7 #include "chrome/browser/devtools/device/webrtc/devtools_bridge_client.h"
8 #include "chrome/common/url_constants.h"
9 #include "content/public/browser/web_ui.h"
10 #include "content/public/browser/web_ui_data_source.h"
11 #include "grit/webrtc_device_provider_resources_map.h"
12 #include "net/base/net_errors.h"
13 #include "net/socket/stream_socket.h"
15 using content::BrowserThread
;
16 using content::WebUIDataSource
;
18 // WebRTCDeviceProvider::WebUI -------------------------------------------------
20 WebRTCDeviceProvider::WebUI::WebUI(content::WebUI
* web_ui
)
21 : content::WebUIController(web_ui
) {
22 Profile
* profile
= Profile::FromWebUI(web_ui
);
24 WebUIDataSource
* source
= WebUIDataSource::Create(
25 chrome::kChromeUIWebRTCDeviceProviderHost
);
27 for (size_t i
= 0; i
< kWebrtcDeviceProviderResourcesSize
; i
++) {
28 source
->AddResourcePath(kWebrtcDeviceProviderResources
[i
].name
,
29 kWebrtcDeviceProviderResources
[i
].value
);
33 DevToolsBridgeClient::FromWebContents(web_ui
->GetWebContents());
35 client
->RegisterMessageHandlers(web_ui
);
37 WebUIDataSource::Add(profile
, source
);
40 WebRTCDeviceProvider::WebUI::~WebUI() {
43 // WebRTCDeviceProvider --------------------------------------------------------
45 WebRTCDeviceProvider::WebRTCDeviceProvider(
47 SigninManagerBase
* signin_manager
,
48 ProfileOAuth2TokenService
* token_service
)
49 : client_(DevToolsBridgeClient::Create(
50 profile
, signin_manager
, token_service
)) {
53 WebRTCDeviceProvider::~WebRTCDeviceProvider() {
54 BrowserThread::PostTask(
57 base::Bind(&DevToolsBridgeClient::DeleteSelf
, client_
));
60 void WebRTCDeviceProvider::QueryDevices(const SerialsCallback
& callback
) {
61 BrowserThread::PostTaskAndReplyWithResult(
64 base::Bind(&DevToolsBridgeClient::GetDevices
, client_
),
68 void WebRTCDeviceProvider::QueryDeviceInfo(const std::string
& serial
,
69 const DeviceInfoCallback
& callback
) {
70 BrowserThread::PostTaskAndReplyWithResult(
73 base::Bind(&DevToolsBridgeClient::GetDeviceInfo
, client_
, serial
),
77 void WebRTCDeviceProvider::OpenSocket(const std::string
& serial
,
78 const std::string
& socket_name
,
79 const SocketCallback
& callback
) {
80 BrowserThread::PostTask(
83 base::Bind(&DevToolsBridgeClient::StartSessionIfNeeded
,
84 client_
, socket_name
));
85 // TODO(serya): Implement
86 scoped_ptr
<net::StreamSocket
> socket
;
87 base::MessageLoop::current()->PostTask(
88 FROM_HERE
, base::Bind(callback
, net::ERR_FAILED
, base::Passed(&socket
)));