• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "chrome/service/cloud_print/cloud_print_wipeout.h"
6 
7 #include "chrome/common/cloud_print/cloud_print_constants.h"
8 #include "chrome/common/cloud_print/cloud_print_helpers.h"
9 
10 const int kMaxWipeoutAttempts = 3;
11 
12 namespace cloud_print {
13 
CloudPrintWipeout(Client * client,const GURL & cloud_print_server_url)14 CloudPrintWipeout::CloudPrintWipeout(Client* client,
15                                      const GURL& cloud_print_server_url)
16   : client_(client), cloud_print_server_url_(cloud_print_server_url) {
17 }
~CloudPrintWipeout()18 CloudPrintWipeout::~CloudPrintWipeout() {
19 }
20 
UnregisterPrinters(const std::string & auth_token,const std::list<std::string> & printer_ids)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();
27 }
28 
UnregisterNextPrinter()29 void CloudPrintWipeout::UnregisterNextPrinter() {
30   if (printer_ids_.empty()) {
31     client_->OnUnregisterPrintersComplete();
32     return;
33   }
34 
35   std::string printer_id = printer_ids_.front();
36   printer_ids_.pop_front();
37 
38   GURL url = GetUrlForPrinterDelete(cloud_print_server_url_,
39                                     printer_id,
40                                     "connector_disabled");
41   request_ = CloudPrintURLFetcher::Create();
42   request_->StartGetRequest(CloudPrintURLFetcher::REQUEST_UNREGISTER,
43                             url, this, kMaxWipeoutAttempts, std::string());
44 }
45 
HandleJSONData(const net::URLFetcher * source,const GURL & url,base::DictionaryValue * json_data,bool succeeded)46 CloudPrintURLFetcher::ResponseAction CloudPrintWipeout::HandleJSONData(
47     const net::URLFetcher* source,
48     const GURL& url,
49     base::DictionaryValue* json_data,
50     bool succeeded) {
51   // We don't care if delete was successful or not here.
52   UnregisterNextPrinter();
53   return CloudPrintURLFetcher::STOP_PROCESSING;
54 }
55 
OnRequestGiveUp()56 void CloudPrintWipeout::OnRequestGiveUp() {
57   UnregisterNextPrinter();
58 }
59 
OnRequestAuthError()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;
64 }
65 
GetAuthHeader()66 std::string CloudPrintWipeout::GetAuthHeader() {
67   return GetCloudPrintAuthHeader(auth_token_);
68 }
69 
70 }  // namespace cloud_print
71