Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / extensions / api / dial / dial_device_data.cc
blobf8f5540485e68f845b30f6c2c3e8df254dc4b1ec
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.
5 #include "chrome/browser/extensions/api/dial/dial_device_data.h"
7 #include "chrome/common/extensions/api/dial.h"
9 namespace extensions {
11 DialDeviceData::DialDeviceData() : max_age_(-1), config_id_(-1) { }
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) {
20 DialDeviceData::~DialDeviceData() { }
22 const GURL& DialDeviceData::device_description_url() const {
23 return device_description_url_;
26 void DialDeviceData::set_device_description_url(const GURL& url) {
27 device_description_url_ = url;
30 // static
31 bool DialDeviceData::IsDeviceDescriptionUrl(const GURL& url) {
32 return url.is_valid() && !url.is_empty() && url.SchemeIsHTTPOrHTTPS();
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;
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_));
56 } // namespace extensions