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

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

Issue 10065040: RefCounted types should not have public destructors, chrome/ remaining parts (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Implementation fixes Created 8 years, 8 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 (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 16 matching lines...) Expand all
27 : client_(client), 27 : client_(client),
28 proxy_id_(proxy_id), 28 proxy_id_(proxy_id),
29 cloud_print_server_url_(cloud_print_server_url), 29 cloud_print_server_url_(cloud_print_server_url),
30 next_response_handler_(NULL) { 30 next_response_handler_(NULL) {
31 if (print_system_settings) { 31 if (print_system_settings) {
32 // It is possible to have no print settings specified. 32 // It is possible to have no print settings specified.
33 print_system_settings_.reset(print_system_settings->DeepCopy()); 33 print_system_settings_.reset(print_system_settings->DeepCopy());
34 } 34 }
35 } 35 }
36 36
37 CloudPrintConnector::~CloudPrintConnector() {
38 }
39
40 bool CloudPrintConnector::Start() { 37 bool CloudPrintConnector::Start() {
41 DCHECK(!print_system_.get()); 38 DCHECK(!print_system_.get());
42 VLOG(1) << "CP_CONNECTOR: Starting connector, id: " << proxy_id_; 39 VLOG(1) << "CP_CONNECTOR: Starting connector, id: " << proxy_id_;
43 40
44 pending_tasks_.clear(); 41 pending_tasks_.clear();
45 42
46 print_system_ = 43 print_system_ =
47 cloud_print::PrintSystem::CreateInstance(print_system_settings_.get()); 44 cloud_print::PrintSystem::CreateInstance(print_system_settings_.get());
48 if (!print_system_.get()) { 45 if (!print_system_.get()) {
49 NOTREACHED(); 46 NOTREACHED();
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 const GURL& url, 135 const GURL& url,
139 DictionaryValue* json_data, 136 DictionaryValue* json_data,
140 bool succeeded) { 137 bool succeeded) {
141 if (!IsRunning()) // Orphant response. Connector has been stopped already. 138 if (!IsRunning()) // Orphant response. Connector has been stopped already.
142 return CloudPrintURLFetcher::STOP_PROCESSING; 139 return CloudPrintURLFetcher::STOP_PROCESSING;
143 140
144 DCHECK(next_response_handler_); 141 DCHECK(next_response_handler_);
145 return (this->*next_response_handler_)(source, url, json_data, succeeded); 142 return (this->*next_response_handler_)(source, url, json_data, succeeded);
146 } 143 }
147 144
145 CloudPrintURLFetcher::ResponseAction CloudPrintConnector::OnRequestAuthError() {
146 OnAuthError();
147 return CloudPrintURLFetcher::STOP_PROCESSING;
148 }
149
150 std::string CloudPrintConnector::GetAuthHeader() {
151 return CloudPrintHelpers::GetCloudPrintAuthHeader();
152 }
153
154 CloudPrintConnector::~CloudPrintConnector() {}
155
148 CloudPrintURLFetcher::ResponseAction 156 CloudPrintURLFetcher::ResponseAction
149 CloudPrintConnector::HandlePrinterListResponse( 157 CloudPrintConnector::HandlePrinterListResponse(
150 const content::URLFetcher* source, 158 const content::URLFetcher* source,
151 const GURL& url, 159 const GURL& url,
152 DictionaryValue* json_data, 160 DictionaryValue* json_data,
153 bool succeeded) { 161 bool succeeded) {
154 DCHECK(succeeded); 162 DCHECK(succeeded);
155 if (!succeeded) 163 if (!succeeded)
156 return CloudPrintURLFetcher::RETRY_REQUEST; 164 return CloudPrintURLFetcher::RETRY_REQUEST;
157 165
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 DictionaryValue* printer_data = NULL; 247 DictionaryValue* printer_data = NULL;
240 if (printer_list->GetDictionary(0, &printer_data)) 248 if (printer_list->GetDictionary(0, &printer_data))
241 InitJobHandlerForPrinter(printer_data); 249 InitJobHandlerForPrinter(printer_data);
242 } 250 }
243 } 251 }
244 ContinuePendingTaskProcessing(); // Continue processing background tasks. 252 ContinuePendingTaskProcessing(); // Continue processing background tasks.
245 return CloudPrintURLFetcher::STOP_PROCESSING; 253 return CloudPrintURLFetcher::STOP_PROCESSING;
246 } 254 }
247 255
248 256
249 CloudPrintURLFetcher::ResponseAction CloudPrintConnector::OnRequestAuthError() {
250 OnAuthError();
251 return CloudPrintURLFetcher::STOP_PROCESSING;
252 }
253
254 std::string CloudPrintConnector::GetAuthHeader() {
255 return CloudPrintHelpers::GetCloudPrintAuthHeader();
256 }
257
258 void CloudPrintConnector::StartGetRequest(const GURL& url, 257 void CloudPrintConnector::StartGetRequest(const GURL& url,
259 int max_retries, 258 int max_retries,
260 ResponseHandler handler) { 259 ResponseHandler handler) {
261 next_response_handler_ = handler; 260 next_response_handler_ = handler;
262 request_ = new CloudPrintURLFetcher; 261 request_ = new CloudPrintURLFetcher;
263 request_->StartGetRequest(url, this, max_retries, std::string()); 262 request_->StartGetRequest(url, this, max_retries, std::string());
264 } 263 }
265 264
266 void CloudPrintConnector::StartPostRequest(const GURL& url, 265 void CloudPrintConnector::StartPostRequest(const GURL& url,
267 int max_retries, 266 int max_retries,
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 OnPrinterRegister(task.printer_info); 401 OnPrinterRegister(task.printer_info);
403 break; 402 break;
404 case PENDING_PRINTER_DELETE : 403 case PENDING_PRINTER_DELETE :
405 OnPrinterDelete(task.printer_id); 404 OnPrinterDelete(task.printer_id);
406 break; 405 break;
407 default: 406 default:
408 NOTREACHED(); 407 NOTREACHED();
409 } 408 }
410 } 409 }
411 410
411 void CloudPrintConnector::ContinuePendingTaskProcessing() {
412 if (pending_tasks_.size() == 0)
413 return; // No pending tasks.
414
415 // Delete current task and repost if we have more task available.
416 pending_tasks_.pop_front();
417 if (pending_tasks_.size() != 0) {
418 MessageLoop::current()->PostTask(
419 FROM_HERE, base::Bind(&CloudPrintConnector::ProcessPendingTask, this));
420 }
421 }
422
412 void CloudPrintConnector::OnPrintersAvailable() { 423 void CloudPrintConnector::OnPrintersAvailable() {
413 GURL printer_list_url = 424 GURL printer_list_url =
414 CloudPrintHelpers::GetUrlForPrinterList(cloud_print_server_url_, 425 CloudPrintHelpers::GetUrlForPrinterList(cloud_print_server_url_,
415 proxy_id_); 426 proxy_id_);
416 StartGetRequest(printer_list_url, 427 StartGetRequest(printer_list_url,
417 kCloudPrintRegisterMaxRetryCount, 428 kCloudPrintRegisterMaxRetryCount,
418 &CloudPrintConnector::HandlePrinterListResponse); 429 &CloudPrintConnector::HandlePrinterListResponse);
419 } 430 }
420 431
421 void CloudPrintConnector::OnPrinterRegister( 432 void CloudPrintConnector::OnPrinterRegister(
(...skipping 26 matching lines...) Expand all
448 // TODO(gene): We probably should not try indefinitely here. Just once or 459 // TODO(gene): We probably should not try indefinitely here. Just once or
449 // twice should be enough. 460 // twice should be enough.
450 // Bug: http://code.google.com/p/chromium/issues/detail?id=101850 461 // Bug: http://code.google.com/p/chromium/issues/detail?id=101850
451 GURL url = CloudPrintHelpers::GetUrlForPrinterDelete(cloud_print_server_url_, 462 GURL url = CloudPrintHelpers::GetUrlForPrinterDelete(cloud_print_server_url_,
452 printer_id); 463 printer_id);
453 StartGetRequest(url, 464 StartGetRequest(url,
454 kCloudPrintAPIMaxRetryCount, 465 kCloudPrintAPIMaxRetryCount,
455 &CloudPrintConnector::HandlePrinterDeleteResponse); 466 &CloudPrintConnector::HandlePrinterDeleteResponse);
456 } 467 }
457 468
458 void CloudPrintConnector::ContinuePendingTaskProcessing() {
459 if (pending_tasks_.size() == 0)
460 return; // No pending tasks.
461
462 // Delete current task and repost if we have more task available.
463 pending_tasks_.pop_front();
464 if (pending_tasks_.size() != 0) {
465 MessageLoop::current()->PostTask(
466 FROM_HERE, base::Bind(&CloudPrintConnector::ProcessPendingTask, this));
467 }
468 }
469
470 void CloudPrintConnector::OnReceivePrinterCaps( 469 void CloudPrintConnector::OnReceivePrinterCaps(
471 bool succeeded, 470 bool succeeded,
472 const std::string& printer_name, 471 const std::string& printer_name,
473 const printing::PrinterCapsAndDefaults& caps_and_defaults) { 472 const printing::PrinterCapsAndDefaults& caps_and_defaults) {
474 if (!IsRunning()) 473 if (!IsRunning())
475 return; // Orphant call. 474 return; // Orphant call.
476 DCHECK(pending_tasks_.size() > 0 && 475 DCHECK(pending_tasks_.size() > 0 &&
477 pending_tasks_.front().type == PENDING_PRINTER_REGISTER); 476 pending_tasks_.front().type == PENDING_PRINTER_REGISTER);
478 477
479 if (!succeeded) { 478 if (!succeeded) {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 mime_type, 535 mime_type,
537 post_data, 536 post_data,
538 &CloudPrintConnector::HandleRegisterPrinterResponse); 537 &CloudPrintConnector::HandleRegisterPrinterResponse);
539 } 538 }
540 539
541 bool CloudPrintConnector::IsSamePrinter(const std::string& name1, 540 bool CloudPrintConnector::IsSamePrinter(const std::string& name1,
542 const std::string& name2) const { 541 const std::string& name2) const {
543 return (0 == base::strcasecmp(name1.c_str(), name2.c_str())); 542 return (0 == base::strcasecmp(name1.c_str(), name2.c_str()));
544 } 543 }
545 544
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698