1 // Copyright 2015 The Weave 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.
4 
5 #include "src/privet/device_delegate.h"
6 
7 #include <base/guid.h>
8 #include <weave/provider/task_runner.h>
9 
10 #include "src/privet/constants.h"
11 
12 namespace weave {
13 namespace privet {
14 
15 namespace {
16 
17 class DeviceDelegateImpl : public DeviceDelegate {
18  public:
DeviceDelegateImpl(provider::TaskRunner * task_runner,uint16_t http_port,uint16_t https_port,base::TimeDelta http_request_timeout)19   DeviceDelegateImpl(provider::TaskRunner* task_runner,
20                      uint16_t http_port,
21                      uint16_t https_port,
22                      base::TimeDelta http_request_timeout)
23       : task_runner_{task_runner},
24         http_request_timeout_{http_request_timeout},
25         http_port_{http_port},
26         https_port_{https_port} {}
27   ~DeviceDelegateImpl() override = default;
28 
GetHttpEnpoint() const29   std::pair<uint16_t, uint16_t> GetHttpEnpoint() const override {
30     return std::make_pair(http_port_, http_port_);
31   }
GetHttpsEnpoint() const32   std::pair<uint16_t, uint16_t> GetHttpsEnpoint() const override {
33     return std::make_pair(https_port_, https_port_);
34   }
GetHttpRequestTimeout() const35   base::TimeDelta GetHttpRequestTimeout() const override {
36     return http_request_timeout_;
37   }
38 
PostDelayedTask(const tracked_objects::Location & from_here,const base::Closure & task,base::TimeDelta delay)39   void PostDelayedTask(const tracked_objects::Location& from_here,
40                        const base::Closure& task,
41                        base::TimeDelta delay) override {
42     task_runner_->PostDelayedTask(from_here, task, delay);
43   }
44 
45  private:
46   provider::TaskRunner* task_runner_;
47   base::TimeDelta http_request_timeout_;
48   uint16_t http_port_{0};
49   uint16_t https_port_{0};
50 };
51 
52 }  // namespace
53 
DeviceDelegate()54 DeviceDelegate::DeviceDelegate() {}
55 
~DeviceDelegate()56 DeviceDelegate::~DeviceDelegate() {}
57 
58 // static
CreateDefault(provider::TaskRunner * task_runner,uint16_t http_port,uint16_t https_port,base::TimeDelta http_request_timeout)59 std::unique_ptr<DeviceDelegate> DeviceDelegate::CreateDefault(
60     provider::TaskRunner* task_runner,
61     uint16_t http_port,
62     uint16_t https_port,
63     base::TimeDelta http_request_timeout) {
64   return std::unique_ptr<DeviceDelegate>(new DeviceDelegateImpl(
65       task_runner, http_port, https_port, http_request_timeout));
66 }
67 
68 }  // namespace privet
69 }  // namespace weave
70