| 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> |
| 8 #include <vector> |
| 9 |
| 7 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 8 #include "base/md5.h" | 11 #include "base/md5.h" |
| 9 #include "base/rand_util.h" | 12 #include "base/rand_util.h" |
| 10 #include "base/string_split.h" | 13 #include "base/string_split.h" |
| 11 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 12 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 13 #include "base/values.h" | 16 #include "base/values.h" |
| 14 #include "chrome/common/net/http_return.h" | 17 #include "chrome/common/net/http_return.h" |
| 15 #include "chrome/service/cloud_print/cloud_print_consts.h" | 18 #include "chrome/service/cloud_print/cloud_print_consts.h" |
| 16 #include "chrome/service/cloud_print/cloud_print_helpers.h" | 19 #include "chrome/service/cloud_print/cloud_print_helpers.h" |
| 17 #include "chrome/service/cloud_print/printer_job_handler.h" | 20 #include "chrome/service/cloud_print/printer_job_handler.h" |
| 18 #include "chrome/service/gaia/service_gaia_authenticator.h" | 21 #include "chrome/service/gaia/service_gaia_authenticator.h" |
| 19 #include "chrome/service/service_process.h" | 22 #include "chrome/service/service_process.h" |
| 23 #include "googleurl/src/gurl.h" |
| 20 #include "jingle/notifier/base/notifier_options.h" | 24 #include "jingle/notifier/base/notifier_options.h" |
| 21 #include "jingle/notifier/listener/push_notifications_thread.h" | 25 #include "jingle/notifier/listener/push_notifications_thread.h" |
| 22 #include "jingle/notifier/listener/talk_mediator_impl.h" | 26 #include "jingle/notifier/listener/talk_mediator_impl.h" |
| 23 | |
| 24 #include "googleurl/src/gurl.h" | |
| 25 #include "net/url_request/url_request_status.h" | 27 #include "net/url_request/url_request_status.h" |
| 26 | 28 |
| 27 // The real guts of CloudPrintProxyBackend, to keep the public client API clean. | 29 // The real guts of CloudPrintProxyBackend, to keep the public client API clean. |
| 28 class CloudPrintProxyBackend::Core | 30 class CloudPrintProxyBackend::Core |
| 29 : public base::RefCountedThreadSafe<CloudPrintProxyBackend::Core>, | 31 : public base::RefCountedThreadSafe<CloudPrintProxyBackend::Core>, |
| 30 public URLFetcherDelegate, | 32 public URLFetcherDelegate, |
| 31 public cloud_print::PrintServerWatcherDelegate, | 33 public cloud_print::PrintServerWatcherDelegate, |
| 32 public PrinterJobHandlerDelegate, | 34 public PrinterJobHandlerDelegate, |
| 33 public notifier::TalkMediator::Delegate { | 35 public notifier::TalkMediator::Delegate { |
| 34 public: | 36 public: |
| (...skipping 16 matching lines...) Expand all Loading... |
| 51 const std::string& proxy_id); | 53 const std::string& proxy_id); |
| 52 void DoInitializeWithToken(const std::string cloud_print_token, | 54 void DoInitializeWithToken(const std::string cloud_print_token, |
| 53 const std::string cloud_print_xmpp_token, | 55 const std::string cloud_print_xmpp_token, |
| 54 const std::string email, | 56 const std::string email, |
| 55 const std::string& proxy_id); | 57 const std::string& proxy_id); |
| 56 | 58 |
| 57 // Called on the CloudPrintProxyBackend core_thread_ to perform | 59 // Called on the CloudPrintProxyBackend core_thread_ to perform |
| 58 // shutdown. | 60 // shutdown. |
| 59 void DoShutdown(); | 61 void DoShutdown(); |
| 60 void DoRegisterSelectedPrinters( | 62 void DoRegisterSelectedPrinters( |
| 61 const cloud_print::PrinterList& printer_list); | 63 const printing::PrinterList& printer_list); |
| 62 | 64 |
| 63 // URLFetcher::Delegate implementation. | 65 // URLFetcher::Delegate implementation. |
| 64 virtual void OnURLFetchComplete(const URLFetcher* source, const GURL& url, | 66 virtual void OnURLFetchComplete(const URLFetcher* source, const GURL& url, |
| 65 const URLRequestStatus& status, | 67 const URLRequestStatus& status, |
| 66 int response_code, | 68 int response_code, |
| 67 const ResponseCookies& cookies, | 69 const ResponseCookies& cookies, |
| 68 const std::string& data); | 70 const std::string& data); |
| 69 // cloud_print::PrintServerWatcherDelegate implementation | 71 // cloud_print::PrintServerWatcherDelegate implementation |
| 70 virtual void OnPrinterAdded(); | 72 virtual void OnPrinterAdded(); |
| 71 // PrinterJobHandler::Delegate implementation | 73 // PrinterJobHandler::Delegate implementation |
| (...skipping 24 matching lines...) Expand all Loading... |
| 96 const GURL& url, | 98 const GURL& url, |
| 97 const URLRequestStatus& status, | 99 const URLRequestStatus& status, |
| 98 int response_code, | 100 int response_code, |
| 99 const ResponseCookies& cookies, | 101 const ResponseCookies& cookies, |
| 100 const std::string& data); | 102 const std::string& data); |
| 101 // End response handlers | 103 // End response handlers |
| 102 | 104 |
| 103 // NotifyXXX is how the Core communicates with the frontend across | 105 // NotifyXXX is how the Core communicates with the frontend across |
| 104 // threads. | 106 // threads. |
| 105 void NotifyPrinterListAvailable( | 107 void NotifyPrinterListAvailable( |
| 106 const cloud_print::PrinterList& printer_list); | 108 const printing::PrinterList& printer_list); |
| 107 void NotifyAuthenticated( | 109 void NotifyAuthenticated( |
| 108 const std::string& cloud_print_token, | 110 const std::string& cloud_print_token, |
| 109 const std::string& cloud_print_xmpp_token, | 111 const std::string& cloud_print_xmpp_token, |
| 110 const std::string& email); | 112 const std::string& email); |
| 111 void NotifyAuthenticationFailed(); | 113 void NotifyAuthenticationFailed(); |
| 112 | 114 |
| 113 // Starts a new printer registration process. | 115 // Starts a new printer registration process. |
| 114 void StartRegistration(); | 116 void StartRegistration(); |
| 115 // Ends the printer registration process. | 117 // Ends the printer registration process. |
| 116 void EndRegistration(); | 118 void EndRegistration(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 142 scoped_ptr<DictionaryValue> print_system_settings_; | 144 scoped_ptr<DictionaryValue> print_system_settings_; |
| 143 // Pointer to current print system. | 145 // Pointer to current print system. |
| 144 scoped_refptr<cloud_print::PrintSystem> print_system_; | 146 scoped_refptr<cloud_print::PrintSystem> print_system_; |
| 145 // The list of printers to be registered with the cloud print server. | 147 // The list of printers to be registered with the cloud print server. |
| 146 // To begin with,this list is initialized with the list of local and network | 148 // To begin with,this list is initialized with the list of local and network |
| 147 // printers available. Then we query the server for the list of printers | 149 // printers available. Then we query the server for the list of printers |
| 148 // already registered. We trim this list to remove the printers already | 150 // already registered. We trim this list to remove the printers already |
| 149 // registered. We then pass a copy of this list to the frontend to give the | 151 // registered. We then pass a copy of this list to the frontend to give the |
| 150 // user a chance to further trim the list. When the frontend gives us the | 152 // user a chance to further trim the list. When the frontend gives us the |
| 151 // final list we make a copy into this so that we can start registering. | 153 // final list we make a copy into this so that we can start registering. |
| 152 cloud_print::PrinterList printer_list_; | 154 printing::PrinterList printer_list_; |
| 153 // The URLFetcher instance for the current request | 155 // The URLFetcher instance for the current request |
| 154 scoped_ptr<URLFetcher> request_; | 156 scoped_ptr<URLFetcher> request_; |
| 155 // The index of the nex printer to be uploaded. | 157 // The index of the nex printer to be uploaded. |
| 156 size_t next_upload_index_; | 158 size_t next_upload_index_; |
| 157 // The unique id for this proxy | 159 // The unique id for this proxy |
| 158 std::string proxy_id_; | 160 std::string proxy_id_; |
| 159 // The GAIA auth token | 161 // The GAIA auth token |
| 160 std::string auth_token_; | 162 std::string auth_token_; |
| 161 // The number of consecutive times that connecting to the server failed. | 163 // The number of consecutive times that connecting to the server failed. |
| 162 int server_error_count_; | 164 int server_error_count_; |
| 163 // Cached info about the last printer that we tried to upload. We cache this | 165 // Cached info about the last printer that we tried to upload. We cache this |
| 164 // so we won't have to requery the printer if the upload fails and we need | 166 // so we won't have to requery the printer if the upload fails and we need |
| 165 // to retry. | 167 // to retry. |
| 166 std::string last_uploaded_printer_name_; | 168 std::string last_uploaded_printer_name_; |
| 167 cloud_print::PrinterCapsAndDefaults last_uploaded_printer_info_; | 169 printing::PrinterCapsAndDefaults last_uploaded_printer_info_; |
| 168 // A map of printer id to job handler. | 170 // A map of printer id to job handler. |
| 169 typedef std::map<std::string, scoped_refptr<PrinterJobHandler> > | 171 typedef std::map<std::string, scoped_refptr<PrinterJobHandler> > |
| 170 JobHandlerMap; | 172 JobHandlerMap; |
| 171 JobHandlerMap job_handler_map_; | 173 JobHandlerMap job_handler_map_; |
| 172 ResponseHandler next_response_handler_; | 174 ResponseHandler next_response_handler_; |
| 173 scoped_refptr<cloud_print::PrintSystem::PrintServerWatcher> | 175 scoped_refptr<cloud_print::PrintSystem::PrintServerWatcher> |
| 174 print_server_watcher_; | 176 print_server_watcher_; |
| 175 bool new_printers_available_; | 177 bool new_printers_available_; |
| 176 // Notification (xmpp) handler. | 178 // Notification (xmpp) handler. |
| 177 scoped_ptr<notifier::TalkMediator> talk_mediator_; | 179 scoped_ptr<notifier::TalkMediator> talk_mediator_; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 | 230 |
| 229 void CloudPrintProxyBackend::Shutdown() { | 231 void CloudPrintProxyBackend::Shutdown() { |
| 230 core_thread_.message_loop()->PostTask(FROM_HERE, | 232 core_thread_.message_loop()->PostTask(FROM_HERE, |
| 231 NewRunnableMethod(core_.get(), | 233 NewRunnableMethod(core_.get(), |
| 232 &CloudPrintProxyBackend::Core::DoShutdown)); | 234 &CloudPrintProxyBackend::Core::DoShutdown)); |
| 233 core_thread_.Stop(); | 235 core_thread_.Stop(); |
| 234 core_ = NULL; // Releases reference to core_. | 236 core_ = NULL; // Releases reference to core_. |
| 235 } | 237 } |
| 236 | 238 |
| 237 void CloudPrintProxyBackend::RegisterPrinters( | 239 void CloudPrintProxyBackend::RegisterPrinters( |
| 238 const cloud_print::PrinterList& printer_list) { | 240 const printing::PrinterList& printer_list) { |
| 239 core_thread_.message_loop()->PostTask(FROM_HERE, | 241 core_thread_.message_loop()->PostTask(FROM_HERE, |
| 240 NewRunnableMethod( | 242 NewRunnableMethod( |
| 241 core_.get(), | 243 core_.get(), |
| 242 &CloudPrintProxyBackend::Core::DoRegisterSelectedPrinters, | 244 &CloudPrintProxyBackend::Core::DoRegisterSelectedPrinters, |
| 243 printer_list)); | 245 printer_list)); |
| 244 } | 246 } |
| 245 | 247 |
| 246 CloudPrintProxyBackend::Core::Core(CloudPrintProxyBackend* backend, | 248 CloudPrintProxyBackend::Core::Core(CloudPrintProxyBackend* backend, |
| 247 const GURL& cloud_print_server_url, | 249 const GURL& cloud_print_server_url, |
| 248 const DictionaryValue* print_system_settings) | 250 const DictionaryValue* print_system_settings) |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 print_server_watcher_ = print_system_->CreatePrintServerWatcher(); | 339 print_server_watcher_ = print_system_->CreatePrintServerWatcher(); |
| 338 print_server_watcher_->StartWatching(this); | 340 print_server_watcher_->StartWatching(this); |
| 339 | 341 |
| 340 proxy_id_ = proxy_id; | 342 proxy_id_ = proxy_id; |
| 341 StartRegistration(); | 343 StartRegistration(); |
| 342 } | 344 } |
| 343 | 345 |
| 344 void CloudPrintProxyBackend::Core::StartRegistration() { | 346 void CloudPrintProxyBackend::Core::StartRegistration() { |
| 345 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); | 347 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); |
| 346 printer_list_.clear(); | 348 printer_list_.clear(); |
| 347 print_system_->EnumeratePrinters(&printer_list_); | 349 print_system_->GetPrintBackend()->EnumeratePrinters(&printer_list_); |
| 348 server_error_count_ = 0; | 350 server_error_count_ = 0; |
| 349 // Now we need to ask the server about printers that were registered on the | 351 // Now we need to ask the server about printers that were registered on the |
| 350 // server so that we can trim this list. | 352 // server so that we can trim this list. |
| 351 GetRegisteredPrinters(); | 353 GetRegisteredPrinters(); |
| 352 } | 354 } |
| 353 | 355 |
| 354 void CloudPrintProxyBackend::Core::EndRegistration() { | 356 void CloudPrintProxyBackend::Core::EndRegistration() { |
| 355 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); | 357 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); |
| 356 request_.reset(); | 358 request_.reset(); |
| 357 if (new_printers_available_) { | 359 if (new_printers_available_) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 374 index->second->Shutdown(); | 376 index->second->Shutdown(); |
| 375 } | 377 } |
| 376 // Important to delete the TalkMediator on this thread. | 378 // Important to delete the TalkMediator on this thread. |
| 377 talk_mediator_.reset(); | 379 talk_mediator_.reset(); |
| 378 notifications_enabled_ = false; | 380 notifications_enabled_ = false; |
| 379 request_.reset(); | 381 request_.reset(); |
| 380 MessageLoop::current()->QuitNow(); | 382 MessageLoop::current()->QuitNow(); |
| 381 } | 383 } |
| 382 | 384 |
| 383 void CloudPrintProxyBackend::Core::DoRegisterSelectedPrinters( | 385 void CloudPrintProxyBackend::Core::DoRegisterSelectedPrinters( |
| 384 const cloud_print::PrinterList& printer_list) { | 386 const printing::PrinterList& printer_list) { |
| 385 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); | 387 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); |
| 386 if (!print_system_.get()) | 388 if (!print_system_.get()) |
| 387 return; // No print system available. | 389 return; // No print system available. |
| 388 server_error_count_ = 0; | 390 server_error_count_ = 0; |
| 389 printer_list_.assign(printer_list.begin(), printer_list.end()); | 391 printer_list_.assign(printer_list.begin(), printer_list.end()); |
| 390 next_upload_index_ = 0; | 392 next_upload_index_ = 0; |
| 391 RegisterNextPrinter(); | 393 RegisterNextPrinter(); |
| 392 } | 394 } |
| 393 | 395 |
| 394 void CloudPrintProxyBackend::Core::GetRegisteredPrinters() { | 396 void CloudPrintProxyBackend::Core::GetRegisteredPrinters() { |
| 395 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); | 397 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); |
| 396 request_.reset( | 398 request_.reset( |
| 397 new URLFetcher( | 399 new URLFetcher( |
| 398 CloudPrintHelpers::GetUrlForPrinterList(cloud_print_server_url_, | 400 CloudPrintHelpers::GetUrlForPrinterList(cloud_print_server_url_, |
| 399 proxy_id_), | 401 proxy_id_), |
| 400 URLFetcher::GET, this)); | 402 URLFetcher::GET, this)); |
| 401 CloudPrintHelpers::PrepCloudPrintRequest(request_.get(), auth_token_); | 403 CloudPrintHelpers::PrepCloudPrintRequest(request_.get(), auth_token_); |
| 402 next_response_handler_ = | 404 next_response_handler_ = |
| 403 &CloudPrintProxyBackend::Core::HandlePrinterListResponse; | 405 &CloudPrintProxyBackend::Core::HandlePrinterListResponse; |
| 404 request_->Start(); | 406 request_->Start(); |
| 405 } | 407 } |
| 406 | 408 |
| 407 void CloudPrintProxyBackend::Core::RegisterNextPrinter() { | 409 void CloudPrintProxyBackend::Core::RegisterNextPrinter() { |
| 408 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); | 410 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); |
| 409 // For the next printer to be uploaded, create a multi-part post request to | 411 // For the next printer to be uploaded, create a multi-part post request to |
| 410 // upload the printer capabilities and the printer defaults. | 412 // upload the printer capabilities and the printer defaults. |
| 411 if (next_upload_index_ < printer_list_.size()) { | 413 if (next_upload_index_ < printer_list_.size()) { |
| 412 const cloud_print::PrinterBasicInfo& info = | 414 const printing::PrinterBasicInfo& info = |
| 413 printer_list_.at(next_upload_index_); | 415 printer_list_.at(next_upload_index_); |
| 414 bool have_printer_info = true; | 416 bool have_printer_info = true; |
| 415 // If we are retrying a previous upload, we don't need to fetch the caps | 417 // If we are retrying a previous upload, we don't need to fetch the caps |
| 416 // and defaults again. | 418 // and defaults again. |
| 417 if (info.printer_name != last_uploaded_printer_name_) { | 419 if (info.printer_name != last_uploaded_printer_name_) { |
| 418 have_printer_info = print_system_->GetPrinterCapsAndDefaults( | 420 have_printer_info = |
| 419 info.printer_name.c_str(), &last_uploaded_printer_info_); | 421 print_system_->GetPrintBackend()->GetPrinterCapsAndDefaults( |
| 422 info.printer_name.c_str(), &last_uploaded_printer_info_); |
| 420 } | 423 } |
| 421 if (have_printer_info) { | 424 if (have_printer_info) { |
| 422 last_uploaded_printer_name_ = info.printer_name; | 425 last_uploaded_printer_name_ = info.printer_name; |
| 423 std::string mime_boundary; | 426 std::string mime_boundary; |
| 424 CloudPrintHelpers::CreateMimeBoundaryForUpload(&mime_boundary); | 427 CloudPrintHelpers::CreateMimeBoundaryForUpload(&mime_boundary); |
| 425 std::string post_data; | 428 std::string post_data; |
| 426 CloudPrintHelpers::AddMultipartValueForUpload(kProxyIdValue, proxy_id_, | 429 CloudPrintHelpers::AddMultipartValueForUpload(kProxyIdValue, proxy_id_, |
| 427 mime_boundary, | 430 mime_boundary, |
| 428 std::string(), &post_data); | 431 std::string(), &post_data); |
| 429 CloudPrintHelpers::AddMultipartValueForUpload(kPrinterNameValue, | 432 CloudPrintHelpers::AddMultipartValueForUpload(kPrinterNameValue, |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 &Core::NotifyAuthenticationFailed)); | 532 &Core::NotifyAuthenticationFailed)); |
| 530 } else { | 533 } else { |
| 531 // We need a next response handler | 534 // We need a next response handler |
| 532 DCHECK(next_response_handler_); | 535 DCHECK(next_response_handler_); |
| 533 (this->*next_response_handler_)(source, url, status, response_code, | 536 (this->*next_response_handler_)(source, url, status, response_code, |
| 534 cookies, data); | 537 cookies, data); |
| 535 } | 538 } |
| 536 } | 539 } |
| 537 | 540 |
| 538 void CloudPrintProxyBackend::Core::NotifyPrinterListAvailable( | 541 void CloudPrintProxyBackend::Core::NotifyPrinterListAvailable( |
| 539 const cloud_print::PrinterList& printer_list) { | 542 const printing::PrinterList& printer_list) { |
| 540 DCHECK(MessageLoop::current() == backend_->frontend_loop_); | 543 DCHECK(MessageLoop::current() == backend_->frontend_loop_); |
| 541 backend_->frontend_->OnPrinterListAvailable(printer_list); | 544 backend_->frontend_->OnPrinterListAvailable(printer_list); |
| 542 } | 545 } |
| 543 | 546 |
| 544 void CloudPrintProxyBackend::Core::NotifyAuthenticated( | 547 void CloudPrintProxyBackend::Core::NotifyAuthenticated( |
| 545 const std::string& cloud_print_token, | 548 const std::string& cloud_print_token, |
| 546 const std::string& cloud_print_xmpp_token, | 549 const std::string& cloud_print_xmpp_token, |
| 547 const std::string& email) { | 550 const std::string& email) { |
| 548 DCHECK(MessageLoop::current() == backend_->frontend_loop_); | 551 DCHECK(MessageLoop::current() == backend_->frontend_loop_); |
| 549 backend_->frontend_->OnAuthenticated(cloud_print_token, | 552 backend_->frontend_->OnAuthenticated(cloud_print_token, |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 610 DCHECK(printer_data); | 613 DCHECK(printer_data); |
| 611 PrinterJobHandler::PrinterInfoFromCloud printer_info_cloud; | 614 PrinterJobHandler::PrinterInfoFromCloud printer_info_cloud; |
| 612 printer_data->GetString(kIdValue, &printer_info_cloud.printer_id); | 615 printer_data->GetString(kIdValue, &printer_info_cloud.printer_id); |
| 613 DCHECK(!printer_info_cloud.printer_id.empty()); | 616 DCHECK(!printer_info_cloud.printer_id.empty()); |
| 614 VLOG(1) << "CP_PROXY: Init job handler for printer id: " | 617 VLOG(1) << "CP_PROXY: Init job handler for printer id: " |
| 615 << printer_info_cloud.printer_id; | 618 << printer_info_cloud.printer_id; |
| 616 JobHandlerMap::iterator index = job_handler_map_.find( | 619 JobHandlerMap::iterator index = job_handler_map_.find( |
| 617 printer_info_cloud.printer_id); | 620 printer_info_cloud.printer_id); |
| 618 // We might already have a job handler for this printer | 621 // We might already have a job handler for this printer |
| 619 if (index == job_handler_map_.end()) { | 622 if (index == job_handler_map_.end()) { |
| 620 cloud_print::PrinterBasicInfo printer_info; | 623 printing::PrinterBasicInfo printer_info; |
| 621 printer_data->GetString(kNameValue, &printer_info.printer_name); | 624 printer_data->GetString(kNameValue, &printer_info.printer_name); |
| 622 DCHECK(!printer_info.printer_name.empty()); | 625 DCHECK(!printer_info.printer_name.empty()); |
| 623 printer_data->GetString(kPrinterDescValue, | 626 printer_data->GetString(kPrinterDescValue, |
| 624 &printer_info.printer_description); | 627 &printer_info.printer_description); |
| 625 printer_data->GetInteger(kPrinterStatusValue, | 628 printer_data->GetInteger(kPrinterStatusValue, |
| 626 &printer_info.printer_status); | 629 &printer_info.printer_status); |
| 627 printer_data->GetString(kPrinterCapsHashValue, | 630 printer_data->GetString(kPrinterCapsHashValue, |
| 628 &printer_info_cloud.caps_hash); | 631 &printer_info_cloud.caps_hash); |
| 629 ListValue* tags_list = NULL; | 632 ListValue* tags_list = NULL; |
| 630 printer_data->GetList(kPrinterTagsValue, &tags_list); | 633 printer_data->GetList(kPrinterTagsValue, &tags_list); |
| 631 if (tags_list) { | 634 if (tags_list) { |
| 632 for (size_t index = 0; index < tags_list->GetSize(); index++) { | 635 for (size_t index = 0; index < tags_list->GetSize(); index++) { |
| 633 std::string tag; | 636 std::string tag; |
| 634 tags_list->GetString(index, &tag); | 637 tags_list->GetString(index, &tag); |
| 635 if (StartsWithASCII(tag, kTagsHashTagName, false)) { | 638 if (StartsWithASCII(tag, kTagsHashTagName, false)) { |
| 636 std::vector<std::string> tag_parts; | 639 std::vector<std::string> tag_parts; |
| 637 base::SplitStringDontTrim(tag, '=', &tag_parts); | 640 base::SplitStringDontTrim(tag, '=', &tag_parts); |
| 638 DCHECK(tag_parts.size() == 2); | 641 DCHECK_EQ(tag_parts.size(), 2U); |
| 639 if (tag_parts.size() == 2) | 642 if (tag_parts.size() == 2) |
| 640 printer_info_cloud.tags_hash = tag_parts[1]; | 643 printer_info_cloud.tags_hash = tag_parts[1]; |
| 641 } | 644 } |
| 642 } | 645 } |
| 643 } | 646 } |
| 644 scoped_refptr<PrinterJobHandler> job_handler; | 647 scoped_refptr<PrinterJobHandler> job_handler; |
| 645 job_handler = new PrinterJobHandler(printer_info, printer_info_cloud, | 648 job_handler = new PrinterJobHandler(printer_info, printer_info_cloud, |
| 646 auth_token_, cloud_print_server_url_, | 649 auth_token_, cloud_print_server_url_, |
| 647 print_system_.get(), this); | 650 print_system_.get(), this); |
| 648 job_handler_map_[printer_info_cloud.printer_id] = job_handler; | 651 job_handler_map_[printer_info_cloud.printer_id] = job_handler; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); | 691 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); |
| 689 VLOG(1) << "CP_PROXY: Server error."; | 692 VLOG(1) << "CP_PROXY: Server error."; |
| 690 CloudPrintHelpers::HandleServerError( | 693 CloudPrintHelpers::HandleServerError( |
| 691 &server_error_count_, -1, kMaxRetryInterval, kBaseRetryInterval, | 694 &server_error_count_, -1, kMaxRetryInterval, kBaseRetryInterval, |
| 692 task_to_retry, NULL); | 695 task_to_retry, NULL); |
| 693 } | 696 } |
| 694 | 697 |
| 695 bool CloudPrintProxyBackend::Core::RemovePrinterFromList( | 698 bool CloudPrintProxyBackend::Core::RemovePrinterFromList( |
| 696 const std::string& printer_name) { | 699 const std::string& printer_name) { |
| 697 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); | 700 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); |
| 698 for (cloud_print::PrinterList::iterator index = printer_list_.begin(); | 701 for (printing::PrinterList::iterator index = printer_list_.begin(); |
| 699 index != printer_list_.end(); index++) { | 702 index != printer_list_.end(); index++) { |
| 700 if (0 == base::strcasecmp(index->printer_name.c_str(), | 703 if (0 == base::strcasecmp(index->printer_name.c_str(), |
| 701 printer_name.c_str())) { | 704 printer_name.c_str())) { |
| 702 index = printer_list_.erase(index); | 705 index = printer_list_.erase(index); |
| 703 return true; | 706 return true; |
| 704 } | 707 } |
| 705 } | 708 } |
| 706 return false; | 709 return false; |
| 707 } | 710 } |
| 708 | 711 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 751 VLOG(1) << "CP_PROXY: Printer job handle shutdown, id " << printer_id; | 754 VLOG(1) << "CP_PROXY: Printer job handle shutdown, id " << printer_id; |
| 752 job_handler_map_.erase(printer_id); | 755 job_handler_map_.erase(printer_id); |
| 753 } | 756 } |
| 754 | 757 |
| 755 void CloudPrintProxyBackend::Core::OnAuthError() { | 758 void CloudPrintProxyBackend::Core::OnAuthError() { |
| 756 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); | 759 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); |
| 757 VLOG(1) << "CP_PROXY: Auth Error"; | 760 VLOG(1) << "CP_PROXY: Auth Error"; |
| 758 backend_->frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, | 761 backend_->frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, |
| 759 &Core::NotifyAuthenticationFailed)); | 762 &Core::NotifyAuthenticationFailed)); |
| 760 } | 763 } |
| 761 | |
| OLD | NEW |