Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Side by Side Diff: chrome/browser/local_discovery/cloud_device_list.cc

Issue 284223004: List cloud devices in chrome://devices page. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #include "chrome/browser/local_discovery/cloud_device_list.h"
6
7 #include <utility>
8
9 #include "base/strings/stringprintf.h"
10 #include "components/cloud_devices/common/cloud_devices_urls.h"
11
12 namespace local_discovery {
13
14 CloudDeviceList::CloudDeviceList(net::URLRequestContextGetter* request_context,
15 OAuth2TokenService* token_service,
16 const std::string& account_id,
17 CloudDeviceListDelegate* delegate)
18 : request_context_(request_context),
19 delegate_(delegate),
20 api_flow_(request_context_,
21 token_service,
22 account_id,
23 cloud_devices::GetCloudDevicesRelativeURL("devices"),
24 this) {
25 }
26
27 CloudDeviceList::~CloudDeviceList() {
28 }
29
30 void CloudDeviceList::Start() {
31 api_flow_.Start();
32 }
33
34 void CloudDeviceList::OnGCDAPIFlowError(GCDBaseApiFlow* flow,
35 GCDBaseApiFlow::Status status) {
36 delegate_->OnDeviceListUnavailable();
37 }
38
39 void CloudDeviceList::OnGCDAPIFlowComplete(GCDBaseApiFlow* flow,
40 const base::DictionaryValue* value) {
41 const base::ListValue* devices;
42
43 if (!value->GetList("devices", &devices)) {
44 delegate_->OnDeviceListUnavailable();
45 return;
46 }
47
48 for (base::ListValue::const_iterator i = devices->begin();
49 i != devices->end(); i++) {
50 base::DictionaryValue* device;
51 CloudDeviceListDelegate::Device details;
52
53 if (!(*i)->GetAsDictionary(&device))
54 continue;
55
56 if (!FillDeviceDetails(device, &details))
57 continue;
58
59 device_list_.push_back(details);
60 }
61
62 delegate_->OnDeviceListReady();
63 }
64
65 bool CloudDeviceList::GCDIsCloudPrint() {
66 return false;
67 }
68
69 bool CloudDeviceList::FillDeviceDetails(
70 const base::DictionaryValue* device_value,
71 CloudDeviceListDelegate::Device* details) {
72 if (!device_value->GetString("id", &details->id))
73 return false;
74
75 if (!device_value->GetString("displayName", &details->display_name) &&
76 !device_value->GetString("systemName", &details->display_name)) {
77 return false;
78 }
79
80 if (!device_value->GetString("deviceKind", &details->type))
81 return false;
82
83 // Non-essential.
84 device_value->GetString("description", &details->description);
85
86 return true;
87 }
88
89 } // namespace local_discovery
OLDNEW
« no previous file with comments | « chrome/browser/local_discovery/cloud_device_list.h ('k') | chrome/browser/local_discovery/cloud_device_list_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698