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
3 // found in the LICENSE file.
5 #include "chrome/service/cloud_print/cloud_print_wipeout.h"
7 #include "chrome/common/cloud_print/cloud_print_constants.h"
8 #include "chrome/common/cloud_print/cloud_print_helpers.h"
10 const int kMaxWipeoutAttempts
= 3;
12 namespace cloud_print
{
14 CloudPrintWipeout::CloudPrintWipeout(Client
* client
,
15 const GURL
& cloud_print_server_url
)
16 : client_(client
), cloud_print_server_url_(cloud_print_server_url
) {
18 CloudPrintWipeout::~CloudPrintWipeout() {
21 void CloudPrintWipeout::UnregisterPrinters(
22 const std::string
& auth_token
,
23 const std::list
<std::string
>& printer_ids
) {
24 auth_token_
= auth_token
;
25 printer_ids_
= printer_ids
;
26 UnregisterNextPrinter();
29 void CloudPrintWipeout::UnregisterNextPrinter() {
30 if (printer_ids_
.empty()) {
31 client_
->OnUnregisterPrintersComplete();
35 std::string printer_id
= printer_ids_
.front();
36 printer_ids_
.pop_front();
38 GURL url
= GetUrlForPrinterDelete(cloud_print_server_url_
,
40 "connector_disabled");
41 request_
= CloudPrintURLFetcher::Create();
42 request_
->StartGetRequest(CloudPrintURLFetcher::REQUEST_UNREGISTER
,
43 url
, this, kMaxWipeoutAttempts
, std::string());
46 CloudPrintURLFetcher::ResponseAction
CloudPrintWipeout::HandleJSONData(
47 const net::URLFetcher
* source
,
49 base::DictionaryValue
* json_data
,
51 // We don't care if delete was successful or not here.
52 UnregisterNextPrinter();
53 return CloudPrintURLFetcher::STOP_PROCESSING
;
56 void CloudPrintWipeout::OnRequestGiveUp() {
57 UnregisterNextPrinter();
60 CloudPrintURLFetcher::ResponseAction
CloudPrintWipeout::OnRequestAuthError() {
61 // We can't recover from auth error. Report completion to stop service.
62 client_
->OnUnregisterPrintersComplete();
63 return CloudPrintURLFetcher::STOP_PROCESSING
;
66 std::string
CloudPrintWipeout::GetAuthHeader() {
67 return GetCloudPrintAuthHeader(auth_token_
);
70 } // namespace cloud_print