| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 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 package org.chromium.sdk.internal.wip; | |
| 6 | |
| 7 import java.util.ArrayList; | |
| 8 import java.util.List; | |
| 9 | |
| 10 import org.chromium.sdk.internal.BaseCommandProcessor; | |
| 11 import org.chromium.sdk.internal.wip.protocol.input.WipCommandResponse; | |
| 12 | |
| 13 /** | |
| 14 * An explicit interface for a generic type {@link BaseCommandProcessor.Callback
}. | |
| 15 */ | |
| 16 public interface WipCommandCallback extends BaseCommandProcessor.Callback<WipCom
mandResponse> { | |
| 17 | |
| 18 /** | |
| 19 * A default implementation of the callback that separates error responses fro
m | |
| 20 * success responses. | |
| 21 */ | |
| 22 abstract class Default implements WipCommandCallback { | |
| 23 protected abstract void onSuccess(WipCommandResponse.Success success); | |
| 24 protected abstract void onError(String message); | |
| 25 | |
| 26 @Override | |
| 27 public void messageReceived(WipCommandResponse response) { | |
| 28 WipCommandResponse.Success asSuccess = response.asSuccess(); | |
| 29 if (asSuccess != null) { | |
| 30 onSuccess(asSuccess); | |
| 31 } else { | |
| 32 String message; | |
| 33 WipCommandResponse.Error asError = response.asError(); | |
| 34 if (asError == null) { | |
| 35 message = "Internal messaging error"; | |
| 36 } else { | |
| 37 List<String> messageList = new ArrayList<String>(2); | |
| 38 messageList.add(asError.error().message()); | |
| 39 List<String> data = asError.error().data(); | |
| 40 if (data != null) { | |
| 41 messageList.addAll(data); | |
| 42 } | |
| 43 message = messageList.toString(); | |
| 44 } | |
| 45 onError(message); | |
| 46 } | |
| 47 } | |
| 48 | |
| 49 @Override | |
| 50 public void failure(String message) { | |
| 51 onError(message); | |
| 52 } | |
| 53 } | |
| 54 } | |
| OLD | NEW |