mobile/android/base/sync/config/ClientRecordTerminator.java

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 package org.mozilla.gecko.sync.config;
     7 import java.net.URI;
     9 import org.mozilla.gecko.background.common.log.Logger;
    10 import org.mozilla.gecko.sync.SyncConfiguration;
    11 import org.mozilla.gecko.sync.net.AuthHeaderProvider;
    12 import org.mozilla.gecko.sync.net.BaseResource;
    13 import org.mozilla.gecko.sync.net.SyncStorageRecordRequest;
    14 import org.mozilla.gecko.sync.net.SyncStorageRequestDelegate;
    15 import org.mozilla.gecko.sync.net.SyncStorageResponse;
    17 /**
    18  * Bug 770785: when an Android Account is deleted, we need to (try to) delete
    19  * the associated client GUID from the server's clients table.
    20  * <p>
    21  * This class provides a static method to do that.
    22  */
    23 public class ClientRecordTerminator {
    24   public static final String LOG_TAG = "ClientRecTerminator";
    26   protected ClientRecordTerminator() {
    27     super(); // Stop this class from being instantiated.
    28   }
    30   public static void deleteClientRecord(final SyncConfiguration config, final String clientGUID)
    31     throws Exception {
    33     final String collection = "clients";
    34     final URI wboURI = config.wboURI(collection, clientGUID);
    36     // Would prefer to break this out into a self-contained client library.
    37     final SyncStorageRecordRequest r = new SyncStorageRecordRequest(wboURI);
    38     r.delegate = new SyncStorageRequestDelegate() {
    39       @Override
    40       public AuthHeaderProvider getAuthHeaderProvider() {
    41         return config.getAuthHeaderProvider();
    42       }
    44       @Override
    45       public String ifUnmodifiedSince() {
    46         return null;
    47       }
    49       @Override
    50       public void handleRequestSuccess(SyncStorageResponse response) {
    51         Logger.info(LOG_TAG, "Deleted client record with GUID " + clientGUID + " from server.");
    52         BaseResource.consumeEntity(response);
    53       }
    55       @Override
    56       public void handleRequestFailure(SyncStorageResponse response) {
    57         Logger.warn(LOG_TAG, "Failed to delete client record with GUID " + clientGUID + " from server.");
    58         try {
    59           Logger.warn(LOG_TAG, "Server error message was: " + response.getErrorMessage());
    60         } catch (Exception e) {
    61           // Do nothing.
    62         }
    63         BaseResource.consumeEntity(response);
    64       }
    66       @Override
    67       public void handleRequestError(Exception ex) {
    68         // It could be that we don't have network access when trying
    69         // to remove an Account; not much to be done in this situation.
    70         Logger.error(LOG_TAG, "Got exception trying to delete client record with GUID " + clientGUID + " from server; ignoring.", ex);
    71       }
    72     };
    74     r.delete();
    75   }
    76 }

mercurial