com.google.ipc.invalidation.external.client.SystemResources.Logger Java Examples

The following examples show how to use com.google.ipc.invalidation.external.client.SystemResources.Logger. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PersistenceUtils.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Deserializes a Ticl state blob. Returns either the parsed state or {@code null}
 * if it could not be parsed.
 */
public static PersistentTiclState deserializeState(Logger logger, byte[] stateBlobBytes,
    DigestFunction digestFn) {
  PersistentStateBlob stateBlob;
  try {
    // Try parsing the envelope protocol buffer.
    stateBlob = PersistentStateBlob.parseFrom(stateBlobBytes);
  } catch (ValidationException exception) {
    logger.severe("Failed deserializing Ticl state: %s", exception.getMessage());
    return null;
  }

  // Check the mac in the envelope against the recomputed mac from the state.
  PersistentTiclState ticlState = stateBlob.getTiclState();
  Bytes mac = generateMac(ticlState, digestFn);
  if (!TypedUtil.<Bytes>equals(mac, stateBlob.getAuthenticationCode())) {
    logger.warning("Ticl state failed MAC check: computed %s vs %s", mac,
        stateBlob.getAuthenticationCode());
    return null;
  }
  return ticlState;
}
 
Example #2
Source File: RecurringTask.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Creates a recurring task with the given parameters. The specs of the parameters are given in
 * the instance variables.
 * <p>
 * The created task is first scheduled with a smeared delay of {@code initialDelayMs}. If the
 * {@code this.run()} returns true on its execution, the task is rescheduled after a
 * {@code timeoutDelayMs} + smeared delay of {@code initialDelayMs} or {@code timeoutDelayMs} +
 * {@code delayGenerator.getNextDelay()} depending on whether the {@code delayGenerator} is null
 * or not.
 */

public RecurringTask(String name, Scheduler scheduler, Logger logger, Smearer smearer,
    TiclExponentialBackoffDelayGenerator delayGenerator,
    final int initialDelayMs, final int timeoutDelayMs) {
  this.delayGenerator = delayGenerator;
  this.name = Preconditions.checkNotNull(name);
  this.logger = Preconditions.checkNotNull(logger);
  this.scheduler = Preconditions.checkNotNull(scheduler);
  this.smearer = Preconditions.checkNotNull(smearer);
  this.initialDelayMs = initialDelayMs;
  this.isScheduled = false;
  this.timeoutDelayMs = timeoutDelayMs;

  // Create a runnable that runs the task. If the task asks for a retry, reschedule it after
  // at a timeout delay. Otherwise, resets the delayGenerator.
  this.runnable = createRunnable();
}
 
Example #3
Source File: RegistrationManager.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public RegistrationManager(Logger logger, Statistics statistics, DigestFunction digestFn,
    RegistrationManagerStateP registrationManagerState) {
  this.logger = logger;
  this.statistics = statistics;
  this.desiredRegistrations = new SimpleRegistrationStore(digestFn);

  if (registrationManagerState == null) {
    // Initialize the server summary with a 0 size and the digest corresponding
    // to it.  Using defaultInstance would wrong since the server digest will
    // not match unnecessarily and result in an info message being sent.
    this.lastKnownServerSummary = ProtoWrapper.of(getRegistrationSummary());
  } else {
    this.lastKnownServerSummary =
      ProtoWrapper.of(registrationManagerState.getLastKnownServerSummary());
    desiredRegistrations.add(registrationManagerState.getRegistrationsList());
    for (RegistrationP regOp : registrationManagerState.getPendingOperationsList()) {
      pendingOperations.put(ProtoWrapper.of(regOp.getObjectId()), regOp.getOpType());
    }
  }
}
 
