OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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.chrome.browser.rlz; |
| 6 |
| 7 import android.content.Context; |
| 8 import android.content.SharedPreferences; |
| 9 import android.preference.PreferenceManager; |
| 10 |
| 11 import org.chromium.base.ApplicationStatus; |
| 12 import org.chromium.base.JNINamespace; |
| 13 import org.chromium.chrome.browser.ChromeMobileApplication; |
| 14 import org.chromium.chrome.browser.Tab; |
| 15 |
| 16 import java.util.concurrent.atomic.AtomicReference; |
| 17 |
| 18 /** |
| 19 * Utility class for managing revenue sharing information. |
| 20 */ |
| 21 @JNINamespace("chrome::android") |
| 22 public class RevenueStats { |
| 23 private static final String PREF_RLZ_NOTIFIED = "rlz_first_search_notified"; |
| 24 |
| 25 // Use an AtomicReference since getInstance() can be called from multiple th
reads. |
| 26 private static AtomicReference<RevenueStats> sInstance = new AtomicReference
<RevenueStats>(); |
| 27 |
| 28 /** |
| 29 * Returns the singleton instance of ExternalAuthUtils, creating it if neede
d. |
| 30 */ |
| 31 public static RevenueStats getInstance() { |
| 32 if (sInstance.get() == null) { |
| 33 ChromeMobileApplication application = |
| 34 (ChromeMobileApplication) ApplicationStatus.getApplicationCo
ntext(); |
| 35 sInstance.compareAndSet(null, application.createRevenueStatsInstance
()); |
| 36 } |
| 37 return sInstance.get(); |
| 38 } |
| 39 |
| 40 /** |
| 41 * Notifies tab creation event. |
| 42 */ |
| 43 public void tabCreated(Tab chromeTab) {} |
| 44 |
| 45 /** |
| 46 * Retrieves the client ID string. |
| 47 */ |
| 48 public String retrieveClientId() { |
| 49 return null; |
| 50 } |
| 51 |
| 52 /** |
| 53 * Returns whether the RLZ provider has been notified that the first search
has occurred. |
| 54 */ |
| 55 protected static boolean getRlzNotified(Context context) { |
| 56 return PreferenceManager.getDefaultSharedPreferences(context).getBoolean
( |
| 57 PREF_RLZ_NOTIFIED, false); |
| 58 } |
| 59 |
| 60 /** |
| 61 * Stores whether the RLZ provider has been notified that the first search h
as occurred as |
| 62 * shared preference. |
| 63 */ |
| 64 protected static void setRlzNotified(Context context, boolean notified) { |
| 65 SharedPreferences.Editor sharedPreferencesEditor = |
| 66 PreferenceManager.getDefaultSharedPreferences(context).edit(); |
| 67 sharedPreferencesEditor.putBoolean(PREF_RLZ_NOTIFIED, notified); |
| 68 sharedPreferencesEditor.apply(); |
| 69 } |
| 70 |
| 71 /** |
| 72 * Sets search client id. |
| 73 */ |
| 74 protected static void setSearchClient(String client) { |
| 75 nativeSetSearchClient(client); |
| 76 } |
| 77 |
| 78 /** |
| 79 * Sets rlz value. |
| 80 */ |
| 81 protected static void setRlzParameterValue(String rlz) { |
| 82 nativeSetRlzParameterValue(rlz); |
| 83 } |
| 84 |
| 85 private static native void nativeSetSearchClient(String client); |
| 86 private static native void nativeSetRlzParameterValue(String rlz); |
| 87 } |
OLD | NEW |