Allow the minimum time between banner trigger visits to be varied via field trials.
[chromium-blink-merge.git] / chrome / browser / local_discovery / cloud_device_list.cc
blob95c2a7f91249627f668b63e1a9ef62e8e7d929c3
1 // Copyright 2014 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/local_discovery/cloud_device_list.h"
7 #include <utility>
9 #include "base/strings/stringprintf.h"
10 #include "chrome/browser/local_discovery/gcd_constants.h"
11 #include "components/cloud_devices/common/cloud_devices_urls.h"
13 namespace local_discovery {
15 namespace {
16 const char kKindDevicesList[] = "clouddevices#devicesListResponse";
19 CloudDeviceList::CloudDeviceList(CloudDeviceListDelegate* delegate)
20 : delegate_(delegate) {
23 CloudDeviceList::~CloudDeviceList() {
26 void CloudDeviceList::OnGCDAPIFlowError(GCDApiFlow::Status status) {
27 delegate_->OnDeviceListUnavailable();
30 void CloudDeviceList::OnGCDAPIFlowComplete(const base::DictionaryValue& value) {
31 std::string kind;
32 value.GetString(kGCDKeyKind, &kind);
34 const base::ListValue* devices = NULL;
35 if (kind != kKindDevicesList || !value.GetList("devices", &devices)) {
36 delegate_->OnDeviceListUnavailable();
37 return;
40 std::vector<CloudDeviceListDelegate::Device> result;
41 for (base::ListValue::const_iterator i = devices->begin();
42 i != devices->end(); i++) {
43 base::DictionaryValue* device;
44 CloudDeviceListDelegate::Device details;
46 if (!(*i)->GetAsDictionary(&device))
47 continue;
49 if (!FillDeviceDetails(*device, &details))
50 continue;
52 result.push_back(details);
55 delegate_->OnDeviceListReady(result);
58 GURL CloudDeviceList::GetURL() {
59 return cloud_devices::GetCloudDevicesRelativeURL("devices");
62 bool CloudDeviceList::FillDeviceDetails(
63 const base::DictionaryValue& device_value,
64 CloudDeviceListDelegate::Device* details) {
65 if (!device_value.GetString("id", &details->id))
66 return false;
68 if (!device_value.GetString("displayName", &details->display_name) &&
69 !device_value.GetString("systemName", &details->display_name)) {
70 return false;
73 if (!device_value.GetString("deviceKind", &details->type))
74 return false;
76 // Non-essential.
77 device_value.GetString("description", &details->description);
79 return true;
82 } // namespace local_discovery