Example #4
Source File: RegistrationManager.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public RegistrationManager(Logger logger, Statistics statistics, DigestFunction digestFn,
    RegistrationManagerStateP registrationManagerState) {
  this.logger = logger;
  this.statistics = statistics;
  this.desiredRegistrations = new SimpleRegistrationStore(digestFn);

  if (registrationManagerState == null) {
    // Initialize the server summary with a 0 size and the digest corresponding
    // to it.  Using defaultInstance would wrong since the server digest will
    // not match unnecessarily and result in an info message being sent.
    this.lastKnownServerSummary = ProtoWrapper.of(getRegistrationSummary());
  } else {
    this.lastKnownServerSummary =
      ProtoWrapper.of(registrationManagerState.getLastKnownServerSummary());
    desiredRegistrations.add(registrationManagerState.getRegistrationsList());
    for (RegistrationP regOp : registrationManagerState.getPendingOperationsList()) {
      pendingOperations.put(ProtoWrapper.of(regOp.getObjectId()), regOp.getOpType());
    }
  }
}
 
Example #5
Source File: RecurringTask.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Creates a recurring task with the given parameters. The specs of the parameters are given in
 * the instance variables.
 * <p>
 * The created task is first scheduled with a smeared delay of {@code initialDelayMs}. If the
 * {@code this.run()} returns true on its execution, the task is rescheduled after a
 * {@code timeoutDelayMs} + smeared delay of {@code initialDelayMs} or {@code timeoutDelayMs} +
 * {@code delayGenerator.getNextDelay()} depending on whether the {@code delayGenerator} is null
 * or not.
 */

public RecurringTask(String name, Scheduler scheduler, Logger logger, Smearer smearer,
    TiclExponentialBackoffDelayGenerator delayGenerator,
    final int initialDelayMs, final int timeoutDelayMs) {
  this.delayGenerator = delayGenerator;
  this.name = Preconditions.checkNotNull(name);
  this.logger = Preconditions.checkNotNull(logger);
  this.scheduler = Preconditions.checkNotNull(scheduler);
  this.smearer = Preconditions.checkNotNull(smearer);
  this.initialDelayMs = initialDelayMs;
  this.isScheduled = false;
  this.timeoutDelayMs = timeoutDelayMs;

  // Create a runnable that runs the task. If the task asks for a retry, reschedule it after
  // at a timeout delay. Otherwise, resets the delayGenerator.
  this.runnable = createRunnable();
}
 
Example #6
Source File: RegistrationManager.java    From 365browser with Apache License 2.0 6 votes vote down vote up
public RegistrationManager(Logger logger, Statistics statistics, DigestFunction digestFn,
    RegistrationManagerStateP registrationManagerState) {
  this.logger = logger;
  this.statistics = statistics;
  this.desiredRegistrations = new SimpleRegistrationStore(digestFn);

  if (registrationManagerState == null) {
    // Initialize the server summary with a 0 size and the digest corresponding
    // to it.  Using defaultInstance would wrong since the server digest will
    // not match unnecessarily and result in an info message being sent.
    this.lastKnownServerSummary = getRegistrationSummary();
  } else {
    this.lastKnownServerSummary = registrationManagerState.getNullableLastKnownServerSummary();
    if (this.lastKnownServerSummary == null) {
      // If no server summary is set, use a default with size 0.
      this.lastKnownServerSummary = getRegistrationSummary();
    }
    desiredRegistrations.add(registrationManagerState.getRegistrations());
    for (RegistrationP regOp : registrationManagerState.getPendingOperations()) {
      pendingOperations.put(regOp.getObjectId(), regOp.getOpType());
    }
  }
}
 
Example #7
Source File: RecurringTask.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a recurring task with the given parameters. The specs of the parameters are given in
 * the instance variables.
 * <p>
 * The created task is first scheduled with a smeared delay of {@code initialDelayMs}. If the
 * {@code this.run()} returns true on its execution, the task is rescheduled after a
 * {@code timeoutDelayMs} + smeared delay of {@code initialDelayMs} or {@code timeoutDelayMs} +
 * {@code delayGenerator.getNextDelay()} depending on whether the {@code delayGenerator} is null
 * or not.
 */

