OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/service/cloud_print/cloud_print_proxy_backend.h" | 5 #include "chrome/service/cloud_print/cloud_print_proxy_backend.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "app/l10n_util.h" | |
10 #include "base/file_util.h" | 11 #include "base/file_util.h" |
11 #include "base/md5.h" | 12 #include "base/md5.h" |
12 #include "base/rand_util.h" | 13 #include "base/rand_util.h" |
13 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
14 #include "base/string_split.h" | 15 #include "base/string_split.h" |
15 #include "base/string_util.h" | 16 #include "base/string_util.h" |
16 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
17 #include "base/values.h" | 18 #include "base/values.h" |
18 #include "chrome/service/cloud_print/cloud_print_consts.h" | 19 #include "chrome/service/cloud_print/cloud_print_consts.h" |
19 #include "chrome/service/cloud_print/cloud_print_helpers.h" | 20 #include "chrome/service/cloud_print/cloud_print_helpers.h" |
20 #include "chrome/service/cloud_print/cloud_print_url_fetcher.h" | 21 #include "chrome/service/cloud_print/cloud_print_url_fetcher.h" |
21 #include "chrome/service/cloud_print/printer_job_handler.h" | 22 #include "chrome/service/cloud_print/printer_job_handler.h" |
22 #include "chrome/service/gaia/service_gaia_authenticator.h" | 23 #include "chrome/service/gaia/service_gaia_authenticator.h" |
23 #include "chrome/service/service_process.h" | 24 #include "chrome/service/service_process.h" |
24 #include "googleurl/src/gurl.h" | 25 #include "googleurl/src/gurl.h" |
26 #include "grit/generated_resources.h" | |
25 #include "jingle/notifier/base/notifier_options.h" | 27 #include "jingle/notifier/base/notifier_options.h" |
26 #include "jingle/notifier/listener/push_notifications_thread.h" | 28 #include "jingle/notifier/listener/push_notifications_thread.h" |
27 #include "jingle/notifier/listener/talk_mediator_impl.h" | 29 #include "jingle/notifier/listener/talk_mediator_impl.h" |
28 #include "net/url_request/url_request_status.h" | 30 #include "net/url_request/url_request_status.h" |
29 | 31 |
30 // The real guts of CloudPrintProxyBackend, to keep the public client API clean. | 32 // The real guts of CloudPrintProxyBackend, to keep the public client API clean. |
31 class CloudPrintProxyBackend::Core | 33 class CloudPrintProxyBackend::Core |
32 : public base::RefCountedThreadSafe<CloudPrintProxyBackend::Core>, | 34 : public base::RefCountedThreadSafe<CloudPrintProxyBackend::Core>, |
33 public CloudPrintURLFetcherDelegate, | 35 public CloudPrintURLFetcherDelegate, |
34 public cloud_print::PrintServerWatcherDelegate, | 36 public cloud_print::PrintServerWatcherDelegate, |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
99 const URLFetcher* source, | 101 const URLFetcher* source, |
100 const GURL& url, | 102 const GURL& url, |
101 DictionaryValue* json_data, | 103 DictionaryValue* json_data, |
102 bool succeeded); | 104 bool succeeded); |
103 | 105 |
104 CloudPrintURLFetcher::ResponseAction HandleRegisterPrinterResponse( | 106 CloudPrintURLFetcher::ResponseAction HandleRegisterPrinterResponse( |
105 const URLFetcher* source, | 107 const URLFetcher* source, |
106 const GURL& url, | 108 const GURL& url, |
107 DictionaryValue* json_data, | 109 DictionaryValue* json_data, |
108 bool succeeded); | 110 bool succeeded); |
111 | |
112 CloudPrintURLFetcher::ResponseAction HandleRegisterFailedStatusResponse( | |
113 const URLFetcher* source, | |
114 const GURL& url, | |
115 DictionaryValue* json_data, | |
116 bool succeeded); | |
117 | |
118 CloudPrintURLFetcher::ResponseAction HandlePrintSystemUnavailableResponse( | |
119 const URLFetcher* source, | |
120 const GURL& url, | |
121 DictionaryValue* json_data, | |
122 bool succeeded); | |
109 // End response handlers | 123 // End response handlers |
110 | 124 |
111 // NotifyXXX is how the Core communicates with the frontend across | 125 // NotifyXXX is how the Core communicates with the frontend across |
112 // threads. | 126 // threads. |
113 void NotifyPrinterListAvailable( | 127 void NotifyPrinterListAvailable( |
114 const printing::PrinterList& printer_list); | 128 const printing::PrinterList& printer_list); |
115 void NotifyAuthenticated( | 129 void NotifyAuthenticated( |
116 const std::string& cloud_print_token, | 130 const std::string& cloud_print_token, |
117 const std::string& cloud_print_xmpp_token, | 131 const std::string& cloud_print_xmpp_token, |
118 const std::string& email); | 132 const std::string& email); |
119 void NotifyAuthenticationFailed(); | 133 void NotifyAuthenticationFailed(); |
134 void NotifyPrintSystemUnavailable(); | |
120 | 135 |
121 // Starts a new printer registration process. | 136 // Starts a new printer registration process. |
122 void StartRegistration(); | 137 void StartRegistration(); |
123 // Ends the printer registration process. | 138 // Ends the printer registration process. |
124 void EndRegistration(); | 139 void EndRegistration(); |
125 // Registers printer capabilities and defaults for the next printer in the | 140 // Registers printer capabilities and defaults for the next printer in the |
126 // list with the cloud print server. | 141 // list with the cloud print server. |
127 void RegisterNextPrinter(); | 142 void RegisterNextPrinter(); |
128 // Retrieves the list of registered printers for this user/proxy combination | 143 // Retrieves the list of registered printers for this user/proxy combination |
129 // from the cloud print server. | 144 // from the cloud print server. |
130 void GetRegisteredPrinters(); | 145 void GetRegisteredPrinters(); |
131 // Removes the given printer from the list. Returns false if the printer | 146 // Removes the given printer from the list. Returns false if the printer |
132 // did not exist in the list. | 147 // did not exist in the list. |
133 bool RemovePrinterFromList(const std::string& printer_name); | 148 bool RemovePrinterFromList(const std::string& printer_name); |
134 // Initializes a job handler object for the specified printer. The job | 149 // Initializes a job handler object for the specified printer. The job |
135 // handler is responsible for checking for pending print jobs for this | 150 // handler is responsible for checking for pending print jobs for this |
136 // printer and print them. | 151 // printer and print them. |
137 void InitJobHandlerForPrinter(DictionaryValue* printer_data); | 152 void InitJobHandlerForPrinter(DictionaryValue* printer_data); |
153 // Sends a diagnostic message to the cloud print server that the print | |
154 // system failed to initialize. | |
155 void ReportPrintSystemUnavailable(const std::string& failure_message); | |
138 | 156 |
139 // Callback method for GetPrinterCapsAndDefaults. | 157 // Callback method for GetPrinterCapsAndDefaults. |
140 void OnReceivePrinterCaps( | 158 void OnReceivePrinterCaps( |
141 bool succeeded, | 159 bool succeeded, |
142 const std::string& printer_name, | 160 const std::string& printer_name, |
143 const printing::PrinterCapsAndDefaults& caps_and_defaults); | 161 const printing::PrinterCapsAndDefaults& caps_and_defaults); |
144 | 162 |
145 void HandlePrinterNotification(const std::string& printer_id); | 163 void HandlePrinterNotification(const std::string& printer_id); |
146 void PollForJobs(); | 164 void PollForJobs(); |
147 // Schedules a task to poll for jobs. Does nothing if a task is already | 165 // Schedules a task to poll for jobs. Does nothing if a task is already |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
326 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); | 344 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); |
327 VLOG(1) << "CP_PROXY: Starting proxy, id: " << proxy_id; | 345 VLOG(1) << "CP_PROXY: Starting proxy, id: " << proxy_id; |
328 | 346 |
329 print_system_ = | 347 print_system_ = |
330 cloud_print::PrintSystem::CreateInstance(print_system_settings_.get()); | 348 cloud_print::PrintSystem::CreateInstance(print_system_settings_.get()); |
331 if (!print_system_.get()) { | 349 if (!print_system_.get()) { |
332 NOTREACHED(); | 350 NOTREACHED(); |
333 return; // No print system available, fail initalization. | 351 return; // No print system available, fail initalization. |
334 } | 352 } |
335 | 353 |
336 print_system_->Init(); | 354 cloud_print::PrintSystem::PrintSystemResult result = print_system_->Init(); |
337 | 355 |
338 // TODO(sanjeevr): Validate the tokens. | 356 // TODO(sanjeevr): Validate the tokens. |
339 auth_token_ = cloud_print_token; | 357 auth_token_ = cloud_print_token; |
340 | 358 |
341 const notifier::NotifierOptions kNotifierOptions; | 359 if (result.succeeded()) { |
342 const bool kInvalidateXmppAuthToken = false; | 360 const notifier::NotifierOptions kNotifierOptions; |
343 const bool kAllowInsecureXmppConnection = false; | 361 const bool kInvalidateXmppAuthToken = false; |
344 talk_mediator_.reset(new notifier::TalkMediatorImpl( | 362 const bool kAllowInsecureXmppConnection = false; |
345 new notifier::PushNotificationsThread(kNotifierOptions, | 363 talk_mediator_.reset(new notifier::TalkMediatorImpl( |
346 kCloudPrintPushNotificationsSource), | 364 new notifier::PushNotificationsThread( |
347 kInvalidateXmppAuthToken, | 365 kNotifierOptions, |
348 kAllowInsecureXmppConnection)); | 366 kCloudPrintPushNotificationsSource), |
349 push_notifications_channel_ = kCloudPrintPushNotificationsSource; | 367 kInvalidateXmppAuthToken, |
350 push_notifications_channel_.append("/proxy/"); | 368 kAllowInsecureXmppConnection)); |
351 push_notifications_channel_.append(proxy_id); | 369 push_notifications_channel_ = kCloudPrintPushNotificationsSource; |
352 talk_mediator_->AddSubscribedServiceUrl(push_notifications_channel_); | 370 push_notifications_channel_.append("/proxy/"); |
353 talk_mediator_->SetDelegate(this); | 371 push_notifications_channel_.append(proxy_id); |
354 talk_mediator_->SetAuthToken(email, cloud_print_xmpp_token, | 372 talk_mediator_->AddSubscribedServiceUrl(push_notifications_channel_); |
355 kSyncGaiaServiceId); | 373 talk_mediator_->SetDelegate(this); |
356 talk_mediator_->Login(); | 374 talk_mediator_->SetAuthToken(email, cloud_print_xmpp_token, |
375 kSyncGaiaServiceId); | |
376 talk_mediator_->Login(); | |
357 | 377 |
358 print_server_watcher_ = print_system_->CreatePrintServerWatcher(); | 378 print_server_watcher_ = print_system_->CreatePrintServerWatcher(); |
359 print_server_watcher_->StartWatching(this); | 379 print_server_watcher_->StartWatching(this); |
360 | 380 |
361 proxy_id_ = proxy_id; | 381 proxy_id_ = proxy_id; |
362 | 382 |
363 StartRegistration(); | 383 StartRegistration(); |
384 } else { | |
385 // We could not initialize the print system. We need to notify the server. | |
386 ReportPrintSystemUnavailable(result.message()); | |
387 } | |
364 } | 388 } |
365 | 389 |
366 void CloudPrintProxyBackend::Core::StartRegistration() { | 390 void CloudPrintProxyBackend::Core::StartRegistration() { |
367 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); | 391 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); |
368 printer_list_.clear(); | 392 printer_list_.clear(); |
369 print_system_->EnumeratePrinters(&printer_list_); | 393 print_system_->EnumeratePrinters(&printer_list_); |
370 // Now we need to ask the server about printers that were registered on the | 394 // Now we need to ask the server about printers that were registered on the |
371 // server so that we can trim this list. | 395 // server so that we can trim this list. |
372 GetRegisteredPrinters(); | 396 GetRegisteredPrinters(); |
373 } | 397 } |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
448 } else { | 472 } else { |
449 EndRegistration(); | 473 EndRegistration(); |
450 } | 474 } |
451 } | 475 } |
452 | 476 |
453 void CloudPrintProxyBackend::Core::OnReceivePrinterCaps( | 477 void CloudPrintProxyBackend::Core::OnReceivePrinterCaps( |
454 bool succeeded, | 478 bool succeeded, |
455 const std::string& printer_name, | 479 const std::string& printer_name, |
456 const printing::PrinterCapsAndDefaults& caps_and_defaults) { | 480 const printing::PrinterCapsAndDefaults& caps_and_defaults) { |
457 DCHECK(next_upload_index_ < printer_list_.size()); | 481 DCHECK(next_upload_index_ < printer_list_.size()); |
482 std::string mime_boundary; | |
483 CloudPrintHelpers::CreateMimeBoundaryForUpload(&mime_boundary); | |
484 std::string post_data; | |
485 GURL post_url; | |
458 if (succeeded) { | 486 if (succeeded) { |
459 const printing::PrinterBasicInfo& info = | 487 const printing::PrinterBasicInfo& info = |
460 printer_list_.at(next_upload_index_); | 488 printer_list_.at(next_upload_index_); |
461 | 489 |
462 last_uploaded_printer_name_ = info.printer_name; | 490 last_uploaded_printer_name_ = info.printer_name; |
463 last_uploaded_printer_info_ = caps_and_defaults; | 491 last_uploaded_printer_info_ = caps_and_defaults; |
464 | 492 |
465 std::string mime_boundary; | |
466 CloudPrintHelpers::CreateMimeBoundaryForUpload(&mime_boundary); | |
467 std::string post_data; | |
468 CloudPrintHelpers::AddMultipartValueForUpload(kProxyIdValue, proxy_id_, | 493 CloudPrintHelpers::AddMultipartValueForUpload(kProxyIdValue, proxy_id_, |
469 mime_boundary, | 494 mime_boundary, |
470 std::string(), &post_data); | 495 std::string(), &post_data); |
471 CloudPrintHelpers::AddMultipartValueForUpload(kPrinterNameValue, | 496 CloudPrintHelpers::AddMultipartValueForUpload(kPrinterNameValue, |
472 info.printer_name, | 497 info.printer_name, |
473 mime_boundary, | 498 mime_boundary, |
474 std::string(), &post_data); | 499 std::string(), &post_data); |
475 CloudPrintHelpers::AddMultipartValueForUpload(kPrinterDescValue, | 500 CloudPrintHelpers::AddMultipartValueForUpload(kPrinterDescValue, |
476 info.printer_description, | 501 info.printer_description, |
477 mime_boundary, | 502 mime_boundary, |
(...skipping 13 matching lines...) Expand all Loading... | |
491 CloudPrintHelpers::AddMultipartValueForUpload( | 516 CloudPrintHelpers::AddMultipartValueForUpload( |
492 kPrinterDefaultsValue, last_uploaded_printer_info_.printer_defaults, | 517 kPrinterDefaultsValue, last_uploaded_printer_info_.printer_defaults, |
493 mime_boundary, last_uploaded_printer_info_.defaults_mime_type, | 518 mime_boundary, last_uploaded_printer_info_.defaults_mime_type, |
494 &post_data); | 519 &post_data); |
495 // Send a hash of the printer capabilities to the server. We will use this | 520 // Send a hash of the printer capabilities to the server. We will use this |
496 // later to check if the capabilities have changed | 521 // later to check if the capabilities have changed |
497 CloudPrintHelpers::AddMultipartValueForUpload( | 522 CloudPrintHelpers::AddMultipartValueForUpload( |
498 kPrinterCapsHashValue, | 523 kPrinterCapsHashValue, |
499 MD5String(last_uploaded_printer_info_.printer_capabilities), | 524 MD5String(last_uploaded_printer_info_.printer_capabilities), |
500 mime_boundary, std::string(), &post_data); | 525 mime_boundary, std::string(), &post_data); |
501 // Terminate the request body | 526 post_url = CloudPrintHelpers::GetUrlForPrinterRegistration( |
502 post_data.append("--" + mime_boundary + "--\r\n"); | |
503 std::string mime_type("multipart/form-data; boundary="); | |
504 mime_type += mime_boundary; | |
505 GURL register_url = CloudPrintHelpers::GetUrlForPrinterRegistration( | |
506 cloud_print_server_url_); | 527 cloud_print_server_url_); |
507 | 528 |
508 next_response_handler_ = | 529 next_response_handler_ = |
509 &CloudPrintProxyBackend::Core::HandleRegisterPrinterResponse; | 530 &CloudPrintProxyBackend::Core::HandleRegisterPrinterResponse; |
510 request_ = new CloudPrintURLFetcher; | |
511 request_->StartPostRequest(register_url, this, auth_token_, | |
512 kCloudPrintAPIMaxRetryCount, mime_type, | |
513 post_data); | |
514 } else { | 531 } else { |
515 LOG(ERROR) << "CP_PROXY: Failed to get printer info for: " << | 532 LOG(ERROR) << "CP_PROXY: Failed to get printer info for: " << |
516 printer_name; | 533 printer_name; |
517 next_upload_index_++; | 534 // This printer failed to register, notify the server of this failure. |
518 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(this, | 535 post_url = CloudPrintHelpers::GetUrlForUserMessage( |
519 &CloudPrintProxyBackend::Core::RegisterNextPrinter)); | 536 cloud_print_server_url_, |
537 kGetPrinterCapsFailedMessageId); | |
538 string16 printer_name_utf16 = UTF8ToUTF16(printer_name); | |
539 std::string status_message = l10n_util::GetStringFUTF8( | |
540 IDS_CLOUD_PRINT_REGISTER_PRINTER_FAILED, | |
541 printer_name_utf16); | |
542 CloudPrintHelpers::AddMultipartValueForUpload(kMessageTextValue, | |
543 status_message, | |
544 mime_boundary, | |
545 std::string(), | |
546 &post_data); | |
547 next_response_handler_ = | |
548 &CloudPrintProxyBackend::Core::HandleRegisterFailedStatusResponse; | |
520 } | 549 } |
550 // Terminate the request body | |
551 post_data.append("--" + mime_boundary + "--\r\n"); | |
552 std::string mime_type("multipart/form-data; boundary="); | |
553 mime_type += mime_boundary; | |
554 request_ = new CloudPrintURLFetcher; | |
555 request_->StartPostRequest(post_url, this, auth_token_, | |
556 kCloudPrintAPIMaxRetryCount, mime_type, | |
557 post_data); | |
521 } | 558 } |
522 | 559 |
523 void CloudPrintProxyBackend::Core::HandlePrinterNotification( | 560 void CloudPrintProxyBackend::Core::HandlePrinterNotification( |
524 const std::string& printer_id) { | 561 const std::string& printer_id) { |
525 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); | 562 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); |
526 VLOG(1) << "CP_PROXY: Handle printer notification, id: " << printer_id; | 563 VLOG(1) << "CP_PROXY: Handle printer notification, id: " << printer_id; |
527 JobHandlerMap::iterator index = job_handler_map_.find(printer_id); | 564 JobHandlerMap::iterator index = job_handler_map_.find(printer_id); |
528 if (index != job_handler_map_.end()) | 565 if (index != job_handler_map_.end()) |
529 index->second->CheckForJobs(kJobFetchReasonNotified); | 566 index->second->CheckForJobs(kJobFetchReasonNotified); |
530 } | 567 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
588 DCHECK(MessageLoop::current() == backend_->frontend_loop_); | 625 DCHECK(MessageLoop::current() == backend_->frontend_loop_); |
589 backend_->frontend_->OnAuthenticated(cloud_print_token, | 626 backend_->frontend_->OnAuthenticated(cloud_print_token, |
590 cloud_print_xmpp_token, email); | 627 cloud_print_xmpp_token, email); |
591 } | 628 } |
592 | 629 |
593 void CloudPrintProxyBackend::Core::NotifyAuthenticationFailed() { | 630 void CloudPrintProxyBackend::Core::NotifyAuthenticationFailed() { |
594 DCHECK(MessageLoop::current() == backend_->frontend_loop_); | 631 DCHECK(MessageLoop::current() == backend_->frontend_loop_); |
595 backend_->frontend_->OnAuthenticationFailed(); | 632 backend_->frontend_->OnAuthenticationFailed(); |
596 } | 633 } |
597 | 634 |
635 void CloudPrintProxyBackend::Core::NotifyPrintSystemUnavailable() { | |
636 DCHECK(MessageLoop::current() == backend_->frontend_loop_); | |
637 backend_->frontend_->OnPrintSystemUnavailable(); | |
638 } | |
639 | |
598 CloudPrintURLFetcher::ResponseAction | 640 CloudPrintURLFetcher::ResponseAction |
599 CloudPrintProxyBackend::Core::HandlePrinterListResponse( | 641 CloudPrintProxyBackend::Core::HandlePrinterListResponse( |
600 const URLFetcher* source, | 642 const URLFetcher* source, |
601 const GURL& url, | 643 const GURL& url, |
602 DictionaryValue* json_data, | 644 DictionaryValue* json_data, |
603 bool succeeded) { | 645 bool succeeded) { |
604 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); | 646 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); |
605 if (!succeeded) { | 647 if (!succeeded) { |
606 NOTREACHED(); | 648 NOTREACHED(); |
607 return CloudPrintURLFetcher::RETRY_REQUEST; | 649 return CloudPrintURLFetcher::RETRY_REQUEST; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
677 } | 719 } |
678 scoped_refptr<PrinterJobHandler> job_handler; | 720 scoped_refptr<PrinterJobHandler> job_handler; |
679 job_handler = new PrinterJobHandler(printer_info, printer_info_cloud, | 721 job_handler = new PrinterJobHandler(printer_info, printer_info_cloud, |
680 auth_token_, cloud_print_server_url_, | 722 auth_token_, cloud_print_server_url_, |
681 print_system_.get(), this); | 723 print_system_.get(), this); |
682 job_handler_map_[printer_info_cloud.printer_id] = job_handler; | 724 job_handler_map_[printer_info_cloud.printer_id] = job_handler; |
683 job_handler->Initialize(); | 725 job_handler->Initialize(); |
684 } | 726 } |
685 } | 727 } |
686 | 728 |
729 void CloudPrintProxyBackend::Core::ReportPrintSystemUnavailable( | |
730 const std::string& failure_message) { | |
731 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); | |
732 std::string mime_boundary; | |
733 CloudPrintHelpers::CreateMimeBoundaryForUpload(&mime_boundary); | |
734 GURL post_url = CloudPrintHelpers::GetUrlForUserMessage( | |
735 cloud_print_server_url_, | |
736 kPrintSystemFailedMessageId); | |
737 std::string post_data; | |
738 CloudPrintHelpers::AddMultipartValueForUpload(kMessageTextValue, | |
739 failure_message, | |
740 mime_boundary, | |
741 std::string(), | |
742 &post_data); | |
743 next_response_handler_ = | |
744 &CloudPrintProxyBackend::Core::HandlePrintSystemUnavailableResponse; | |
745 // Terminate the request body | |
Scott Byer
2011/01/20 19:09:03
nit: indentation
| |
746 post_data.append("--" + mime_boundary + "--\r\n"); | |
747 std::string mime_type("multipart/form-data; boundary="); | |
748 mime_type += mime_boundary; | |
749 request_ = new CloudPrintURLFetcher; | |
750 request_->StartPostRequest(post_url, this, auth_token_, | |
751 kCloudPrintAPIMaxRetryCount, mime_type, | |
752 post_data); | |
753 } | |
754 | |
687 CloudPrintURLFetcher::ResponseAction | 755 CloudPrintURLFetcher::ResponseAction |
688 CloudPrintProxyBackend::Core::HandleRegisterPrinterResponse( | 756 CloudPrintProxyBackend::Core::HandleRegisterPrinterResponse( |
689 const URLFetcher* source, | 757 const URLFetcher* source, |
690 const GURL& url, | 758 const GURL& url, |
691 DictionaryValue* json_data, | 759 DictionaryValue* json_data, |
692 bool succeeded) { | 760 bool succeeded) { |
693 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); | 761 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); |
694 if (succeeded) { | 762 if (succeeded) { |
695 ListValue* printer_list = NULL; | 763 ListValue* printer_list = NULL; |
696 json_data->GetList(kPrinterListValue, &printer_list); | 764 json_data->GetList(kPrinterListValue, &printer_list); |
697 // There should be a "printers" value in the JSON | 765 // There should be a "printers" value in the JSON |
698 DCHECK(printer_list); | 766 DCHECK(printer_list); |
699 if (printer_list) { | 767 if (printer_list) { |
700 DictionaryValue* printer_data = NULL; | 768 DictionaryValue* printer_data = NULL; |
701 if (printer_list->GetDictionary(0, &printer_data)) | 769 if (printer_list->GetDictionary(0, &printer_data)) |
702 InitJobHandlerForPrinter(printer_data); | 770 InitJobHandlerForPrinter(printer_data); |
703 } | 771 } |
704 } | 772 } |
705 next_upload_index_++; | 773 next_upload_index_++; |
706 MessageLoop::current()->PostTask( | 774 MessageLoop::current()->PostTask( |
707 FROM_HERE, | 775 FROM_HERE, |
708 NewRunnableMethod(this, | 776 NewRunnableMethod(this, |
709 &CloudPrintProxyBackend::Core::RegisterNextPrinter)); | 777 &CloudPrintProxyBackend::Core::RegisterNextPrinter)); |
710 return CloudPrintURLFetcher::STOP_PROCESSING; | 778 return CloudPrintURLFetcher::STOP_PROCESSING; |
711 } | 779 } |
712 | 780 |
781 CloudPrintURLFetcher::ResponseAction | |
782 CloudPrintProxyBackend::Core::HandleRegisterFailedStatusResponse( | |
783 const URLFetcher* source, | |
784 const GURL& url, | |
785 DictionaryValue* json_data, | |
786 bool succeeded) { | |
787 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); | |
788 next_upload_index_++; | |
789 MessageLoop::current()->PostTask( | |
790 FROM_HERE, | |
791 NewRunnableMethod(this, | |
792 &CloudPrintProxyBackend::Core::RegisterNextPrinter)); | |
793 return CloudPrintURLFetcher::STOP_PROCESSING; | |
794 } | |
795 | |
796 CloudPrintURLFetcher::ResponseAction | |
797 CloudPrintProxyBackend::Core::HandlePrintSystemUnavailableResponse( | |
798 const URLFetcher* source, | |
799 const GURL& url, | |
800 DictionaryValue* json_data, | |
801 bool succeeded) { | |
802 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); | |
803 // Let the frontend know that we do not have a print system. | |
804 backend_->frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, | |
Scott Byer
2011/01/20 19:09:03
nit: indentation clearer in HandleRegisterFailedSt
| |
805 &Core::NotifyPrintSystemUnavailable)); | |
806 return CloudPrintURLFetcher::STOP_PROCESSING; | |
807 } | |
808 | |
713 bool CloudPrintProxyBackend::Core::RemovePrinterFromList( | 809 bool CloudPrintProxyBackend::Core::RemovePrinterFromList( |
714 const std::string& printer_name) { | 810 const std::string& printer_name) { |
715 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); | 811 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); |
716 for (printing::PrinterList::iterator index = printer_list_.begin(); | 812 for (printing::PrinterList::iterator index = printer_list_.begin(); |
717 index != printer_list_.end(); index++) { | 813 index != printer_list_.end(); index++) { |
718 if (0 == base::strcasecmp(index->printer_name.c_str(), | 814 if (0 == base::strcasecmp(index->printer_name.c_str(), |
719 printer_name.c_str())) { | 815 printer_name.c_str())) { |
720 index = printer_list_.erase(index); | 816 index = printer_list_.erase(index); |
721 return true; | 817 return true; |
722 } | 818 } |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
779 VLOG(1) << "CP_PROXY: Printer job handle shutdown, id " << printer_id; | 875 VLOG(1) << "CP_PROXY: Printer job handle shutdown, id " << printer_id; |
780 job_handler_map_.erase(printer_id); | 876 job_handler_map_.erase(printer_id); |
781 } | 877 } |
782 | 878 |
783 void CloudPrintProxyBackend::Core::OnAuthError() { | 879 void CloudPrintProxyBackend::Core::OnAuthError() { |
784 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); | 880 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); |
785 VLOG(1) << "CP_PROXY: Auth Error"; | 881 VLOG(1) << "CP_PROXY: Auth Error"; |
786 backend_->frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, | 882 backend_->frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, |
787 &Core::NotifyAuthenticationFailed)); | 883 &Core::NotifyAuthenticationFailed)); |
788 } | 884 } |
OLD | NEW |