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

Unified Diff: chrome/browser/ui/webui/local_discovery/local_discovery_ui_handler.cc

Issue 284223004: List cloud devices in chrome://devices page. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fri 05/16/2014 12:52:36.94 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/ui/webui/local_discovery/local_discovery_ui_handler.cc
diff --git a/chrome/browser/ui/webui/local_discovery/local_discovery_ui_handler.cc b/chrome/browser/ui/webui/local_discovery/local_discovery_ui_handler.cc
index 4f3c2477dedc4fd0d620e5fa4a1d76a3a7b1ca21..0c1bde945398d968f0734a6c0cf0f9ccdaf03ba4 100644
--- a/chrome/browser/ui/webui/local_discovery/local_discovery_ui_handler.cc
+++ b/chrome/browser/ui/webui/local_discovery/local_discovery_ui_handler.cc
@@ -98,9 +98,10 @@ void LocalDiscoveryUIHandler::RegisterMessages() {
web_ui()->RegisterMessageCallback("cancelRegistration", base::Bind(
&LocalDiscoveryUIHandler::HandleCancelRegistration,
base::Unretained(this)));
- web_ui()->RegisterMessageCallback("requestPrinterList", base::Bind(
- &LocalDiscoveryUIHandler::HandleRequestPrinterList,
- base::Unretained(this)));
+ web_ui()->RegisterMessageCallback(
+ "requestDeviceList",
+ base::Bind(&LocalDiscoveryUIHandler::HandleRequestDeviceList,
+ base::Unretained(this)));
web_ui()->RegisterMessageCallback("openCloudPrintURL", base::Bind(
&LocalDiscoveryUIHandler::HandleOpenCloudPrintURL,
base::Unretained(this)));
@@ -179,7 +180,7 @@ void LocalDiscoveryUIHandler::HandleCancelRegistration(
ResetCurrentRegistration();
}
-void LocalDiscoveryUIHandler::HandleRequestPrinterList(
+void LocalDiscoveryUIHandler::HandleRequestDeviceList(
const base::ListValue* args) {
Profile* profile = Profile::FromWebUI(web_ui());
ProfileOAuth2TokenService* token_service =
@@ -188,12 +189,22 @@ void LocalDiscoveryUIHandler::HandleRequestPrinterList(
SigninManagerBase* signin_manager =
SigninManagerFactory::GetInstance()->GetForProfile(profile);
+ devices_list_.reset();
+
cloud_print_printer_list_.reset(
new CloudPrintPrinterList(profile->GetRequestContext(),
token_service,
signin_manager->GetAuthenticatedAccountId(),
this));
+
+ cloud_device_list_.reset(
Noam Samuel 2014/05/16 21:13:26 IMPORTANT: Please hide behind flag for now.
Vitaly Buka (NO REVIEWS) 2014/05/17 17:15:37 Done.
+ new CloudDeviceList(profile->GetRequestContext(),
+ token_service,
+ signin_manager->GetAuthenticatedAccountId(),
+ this));
+
cloud_print_printer_list_->Start();
+ cloud_device_list_->Start();
}
void LocalDiscoveryUIHandler::HandleOpenCloudPrintURL(
@@ -383,12 +394,12 @@ void LocalDiscoveryUIHandler::DeviceCacheFlushed() {
}
void LocalDiscoveryUIHandler::OnCloudPrintPrinterListReady() {
- base::ListValue printer_object_list;
+ if (!devices_list_)
+ devices_list_.reset(new base::ListValue());
std::set<std::string> local_ids;
for (DeviceDescriptionMap::iterator i = device_descriptions_.begin();
- i != device_descriptions_.end();
- i++) {
+ i != device_descriptions_.end(); i++) {
std::string device_id = i->second.id;
if (!device_id.empty()) {
const CloudPrintPrinterList::PrinterDetails* details =
@@ -396,7 +407,7 @@ void LocalDiscoveryUIHandler::OnCloudPrintPrinterListReady() {
if (details) {
local_ids.insert(device_id);
- printer_object_list.Append(CreatePrinterInfo(*details).release());
+ devices_list_->Append(CreatePrinterInfo(*details).release());
}
}
}
@@ -404,17 +415,52 @@ void LocalDiscoveryUIHandler::OnCloudPrintPrinterListReady() {
for (CloudPrintPrinterList::iterator i = cloud_print_printer_list_->begin();
i != cloud_print_printer_list_->end(); i++) {
if (local_ids.count(i->id) == 0) {
- printer_object_list.Append(CreatePrinterInfo(*i).release());
+ devices_list_->Append(CreatePrinterInfo(*i).release());
}
}
- web_ui()->CallJavascriptFunction(
- "local_discovery.onCloudDeviceListAvailable", printer_object_list);
+ cloud_print_printer_list_.reset();
+ CheckListingDone();
}
void LocalDiscoveryUIHandler::OnCloudPrintPrinterListUnavailable() {
- web_ui()->CallJavascriptFunction(
- "local_discovery.onCloudDeviceListUnavailable");
+ cloud_print_printer_list_.reset();
+ CheckListingDone();
+}
+
+void LocalDiscoveryUIHandler::OnCloudDeviceListReady() {
+ if (!devices_list_)
+ devices_list_.reset(new base::ListValue());
+ std::set<std::string> local_ids;
+
+ for (DeviceDescriptionMap::iterator i = device_descriptions_.begin();
+ i != device_descriptions_.end(); i++) {
+ std::string device_id = i->second.id;
+ if (!device_id.empty()) {
+ const CloudDeviceList::DeviceDetails* details =
+ cloud_device_list_->GetDetailsFor(device_id);
+
+ if (details) {
+ local_ids.insert(device_id);
+ devices_list_->Append(CreateDeviceInfo(*details).release());
+ }
+ }
+ }
+
+ for (CloudDeviceList::iterator i = cloud_device_list_->begin();
+ i != cloud_device_list_->end(); i++) {
+ if (local_ids.count(i->id) == 0) {
+ devices_list_->Append(CreateDeviceInfo(*i).release());
+ }
+ }
+
+ cloud_device_list_.reset();
+ CheckListingDone();
+}
+
+void LocalDiscoveryUIHandler::OnCloudDeviceListUnavailable() {
+ cloud_device_list_.reset();
+ CheckListingDone();
}
void LocalDiscoveryUIHandler::GoogleSigninSucceeded(
@@ -482,7 +528,19 @@ scoped_ptr<base::DictionaryValue> LocalDiscoveryUIHandler::CreatePrinterInfo(
return_value->SetString("id", description.id);
return_value->SetString("display_name", description.display_name);
return_value->SetString("description", description.description);
- return_value->SetString("type", "printer");
+ return_value->SetString("type", kDeviceTypePrinter);
+
+ return return_value.Pass();
+}
+
+scoped_ptr<base::DictionaryValue> LocalDiscoveryUIHandler::CreateDeviceInfo(
+ const CloudDeviceList::DeviceDetails& description) {
+ scoped_ptr<base::DictionaryValue> return_value(new base::DictionaryValue);
+
+ return_value->SetString("id", description.id);
+ return_value->SetString("display_name", description.display_name);
+ return_value->SetString("description", description.description);
+ return_value->SetString("type", description.type);
return return_value.Pass();
}
@@ -493,6 +551,19 @@ void LocalDiscoveryUIHandler::CheckUserLoggedIn() {
logged_in_value);
}
+void LocalDiscoveryUIHandler::CheckListingDone() {
+ if (cloud_print_printer_list_ || cloud_device_list_)
+ return;
+ if (devices_list_) {
+ web_ui()->CallJavascriptFunction(
+ "local_discovery.onCloudDeviceListAvailable", *devices_list_);
+ devices_list_.reset();
+ } else {
+ web_ui()->CallJavascriptFunction(
+ "local_discovery.onCloudDeviceListUnavailable");
+ }
+}
+
#if defined(CLOUD_PRINT_CONNECTOR_UI_AVAILABLE)
void LocalDiscoveryUIHandler::StartCloudPrintConnector() {
Profile* profile = Profile::FromWebUI(web_ui());

Powered by Google App Engine
This is Rietveld 408576698