public RecurringTask(String name, Scheduler scheduler, Logger logger, Smearer smearer,
    TiclExponentialBackoffDelayGenerator delayGenerator,
    final int initialDelayMs, final int timeoutDelayMs) {
  this.delayGenerator = delayGenerator;
  this.name = Preconditions.checkNotNull(name);
  this.logger = Preconditions.checkNotNull(logger);
  this.scheduler = Preconditions.checkNotNull(scheduler);
  this.smearer = Preconditions.checkNotNull(smearer);
  this.initialDelayMs = initialDelayMs;
  this.isScheduled = false;
  this.timeoutDelayMs = timeoutDelayMs;

  // Create a runnable that runs the task. If the task asks for a retry, reschedule it after
  // at a timeout delay. Otherwise, resets the delayGenerator.
  this.runnable = createRunnable();
}
 
Example #8
Source File: PersistenceUtils.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Deserializes a Ticl state blob. Returns either the parsed state or {@code null}
 * if it could not be parsed.
 */
public static PersistentTiclState deserializeState(Logger logger, byte[] stateBlobBytes,
    DigestFunction digestFn) {
  PersistentStateBlob stateBlob;
  try {
    // Try parsing the envelope protocol buffer.
    stateBlob = PersistentStateBlob.parseFrom(stateBlobBytes);
  } catch (InvalidProtocolBufferException exception) {
    logger.severe("Failed deserializing Ticl state: %s", exception.getMessage());
    return null;
  }

  // Check the mac in the envelope against the recomputed mac from the state.
  PersistentTiclState ticlState = stateBlob.getTiclState();
  ByteString mac = generateMac(ticlState, digestFn);
  if (!TypedUtil.<ByteString>equals(mac, stateBlob.getAuthenticationCode())) {
    logger.warning("Ticl state failed MAC check: computed %s vs %s", mac,
        stateBlob.getAuthenticationCode());
    return null;
  }
  return ticlState;
}
 
Example #9
Source File: PersistenceUtils.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Deserializes a Ticl state blob. Returns either the parsed state or {@code null}
 * if it could not be parsed.
 */
public static PersistentTiclState deserializeState(Logger logger, byte[] stateBlobBytes,
    DigestFunction digestFn) {
  PersistentStateBlob stateBlob;
  try {
    // Try parsing the envelope protocol buffer.
    stateBlob = PersistentStateBlob.parseFrom(stateBlobBytes);
  } catch (InvalidProtocolBufferException exception) {
    logger.severe("Failed deserializing Ticl state: %s", exception.getMessage());
    return null;
  }

  // Check the mac in the envelope against the recomputed mac from the state.
  PersistentTiclState ticlState = stateBlob.getTiclState();
  ByteString mac = generateMac(ticlState, digestFn);
  if (!TypedUtil.<ByteString>equals(mac, stateBlob.getAuthenticationCode())) {
    logger.warning("Ticl state failed MAC check: computed %s vs %s", mac,
        stateBlob.getAuthenticationCode());
    return null;
  }
  return ticlState;
}
 
Example #10
Source File: TiclStateManager.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/** Returns whether the digest in {@code state} is correct. */
private static boolean isDigestValid(AndroidTiclStateWithDigest state, Logger logger) {
  Sha1DigestFunction digester = new Sha1DigestFunction();
  digester.update(state.getState().toByteArray());
  ByteString computedDigest = ByteString.copyFrom(digester.getDigest());
  if (!computedDigest.equals(state.getDigest())) {
    logger.warning("Android Ticl state digest mismatch; computed %s for %s",
        computedDigest, state);
    return false;
  }
  return true;
}
 
Example #11
Source File: Statistics.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Given the serialized {@code performanceCounters} of the client statistics, returns a Statistics
 * object with the performance counter values from {@code performanceCounters}.
 */

