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.

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

mercurial