Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(401)

Side by Side Diff: sync/android/java/src/org/chromium/sync/notifier/RandomizedInvalidationClientNameGenerator.java

Issue 2130453004: [Sync] Move //sync to //components/sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2013 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.sync.notifier;
6
7 import android.util.Base64;
8
9 import org.chromium.base.annotations.MainDex;
10
11 import java.util.Random;
12
13 /**
14 * Generates a fully random client ID.
15 *
16 * This ID will not persist across restarts. Using this ID will break the inval idator's "reflection
17 * blocking" feature. That's unfortunate, but better than using a hard-coded ID . A hard-coded ID
18 * could prevent invalidations from being delivered.
19 */
20 @MainDex
21 class RandomizedInvalidationClientNameGenerator implements InvalidationClientNam eGenerator {
22 private static final Random RANDOM = new Random();
23
24 RandomizedInvalidationClientNameGenerator() {}
25
26 /**
27 * Generates a random ID prefixed with the string "BadID".
28 *
29 * The prefix is intended to grab attention. We should never use it in real builds. Hopefully,
30 * it will induce someone to file a bug if they see it.
31 *
32 * However, as bad as it is, this ID is better than a hard-coded default or none at all. See
33 * the class description for more details.
34 */
35 public byte[] generateInvalidatorClientName() {
36 byte[] randomBytes = new byte[8];
37 RANDOM.nextBytes(randomBytes);
38 String encoded = Base64.encodeToString(randomBytes, 0, randomBytes.lengt h, Base64.NO_WRAP);
39 String idString = "BadID" + encoded;
40 return idString.getBytes();
41 }
42 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698