public static Statistics deserializeStatistics(Logger logger,
    Collection<PropertyRecord> performanceCounters) {
  Statistics statistics = new Statistics();

  // For each counter, parse out the counter name and value.
  for (PropertyRecord performanceCounter : performanceCounters) {
    String counterName = performanceCounter.getName();
    String[] parts = counterName.split("\\.");
    if (parts.length != 2) {
      logger.warning("Perf counter name must of form: class.value, skipping: %s", counterName);
      continue;
    }
    String className = parts[0];
    String fieldName = parts[1];
    int counterValue = performanceCounter.getValue();

    // Call the relevant method in a loop (i.e., depending on the type of the class).
    if (TypedUtil.<String>equals(className, SENT_MESSAGE_TYPE_NAME)) {
      incrementPerformanceCounterValue(logger, SENT_MESSAGE_TYPE_NAME_TO_VALUE_MAP,
          statistics.sentMessageTypes, fieldName, counterValue);
    } else if (TypedUtil.<String>equals(className, INCOMING_OPERATION_TYPE_NAME)) {
      incrementPerformanceCounterValue(logger, INCOMING_OPERATION_TYPE_NAME_TO_VALUE_MAP,
          statistics.incomingOperationTypes, fieldName, counterValue);
    } else if (TypedUtil.<String>equals(className, RECEIVED_MESSAGE_TYPE_NAME)) {
      incrementPerformanceCounterValue(logger, RECEIVED_MESSAGE_TYPE_NAME_TO_VALUE_MAP,
          statistics.receivedMessageTypes, fieldName, counterValue);
    } else if (TypedUtil.<String>equals(className,  LISTENER_EVENT_TYPE_NAME)) {
      incrementPerformanceCounterValue(logger, LISTENER_EVENT_TYPE_NAME_TO_VALUE_MAP,
          statistics.listenerEventTypes, fieldName, counterValue);
    } else if (TypedUtil.<String>equals(className,  CLIENT_ERROR_TYPE_NAME)) {
      incrementPerformanceCounterValue(logger, CLIENT_ERROR_TYPE_NAME_TO_VALUE_MAP,
          statistics.clientErrorTypes, fieldName, counterValue);
    } else {
      logger.warning("Skipping unknown enum class name %s", className);
    }
  }
  return statistics;
}
 
Example #12
Source File: CheckingInvalidationListener.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
CheckingInvalidationListener(InvalidationListener delegate, Scheduler internalScheduler,
    Scheduler listenerScheduler, Logger logger) {
  this.delegate = Preconditions.checkNotNull(delegate, "Delegate cannot be null");
  this.internalScheduler = Preconditions.checkNotNull(internalScheduler,
      "Internal scheduler cannot be null");
  this.listenerScheduler = Preconditions.checkNotNull(listenerScheduler,
      "Listener scheduler cannot be null");
  this.logger = Preconditions.checkNotNull(logger, "Logger cannot be null");
}
 
Example #13
Source File: RecurringTask.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Creates a recurring task from {@code marshalledState}. Other parameters are as in the
 * constructor above.
 */
RecurringTask(String name, Scheduler scheduler, Logger logger, Smearer smearer,
    TiclExponentialBackoffDelayGenerator delayGenerator,
    RecurringTaskState marshalledState) {
  this(name, scheduler, logger, smearer, delayGenerator, marshalledState.getInitialDelayMs(),
      marshalledState.getTimeoutDelayMs());
  this.isScheduled = marshalledState.getScheduled();
}
 
Example #14
Source File: SystemResourcesBuilder.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/** See specs at {@code DefaultResourcesFactory.createDefaultResourcesBuilder}. */
public SystemResourcesBuilder(Logger logger, Scheduler internalScheduler,
    Scheduler listenerScheduler, NetworkChannel network, Storage storage) {
  this.logger = logger;
  this.internalScheduler = internalScheduler;
  this.listenerScheduler = listenerScheduler;
  this.network = network;
  this.storage = storage;
}
 
Example #15
Source File: Statistics.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Given the serialized {@code performanceCounters} of the client statistics, returns a Statistics
 * object with the performance counter values from {@code performanceCounters}.
 */

