16a460fede07b768210d256191cd126013a0df273Christopher Wiley// Copyright 2015 The Android Open Source Project
26a460fede07b768210d256191cd126013a0df273Christopher Wiley//
36a460fede07b768210d256191cd126013a0df273Christopher Wiley// Licensed under the Apache License, Version 2.0 (the "License");
46a460fede07b768210d256191cd126013a0df273Christopher Wiley// you may not use this file except in compliance with the License.
56a460fede07b768210d256191cd126013a0df273Christopher Wiley// You may obtain a copy of the License at
66a460fede07b768210d256191cd126013a0df273Christopher Wiley//
76a460fede07b768210d256191cd126013a0df273Christopher Wiley//      http://www.apache.org/licenses/LICENSE-2.0
86a460fede07b768210d256191cd126013a0df273Christopher Wiley//
96a460fede07b768210d256191cd126013a0df273Christopher Wiley// Unless required by applicable law or agreed to in writing, software
106a460fede07b768210d256191cd126013a0df273Christopher Wiley// distributed under the License is distributed on an "AS IS" BASIS,
116a460fede07b768210d256191cd126013a0df273Christopher Wiley// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
126a460fede07b768210d256191cd126013a0df273Christopher Wiley// See the License for the specific language governing permissions and
136a460fede07b768210d256191cd126013a0df273Christopher Wiley// limitations under the License.
146a460fede07b768210d256191cd126013a0df273Christopher Wiley
156a460fede07b768210d256191cd126013a0df273Christopher Wiley#include <libwebserv/dbus_server.h>
166a460fede07b768210d256191cd126013a0df273Christopher Wiley
176a460fede07b768210d256191cd126013a0df273Christopher Wiley#include <tuple>
186a460fede07b768210d256191cd126013a0df273Christopher Wiley#include <vector>
196a460fede07b768210d256191cd126013a0df273Christopher Wiley
203320726e9ccf678a9accdd6994e28f0cb8454eabChristopher Wiley#include <libwebserv/dbus_protocol_handler.h>
216a460fede07b768210d256191cd126013a0df273Christopher Wiley#include <libwebserv/request_impl.h>
226a460fede07b768210d256191cd126013a0df273Christopher Wiley
236a460fede07b768210d256191cd126013a0df273Christopher Wiley#include "dbus_bindings/org.chromium.WebServer.RequestHandler.h"
246a460fede07b768210d256191cd126013a0df273Christopher Wiley#include "webservd/dbus-proxies.h"
256a460fede07b768210d256191cd126013a0df273Christopher Wiley
266a460fede07b768210d256191cd126013a0df273Christopher Wileynamespace libwebserv {
276a460fede07b768210d256191cd126013a0df273Christopher Wiley
286a460fede07b768210d256191cd126013a0df273Christopher Wileyclass DBusServer::RequestHandler final
296a460fede07b768210d256191cd126013a0df273Christopher Wiley    : public org::chromium::WebServer::RequestHandlerInterface {
306a460fede07b768210d256191cd126013a0df273Christopher Wiley public:
316a460fede07b768210d256191cd126013a0df273Christopher Wiley  explicit RequestHandler(DBusServer* server) : server_{server} {}
326a460fede07b768210d256191cd126013a0df273Christopher Wiley  bool ProcessRequest(
336a460fede07b768210d256191cd126013a0df273Christopher Wiley      brillo::ErrorPtr* error,
346a460fede07b768210d256191cd126013a0df273Christopher Wiley      const std::tuple<std::string, std::string, std::string, std::string,
356a460fede07b768210d256191cd126013a0df273Christopher Wiley                       std::string>& in_request_info,
366a460fede07b768210d256191cd126013a0df273Christopher Wiley      const std::vector<std::tuple<std::string, std::string>>& in_headers,
376a460fede07b768210d256191cd126013a0df273Christopher Wiley      const std::vector<std::tuple<bool, std::string, std::string>>& in_params,
386a460fede07b768210d256191cd126013a0df273Christopher Wiley      const std::vector<std::tuple<int32_t, std::string, std::string,
396a460fede07b768210d256191cd126013a0df273Christopher Wiley                                   std::string, std::string>>& in_files,
406a460fede07b768210d256191cd126013a0df273Christopher Wiley      const dbus::FileDescriptor& in_body) override;
416a460fede07b768210d256191cd126013a0df273Christopher Wiley
426a460fede07b768210d256191cd126013a0df273Christopher Wiley private:
436a460fede07b768210d256191cd126013a0df273Christopher Wiley  DBusServer* server_{nullptr};
446a460fede07b768210d256191cd126013a0df273Christopher Wiley  DISALLOW_COPY_AND_ASSIGN(RequestHandler);
456a460fede07b768210d256191cd126013a0df273Christopher Wiley};
466a460fede07b768210d256191cd126013a0df273Christopher Wiley
476a460fede07b768210d256191cd126013a0df273Christopher Wileybool DBusServer::RequestHandler::ProcessRequest(
486a460fede07b768210d256191cd126013a0df273Christopher Wiley    brillo::ErrorPtr* error,
496a460fede07b768210d256191cd126013a0df273Christopher Wiley    const std::tuple<std::string, std::string, std::string, std::string,
506a460fede07b768210d256191cd126013a0df273Christopher Wiley                     std::string>& in_request_info,
516a460fede07b768210d256191cd126013a0df273Christopher Wiley    const std::vector<std::tuple<std::string, std::string>>& in_headers,
526a460fede07b768210d256191cd126013a0df273Christopher Wiley    const std::vector<std::tuple<bool, std::string, std::string>>& in_params,
536a460fede07b768210d256191cd126013a0df273Christopher Wiley    const std::vector<std::tuple<int32_t, std::string, std::string, std::string,
546a460fede07b768210d256191cd126013a0df273Christopher Wiley                                 std::string>>& in_files,
556a460fede07b768210d256191cd126013a0df273Christopher Wiley    const dbus::FileDescriptor& in_body) {
566a460fede07b768210d256191cd126013a0df273Christopher Wiley  std::string protocol_handler_id = std::get<0>(in_request_info);
576a460fede07b768210d256191cd126013a0df273Christopher Wiley  std::string request_handler_id = std::get<1>(in_request_info);
586a460fede07b768210d256191cd126013a0df273Christopher Wiley  std::string request_id = std::get<2>(in_request_info);
596a460fede07b768210d256191cd126013a0df273Christopher Wiley  std::string url = std::get<3>(in_request_info);
606a460fede07b768210d256191cd126013a0df273Christopher Wiley  std::string method = std::get<4>(in_request_info);
613320726e9ccf678a9accdd6994e28f0cb8454eabChristopher Wiley  DBusProtocolHandler* protocol_handler =
626a460fede07b768210d256191cd126013a0df273Christopher Wiley      server_->GetProtocolHandlerByID(protocol_handler_id);
636a460fede07b768210d256191cd126013a0df273Christopher Wiley  if (!protocol_handler) {
646a460fede07b768210d256191cd126013a0df273Christopher Wiley    brillo::Error::AddToPrintf(error, FROM_HERE,
656a460fede07b768210d256191cd126013a0df273Christopher Wiley                               brillo::errors::dbus::kDomain,
666a460fede07b768210d256191cd126013a0df273Christopher Wiley                               DBUS_ERROR_FAILED,
676a460fede07b768210d256191cd126013a0df273Christopher Wiley                               "Unknown protocol handler '%s'",
686a460fede07b768210d256191cd126013a0df273Christopher Wiley                               protocol_handler_id.c_str());
696a460fede07b768210d256191cd126013a0df273Christopher Wiley    return false;
706a460fede07b768210d256191cd126013a0df273Christopher Wiley  }
716a460fede07b768210d256191cd126013a0df273Christopher Wiley  std::unique_ptr<RequestImpl> request{
726a460fede07b768210d256191cd126013a0df273Christopher Wiley    new RequestImpl{protocol_handler, url, method}};
736a460fede07b768210d256191cd126013a0df273Christopher Wiley  // Convert request data into format required by the Request object.
746a460fede07b768210d256191cd126013a0df273Christopher Wiley  for (const auto& tuple : in_params) {
756a460fede07b768210d256191cd126013a0df273Christopher Wiley    if (std::get<0>(tuple))
766a460fede07b768210d256191cd126013a0df273Christopher Wiley      request->post_data_.emplace(std::get<1>(tuple), std::get<2>(tuple));
776a460fede07b768210d256191cd126013a0df273Christopher Wiley    else
786a460fede07b768210d256191cd126013a0df273Christopher Wiley      request->get_data_.emplace(std::get<1>(tuple), std::get<2>(tuple));
796a460fede07b768210d256191cd126013a0df273Christopher Wiley  }
806a460fede07b768210d256191cd126013a0df273Christopher Wiley
816a460fede07b768210d256191cd126013a0df273Christopher Wiley  for (const auto& tuple : in_headers)
826a460fede07b768210d256191cd126013a0df273Christopher Wiley    request->headers_.emplace(std::get<0>(tuple), std::get<1>(tuple));
836a460fede07b768210d256191cd126013a0df273Christopher Wiley
846a460fede07b768210d256191cd126013a0df273Christopher Wiley  for (const auto& tuple : in_files) {
856a460fede07b768210d256191cd126013a0df273Christopher Wiley    request->file_info_.emplace(
866a460fede07b768210d256191cd126013a0df273Christopher Wiley        std::get<1>(tuple),  // field_name
876a460fede07b768210d256191cd126013a0df273Christopher Wiley        std::unique_ptr<FileInfo>{new FileInfo{
886a460fede07b768210d256191cd126013a0df273Christopher Wiley            protocol_handler,
896a460fede07b768210d256191cd126013a0df273Christopher Wiley            std::get<0>(tuple),     // file_id
906a460fede07b768210d256191cd126013a0df273Christopher Wiley            request_id,
916a460fede07b768210d256191cd126013a0df273Christopher Wiley            std::get<2>(tuple),     // file_name
926a460fede07b768210d256191cd126013a0df273Christopher Wiley            std::get<3>(tuple),     // content_type
936a460fede07b768210d256191cd126013a0df273Christopher Wiley            std::get<4>(tuple)}});  // transfer_encoding
946a460fede07b768210d256191cd126013a0df273Christopher Wiley  }
956a460fede07b768210d256191cd126013a0df273Christopher Wiley
966a460fede07b768210d256191cd126013a0df273Christopher Wiley  request->raw_data_fd_ = base::File(dup(in_body.value()));
976a460fede07b768210d256191cd126013a0df273Christopher Wiley  CHECK(request->raw_data_fd_.IsValid());
986a460fede07b768210d256191cd126013a0df273Christopher Wiley
996a460fede07b768210d256191cd126013a0df273Christopher Wiley  return protocol_handler->ProcessRequest(protocol_handler_id,
1006a460fede07b768210d256191cd126013a0df273Christopher Wiley                                          request_handler_id,
1016a460fede07b768210d256191cd126013a0df273Christopher Wiley                                          request_id,
1026a460fede07b768210d256191cd126013a0df273Christopher Wiley                                          std::move(request),
1036a460fede07b768210d256191cd126013a0df273Christopher Wiley                                          error);
1046a460fede07b768210d256191cd126013a0df273Christopher Wiley}
1056a460fede07b768210d256191cd126013a0df273Christopher Wiley
1066a460fede07b768210d256191cd126013a0df273Christopher WileyDBusServer::DBusServer()
1076a460fede07b768210d256191cd126013a0df273Christopher Wiley    : request_handler_{new RequestHandler{this}},
1086a460fede07b768210d256191cd126013a0df273Christopher Wiley      dbus_adaptor_{new org::chromium::WebServer::RequestHandlerAdaptor{
1096a460fede07b768210d256191cd126013a0df273Christopher Wiley          request_handler_.get()}} {}
1106a460fede07b768210d256191cd126013a0df273Christopher Wiley
1116a460fede07b768210d256191cd126013a0df273Christopher Wileyvoid DBusServer::Connect(
1126a460fede07b768210d256191cd126013a0df273Christopher Wiley    const scoped_refptr<dbus::Bus>& bus,
1136a460fede07b768210d256191cd126013a0df273Christopher Wiley    const std::string& service_name,
1146a460fede07b768210d256191cd126013a0df273Christopher Wiley    const brillo::dbus_utils::AsyncEventSequencer::CompletionAction& cb,
1156a460fede07b768210d256191cd126013a0df273Christopher Wiley    const base::Closure& on_server_online,
1166a460fede07b768210d256191cd126013a0df273Christopher Wiley    const base::Closure& on_server_offline) {
1176a460fede07b768210d256191cd126013a0df273Christopher Wiley  service_name_ = service_name;
1186a460fede07b768210d256191cd126013a0df273Christopher Wiley  dbus_object_.reset(new brillo::dbus_utils::DBusObject{
1196a460fede07b768210d256191cd126013a0df273Christopher Wiley      nullptr, bus, dbus_adaptor_->GetObjectPath()});
1206a460fede07b768210d256191cd126013a0df273Christopher Wiley  dbus_adaptor_->RegisterWithDBusObject(dbus_object_.get());
1216a460fede07b768210d256191cd126013a0df273Christopher Wiley  dbus_object_->RegisterAsync(cb);
1226a460fede07b768210d256191cd126013a0df273Christopher Wiley  on_server_online_ = on_server_online;
1236a460fede07b768210d256191cd126013a0df273Christopher Wiley  on_server_offline_ = on_server_offline;
1246a460fede07b768210d256191cd126013a0df273Christopher Wiley  object_manager_.reset(new org::chromium::WebServer::ObjectManagerProxy{bus});
1256a460fede07b768210d256191cd126013a0df273Christopher Wiley  object_manager_->SetServerAddedCallback(
1266a460fede07b768210d256191cd126013a0df273Christopher Wiley      base::Bind(&DBusServer::Online, base::Unretained(this)));
1276a460fede07b768210d256191cd126013a0df273Christopher Wiley  object_manager_->SetServerRemovedCallback(
1286a460fede07b768210d256191cd126013a0df273Christopher Wiley      base::Bind(&DBusServer::Offline, base::Unretained(this)));
1296a460fede07b768210d256191cd126013a0df273Christopher Wiley  object_manager_->SetProtocolHandlerAddedCallback(
1306a460fede07b768210d256191cd126013a0df273Christopher Wiley      base::Bind(&DBusServer::ProtocolHandlerAdded, base::Unretained(this)));
1316a460fede07b768210d256191cd126013a0df273Christopher Wiley  object_manager_->SetProtocolHandlerRemovedCallback(
1326a460fede07b768210d256191cd126013a0df273Christopher Wiley      base::Bind(&DBusServer::ProtocolHandlerRemoved, base::Unretained(this)));
1336a460fede07b768210d256191cd126013a0df273Christopher Wiley}
1346a460fede07b768210d256191cd126013a0df273Christopher Wiley
1356a460fede07b768210d256191cd126013a0df273Christopher Wileyvoid DBusServer::Online(
1366a460fede07b768210d256191cd126013a0df273Christopher Wiley    org::chromium::WebServer::ServerProxyInterface* server) {
1376a460fede07b768210d256191cd126013a0df273Christopher Wiley  VLOG(1) << "Web server is on-line.";
1386a460fede07b768210d256191cd126013a0df273Christopher Wiley  proxy_ = server;
1396a460fede07b768210d256191cd126013a0df273Christopher Wiley  if (!on_server_online_.is_null())
1406a460fede07b768210d256191cd126013a0df273Christopher Wiley    on_server_online_.Run();
1416a460fede07b768210d256191cd126013a0df273Christopher Wiley}
1426a460fede07b768210d256191cd126013a0df273Christopher Wiley
1436a460fede07b768210d256191cd126013a0df273Christopher Wileybool DBusServer::IsConnected() const {
1446a460fede07b768210d256191cd126013a0df273Christopher Wiley  return proxy_ != nullptr;
1456a460fede07b768210d256191cd126013a0df273Christopher Wiley}
1466a460fede07b768210d256191cd126013a0df273Christopher Wiley
147016df0ac2e778e9ea9642415007fbbfe23cb152dChristopher Wileyvoid DBusServer::Offline(const dbus::ObjectPath& /* object_path */) {
1486a460fede07b768210d256191cd126013a0df273Christopher Wiley  if (!on_server_offline_.is_null())
1496a460fede07b768210d256191cd126013a0df273Christopher Wiley    on_server_offline_.Run();
1506a460fede07b768210d256191cd126013a0df273Christopher Wiley  proxy_ = nullptr;
1516a460fede07b768210d256191cd126013a0df273Christopher Wiley  VLOG(1) << "Web server is off-line.";
1526a460fede07b768210d256191cd126013a0df273Christopher Wiley}
1536a460fede07b768210d256191cd126013a0df273Christopher Wiley
1546a460fede07b768210d256191cd126013a0df273Christopher Wileyvoid DBusServer::ProtocolHandlerAdded(
1556a460fede07b768210d256191cd126013a0df273Christopher Wiley    org::chromium::WebServer::ProtocolHandlerProxyInterface* handler) {
1566a460fede07b768210d256191cd126013a0df273Christopher Wiley  VLOG(1) << "Server-side protocol handler with ID '" << handler->id()
1576a460fede07b768210d256191cd126013a0df273Christopher Wiley          << "' is on-line (" << handler->name() << ")";
1586a460fede07b768210d256191cd126013a0df273Christopher Wiley
1596a460fede07b768210d256191cd126013a0df273Christopher Wiley  protocol_handler_id_map_.emplace(handler->GetObjectPath(), handler->id());
1603320726e9ccf678a9accdd6994e28f0cb8454eabChristopher Wiley  DBusProtocolHandler* registered_handler =
1613320726e9ccf678a9accdd6994e28f0cb8454eabChristopher Wiley      GetProtocolHandlerImpl(handler->name());
1626a460fede07b768210d256191cd126013a0df273Christopher Wiley  if (registered_handler) {
1636a460fede07b768210d256191cd126013a0df273Christopher Wiley    protocol_handlers_ids_.emplace(handler->id(), registered_handler);
1646a460fede07b768210d256191cd126013a0df273Christopher Wiley    registered_handler->Connect(handler);
1656a460fede07b768210d256191cd126013a0df273Christopher Wiley    if (!on_protocol_handler_connected_.is_null())
1666a460fede07b768210d256191cd126013a0df273Christopher Wiley      on_protocol_handler_connected_.Run(registered_handler);
1676a460fede07b768210d256191cd126013a0df273Christopher Wiley  }
1686a460fede07b768210d256191cd126013a0df273Christopher Wiley}
1696a460fede07b768210d256191cd126013a0df273Christopher Wiley
1706a460fede07b768210d256191cd126013a0df273Christopher Wileyvoid DBusServer::ProtocolHandlerRemoved(const dbus::ObjectPath& object_path) {
1716a460fede07b768210d256191cd126013a0df273Christopher Wiley  auto p = protocol_handler_id_map_.find(object_path);
1726a460fede07b768210d256191cd126013a0df273Christopher Wiley  if (p == protocol_handler_id_map_.end())
1736a460fede07b768210d256191cd126013a0df273Christopher Wiley    return;
1746a460fede07b768210d256191cd126013a0df273Christopher Wiley
1756a460fede07b768210d256191cd126013a0df273Christopher Wiley  VLOG(1) << "Server-side protocol handler with ID '" << p->second
1766a460fede07b768210d256191cd126013a0df273Christopher Wiley          << "' is off-line.";
1776a460fede07b768210d256191cd126013a0df273Christopher Wiley
1783320726e9ccf678a9accdd6994e28f0cb8454eabChristopher Wiley  DBusProtocolHandler* registered_handler = GetProtocolHandlerByID(p->second);
1796a460fede07b768210d256191cd126013a0df273Christopher Wiley  if (registered_handler) {
1806a460fede07b768210d256191cd126013a0df273Christopher Wiley    if (!on_protocol_handler_disconnected_.is_null())
1816a460fede07b768210d256191cd126013a0df273Christopher Wiley      on_protocol_handler_disconnected_.Run(registered_handler);
1826a460fede07b768210d256191cd126013a0df273Christopher Wiley    registered_handler->Disconnect(object_path);
1836a460fede07b768210d256191cd126013a0df273Christopher Wiley    protocol_handlers_ids_.erase(p->second);
1846a460fede07b768210d256191cd126013a0df273Christopher Wiley  }
1856a460fede07b768210d256191cd126013a0df273Christopher Wiley
1866a460fede07b768210d256191cd126013a0df273Christopher Wiley  protocol_handler_id_map_.erase(p);
1876a460fede07b768210d256191cd126013a0df273Christopher Wiley}
1886a460fede07b768210d256191cd126013a0df273Christopher Wiley
1896a460fede07b768210d256191cd126013a0df273Christopher WileyProtocolHandler* DBusServer::GetProtocolHandler(const std::string& name) {
1903320726e9ccf678a9accdd6994e28f0cb8454eabChristopher Wiley  return GetProtocolHandlerImpl(name);
1913320726e9ccf678a9accdd6994e28f0cb8454eabChristopher Wiley}
1923320726e9ccf678a9accdd6994e28f0cb8454eabChristopher Wiley
1933320726e9ccf678a9accdd6994e28f0cb8454eabChristopher WileyDBusProtocolHandler* DBusServer::GetProtocolHandlerImpl(
1943320726e9ccf678a9accdd6994e28f0cb8454eabChristopher Wiley    const std::string& name) {
1956a460fede07b768210d256191cd126013a0df273Christopher Wiley  auto p = protocol_handlers_names_.find(name);
1966a460fede07b768210d256191cd126013a0df273Christopher Wiley  if (p == protocol_handlers_names_.end()) {
1976a460fede07b768210d256191cd126013a0df273Christopher Wiley    VLOG(1) << "Creating a client-side instance of web server's protocol "
1986a460fede07b768210d256191cd126013a0df273Christopher Wiley            << "handler with name '" << name << "'";
1996a460fede07b768210d256191cd126013a0df273Christopher Wiley    p = protocol_handlers_names_.emplace(
2006a460fede07b768210d256191cd126013a0df273Christopher Wiley        name,
2013320726e9ccf678a9accdd6994e28f0cb8454eabChristopher Wiley        std::unique_ptr<DBusProtocolHandler>{
2023320726e9ccf678a9accdd6994e28f0cb8454eabChristopher Wiley            new DBusProtocolHandler{name, this}}).first;
2036a460fede07b768210d256191cd126013a0df273Christopher Wiley  }
2046a460fede07b768210d256191cd126013a0df273Christopher Wiley  return p->second.get();
2056a460fede07b768210d256191cd126013a0df273Christopher Wiley}
2066a460fede07b768210d256191cd126013a0df273Christopher Wiley
2076a460fede07b768210d256191cd126013a0df273Christopher WileyProtocolHandler* DBusServer::GetDefaultHttpHandler() {
2086a460fede07b768210d256191cd126013a0df273Christopher Wiley  return GetProtocolHandler(ProtocolHandler::kHttp);
2096a460fede07b768210d256191cd126013a0df273Christopher Wiley}
2106a460fede07b768210d256191cd126013a0df273Christopher Wiley
2116a460fede07b768210d256191cd126013a0df273Christopher WileyProtocolHandler* DBusServer::GetDefaultHttpsHandler() {
2126a460fede07b768210d256191cd126013a0df273Christopher Wiley  return GetProtocolHandler(ProtocolHandler::kHttps);
2136a460fede07b768210d256191cd126013a0df273Christopher Wiley}
2146a460fede07b768210d256191cd126013a0df273Christopher Wiley
2153320726e9ccf678a9accdd6994e28f0cb8454eabChristopher WileyDBusProtocolHandler* DBusServer::GetProtocolHandlerByID(
2163320726e9ccf678a9accdd6994e28f0cb8454eabChristopher Wiley    const std::string& id) const {
2176a460fede07b768210d256191cd126013a0df273Christopher Wiley  auto p = protocol_handlers_ids_.find(id);
2186a460fede07b768210d256191cd126013a0df273Christopher Wiley  if (p == protocol_handlers_ids_.end()) {
2196a460fede07b768210d256191cd126013a0df273Christopher Wiley    LOG(ERROR) << "Unable to locate protocol handler with ID '" << id << "'";
2206a460fede07b768210d256191cd126013a0df273Christopher Wiley    return nullptr;
2216a460fede07b768210d256191cd126013a0df273Christopher Wiley  }
2226a460fede07b768210d256191cd126013a0df273Christopher Wiley  return p->second;
2236a460fede07b768210d256191cd126013a0df273Christopher Wiley}
2246a460fede07b768210d256191cd126013a0df273Christopher Wiley
2256a460fede07b768210d256191cd126013a0df273Christopher Wileyvoid DBusServer::OnProtocolHandlerConnected(
2266a460fede07b768210d256191cd126013a0df273Christopher Wiley    const base::Callback<void(ProtocolHandler*)>& callback) {
2276a460fede07b768210d256191cd126013a0df273Christopher Wiley  on_protocol_handler_connected_ = callback;
2286a460fede07b768210d256191cd126013a0df273Christopher Wiley}
2296a460fede07b768210d256191cd126013a0df273Christopher Wiley
2306a460fede07b768210d256191cd126013a0df273Christopher Wileyvoid DBusServer::OnProtocolHandlerDisconnected(
2316a460fede07b768210d256191cd126013a0df273Christopher Wiley    const base::Callback<void(ProtocolHandler*)>& callback) {
2326a460fede07b768210d256191cd126013a0df273Christopher Wiley  on_protocol_handler_disconnected_ = callback;
2336a460fede07b768210d256191cd126013a0df273Christopher Wiley}
2346a460fede07b768210d256191cd126013a0df273Christopher Wiley
2356a460fede07b768210d256191cd126013a0df273Christopher Wileybase::TimeDelta DBusServer::GetDefaultRequestTimeout() const {
2366a460fede07b768210d256191cd126013a0df273Christopher Wiley  int timeout_seconds = proxy_ ? proxy_->default_request_timeout() : -1;
2376a460fede07b768210d256191cd126013a0df273Christopher Wiley  if (timeout_seconds <= 0)
2386a460fede07b768210d256191cd126013a0df273Christopher Wiley    return base::TimeDelta::Max();
2396a460fede07b768210d256191cd126013a0df273Christopher Wiley  return base::TimeDelta::FromSeconds(timeout_seconds);
2406a460fede07b768210d256191cd126013a0df273Christopher Wiley}
2416a460fede07b768210d256191cd126013a0df273Christopher Wiley
2426a460fede07b768210d256191cd126013a0df273Christopher Wiley}  // namespace libwebserv
243