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

Side by Side Diff: chrome/service/cloud_print/cloud_print_connector.cc

Issue 12208089: Changing CloudPrintURLFetcher instantiation to be more testable (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Incorporated Gene's suggestions Created 7 years, 10 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
OLDNEW
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"
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 } 282 }
283 ContinuePendingTaskProcessing(); // Continue processing background tasks. 283 ContinuePendingTaskProcessing(); // Continue processing background tasks.
284 return CloudPrintURLFetcher::STOP_PROCESSING; 284 return CloudPrintURLFetcher::STOP_PROCESSING;
285 } 285 }
286 286
287 287
288 void CloudPrintConnector::StartGetRequest(const GURL& url, 288 void CloudPrintConnector::StartGetRequest(const GURL& url,
289 int max_retries, 289 int max_retries,
290 ResponseHandler handler) { 290 ResponseHandler handler) {
291 next_response_handler_ = handler; 291 next_response_handler_ = handler;
292 request_ = new CloudPrintURLFetcher; 292 request_ = CloudPrintURLFetcher::Create();
293 request_->StartGetRequest(url, this, max_retries, std::string()); 293 request_->StartGetRequest(url, this, max_retries, std::string());
294 } 294 }
295 295
296 void CloudPrintConnector::StartPostRequest(const GURL& url, 296 void CloudPrintConnector::StartPostRequest(const GURL& url,
297 int max_retries, 297 int max_retries,
298 const std::string& mime_type, 298 const std::string& mime_type,
299 const std::string& post_data, 299 const std::string& post_data,
300 ResponseHandler handler) { 300 ResponseHandler handler) {
301 next_response_handler_ = handler; 301 next_response_handler_ = handler;
302 request_ = new CloudPrintURLFetcher; 302 request_ = CloudPrintURLFetcher::Create();
303 request_->StartPostRequest( 303 request_->StartPostRequest(
304 url, this, max_retries, mime_type, post_data, std::string()); 304 url, this, max_retries, mime_type, post_data, std::string());
305 } 305 }
306 306
307 void CloudPrintConnector::ReportUserMessage(const std::string& message_id, 307 void CloudPrintConnector::ReportUserMessage(const std::string& message_id,
308 const std::string& failure_msg) { 308 const std::string& failure_msg) {
309 // This is a fire and forget type of function. 309 // This is a fire and forget type of function.
310 // Result of this request will be ignored. 310 // Result of this request will be ignored.
311 std::string mime_boundary; 311 std::string mime_boundary;
312 CreateMimeBoundaryForUpload(&mime_boundary); 312 CreateMimeBoundaryForUpload(&mime_boundary);
313 GURL url = GetUrlForUserMessage(settings_.server_url(), message_id); 313 GURL url = GetUrlForUserMessage(settings_.server_url(), message_id);
314 std::string post_data; 314 std::string post_data;
315 AddMultipartValueForUpload(kMessageTextValue, failure_msg, mime_boundary, 315 AddMultipartValueForUpload(kMessageTextValue, failure_msg, mime_boundary,
316 std::string(), &post_data); 316 std::string(), &post_data);
317 // Terminate the request body 317 // Terminate the request body
318 post_data.append("--" + mime_boundary + "--\r\n"); 318 post_data.append("--" + mime_boundary + "--\r\n");
319 std::string mime_type("multipart/form-data; boundary="); 319 std::string mime_type("multipart/form-data; boundary=");
320 mime_type += mime_boundary; 320 mime_type += mime_boundary;
321 user_message_request_ = new CloudPrintURLFetcher; 321 user_message_request_ = CloudPrintURLFetcher::Create();
322 user_message_request_->StartPostRequest(url, this, 1, mime_type, post_data, 322 user_message_request_->StartPostRequest(url, this, 1, mime_type, post_data,
323 std::string()); 323 std::string());
324 } 324 }
325 325
326 bool CloudPrintConnector::RemovePrinterFromList( 326 bool CloudPrintConnector::RemovePrinterFromList(
327 const std::string& printer_name, 327 const std::string& printer_name,
328 printing::PrinterList* printer_list) { 328 printing::PrinterList* printer_list) {
329 for (printing::PrinterList::iterator index = printer_list->begin(); 329 for (printing::PrinterList::iterator index = printer_list->begin();
330 index != printer_list->end(); index++) { 330 index != printer_list->end(); index++) {
331 if (IsSamePrinter(index->printer_name, printer_name)) { 331 if (IsSamePrinter(index->printer_name, printer_name)) {
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 post_data, 560 post_data,
561 &CloudPrintConnector::HandleRegisterPrinterResponse); 561 &CloudPrintConnector::HandleRegisterPrinterResponse);
562 } 562 }
563 563
564 bool CloudPrintConnector::IsSamePrinter(const std::string& name1, 564 bool CloudPrintConnector::IsSamePrinter(const std::string& name1,
565 const std::string& name2) const { 565 const std::string& name2) const {
566 return (0 == base::strcasecmp(name1.c_str(), name2.c_str())); 566 return (0 == base::strcasecmp(name1.c_str(), name2.c_str()));
567 } 567 }
568 568
569 } // namespace cloud_print 569 } // namespace cloud_print
OLDNEW
« no previous file with comments | « chrome/service/cloud_print/cloud_print_auth.cc ('k') | chrome/service/cloud_print/cloud_print_url_fetcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698