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