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

Side by Side Diff: chrome/browser/ui/webui/local_discovery/local_discovery_ui_handler.cc

Issue 318283002: Added new GCD/Privet interfaces. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 const base::ListValue* args) { 232 const base::ListValue* args) {
233 ResetCurrentRegistration(); 233 ResetCurrentRegistration();
234 } 234 }
235 235
236 void LocalDiscoveryUIHandler::HandleRequestDeviceList( 236 void LocalDiscoveryUIHandler::HandleRequestDeviceList(
237 const base::ListValue* args) { 237 const base::ListValue* args) {
238 failed_list_count_ = 0; 238 failed_list_count_ = 0;
239 succeded_list_count_ = 0; 239 succeded_list_count_ = 0;
240 cloud_devices_.clear(); 240 cloud_devices_.clear();
241 241
242 cloud_print_printer_list_ = CreateApiFlow( 242 cloud_print_printer_list_ = CreateApiFlow();
243 scoped_ptr<GCDApiFlow::Request>(new CloudPrintPrinterList(this)));
244 if (CommandLine::ForCurrentProcess()->HasSwitch( 243 if (CommandLine::ForCurrentProcess()->HasSwitch(
245 switches::kEnableCloudDevices)) { 244 switches::kEnableCloudDevices)) {
246 cloud_device_list_ = CreateApiFlow( 245 cloud_device_list_ = CreateApiFlow();
247 scoped_ptr<GCDApiFlow::Request>(new CloudDeviceList(this)));
248 } 246 }
249 247
250 if (cloud_print_printer_list_) 248 if (cloud_print_printer_list_) {
251 cloud_print_printer_list_->Start(); 249 cloud_print_printer_list_->Start(
252 if (cloud_device_list_) 250 make_scoped_ptr<GCDApiFlowInterface::Request>(
253 cloud_device_list_->Start(); 251 new CloudPrintPrinterList(this)));
252 }
253 if (cloud_device_list_) {
254 cloud_device_list_->Start(make_scoped_ptr<GCDApiFlowInterface::Request>(
255 new CloudDeviceList(this)));
256 }
254 CheckListingDone(); 257 CheckListingDone();
255 } 258 }
256 259
257 void LocalDiscoveryUIHandler::HandleOpenCloudPrintURL( 260 void LocalDiscoveryUIHandler::HandleOpenCloudPrintURL(
258 const base::ListValue* args) { 261 const base::ListValue* args) {
259 std::string id; 262 std::string id;
260 bool rv = args->GetString(0, &id); 263 bool rv = args->GetString(0, &id);
261 DCHECK(rv); 264 DCHECK(rv);
262 265
263 Browser* browser = chrome::FindBrowserWithWebContents( 266 Browser* browser = chrome::FindBrowserWithWebContents(
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 PrivetRegisterOperation* operation, 306 PrivetRegisterOperation* operation,
304 const std::string& token, 307 const std::string& token,
305 const GURL& url) { 308 const GURL& url) {
306 web_ui()->CallJavascriptFunction( 309 web_ui()->CallJavascriptFunction(
307 "local_discovery.onRegistrationConfirmedOnPrinter"); 310 "local_discovery.onRegistrationConfirmedOnPrinter");
308 if (device_descriptions_.count(current_http_client_->GetName()) == 0) { 311 if (device_descriptions_.count(current_http_client_->GetName()) == 0) {
309 SendRegisterError(); 312 SendRegisterError();
310 return; 313 return;
311 } 314 }
312 315
313 confirm_api_call_flow_ = CreateApiFlow( 316 confirm_api_call_flow_ = CreateApiFlow();
314 scoped_ptr<GCDApiFlow::Request>(new PrivetConfirmApiCallFlow(
315 token,
316 base::Bind(&LocalDiscoveryUIHandler::OnConfirmDone,
317 base::Unretained(this)))));
318 if (!confirm_api_call_flow_) { 317 if (!confirm_api_call_flow_) {
319 SendRegisterError(); 318 SendRegisterError();
320 return; 319 return;
321 } 320 }
322 confirm_api_call_flow_->Start(); 321 confirm_api_call_flow_->Start(make_scoped_ptr<GCDApiFlowInterface::Request>(
322 new PrivetConfirmApiCallFlow(
323 token,
324 base::Bind(&LocalDiscoveryUIHandler::OnConfirmDone,
325 base::Unretained(this)))));
323 } 326 }
324 327
325 void LocalDiscoveryUIHandler::OnPrivetRegisterError( 328 void LocalDiscoveryUIHandler::OnPrivetRegisterError(
326 PrivetRegisterOperation* operation, 329 PrivetRegisterOperation* operation,
327 const std::string& action, 330 const std::string& action,
328 PrivetRegisterOperation::FailureReason reason, 331 PrivetRegisterOperation::FailureReason reason,
329 int printer_http_code, 332 int printer_http_code,
330 const base::DictionaryValue* json) { 333 const base::DictionaryValue* json) {
331 std::string error; 334 std::string error;
332 335
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 476
474 if (!signin_manager) { 477 if (!signin_manager) {
475 return ""; 478 return "";
476 } 479 }
477 480
478 return signin_manager->GetAuthenticatedUsername(); 481 return signin_manager->GetAuthenticatedUsername();
479 } 482 }
480 483
481 // TODO(noamsml): Create master object for registration flow. 484 // TODO(noamsml): Create master object for registration flow.
482 void LocalDiscoveryUIHandler::ResetCurrentRegistration() { 485 void LocalDiscoveryUIHandler::ResetCurrentRegistration() {
483 if (current_register_operation_.get()) { 486 if (current_register_operation_) {
484 current_register_operation_->Cancel(); 487 current_register_operation_->Cancel();
485 current_register_operation_.reset(); 488 current_register_operation_.reset();
486 } 489 }
487 490
488 confirm_api_call_flow_.reset(); 491 confirm_api_call_flow_.reset();
489 privet_resolution_.reset(); 492 privet_resolution_.reset();
490 current_http_client_.reset(); 493 current_http_client_.reset();
491 } 494 }
492 495
493 void LocalDiscoveryUIHandler::CheckUserLoggedIn() { 496 void LocalDiscoveryUIHandler::CheckUserLoggedIn() {
(...skipping 27 matching lines...) Expand all
521 } 524 }
522 525
523 ReadDevicesList(cloud_devices_, local_ids, &devices_list); 526 ReadDevicesList(cloud_devices_, local_ids, &devices_list);
524 527
525 web_ui()->CallJavascriptFunction( 528 web_ui()->CallJavascriptFunction(
526 "local_discovery.onCloudDeviceListAvailable", devices_list); 529 "local_discovery.onCloudDeviceListAvailable", devices_list);
527 cloud_print_printer_list_.reset(); 530 cloud_print_printer_list_.reset();
528 cloud_device_list_.reset(); 531 cloud_device_list_.reset();
529 } 532 }
530 533
531 scoped_ptr<GCDApiFlow> LocalDiscoveryUIHandler::CreateApiFlow( 534 scoped_ptr<GCDApiFlowInterface> LocalDiscoveryUIHandler::CreateApiFlow() {
532 scoped_ptr<GCDApiFlow::Request> request) {
533 Profile* profile = Profile::FromWebUI(web_ui()); 535 Profile* profile = Profile::FromWebUI(web_ui());
534 if (!profile) 536 if (!profile)
535 return scoped_ptr<GCDApiFlow>(); 537 return scoped_ptr<GCDApiFlowInterface>();
536 ProfileOAuth2TokenService* token_service = 538 ProfileOAuth2TokenService* token_service =
537 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); 539 ProfileOAuth2TokenServiceFactory::GetForProfile(profile);
538 if (!token_service) 540 if (!token_service)
539 return scoped_ptr<GCDApiFlow>(); 541 return scoped_ptr<GCDApiFlowInterface>();
540 SigninManagerBase* signin_manager = 542 SigninManagerBase* signin_manager =
541 SigninManagerFactory::GetInstance()->GetForProfile(profile); 543 SigninManagerFactory::GetInstance()->GetForProfile(profile);
542 if (!signin_manager) 544 if (!signin_manager)
543 return scoped_ptr<GCDApiFlow>(); 545 return scoped_ptr<GCDApiFlowInterface>();
544 return make_scoped_ptr( 546 return make_scoped_ptr<GCDApiFlowInterface>(
545 new GCDApiFlow(profile->GetRequestContext(), 547 new GCDApiFlow(profile->GetRequestContext(),
546 token_service, 548 token_service,
547 signin_manager->GetAuthenticatedAccountId(), 549 signin_manager->GetAuthenticatedAccountId()));
548 request.Pass()));
549 } 550 }
550 551
551 #if defined(CLOUD_PRINT_CONNECTOR_UI_AVAILABLE) 552 #if defined(CLOUD_PRINT_CONNECTOR_UI_AVAILABLE)
552 void LocalDiscoveryUIHandler::StartCloudPrintConnector() { 553 void LocalDiscoveryUIHandler::StartCloudPrintConnector() {
553 Profile* profile = Profile::FromWebUI(web_ui()); 554 Profile* profile = Profile::FromWebUI(web_ui());
554 555
555 base::Closure cloud_print_callback = base::Bind( 556 base::Closure cloud_print_callback = base::Bind(
556 &LocalDiscoveryUIHandler::OnCloudPrintPrefsChanged, 557 &LocalDiscoveryUIHandler::OnCloudPrintPrefsChanged,
557 base::Unretained(this)); 558 base::Unretained(this));
558 559
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 scoped_ptr<base::Value> null_value(base::Value::CreateNullValue()); 696 scoped_ptr<base::Value> null_value(base::Value::CreateNullValue());
696 697
697 web_ui()->CallJavascriptFunction( 698 web_ui()->CallJavascriptFunction(
698 "local_discovery.onUnregisteredDeviceUpdate", service_key, *null_value); 699 "local_discovery.onUnregisteredDeviceUpdate", service_key, *null_value);
699 } 700 }
700 } 701 }
701 702
702 #endif // ENABLE_WIFI_BOOTSTRAPPING 703 #endif // ENABLE_WIFI_BOOTSTRAPPING
703 704
704 } // namespace local_discovery 705 } // namespace local_discovery
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698