EMMA Coverage Report (generated Fri Aug 23 16:39:17 PDT 2013)
[all classes][org.chromium.chrome.browser.identity]

COVERAGE SUMMARY FOR SOURCE FILE [UuidBasedUniqueIdentificationGenerator.java]

nameclass, %method, %block, %line, %
UuidBasedUniqueIdentificationGenerator.java100% (1/1)67%  (2/3)93%  (39/42)93%  (13/14)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class UuidBasedUniqueIdentificationGenerator100% (1/1)67%  (2/3)93%  (39/42)93%  (13/14)
getUUID (): String 0%   (0/1)0%   (0/3)0%   (0/1)
UuidBasedUniqueIdentificationGenerator (Context, String): void 100% (1/1)100% (9/9)100% (4/4)
getUniqueId (String): String 100% (1/1)100% (30/30)100% (9/9)

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 
5package org.chromium.chrome.browser.identity;
6 
7import android.content.Context;
8import android.content.SharedPreferences;
9import android.preference.PreferenceManager;
10 
11import com.google.common.annotations.VisibleForTesting;
12 
13import java.util.UUID;
14 
15import javax.annotation.Nullable;
16 
17/**
18 * Generates unique IDs that are {@link UUID} strings.
19 */
20public class UuidBasedUniqueIdentificationGenerator implements UniqueIdentificationGenerator {
21    private final Context mContext;
22    private final String mPreferenceKey;
23 
24    public UuidBasedUniqueIdentificationGenerator(Context context, String preferenceKey) {
25        mContext = context;
26        mPreferenceKey = preferenceKey;
27    }
28 
29    @Override
30    public String getUniqueId(@Nullable String salt) {
31        SharedPreferences preferences = PreferenceManager
32                .getDefaultSharedPreferences(mContext);
33        String storedUniqueId = preferences.getString(mPreferenceKey, null);
34        if (storedUniqueId != null) {
35            return storedUniqueId;
36        }
37 
38        // Generate a new unique ID.
39        String uniqueId = getUUID();
40 
41        // Store the field so we ensure we always return the same unique ID.
42        SharedPreferences.Editor editor = preferences.edit();
43        editor.putString(mPreferenceKey, uniqueId);
44        editor.apply();
45        return uniqueId;
46 
47    }
48 
49    @VisibleForTesting
50    String getUUID() {
51        return UUID.randomUUID().toString();
52    }
53}

[all classes][org.chromium.chrome.browser.identity]
EMMA 2.0.5312 (C) Vladimir Roubtsov