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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/local_discovery/cloud_device_list.cc
diff --git a/chrome/browser/local_discovery/cloud_device_list.cc b/chrome/browser/local_discovery/cloud_device_list.cc
new file mode 100644
index 0000000000000000000000000000000000000000..9ffc3c3fa36516624fc4e65d0f1d00c1cc8a1c3f
--- /dev/null
+++ b/chrome/browser/local_discovery/cloud_device_list.cc
@@ -0,0 +1,89 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/local_discovery/cloud_device_list.h"
+
+#include <utility>
+
+#include "base/strings/stringprintf.h"
+#include "components/cloud_devices/common/cloud_devices_urls.h"
+
+namespace local_discovery {
+
+CloudDeviceList::CloudDeviceList(net::URLRequestContextGetter* request_context,
+ OAuth2TokenService* token_service,
+ const std::string& account_id,
+ CloudDeviceListDelegate* delegate)
+ : request_context_(request_context),
+ delegate_(delegate),
+ api_flow_(request_context_,
+ token_service,
+ account_id,
+ cloud_devices::GetCloudDevicesRelativeURL("devices"),
+ this) {
+}
+
+CloudDeviceList::~CloudDeviceList() {
+}
+
+void CloudDeviceList::Start() {
+ api_flow_.Start();
+}
+
+void CloudDeviceList::OnGCDAPIFlowError(GCDBaseApiFlow* flow,
+ GCDBaseApiFlow::Status status) {
+ delegate_->OnDeviceListUnavailable();
+}
+
+void CloudDeviceList::OnGCDAPIFlowComplete(GCDBaseApiFlow* flow,
+ const base::DictionaryValue* value) {
+ const base::ListValue* devices;
+
+ if (!value->GetList("devices", &devices)) {
+ delegate_->OnDeviceListUnavailable();
+ return;
+ }
+
+ for (base::ListValue::const_iterator i = devices->begin();
+ i != devices->end(); i++) {
+ base::DictionaryValue* device;
+ CloudDeviceListDelegate::Device details;
+
+ if (!(*i)->GetAsDictionary(&device))
+ continue;
+
+ if (!FillDeviceDetails(device, &details))
+ continue;
+
+ device_list_.push_back(details);
+ }
+
+ delegate_->OnDeviceListReady();
+}
+
+bool CloudDeviceList::GCDIsCloudPrint() {
+ return false;
+}
+
+bool CloudDeviceList::FillDeviceDetails(
+ const base::DictionaryValue* device_value,
+ CloudDeviceListDelegate::Device* details) {
+ if (!device_value->GetString("id", &details->id))
+ return false;
+
+ if (!device_value->GetString("displayName", &details->display_name) &&
+ !device_value->GetString("systemName", &details->display_name)) {
+ return false;
+ }
+
+ if (!device_value->GetString("deviceKind", &details->type))
+ return false;
+
+ // Non-essential.
+ device_value->GetString("description", &details->description);
+
+ return true;
+}
+
+} // namespace local_discovery
« 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