OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_connector.h" | 5 #include "chrome/service/cloud_print/cloud_print_connector.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/md5.h" | 9 #include "base/md5.h" |
10 #include "base/rand_util.h" | 10 #include "base/rand_util.h" |
11 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
12 #include "base/string_split.h" | 12 #include "base/string_split.h" |
13 #include "base/stringprintf.h" | 13 #include "base/stringprintf.h" |
14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
15 #include "base/values.h" | 15 #include "base/values.h" |
16 #include "chrome/common/cloud_print/cloud_print_constants.h" | |
16 #include "chrome/common/cloud_print/cloud_print_helpers.h" | 17 #include "chrome/common/cloud_print/cloud_print_helpers.h" |
17 #include "chrome/service/cloud_print/cloud_print_consts.h" | 18 #include "chrome/service/cloud_print/cloud_print_consts.h" |
msw
2012/11/17 00:22:30
Please remove if now unused.
Chen Yu
2012/11/26 12:07:06
Done.
| |
18 #include "chrome/service/cloud_print/cloud_print_helpers.h" | 19 #include "chrome/service/cloud_print/cloud_print_helpers.h" |
19 #include "grit/generated_resources.h" | 20 #include "grit/generated_resources.h" |
20 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
21 | 22 |
22 CloudPrintConnector::CloudPrintConnector(Client* client, | 23 CloudPrintConnector::CloudPrintConnector(Client* client, |
23 const ConnectorSettings& settings) | 24 const ConnectorSettings& settings) |
24 : client_(client), | 25 : client_(client), |
25 next_response_handler_(NULL) { | 26 next_response_handler_(NULL) { |
26 settings_.CopyFrom(settings); | 27 settings_.CopyFrom(settings); |
27 } | 28 } |
28 | 29 |
29 bool CloudPrintConnector::InitPrintSystem() { | 30 bool CloudPrintConnector::InitPrintSystem() { |
30 if (print_system_.get()) | 31 if (print_system_.get()) |
31 return true; | 32 return true; |
32 print_system_ = cloud_print::PrintSystem::CreateInstance( | 33 print_system_ = cloud_print::PrintSystem::CreateInstance( |
33 settings_.print_system_settings()); | 34 settings_.print_system_settings()); |
34 if (!print_system_.get()) { | 35 if (!print_system_.get()) { |
35 NOTREACHED(); | 36 NOTREACHED(); |
36 return false; // No memory. | 37 return false; // No memory. |
37 } | 38 } |
38 cloud_print::PrintSystem::PrintSystemResult result = print_system_->Init(); | 39 cloud_print::PrintSystem::PrintSystemResult result = print_system_->Init(); |
39 if (!result.succeeded()) { | 40 if (!result.succeeded()) { |
40 print_system_ = NULL; | 41 print_system_ = NULL; |
41 // We could not initialize the print system. We need to notify the server. | 42 // We could not initialize the print system. We need to notify the server. |
42 ReportUserMessage(kPrintSystemFailedMessageId, result.message()); | 43 ReportUserMessage(cloud_print::kPrintSystemFailedMessageId, |
msw
2012/11/17 00:22:30
nit: consider putting this file's contents in the
Chen Yu
2012/11/26 12:07:06
Done.
| |
44 result.message()); | |
43 return false; | 45 return false; |
44 } | 46 } |
45 return true; | 47 return true; |
46 } | 48 } |
47 | 49 |
48 bool CloudPrintConnector::Start() { | 50 bool CloudPrintConnector::Start() { |
49 VLOG(1) << "CP_CONNECTOR: Starting connector" | 51 VLOG(1) << "CP_CONNECTOR: Starting connector" |
50 << ", proxy id: " << settings_.proxy_id(); | 52 << ", proxy id: " << settings_.proxy_id(); |
51 | 53 |
52 pending_tasks_.clear(); | 54 pending_tasks_.clear(); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
104 return; | 106 return; |
105 if (!printer_id.empty()) { | 107 if (!printer_id.empty()) { |
106 JobHandlerMap::iterator index = job_handler_map_.find(printer_id); | 108 JobHandlerMap::iterator index = job_handler_map_.find(printer_id); |
107 if (index != job_handler_map_.end()) { | 109 if (index != job_handler_map_.end()) { |
108 index->second->CheckForJobs(reason); | 110 index->second->CheckForJobs(reason); |
109 } else { | 111 } else { |
110 std::string status_message = l10n_util::GetStringUTF8( | 112 std::string status_message = l10n_util::GetStringUTF8( |
111 IDS_CLOUD_PRINT_ZOMBIE_PRINTER); | 113 IDS_CLOUD_PRINT_ZOMBIE_PRINTER); |
112 LOG(ERROR) << "CP_CONNECTOR: " << status_message << | 114 LOG(ERROR) << "CP_CONNECTOR: " << status_message << |
113 " Printer_id: " << printer_id; | 115 " Printer_id: " << printer_id; |
114 ReportUserMessage(kZombiePrinterMessageId, status_message); | 116 ReportUserMessage(cloud_print::kZombiePrinterMessageId, status_message); |
115 } | 117 } |
116 } else { | 118 } else { |
117 for (JobHandlerMap::iterator index = job_handler_map_.begin(); | 119 for (JobHandlerMap::iterator index = job_handler_map_.begin(); |
118 index != job_handler_map_.end(); index++) { | 120 index != job_handler_map_.end(); index++) { |
119 index->second->CheckForJobs(reason); | 121 index->second->CheckForJobs(reason); |
120 } | 122 } |
121 } | 123 } |
122 } | 124 } |
123 | 125 |
124 void CloudPrintConnector::OnPrinterAdded() { | 126 void CloudPrintConnector::OnPrinterAdded() { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
189 printing::PrinterList local_printers; | 191 printing::PrinterList local_printers; |
190 cloud_print::PrintSystem::PrintSystemResult result = | 192 cloud_print::PrintSystem::PrintSystemResult result = |
191 print_system_->EnumeratePrinters(&local_printers); | 193 print_system_->EnumeratePrinters(&local_printers); |
192 bool full_list = result.succeeded(); | 194 bool full_list = result.succeeded(); |
193 if (!full_list) { | 195 if (!full_list) { |
194 std::string message = result.message(); | 196 std::string message = result.message(); |
195 if (message.empty()) | 197 if (message.empty()) |
196 message = l10n_util::GetStringFUTF8(IDS_CLOUD_PRINT_ENUM_FAILED, | 198 message = l10n_util::GetStringFUTF8(IDS_CLOUD_PRINT_ENUM_FAILED, |
197 l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT)); | 199 l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT)); |
198 // There was a failure enumerating printers. Send a message to the server. | 200 // There was a failure enumerating printers. Send a message to the server. |
199 ReportUserMessage(kEnumPrintersFailedMessageId, message); | 201 ReportUserMessage(cloud_print::kEnumPrintersFailedMessageId, message); |
200 } | 202 } |
201 | 203 |
202 // Go through the list of the cloud printers and init print job handlers. | 204 // Go through the list of the cloud printers and init print job handlers. |
203 ListValue* printer_list = NULL; | 205 ListValue* printer_list = NULL; |
204 // There may be no "printers" value in the JSON | 206 // There may be no "printers" value in the JSON |
205 if (json_data->GetList(cloud_print::kPrinterListValue, &printer_list) | 207 if (json_data->GetList(cloud_print::kPrinterListValue, &printer_list) |
206 && printer_list) { | 208 && printer_list) { |
207 for (size_t index = 0; index < printer_list->GetSize(); index++) { | 209 for (size_t index = 0; index < printer_list->GetSize(); index++) { |
208 DictionaryValue* printer_data = NULL; | 210 DictionaryValue* printer_data = NULL; |
209 if (printer_list->GetDictionary(index, &printer_data)) { | 211 if (printer_list->GetDictionary(index, &printer_data)) { |
210 std::string printer_name; | 212 std::string printer_name; |
211 printer_data->GetString(kNameValue, &printer_name); | 213 printer_data->GetString(cloud_print::kNameValue, &printer_name); |
212 std::string printer_id; | 214 std::string printer_id; |
213 printer_data->GetString(kIdValue, &printer_id); | 215 printer_data->GetString(cloud_print::kIdValue, &printer_id); |
214 if (settings_.IsPrinterBlacklisted(printer_name)) { | 216 if (settings_.IsPrinterBlacklisted(printer_name)) { |
215 VLOG(1) << "CP_CONNECTOR: Deleting " << printer_name << | 217 VLOG(1) << "CP_CONNECTOR: Deleting " << printer_name << |
216 " id: " << printer_id << " as blacklisted"; | 218 " id: " << printer_id << " as blacklisted"; |
217 AddPendingDeleteTask(printer_id); | 219 AddPendingDeleteTask(printer_id); |
218 } else if (RemovePrinterFromList(printer_name, &local_printers)) { | 220 } else if (RemovePrinterFromList(printer_name, &local_printers)) { |
219 InitJobHandlerForPrinter(printer_data); | 221 InitJobHandlerForPrinter(printer_data); |
220 } else { | 222 } else { |
221 // Cloud printer is not found on the local system. | 223 // Cloud printer is not found on the local system. |
222 if (full_list || settings_.delete_on_enum_fail()) { | 224 if (full_list || settings_.delete_on_enum_fail()) { |
223 // Delete if we get the full list of printers or | 225 // Delete if we get the full list of printers or |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
302 request_->StartPostRequest( | 304 request_->StartPostRequest( |
303 url, this, max_retries, mime_type, post_data, std::string()); | 305 url, this, max_retries, mime_type, post_data, std::string()); |
304 } | 306 } |
305 | 307 |
306 void CloudPrintConnector::ReportUserMessage(const std::string& message_id, | 308 void CloudPrintConnector::ReportUserMessage(const std::string& message_id, |
307 const std::string& failure_msg) { | 309 const std::string& failure_msg) { |
308 // This is a fire and forget type of function. | 310 // This is a fire and forget type of function. |
309 // Result of this request will be ignored. | 311 // Result of this request will be ignored. |
310 std::string mime_boundary; | 312 std::string mime_boundary; |
311 cloud_print::CreateMimeBoundaryForUpload(&mime_boundary); | 313 cloud_print::CreateMimeBoundaryForUpload(&mime_boundary); |
312 GURL url = CloudPrintHelpers::GetUrlForUserMessage(settings_.server_url(), | 314 GURL url = cloud_print::GetUrlForUserMessage(settings_.server_url(), |
313 message_id); | 315 message_id); |
314 std::string post_data; | 316 std::string post_data; |
315 cloud_print::AddMultipartValueForUpload(kMessageTextValue, failure_msg, | 317 cloud_print::AddMultipartValueForUpload(cloud_print::kMessageTextValue, |
316 mime_boundary, std::string(), &post_data); | 318 failure_msg, mime_boundary, std::string(), &post_data); |
317 // Terminate the request body | 319 // Terminate the request body |
318 post_data.append("--" + mime_boundary + "--\r\n"); | 320 post_data.append("--" + mime_boundary + "--\r\n"); |
319 std::string mime_type("multipart/form-data; boundary="); | 321 std::string mime_type("multipart/form-data; boundary="); |
320 mime_type += mime_boundary; | 322 mime_type += mime_boundary; |
321 user_message_request_ = new CloudPrintURLFetcher; | 323 user_message_request_ = new CloudPrintURLFetcher; |
322 user_message_request_->StartPostRequest(url, this, 1, mime_type, post_data, | 324 user_message_request_->StartPostRequest(url, this, 1, mime_type, post_data, |
323 std::string()); | 325 std::string()); |
324 } | 326 } |
325 | 327 |
326 bool CloudPrintConnector::RemovePrinterFromList( | 328 bool CloudPrintConnector::RemovePrinterFromList( |
327 const std::string& printer_name, | 329 const std::string& printer_name, |
328 printing::PrinterList* printer_list) { | 330 printing::PrinterList* printer_list) { |
329 for (printing::PrinterList::iterator index = printer_list->begin(); | 331 for (printing::PrinterList::iterator index = printer_list->begin(); |
330 index != printer_list->end(); index++) { | 332 index != printer_list->end(); index++) { |
331 if (IsSamePrinter(index->printer_name, printer_name)) { | 333 if (IsSamePrinter(index->printer_name, printer_name)) { |
332 index = printer_list->erase(index); | 334 index = printer_list->erase(index); |
333 return true; | 335 return true; |
334 } | 336 } |
335 } | 337 } |
336 return false; | 338 return false; |
337 } | 339 } |
338 | 340 |
339 void CloudPrintConnector::InitJobHandlerForPrinter( | 341 void CloudPrintConnector::InitJobHandlerForPrinter( |
340 DictionaryValue* printer_data) { | 342 DictionaryValue* printer_data) { |
341 DCHECK(printer_data); | 343 DCHECK(printer_data); |
342 PrinterJobHandler::PrinterInfoFromCloud printer_info_cloud; | 344 PrinterJobHandler::PrinterInfoFromCloud printer_info_cloud; |
343 printer_data->GetString(kIdValue, &printer_info_cloud.printer_id); | 345 printer_data->GetString(cloud_print::kIdValue, |
346 &printer_info_cloud.printer_id); | |
344 DCHECK(!printer_info_cloud.printer_id.empty()); | 347 DCHECK(!printer_info_cloud.printer_id.empty()); |
345 VLOG(1) << "CP_CONNECTOR: Init job handler" | 348 VLOG(1) << "CP_CONNECTOR: Init job handler" |
346 << ", printer id: " << printer_info_cloud.printer_id; | 349 << ", printer id: " << printer_info_cloud.printer_id; |
347 JobHandlerMap::iterator index = job_handler_map_.find( | 350 JobHandlerMap::iterator index = job_handler_map_.find( |
348 printer_info_cloud.printer_id); | 351 printer_info_cloud.printer_id); |
349 if (index != job_handler_map_.end()) | 352 if (index != job_handler_map_.end()) |
350 return; // Nothing to do if we already have a job handler for this printer. | 353 return; // Nothing to do if we already have a job handler for this printer. |
351 | 354 |
352 printing::PrinterBasicInfo printer_info; | 355 printing::PrinterBasicInfo printer_info; |
353 printer_data->GetString(kNameValue, &printer_info.printer_name); | 356 printer_data->GetString(cloud_print::kNameValue, &printer_info.printer_name); |
354 DCHECK(!printer_info.printer_name.empty()); | 357 DCHECK(!printer_info.printer_name.empty()); |
355 printer_data->GetString(kPrinterDescValue, | 358 printer_data->GetString(cloud_print::kPrinterDescValue, |
356 &printer_info.printer_description); | 359 &printer_info.printer_description); |
357 // Printer status is a string value which actually contains an integer. | 360 // Printer status is a string value which actually contains an integer. |
358 std::string printer_status; | 361 std::string printer_status; |
359 if (printer_data->GetString(kPrinterStatusValue, &printer_status)) { | 362 if (printer_data->GetString( |
363 cloud_print::kPrinterStatusValue, &printer_status)) { | |
360 base::StringToInt(printer_status, &printer_info.printer_status); | 364 base::StringToInt(printer_status, &printer_info.printer_status); |
361 } | 365 } |
362 printer_data->GetString(kPrinterCapsHashValue, | 366 printer_data->GetString(cloud_print::kPrinterCapsHashValue, |
363 &printer_info_cloud.caps_hash); | 367 &printer_info_cloud.caps_hash); |
364 ListValue* tags_list = NULL; | 368 ListValue* tags_list = NULL; |
365 if (printer_data->GetList(kTagsValue, &tags_list) && tags_list) { | 369 if (printer_data->GetList(cloud_print::kTagsValue, &tags_list) && tags_list) { |
366 for (size_t index = 0; index < tags_list->GetSize(); index++) { | 370 for (size_t index = 0; index < tags_list->GetSize(); index++) { |
367 std::string tag; | 371 std::string tag; |
368 if (tags_list->GetString(index, &tag) && | 372 if (tags_list->GetString(index, &tag) && |
369 StartsWithASCII(tag, kTagsHashTagName, false)) { | 373 StartsWithASCII(tag, kTagsHashTagName, false)) { |
370 std::vector<std::string> tag_parts; | 374 std::vector<std::string> tag_parts; |
371 base::SplitStringDontTrim(tag, '=', &tag_parts); | 375 base::SplitStringDontTrim(tag, '=', &tag_parts); |
372 DCHECK_EQ(tag_parts.size(), 2U); | 376 DCHECK_EQ(tag_parts.size(), 2U); |
373 if (tag_parts.size() == 2) | 377 if (tag_parts.size() == 2) |
374 printer_info_cloud.tags_hash = tag_parts[1]; | 378 printer_info_cloud.tags_hash = tag_parts[1]; |
375 } | 379 } |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
444 | 448 |
445 // Delete current task and repost if we have more task available. | 449 // Delete current task and repost if we have more task available. |
446 pending_tasks_.pop_front(); | 450 pending_tasks_.pop_front(); |
447 if (pending_tasks_.size() != 0) { | 451 if (pending_tasks_.size() != 0) { |
448 MessageLoop::current()->PostTask( | 452 MessageLoop::current()->PostTask( |
449 FROM_HERE, base::Bind(&CloudPrintConnector::ProcessPendingTask, this)); | 453 FROM_HERE, base::Bind(&CloudPrintConnector::ProcessPendingTask, this)); |
450 } | 454 } |
451 } | 455 } |
452 | 456 |
453 void CloudPrintConnector::OnPrintersAvailable() { | 457 void CloudPrintConnector::OnPrintersAvailable() { |
454 GURL printer_list_url = CloudPrintHelpers::GetUrlForPrinterList( | 458 GURL printer_list_url = cloud_print::GetUrlForPrinterList( |
455 settings_.server_url(), settings_.proxy_id()); | 459 settings_.server_url(), settings_.proxy_id()); |
456 StartGetRequest(printer_list_url, | 460 StartGetRequest(printer_list_url, |
457 kCloudPrintRegisterMaxRetryCount, | 461 kCloudPrintRegisterMaxRetryCount, |
458 &CloudPrintConnector::HandlePrinterListResponse); | 462 &CloudPrintConnector::HandlePrinterListResponse); |
459 } | 463 } |
460 | 464 |
461 void CloudPrintConnector::OnPrinterRegister( | 465 void CloudPrintConnector::OnPrinterRegister( |
462 const printing::PrinterBasicInfo& info) { | 466 const printing::PrinterBasicInfo& info) { |
463 for (JobHandlerMap::iterator it = job_handler_map_.begin(); | 467 for (JobHandlerMap::iterator it = job_handler_map_.begin(); |
464 it != job_handler_map_.end(); ++it) { | 468 it != job_handler_map_.end(); ++it) { |
(...skipping 16 matching lines...) Expand all Loading... | |
481 // Remove corresponding printer job handler. | 485 // Remove corresponding printer job handler. |
482 JobHandlerMap::iterator it = job_handler_map_.find(printer_id); | 486 JobHandlerMap::iterator it = job_handler_map_.find(printer_id); |
483 if (it != job_handler_map_.end()) { | 487 if (it != job_handler_map_.end()) { |
484 it->second->Shutdown(); | 488 it->second->Shutdown(); |
485 job_handler_map_.erase(it); | 489 job_handler_map_.erase(it); |
486 } | 490 } |
487 | 491 |
488 // TODO(gene): We probably should not try indefinitely here. Just once or | 492 // TODO(gene): We probably should not try indefinitely here. Just once or |
489 // twice should be enough. | 493 // twice should be enough. |
490 // Bug: http://code.google.com/p/chromium/issues/detail?id=101850 | 494 // Bug: http://code.google.com/p/chromium/issues/detail?id=101850 |
491 GURL url = CloudPrintHelpers::GetUrlForPrinterDelete( | 495 GURL url = cloud_print::GetUrlForPrinterDelete( |
492 settings_.server_url(), printer_id, "printer_deleted"); | 496 settings_.server_url(), printer_id, "printer_deleted"); |
493 StartGetRequest(url, | 497 StartGetRequest(url, |
494 kCloudPrintAPIMaxRetryCount, | 498 kCloudPrintAPIMaxRetryCount, |
495 &CloudPrintConnector::HandlePrinterDeleteResponse); | 499 &CloudPrintConnector::HandlePrinterDeleteResponse); |
496 } | 500 } |
497 | 501 |
498 void CloudPrintConnector::OnReceivePrinterCaps( | 502 void CloudPrintConnector::OnReceivePrinterCaps( |
499 bool succeeded, | 503 bool succeeded, |
500 const std::string& printer_name, | 504 const std::string& printer_name, |
501 const printing::PrinterCapsAndDefaults& caps_and_defaults) { | 505 const printing::PrinterCapsAndDefaults& caps_and_defaults) { |
502 if (!IsRunning()) | 506 if (!IsRunning()) |
503 return; // Orphant call. | 507 return; // Orphant call. |
504 DCHECK(pending_tasks_.size() > 0 && | 508 DCHECK(pending_tasks_.size() > 0 && |
505 pending_tasks_.front().type == PENDING_PRINTER_REGISTER); | 509 pending_tasks_.front().type == PENDING_PRINTER_REGISTER); |
506 | 510 |
507 if (!succeeded) { | 511 if (!succeeded) { |
508 LOG(ERROR) << "CP_CONNECTOR: Failed to get printer info" | 512 LOG(ERROR) << "CP_CONNECTOR: Failed to get printer info" |
509 << ", printer name: " << printer_name; | 513 << ", printer name: " << printer_name; |
510 // This printer failed to register, notify the server of this failure. | 514 // This printer failed to register, notify the server of this failure. |
511 string16 printer_name_utf16 = UTF8ToUTF16(printer_name); | 515 string16 printer_name_utf16 = UTF8ToUTF16(printer_name); |
512 std::string status_message = l10n_util::GetStringFUTF8( | 516 std::string status_message = l10n_util::GetStringFUTF8( |
513 IDS_CLOUD_PRINT_REGISTER_PRINTER_FAILED, | 517 IDS_CLOUD_PRINT_REGISTER_PRINTER_FAILED, |
514 printer_name_utf16, | 518 printer_name_utf16, |
515 l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT)); | 519 l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT)); |
516 ReportUserMessage(kGetPrinterCapsFailedMessageId, status_message); | 520 ReportUserMessage(cloud_print::kGetPrinterCapsFailedMessageId, |
521 status_message); | |
517 | 522 |
518 ContinuePendingTaskProcessing(); // Skip this printer registration. | 523 ContinuePendingTaskProcessing(); // Skip this printer registration. |
519 return; | 524 return; |
520 } | 525 } |
521 | 526 |
522 const printing::PrinterBasicInfo& info = pending_tasks_.front().printer_info; | 527 const printing::PrinterBasicInfo& info = pending_tasks_.front().printer_info; |
523 DCHECK(IsSamePrinter(info.printer_name, printer_name)); | 528 DCHECK(IsSamePrinter(info.printer_name, printer_name)); |
524 | 529 |
525 std::string mime_boundary; | 530 std::string mime_boundary; |
526 cloud_print::CreateMimeBoundaryForUpload(&mime_boundary); | 531 cloud_print::CreateMimeBoundaryForUpload(&mime_boundary); |
527 std::string post_data; | 532 std::string post_data; |
528 | 533 |
529 cloud_print::AddMultipartValueForUpload(kProxyIdValue, settings_.proxy_id(), | 534 cloud_print::AddMultipartValueForUpload(cloud_print::kProxyIdValue, |
530 mime_boundary, std::string(), &post_data); | 535 settings_.proxy_id(), mime_boundary, std::string(), &post_data); |
531 cloud_print::AddMultipartValueForUpload(kPrinterNameValue, info.printer_name, | 536 cloud_print::AddMultipartValueForUpload(cloud_print::kPrinterNameValue, |
532 mime_boundary, std::string(), &post_data); | 537 info.printer_name, mime_boundary, std::string(), &post_data); |
533 cloud_print::AddMultipartValueForUpload(kPrinterDescValue, | 538 cloud_print::AddMultipartValueForUpload(cloud_print::kPrinterDescValue, |
534 info.printer_description, mime_boundary, std::string() , &post_data); | 539 info.printer_description, mime_boundary, std::string(), &post_data); |
535 cloud_print::AddMultipartValueForUpload(kPrinterStatusValue, | 540 cloud_print::AddMultipartValueForUpload(cloud_print::kPrinterStatusValue, |
536 base::StringPrintf("%d", info.printer_status), | 541 base::StringPrintf("%d", info.printer_status), |
537 mime_boundary, std::string(), &post_data); | 542 mime_boundary, std::string(), &post_data); |
538 post_data += CloudPrintHelpers::GetPostDataForPrinterTags(info, | 543 post_data += CloudPrintHelpers::GetPostDataForPrinterTags(info, |
539 mime_boundary); | 544 mime_boundary); |
540 cloud_print::AddMultipartValueForUpload(kPrinterCapsValue, | 545 cloud_print::AddMultipartValueForUpload(cloud_print::kPrinterCapsValue, |
541 caps_and_defaults.printer_capabilities, mime_boundary, | 546 caps_and_defaults.printer_capabilities, mime_boundary, |
542 caps_and_defaults.caps_mime_type, &post_data); | 547 caps_and_defaults.caps_mime_type, &post_data); |
543 cloud_print::AddMultipartValueForUpload(kPrinterDefaultsValue, | 548 cloud_print::AddMultipartValueForUpload(cloud_print::kPrinterDefaultsValue, |
544 caps_and_defaults.printer_defaults, mime_boundary, | 549 caps_and_defaults.printer_defaults, mime_boundary, |
545 caps_and_defaults.defaults_mime_type, &post_data); | 550 caps_and_defaults.defaults_mime_type, &post_data); |
546 // Send a hash of the printer capabilities to the server. We will use this | 551 // Send a hash of the printer capabilities to the server. We will use this |
547 // later to check if the capabilities have changed | 552 // later to check if the capabilities have changed |
548 cloud_print::AddMultipartValueForUpload(kPrinterCapsHashValue, | 553 cloud_print::AddMultipartValueForUpload(cloud_print::kPrinterCapsHashValue, |
549 base::MD5String(caps_and_defaults.printer_capabilities), | 554 base::MD5String(caps_and_defaults.printer_capabilities), |
550 mime_boundary, std::string(), &post_data); | 555 mime_boundary, std::string(), &post_data); |
551 | 556 |
552 // Terminate the request body | 557 // Terminate the request body |
553 post_data.append("--" + mime_boundary + "--\r\n"); | 558 post_data.append("--" + mime_boundary + "--\r\n"); |
554 std::string mime_type("multipart/form-data; boundary="); | 559 std::string mime_type("multipart/form-data; boundary="); |
555 mime_type += mime_boundary; | 560 mime_type += mime_boundary; |
556 | 561 |
557 GURL post_url = CloudPrintHelpers::GetUrlForPrinterRegistration( | 562 GURL post_url = cloud_print::GetUrlForPrinterRegistration( |
558 settings_.server_url()); | 563 settings_.server_url()); |
559 StartPostRequest(post_url, | 564 StartPostRequest(post_url, |
560 kCloudPrintAPIMaxRetryCount, | 565 kCloudPrintAPIMaxRetryCount, |
561 mime_type, | 566 mime_type, |
562 post_data, | 567 post_data, |
563 &CloudPrintConnector::HandleRegisterPrinterResponse); | 568 &CloudPrintConnector::HandleRegisterPrinterResponse); |
564 } | 569 } |
565 | 570 |
566 bool CloudPrintConnector::IsSamePrinter(const std::string& name1, | 571 bool CloudPrintConnector::IsSamePrinter(const std::string& name1, |
567 const std::string& name2) const { | 572 const std::string& name2) const { |
568 return (0 == base::strcasecmp(name1.c_str(), name2.c_str())); | 573 return (0 == base::strcasecmp(name1.c_str(), name2.c_str())); |
569 } | 574 } |
OLD | NEW |