public static Statistics deserializeStatistics(Logger logger,
    Collection<PropertyRecord> performanceCounters) {
  Statistics statistics = new Statistics();

  // For each counter, parse out the counter name and value.
  for (PropertyRecord performanceCounter : performanceCounters) {
    String counterName = performanceCounter.getName();
    String[] parts = counterName.split("\\.");
    if (parts.length != 2) {
      logger.warning("Perf counter name must of form: class.value, skipping: %s", counterName);
      continue;
    }
    String className = parts[0];
    String fieldName = parts[1];
    int counterValue = performanceCounter.getValue();

    // Call the relevant method in a loop (i.e., depending on the type of the class).
    if (TypedUtil.<String>equals(className, SENT_MESSAGE_TYPE_NAME)) {
      incrementPerformanceCounterValue(logger, SENT_MESSAGE_TYPE_NAME_TO_VALUE_MAP,
          statistics.sentMessageTypes, fieldName, counterValue);
    } else if (TypedUtil.<String>equals(className, INCOMING_OPERATION_TYPE_NAME)) {
      incrementPerformanceCounterValue(logger, INCOMING_OPERATION_TYPE_NAME_TO_VALUE_MAP,
          statistics.incomingOperationTypes, fieldName, counterValue);
    } else if (TypedUtil.<String>equals(className, RECEIVED_MESSAGE_TYPE_NAME)) {
      incrementPerformanceCounterValue(logger, RECEIVED_MESSAGE_TYPE_NAME_TO_VALUE_MAP,
          statistics.receivedMessageTypes, fieldName, counterValue);
    } else if (TypedUtil.<String>equals(className,  LISTENER_EVENT_TYPE_NAME)) {
      incrementPerformanceCounterValue(logger, LISTENER_EVENT_TYPE_NAME_TO_VALUE_MAP,
          statistics.listenerEventTypes, fieldName, counterValue);
    } else if (TypedUtil.<String>equals(className,  CLIENT_ERROR_TYPE_NAME)) {
      incrementPerformanceCounterValue(logger, CLIENT_ERROR_TYPE_NAME_TO_VALUE_MAP,
          statistics.clientErrorTypes, fieldName, counterValue);
    } else {
      logger.warning("Skipping unknown enum class name %s", className);
    }
  }
  return statistics;
}
 
Example #16
Source File: Statistics.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Looks for an enum value with the given {@code fieldName} in {@code valueOfMap} and increments
 * the corresponding entry in {@code counts} by {@code counterValue}. Call to update statistics
 * for a single performance counter.
 */
private static <Key extends Enum<Key>> void incrementPerformanceCounterValue(Logger logger,
    Map<String, Key> valueOfMap, Map<Key, Integer> counts, String fieldName, int counterValue) {
  Key type = TypedUtil.mapGet(valueOfMap, fieldName);
  if (type != null) {
    int currentValue = TypedUtil.mapGet(counts, type);
    counts.put(type, currentValue + counterValue);
  } else {
    logger.warning("Skipping unknown enum value name %s", fieldName);
  }
}
 
Example #17
Source File: AndroidMessageSenderService.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/** Returns the network id for this channel, or {@code null} if one cannot be determined. */


public static NetworkEndpointId getNetworkEndpointId(Context context, Logger logger) {
  String registrationId = GCMRegistrar.getRegistrationId(context);
  if (Strings.isNullOrEmpty(registrationId)) {
    // No registration with GCM; we cannot compute a network id. The GCM documentation says the
    // string is never null, but we'll be paranoid.
    logger.warning("No GCM registration id; cannot determine our network endpoint id: %s",
        registrationId);
    return null;
  }
  return CommonProtos2.newAndroidEndpointId(registrationId,
      NO_CLIENT_KEY, context.getPackageName(), AndroidChannelConstants.CHANNEL_VERSION);
}
 
Example #18
Source File: AndroidMessageReceiverService.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Initializes GCM as a convenience method for tests. In production, applications should handle
 * this.
 */
