| 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_wipeout.h" | 5 #include "chrome/service/cloud_print/cloud_print_wipeout.h" |
| 6 | 6 |
| 7 #include "chrome/service/cloud_print/cloud_print_consts.h" | 7 #include "chrome/common/cloud_print/cloud_print_constants.h" |
| 8 #include "chrome/service/cloud_print/cloud_print_helpers.h" | 8 #include "chrome/common/cloud_print/cloud_print_helpers.h" |
| 9 | 9 |
| 10 const int kMaxWipeoutAttempts = 3; | 10 const int kMaxWipeoutAttempts = 3; |
| 11 | 11 |
| 12 namespace cloud_print { |
| 13 |
| 12 CloudPrintWipeout::CloudPrintWipeout(Client* client, | 14 CloudPrintWipeout::CloudPrintWipeout(Client* client, |
| 13 const GURL& cloud_print_server_url) | 15 const GURL& cloud_print_server_url) |
| 14 : client_(client), cloud_print_server_url_(cloud_print_server_url) { | 16 : client_(client), cloud_print_server_url_(cloud_print_server_url) { |
| 15 } | 17 } |
| 16 CloudPrintWipeout::~CloudPrintWipeout() { | 18 CloudPrintWipeout::~CloudPrintWipeout() { |
| 17 } | 19 } |
| 18 | 20 |
| 19 void CloudPrintWipeout::UnregisterPrinters( | 21 void CloudPrintWipeout::UnregisterPrinters( |
| 20 const std::string& auth_token, | 22 const std::string& auth_token, |
| 21 const std::list<std::string>& printer_ids) { | 23 const std::list<std::string>& printer_ids) { |
| 22 auth_token_ = auth_token; | 24 auth_token_ = auth_token; |
| 23 printer_ids_ = printer_ids; | 25 printer_ids_ = printer_ids; |
| 24 UnregisterNextPrinter(); | 26 UnregisterNextPrinter(); |
| 25 } | 27 } |
| 26 | 28 |
| 27 void CloudPrintWipeout::UnregisterNextPrinter() { | 29 void CloudPrintWipeout::UnregisterNextPrinter() { |
| 28 if (printer_ids_.empty()) { | 30 if (printer_ids_.empty()) { |
| 29 client_->OnUnregisterPrintersComplete(); | 31 client_->OnUnregisterPrintersComplete(); |
| 30 return; | 32 return; |
| 31 } | 33 } |
| 32 | 34 |
| 33 std::string printer_id = printer_ids_.front(); | 35 std::string printer_id = printer_ids_.front(); |
| 34 printer_ids_.pop_front(); | 36 printer_ids_.pop_front(); |
| 35 | 37 |
| 36 GURL url = CloudPrintHelpers::GetUrlForPrinterDelete(cloud_print_server_url_, | 38 GURL url = GetUrlForPrinterDelete(cloud_print_server_url_, |
| 37 printer_id, | 39 printer_id, |
| 38 "connector_disabled"); | 40 "connector_disabled"); |
| 39 request_ = new CloudPrintURLFetcher; | 41 request_ = new CloudPrintURLFetcher; |
| 40 request_->StartGetRequest(url, this, kMaxWipeoutAttempts, std::string()); | 42 request_->StartGetRequest(url, this, kMaxWipeoutAttempts, std::string()); |
| 41 } | 43 } |
| 42 | 44 |
| 43 CloudPrintURLFetcher::ResponseAction CloudPrintWipeout::HandleJSONData( | 45 CloudPrintURLFetcher::ResponseAction CloudPrintWipeout::HandleJSONData( |
| 44 const net::URLFetcher* source, | 46 const net::URLFetcher* source, |
| 45 const GURL& url, | 47 const GURL& url, |
| 46 base::DictionaryValue* json_data, | 48 base::DictionaryValue* json_data, |
| 47 bool succeeded) { | 49 bool succeeded) { |
| 48 // We don't care if delete was sucessful or not here. | 50 // We don't care if delete was sucessful or not here. |
| 49 UnregisterNextPrinter(); | 51 UnregisterNextPrinter(); |
| 50 return CloudPrintURLFetcher::STOP_PROCESSING; | 52 return CloudPrintURLFetcher::STOP_PROCESSING; |
| 51 } | 53 } |
| 52 | 54 |
| 53 void CloudPrintWipeout::OnRequestGiveUp() { | 55 void CloudPrintWipeout::OnRequestGiveUp() { |
| 54 UnregisterNextPrinter(); | 56 UnregisterNextPrinter(); |
| 55 } | 57 } |
| 56 | 58 |
| 57 CloudPrintURLFetcher::ResponseAction CloudPrintWipeout::OnRequestAuthError() { | 59 CloudPrintURLFetcher::ResponseAction CloudPrintWipeout::OnRequestAuthError() { |
| 58 // We can't recover from auth rrror. Report complition to stop service. | 60 // We can't recover from auth rrror. Report complition to stop service. |
| 59 client_->OnUnregisterPrintersComplete(); | 61 client_->OnUnregisterPrintersComplete(); |
| 60 return CloudPrintURLFetcher::STOP_PROCESSING; | 62 return CloudPrintURLFetcher::STOP_PROCESSING; |
| 61 } | 63 } |
| 62 | 64 |
| 63 std::string CloudPrintWipeout::GetAuthHeader() { | 65 std::string CloudPrintWipeout::GetAuthHeader() { |
| 64 return CloudPrintHelpers::GetCloudPrintAuthHeader(auth_token_); | 66 return GetCloudPrintAuthHeader(auth_token_); |
| 65 } | 67 } |
| 66 | 68 |
| 69 } // namespace cloud_print |
| OLD | NEW |