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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/webui/local_discovery/local_discovery_ui_handler.h" 5 #include "chrome/browser/ui/webui/local_discovery/local_discovery_ui_handler.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 base::Unretained(this))); 91 base::Unretained(this)));
92 web_ui()->RegisterMessageCallback("isVisible", base::Bind( 92 web_ui()->RegisterMessageCallback("isVisible", base::Bind(
93 &LocalDiscoveryUIHandler::HandleIsVisible, 93 &LocalDiscoveryUIHandler::HandleIsVisible,
94 base::Unretained(this))); 94 base::Unretained(this)));
95 web_ui()->RegisterMessageCallback("registerDevice", base::Bind( 95 web_ui()->RegisterMessageCallback("registerDevice", base::Bind(
96 &LocalDiscoveryUIHandler::HandleRegisterDevice, 96 &LocalDiscoveryUIHandler::HandleRegisterDevice,
97 base::Unretained(this))); 97 base::Unretained(this)));
98 web_ui()->RegisterMessageCallback("cancelRegistration", base::Bind( 98 web_ui()->RegisterMessageCallback("cancelRegistration", base::Bind(
99 &LocalDiscoveryUIHandler::HandleCancelRegistration, 99 &LocalDiscoveryUIHandler::HandleCancelRegistration,
100 base::Unretained(this))); 100 base::Unretained(this)));
101 web_ui()->RegisterMessageCallback("requestPrinterList", base::Bind( 101 web_ui()->RegisterMessageCallback(
102 &LocalDiscoveryUIHandler::HandleRequestPrinterList, 102 "requestDeviceList",
103 base::Unretained(this))); 103 base::Bind(&LocalDiscoveryUIHandler::HandleRequestDeviceList,
104 base::Unretained(this)));
104 web_ui()->RegisterMessageCallback("openCloudPrintURL", base::Bind( 105 web_ui()->RegisterMessageCallback("openCloudPrintURL", base::Bind(
105 &LocalDiscoveryUIHandler::HandleOpenCloudPrintURL, 106 &LocalDiscoveryUIHandler::HandleOpenCloudPrintURL,
106 base::Unretained(this))); 107 base::Unretained(this)));
107 web_ui()->RegisterMessageCallback("showSyncUI", base::Bind( 108 web_ui()->RegisterMessageCallback("showSyncUI", base::Bind(
108 &LocalDiscoveryUIHandler::HandleShowSyncUI, 109 &LocalDiscoveryUIHandler::HandleShowSyncUI,
109 base::Unretained(this))); 110 base::Unretained(this)));
110 111
111 // Cloud print connector related messages 112 // Cloud print connector related messages
112 #if defined(CLOUD_PRINT_CONNECTOR_UI_AVAILABLE) 113 #if defined(CLOUD_PRINT_CONNECTOR_UI_AVAILABLE)
113 if (cloud_print_connector_ui_enabled_) { 114 if (cloud_print_connector_ui_enabled_) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 base::Bind(&LocalDiscoveryUIHandler::StartRegisterHTTP, 173 base::Bind(&LocalDiscoveryUIHandler::StartRegisterHTTP,
173 base::Unretained(this))); 174 base::Unretained(this)));
174 privet_resolution_->Start(); 175 privet_resolution_->Start();
175 } 176 }
176 177
177 void LocalDiscoveryUIHandler::HandleCancelRegistration( 178 void LocalDiscoveryUIHandler::HandleCancelRegistration(
178 const base::ListValue* args) { 179 const base::ListValue* args) {
179 ResetCurrentRegistration(); 180 ResetCurrentRegistration();
180 } 181 }
181 182
182 void LocalDiscoveryUIHandler::HandleRequestPrinterList( 183 void LocalDiscoveryUIHandler::HandleRequestDeviceList(
183 const base::ListValue* args) { 184 const base::ListValue* args) {
184 Profile* profile = Profile::FromWebUI(web_ui()); 185 Profile* profile = Profile::FromWebUI(web_ui());
185 ProfileOAuth2TokenService* token_service = 186 ProfileOAuth2TokenService* token_service =
186 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); 187 ProfileOAuth2TokenServiceFactory::GetForProfile(profile);
187 188
188 SigninManagerBase* signin_manager = 189 SigninManagerBase* signin_manager =
189 SigninManagerFactory::GetInstance()->GetForProfile(profile); 190 SigninManagerFactory::GetInstance()->GetForProfile(profile);
190 191
192 devices_list_.reset();
193
191 cloud_print_printer_list_.reset( 194 cloud_print_printer_list_.reset(
192 new CloudPrintPrinterList(profile->GetRequestContext(), 195 new CloudPrintPrinterList(profile->GetRequestContext(),
193 token_service, 196 token_service,
194 signin_manager->GetAuthenticatedAccountId(), 197 signin_manager->GetAuthenticatedAccountId(),
195 this)); 198 this));
199
200 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.
201 new CloudDeviceList(profile->GetRequestContext(),
202 token_service,
203 signin_manager->GetAuthenticatedAccountId(),
204 this));
205
196 cloud_print_printer_list_->Start(); 206 cloud_print_printer_list_->Start();
207 cloud_device_list_->Start();
197 } 208 }
198 209
199 void LocalDiscoveryUIHandler::HandleOpenCloudPrintURL( 210 void LocalDiscoveryUIHandler::HandleOpenCloudPrintURL(
200 const base::ListValue* args) { 211 const base::ListValue* args) {
201 std::string id; 212 std::string id;
202 bool rv = args->GetString(0, &id); 213 bool rv = args->GetString(0, &id);
203 DCHECK(rv); 214 DCHECK(rv);
204 215
205 Browser* browser = chrome::FindBrowserWithWebContents( 216 Browser* browser = chrome::FindBrowserWithWebContents(
206 web_ui()->GetWebContents()); 217 web_ui()->GetWebContents());
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 web_ui()->CallJavascriptFunction("local_discovery.onUnregisteredDeviceUpdate", 387 web_ui()->CallJavascriptFunction("local_discovery.onUnregisteredDeviceUpdate",
377 name_value, *null_value); 388 name_value, *null_value);
378 } 389 }
379 390
380 void LocalDiscoveryUIHandler::DeviceCacheFlushed() { 391 void LocalDiscoveryUIHandler::DeviceCacheFlushed() {
381 web_ui()->CallJavascriptFunction("local_discovery.onDeviceCacheFlushed"); 392 web_ui()->CallJavascriptFunction("local_discovery.onDeviceCacheFlushed");
382 privet_lister_->DiscoverNewDevices(false); 393 privet_lister_->DiscoverNewDevices(false);
383 } 394 }
384 395
385 void LocalDiscoveryUIHandler::OnCloudPrintPrinterListReady() { 396 void LocalDiscoveryUIHandler::OnCloudPrintPrinterListReady() {
386 base::ListValue printer_object_list; 397 if (!devices_list_)
398 devices_list_.reset(new base::ListValue());
387 std::set<std::string> local_ids; 399 std::set<std::string> local_ids;
388 400
389 for (DeviceDescriptionMap::iterator i = device_descriptions_.begin(); 401 for (DeviceDescriptionMap::iterator i = device_descriptions_.begin();
390 i != device_descriptions_.end(); 402 i != device_descriptions_.end(); i++) {
391 i++) {
392 std::string device_id = i->second.id; 403 std::string device_id = i->second.id;
393 if (!device_id.empty()) { 404 if (!device_id.empty()) {
394 const CloudPrintPrinterList::PrinterDetails* details = 405 const CloudPrintPrinterList::PrinterDetails* details =
395 cloud_print_printer_list_->GetDetailsFor(device_id); 406 cloud_print_printer_list_->GetDetailsFor(device_id);
396 407
397 if (details) { 408 if (details) {
398 local_ids.insert(device_id); 409 local_ids.insert(device_id);
399 printer_object_list.Append(CreatePrinterInfo(*details).release()); 410 devices_list_->Append(CreatePrinterInfo(*details).release());
400 } 411 }
401 } 412 }
402 } 413 }
403 414
404 for (CloudPrintPrinterList::iterator i = cloud_print_printer_list_->begin(); 415 for (CloudPrintPrinterList::iterator i = cloud_print_printer_list_->begin();
405 i != cloud_print_printer_list_->end(); i++) { 416 i != cloud_print_printer_list_->end(); i++) {
406 if (local_ids.count(i->id) == 0) { 417 if (local_ids.count(i->id) == 0) {
407 printer_object_list.Append(CreatePrinterInfo(*i).release()); 418 devices_list_->Append(CreatePrinterInfo(*i).release());
408 } 419 }
409 } 420 }
410 421
411 web_ui()->CallJavascriptFunction( 422 cloud_print_printer_list_.reset();
412 "local_discovery.onCloudDeviceListAvailable", printer_object_list); 423 CheckListingDone();
413 } 424 }
414 425
415 void LocalDiscoveryUIHandler::OnCloudPrintPrinterListUnavailable() { 426 void LocalDiscoveryUIHandler::OnCloudPrintPrinterListUnavailable() {
416 web_ui()->CallJavascriptFunction( 427 cloud_print_printer_list_.reset();
417 "local_discovery.onCloudDeviceListUnavailable"); 428 CheckListingDone();
429 }
430
431 void LocalDiscoveryUIHandler::OnCloudDeviceListReady() {
432 if (!devices_list_)
433 devices_list_.reset(new base::ListValue());
434 std::set<std::string> local_ids;
435
436 for (DeviceDescriptionMap::iterator i = device_descriptions_.begin();
437 i != device_descriptions_.end(); i++) {
438 std::string device_id = i->second.id;
439 if (!device_id.empty()) {
440 const CloudDeviceList::DeviceDetails* details =
441 cloud_device_list_->GetDetailsFor(device_id);
442
443 if (details) {
444 local_ids.insert(device_id);
445 devices_list_->Append(CreateDeviceInfo(*details).release());
446 }
447 }
448 }
449
450 for (CloudDeviceList::iterator i = cloud_device_list_->begin();
451 i != cloud_device_list_->end(); i++) {
452 if (local_ids.count(i->id) == 0) {
453 devices_list_->Append(CreateDeviceInfo(*i).release());
454 }
455 }
456
457 cloud_device_list_.reset();
458 CheckListingDone();
459 }
460
461 void LocalDiscoveryUIHandler::OnCloudDeviceListUnavailable() {
462 cloud_device_list_.reset();
463 CheckListingDone();
418 } 464 }
419 465
420 void LocalDiscoveryUIHandler::GoogleSigninSucceeded( 466 void LocalDiscoveryUIHandler::GoogleSigninSucceeded(
421 const std::string& username, 467 const std::string& username,
422 const std::string& password) { 468 const std::string& password) {
423 CheckUserLoggedIn(); 469 CheckUserLoggedIn();
424 } 470 }
425 471
426 void LocalDiscoveryUIHandler::GoogleSignedOut(const std::string& username) { 472 void LocalDiscoveryUIHandler::GoogleSignedOut(const std::string& username) {
427 CheckUserLoggedIn(); 473 CheckUserLoggedIn();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 current_register_operation_->Cancel(); 515 current_register_operation_->Cancel();
470 current_register_operation_.reset(); 516 current_register_operation_.reset();
471 } 517 }
472 518
473 confirm_api_call_flow_.reset(); 519 confirm_api_call_flow_.reset();
474 privet_resolution_.reset(); 520 privet_resolution_.reset();
475 current_http_client_.reset(); 521 current_http_client_.reset();
476 } 522 }
477 523
478 scoped_ptr<base::DictionaryValue> LocalDiscoveryUIHandler::CreatePrinterInfo( 524 scoped_ptr<base::DictionaryValue> LocalDiscoveryUIHandler::CreatePrinterInfo(
479 const CloudPrintPrinterList::PrinterDetails& description) { 525 const CloudPrintPrinterList::PrinterDetails& description) {
Noam Samuel 2014/05/16 21:13:26 Maybe it makes sense to just migrate CloudPrintPri
Vitaly Buka (NO REVIEWS) 2014/05/17 17:15:37 Done.
480 scoped_ptr<base::DictionaryValue> return_value(new base::DictionaryValue); 526 scoped_ptr<base::DictionaryValue> return_value(new base::DictionaryValue);
481 527
482 return_value->SetString("id", description.id); 528 return_value->SetString("id", description.id);
483 return_value->SetString("display_name", description.display_name); 529 return_value->SetString("display_name", description.display_name);
484 return_value->SetString("description", description.description); 530 return_value->SetString("description", description.description);
485 return_value->SetString("type", "printer"); 531 return_value->SetString("type", kDeviceTypePrinter);
486 532
487 return return_value.Pass(); 533 return return_value.Pass();
488 } 534 }
535
536 scoped_ptr<base::DictionaryValue> LocalDiscoveryUIHandler::CreateDeviceInfo(
537 const CloudDeviceList::DeviceDetails& description) {
538 scoped_ptr<base::DictionaryValue> return_value(new base::DictionaryValue);
539
540 return_value->SetString("id", description.id);
541 return_value->SetString("display_name", description.display_name);
542 return_value->SetString("description", description.description);
543 return_value->SetString("type", description.type);
544
545 return return_value.Pass();
546 }
489 547
490 void LocalDiscoveryUIHandler::CheckUserLoggedIn() { 548 void LocalDiscoveryUIHandler::CheckUserLoggedIn() {
491 base::FundamentalValue logged_in_value(!GetSyncAccount().empty()); 549 base::FundamentalValue logged_in_value(!GetSyncAccount().empty());
492 web_ui()->CallJavascriptFunction("local_discovery.setUserLoggedIn", 550 web_ui()->CallJavascriptFunction("local_discovery.setUserLoggedIn",
493 logged_in_value); 551 logged_in_value);
494 } 552 }
495 553
554 void LocalDiscoveryUIHandler::CheckListingDone() {
555 if (cloud_print_printer_list_ || cloud_device_list_)
556 return;
557 if (devices_list_) {
558 web_ui()->CallJavascriptFunction(
559 "local_discovery.onCloudDeviceListAvailable", *devices_list_);
560 devices_list_.reset();
561 } else {
562 web_ui()->CallJavascriptFunction(
563 "local_discovery.onCloudDeviceListUnavailable");
564 }
565 }
566
496 #if defined(CLOUD_PRINT_CONNECTOR_UI_AVAILABLE) 567 #if defined(CLOUD_PRINT_CONNECTOR_UI_AVAILABLE)
497 void LocalDiscoveryUIHandler::StartCloudPrintConnector() { 568 void LocalDiscoveryUIHandler::StartCloudPrintConnector() {
498 Profile* profile = Profile::FromWebUI(web_ui()); 569 Profile* profile = Profile::FromWebUI(web_ui());
499 570
500 base::Closure cloud_print_callback = base::Bind( 571 base::Closure cloud_print_callback = base::Bind(
501 &LocalDiscoveryUIHandler::OnCloudPrintPrefsChanged, 572 &LocalDiscoveryUIHandler::OnCloudPrintPrefsChanged,
502 base::Unretained(this)); 573 base::Unretained(this));
503 574
504 if (cloud_print_connector_email_.GetPrefName().empty()) { 575 if (cloud_print_connector_email_.GetPrefName().empty()) {
505 cloud_print_connector_email_.Init( 576 cloud_print_connector_email_.Init(
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 } 665 }
595 666
596 void LocalDiscoveryUIHandler::RefreshCloudPrintStatusFromService() { 667 void LocalDiscoveryUIHandler::RefreshCloudPrintStatusFromService() {
597 if (cloud_print_connector_ui_enabled_) 668 if (cloud_print_connector_ui_enabled_)
598 CloudPrintProxyServiceFactory::GetForProfile(Profile::FromWebUI(web_ui()))-> 669 CloudPrintProxyServiceFactory::GetForProfile(Profile::FromWebUI(web_ui()))->
599 RefreshStatusFromService(); 670 RefreshStatusFromService();
600 } 671 }
601 #endif // cloud print connector option stuff 672 #endif // cloud print connector option stuff
602 673
603 } // namespace local_discovery 674 } // namespace local_discovery
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698