Only grant permissions to new extensions from sync if they have the expected version
[chromium-blink-merge.git] / chrome / browser / devtools / device / webrtc / webrtc_device_provider.cc
blob127f092f5bdb7bc05c887e343af7d3ec2881ad1d
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 "base/location.h"
8 #include "base/single_thread_task_runner.h"
9 #include "base/thread_task_runner_handle.h"
10 #include "chrome/browser/devtools/device/webrtc/devtools_bridge_client.h"
11 #include "chrome/common/url_constants.h"
12 #include "content/public/browser/web_ui.h"
13 #include "content/public/browser/web_ui_data_source.h"
14 #include "grit/webrtc_device_provider_resources_map.h"
15 #include "net/base/net_errors.h"
16 #include "net/socket/stream_socket.h"
18 using content::BrowserThread;
19 using content::WebUIDataSource;
21 // WebRTCDeviceProvider::WebUI -------------------------------------------------
23 WebRTCDeviceProvider::WebUI::WebUI(content::WebUI* web_ui)
24 : content::WebUIController(web_ui) {
25 Profile* profile = Profile::FromWebUI(web_ui);
27 WebUIDataSource* source = WebUIDataSource::Create(
28 chrome::kChromeUIWebRTCDeviceProviderHost);
30 for (size_t i = 0; i < kWebrtcDeviceProviderResourcesSize; i++) {
31 source->AddResourcePath(kWebrtcDeviceProviderResources[i].name,
32 kWebrtcDeviceProviderResources[i].value);
35 auto client =
36 DevToolsBridgeClient::FromWebContents(web_ui->GetWebContents());
37 if (client)
38 client->RegisterMessageHandlers(web_ui);
40 WebUIDataSource::Add(profile, source);
43 WebRTCDeviceProvider::WebUI::~WebUI() {
46 // WebRTCDeviceProvider --------------------------------------------------------
48 WebRTCDeviceProvider::WebRTCDeviceProvider(
49 Profile* profile,
50 SigninManagerBase* signin_manager,
51 ProfileOAuth2TokenService* token_service)
52 : client_(DevToolsBridgeClient::Create(
53 profile, signin_manager, token_service)) {
56 WebRTCDeviceProvider::~WebRTCDeviceProvider() {
57 BrowserThread::PostTask(
58 BrowserThread::UI,
59 FROM_HERE,
60 base::Bind(&DevToolsBridgeClient::DeleteSelf, client_));
63 void WebRTCDeviceProvider::QueryDevices(const SerialsCallback& callback) {
64 BrowserThread::PostTaskAndReplyWithResult(
65 BrowserThread::UI,
66 FROM_HERE,
67 base::Bind(&DevToolsBridgeClient::GetDevices, client_),
68 callback);
71 void WebRTCDeviceProvider::QueryDeviceInfo(const std::string& serial,
72 const DeviceInfoCallback& callback) {
73 BrowserThread::PostTaskAndReplyWithResult(
74 BrowserThread::UI,
75 FROM_HERE,
76 base::Bind(&DevToolsBridgeClient::GetDeviceInfo, client_, serial),
77 callback);
80 void WebRTCDeviceProvider::OpenSocket(const std::string& serial,
81 const std::string& socket_name,
82 const SocketCallback& callback) {
83 BrowserThread::PostTask(
84 BrowserThread::UI,
85 FROM_HERE,
86 base::Bind(&DevToolsBridgeClient::StartSessionIfNeeded,
87 client_, socket_name));
88 // TODO(serya): Implement
89 scoped_ptr<net::StreamSocket> socket;
90 base::ThreadTaskRunnerHandle::Get()->PostTask(
91 FROM_HERE, base::Bind(callback, net::ERR_FAILED, base::Passed(&socket)));