| OLD | NEW |
| 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 "components/devtools_service/devtools_service_delegate.h" | 5 #include "components/devtools_service/devtools_service_delegate.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "components/devtools_service/devtools_registry_impl.h" | 10 #include "components/devtools_service/devtools_registry_impl.h" |
| 11 #include "components/devtools_service/devtools_service.h" | 11 #include "components/devtools_service/devtools_service.h" |
| 12 #include "mojo/common/url_type_converters.h" | 12 #include "mojo/common/url_type_converters.h" |
| 13 #include "mojo/shell/public/cpp/application_connection.h" | 13 #include "mojo/shell/public/cpp/connection.h" |
| 14 #include "mojo/shell/public/cpp/shell.h" | 14 #include "mojo/shell/public/cpp/shell.h" |
| 15 #include "url/gurl.h" | 15 #include "url/gurl.h" |
| 16 | 16 |
| 17 namespace devtools_service { | 17 namespace devtools_service { |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 bool IsShell(const GURL& requestor_url) { | 21 bool IsShell(const GURL& requestor_url) { |
| 22 // TODO(yzshen): http://crbug.com/491656 "mojo://shell/" has to be used | 22 // TODO(yzshen): http://crbug.com/491656 "mojo://shell/" has to be used |
| 23 // instead of "mojo:shell" because "mojo" is not treated as a standard scheme. | 23 // instead of "mojo:shell" because "mojo" is not treated as a standard scheme. |
| 24 return requestor_url == GURL("mojo://shell/"); | 24 return requestor_url == GURL("mojo://shell/"); |
| 25 } | 25 } |
| 26 | 26 |
| 27 } // namespace | 27 } // namespace |
| 28 | 28 |
| 29 DevToolsServiceDelegate::DevToolsServiceDelegate() { | 29 DevToolsServiceDelegate::DevToolsServiceDelegate() { |
| 30 } | 30 } |
| 31 | 31 |
| 32 DevToolsServiceDelegate::~DevToolsServiceDelegate() { | 32 DevToolsServiceDelegate::~DevToolsServiceDelegate() { |
| 33 } | 33 } |
| 34 | 34 |
| 35 void DevToolsServiceDelegate::Initialize(mojo::Shell* shell, | 35 void DevToolsServiceDelegate::Initialize(mojo::Shell* shell, |
| 36 const std::string& url, | 36 const std::string& url, |
| 37 uint32_t id) { | 37 uint32_t id) { |
| 38 service_.reset(new DevToolsService(shell)); | 38 service_.reset(new DevToolsService(shell)); |
| 39 } | 39 } |
| 40 | 40 |
| 41 bool DevToolsServiceDelegate::AcceptConnection( | 41 bool DevToolsServiceDelegate::AcceptConnection(mojo::Connection* connection) { |
| 42 mojo::ApplicationConnection* connection) { | |
| 43 connection->AddService<DevToolsRegistry>(this); | 42 connection->AddService<DevToolsRegistry>(this); |
| 44 | 43 |
| 45 // DevToolsCoordinator is a privileged interface and only allowed for the | 44 // DevToolsCoordinator is a privileged interface and only allowed for the |
| 46 // shell. | 45 // shell. |
| 47 if (IsShell(GURL(connection->GetRemoteApplicationURL()))) | 46 if (IsShell(GURL(connection->GetRemoteApplicationURL()))) |
| 48 connection->AddService<DevToolsCoordinator>(this); | 47 connection->AddService<DevToolsCoordinator>(this); |
| 49 return true; | 48 return true; |
| 50 } | 49 } |
| 51 | 50 |
| 52 void DevToolsServiceDelegate::Quit() { | 51 void DevToolsServiceDelegate::Quit() { |
| 53 service_.reset(); | 52 service_.reset(); |
| 54 } | 53 } |
| 55 | 54 |
| 56 void DevToolsServiceDelegate::Create( | 55 void DevToolsServiceDelegate::Create( |
| 57 mojo::ApplicationConnection* connection, | 56 mojo::Connection* connection, |
| 58 mojo::InterfaceRequest<DevToolsRegistry> request) { | 57 mojo::InterfaceRequest<DevToolsRegistry> request) { |
| 59 service_->registry()->BindToRegistryRequest(std::move(request)); | 58 service_->registry()->BindToRegistryRequest(std::move(request)); |
| 60 } | 59 } |
| 61 | 60 |
| 62 void DevToolsServiceDelegate::Create( | 61 void DevToolsServiceDelegate::Create( |
| 63 mojo::ApplicationConnection* connection, | 62 mojo::Connection* connection, |
| 64 mojo::InterfaceRequest<DevToolsCoordinator> request) { | 63 mojo::InterfaceRequest<DevToolsCoordinator> request) { |
| 65 service_->BindToCoordinatorRequest(std::move(request)); | 64 service_->BindToCoordinatorRequest(std::move(request)); |
| 66 } | 65 } |
| 67 | 66 |
| 68 } // namespace devtools_service | 67 } // namespace devtools_service |
| OLD | NEW |