public static void initializeGcmForTest(Context context, Logger logger, String senderId) {
  // Initialize GCM.
  GCMRegistrar.checkDevice(context);
  GCMRegistrar.checkManifest(context);
  String regId = GCMRegistrar.getRegistrationId(context);
  if (regId.equals("")) {
    logger.info("Not registered with GCM; registering");
    GCMRegistrar.register(context, senderId);
  } else {
    logger.fine("Already registered with GCM: %s", regId);
  }
}
 
Example #19
Source File: TiclStateManager.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/** Returns whether the digest in {@code state} is correct. */
private static boolean isDigestValid(AndroidTiclStateWithDigest state, Logger logger) {
  Sha1DigestFunction digester = new Sha1DigestFunction();
  digester.update(state.getState().toByteArray());
  ByteString computedDigest = ByteString.copyFrom(digester.getDigest());
  if (!computedDigest.equals(state.getDigest())) {
    logger.warning("Android Ticl state digest mismatch; computed %s for %s",
        computedDigest, state);
    return false;
  }
  return true;
}
 
Example #20
Source File: CheckingInvalidationListener.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
CheckingInvalidationListener(InvalidationListener delegate, Scheduler internalScheduler,
    Scheduler listenerScheduler, Logger logger) {
  this.delegate = Preconditions.checkNotNull(delegate, "Delegate cannot be null");
  this.internalScheduler = Preconditions.checkNotNull(internalScheduler,
      "Internal scheduler cannot be null");
  this.listenerScheduler = Preconditions.checkNotNull(listenerScheduler,
      "Listener scheduler cannot be null");
  this.logger = Preconditions.checkNotNull(logger, "Logger cannot be null");
}
 
Example #21
Source File: RecurringTask.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Creates a recurring task from {@code marshalledState}. Other parameters are as in the
 * constructor above.
 */
RecurringTask(String name, Scheduler scheduler, Logger logger, Smearer smearer,
    TiclExponentialBackoffDelayGenerator delayGenerator,
    RecurringTaskState marshalledState) {
  this(name, scheduler, logger, smearer, delayGenerator, marshalledState.getInitialDelayMs(),
      marshalledState.getTimeoutDelayMs());
  this.isScheduled = marshalledState.getScheduled();
}
 
Example #22
Source File: SystemResourcesBuilder.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/** See specs at {@code DefaultResourcesFactory.createDefaultResourcesBuilder}. */
public SystemResourcesBuilder(Logger logger, Scheduler internalScheduler,
    Scheduler listenerScheduler, NetworkChannel network, Storage storage) {
  this.logger = logger;
  this.internalScheduler = internalScheduler;
  this.listenerScheduler = listenerScheduler;
  this.network = network;
  this.storage = storage;
}
 
Example #23
Source File: CheckingInvalidationListener.java    From 365browser with Apache License 2.0 5 votes vote down vote up
CheckingInvalidationListener(InvalidationListener delegate, Scheduler internalScheduler,
    Scheduler listenerScheduler, Logger logger) {
  this.delegate = Preconditions.checkNotNull(delegate, "Delegate cannot be null");
  this.internalScheduler = Preconditions.checkNotNull(internalScheduler,
      "Internal scheduler cannot be null");
  this.listenerScheduler = Preconditions.checkNotNull(listenerScheduler,
      "Listener scheduler cannot be null");
  this.logger = Preconditions.checkNotNull(logger, "Logger cannot be null");
}
 
Example #24
Source File: TiclStateManager.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/** Returns whether the digest in {@code state} is correct. */
private static boolean isDigestValid(AndroidTiclStateWithDigest state, Logger logger) {
  Sha1DigestFunction digester = new Sha1DigestFunction();
  digester.update(state.getState().toByteArray());
  byte[] computedDigest = digester.getDigest();
  if (!TypedUtil.<Bytes>equals(new Bytes(computedDigest), state.getDigest())) {
    logger.warning("Android TICL state digest mismatch; computed %s for %s",
        computedDigest, state);
    return false;
  }
  return true;
}
 
