Home | History | Annotate | Download | only in dial
      1 // Copyright (c) 2012 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.
      4 
      5 #include "chrome/browser/extensions/api/dial/dial_device_data.h"
      6 
      7 #include "chrome/common/extensions/api/dial.h"
      8 
      9 namespace extensions {
     10 
     11 DialDeviceData::DialDeviceData() : max_age_(-1), config_id_(-1) { }
     12 
     13 DialDeviceData::DialDeviceData(const std::string& device_id,
     14                                const GURL& device_description_url,
     15                                const base::Time& response_time)
     16     : device_id_(device_id), device_description_url_(device_description_url),
     17       response_time_(response_time), max_age_(-1), config_id_(-1) {
     18 }
     19 
     20 DialDeviceData::~DialDeviceData() { }
     21 
     22 const GURL& DialDeviceData::device_description_url() const {
     23   return device_description_url_;
     24 }
     25 
     26 void DialDeviceData::set_device_description_url(const GURL& url) {
     27   device_description_url_ = url;
     28 }
     29 
     30 // static
     31 bool DialDeviceData::IsDeviceDescriptionUrl(const GURL& url) {
     32   return url.is_valid() && !url.is_empty() && url.SchemeIsHTTPOrHTTPS();
     33 }
     34 
     35 bool DialDeviceData::UpdateFrom(const DialDeviceData& new_data) {
     36   DCHECK(new_data.device_id() == device_id_);
     37   DCHECK(new_data.label().empty());
     38   std::string label_tmp(label_);
     39   bool updated_api_visible_field =
     40       (new_data.device_description_url() != device_description_url_) ||
     41       (new_data.config_id() != config_id_);
     42   *this = new_data;
     43   label_ = label_tmp;
     44   return updated_api_visible_field;
     45 }
     46 
     47 void DialDeviceData::FillDialDevice(api::dial::DialDevice* device) const {
     48   DCHECK(!device_id_.empty());
     49   DCHECK(IsDeviceDescriptionUrl(device_description_url_));
     50   device->device_label = label_;
     51   device->device_description_url = device_description_url_.spec();
     52   if (has_config_id())
     53     device->config_id.reset(new int(config_id_));
     54 }
     55 
     56 }  // namespace extensions
     57