Home | History | Annotate | Download | only in cloud_print
      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 
     14 CloudPrintWipeout::CloudPrintWipeout(Client* client,
     15                                      const GURL& cloud_print_server_url)
     16   : client_(client), cloud_print_server_url_(cloud_print_server_url) {
     17 }
     18 CloudPrintWipeout::~CloudPrintWipeout() {
     19 }
     20 
     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 
     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(url, this, kMaxWipeoutAttempts, std::string());
     43 }
     44 
     45 CloudPrintURLFetcher::ResponseAction CloudPrintWipeout::HandleJSONData(
     46     const net::URLFetcher* source,
     47     const GURL& url,
     48     base::DictionaryValue* json_data,
     49     bool succeeded) {
     50   // We don't care if delete was sucessful or not here.
     51   UnregisterNextPrinter();
     52   return CloudPrintURLFetcher::STOP_PROCESSING;
     53 }
     54 
     55 void CloudPrintWipeout::OnRequestGiveUp() {
     56   UnregisterNextPrinter();
     57 }
     58 
     59 CloudPrintURLFetcher::ResponseAction CloudPrintWipeout::OnRequestAuthError() {
     60   // We can't recover from auth rrror. Report complition to stop service.
     61   client_->OnUnregisterPrintersComplete();
     62   return CloudPrintURLFetcher::STOP_PROCESSING;
     63 }
     64 
     65 std::string CloudPrintWipeout::GetAuthHeader() {
     66   return GetCloudPrintAuthHeader(auth_token_);
     67 }
     68 
     69 }  // namespace cloud_print
     70