Example #25
Source File: AndroidMessageReceiverService.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Initializes GCM as a convenience method for tests. In production, applications should handle
 * this.
 */
public static void initializeGcmForTest(Context context, Logger logger, String senderId) {
  // Initialize GCM.
  GCMRegistrar.checkDevice(context);
  GCMRegistrar.checkManifest(context);
  String regId = GCMRegistrar.getRegistrationId(context);
  if (regId.equals("")) {
    logger.info("Not registered with GCM; registering");
    GCMRegistrar.register(context, senderId);
  } else {
    logger.fine("Already registered with GCM: %s", regId);
  }
}
 
Example #26
Source File: AndroidMessageSenderService.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/** Returns the network id for this channel, or {@code null} if one cannot be determined. */


public static NetworkEndpointId getNetworkEndpointId(Context context, Logger logger) {
  String registrationId = GCMRegistrar.getRegistrationId(context);
  if (Strings.isNullOrEmpty(registrationId)) {
    // No registration with GCM; we cannot compute a network id. The GCM documentation says the
    // string is never null, but we'll be paranoid.
    logger.warning("No GCM registration id; cannot determine our network endpoint id: %s",
        registrationId);
    return null;
  }
  return CommonProtos2.newAndroidEndpointId(registrationId,
      NO_CLIENT_KEY, context.getPackageName(), AndroidChannelConstants.CHANNEL_VERSION);
}
 
Example #27
Source File: Statistics.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Looks for an enum value with the given {@code fieldName} in {@code valueOfMap} and increments
 * the corresponding entry in {@code counts} by {@code counterValue}. Call to update statistics
 * for a single performance counter.
 */
private static <Key extends Enum<Key>> void incrementPerformanceCounterValue(Logger logger,
    Map<String, Key> valueOfMap, Map<Key, Integer> counts, String fieldName, int counterValue) {
  Key type = TypedUtil.mapGet(valueOfMap, fieldName);
  if (type != null) {
    int currentValue = TypedUtil.mapGet(counts, type);
    counts.put(type, currentValue + counterValue);
  } else {
    logger.warning("Skipping unknown enum value name %s", fieldName);
  }
}
 
Example #28
Source File: RecurringTask.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a recurring task from {@code marshalledState}. Other parameters are as in the
 * constructor above.
 */
RecurringTask(String name, Scheduler scheduler, Logger logger, Smearer smearer,
    TiclExponentialBackoffDelayGenerator delayGenerator,
    RecurringTaskState marshalledState) {
  this(name, scheduler, logger, smearer, delayGenerator, marshalledState.getInitialDelayMs(),
      marshalledState.getTimeoutDelayMs());
  this.isScheduled = marshalledState.getScheduled();
}
 
Example #29
Source File: Statistics.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Looks for an enum value with the given {@code fieldName} in {@code valueOfMap} and increments
 * the corresponding entry in {@code counts} by {@code counterValue}. Call to update statistics
 * for a single performance counter.
 */
private static <Key extends Enum<Key>> void incrementPerformanceCounterValue(Logger logger,
    Map<String, Key> valueOfMap, Map<Key, Integer> counts, String fieldName, int counterValue) {
  Key type = TypedUtil.mapGet(valueOfMap, fieldName);
  if (type != null) {
    int currentValue = TypedUtil.mapGet(counts, type);
    counts.put(type, currentValue + counterValue);
  } else {
    logger.warning("Skipping unknown enum value name %s", fieldName);
  }
}
 
Example #30
Source File: SystemResourcesBuilder.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/** See specs at {@code DefaultResourcesFactory.createDefaultResourcesBuilder}. */
public SystemResourcesBuilder(Logger logger, Scheduler internalScheduler,
    Scheduler listenerScheduler, NetworkChannel network, Storage storage) {
  this.logger = logger;
  this.internalScheduler = internalScheduler;
  this.listenerScheduler = listenerScheduler;
  this.network = network;
  this.storage = storage;
}