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

Side by Side Diff: components/signin/core/browser/android/java/src/org/chromium/components/signin/ChromeSigninController.java

Issue 2784353002: Android: Remove GetApplicationContext part 2 (Closed)
Patch Set: Fix tests Created 3 years, 8 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.components.signin; 5 package org.chromium.components.signin;
6 6
7 import android.accounts.Account; 7 import android.accounts.Account;
8 import android.content.Context;
9 8
10 import org.chromium.base.ContextUtils; 9 import org.chromium.base.ContextUtils;
11 10
12 /** 11 /**
13 * Caches the signed-in username in the app prefs. 12 * Caches the signed-in username in the app prefs.
14 */ 13 */
15 public class ChromeSigninController { 14 public class ChromeSigninController {
16 public static final String TAG = "ChromeSigninController"; 15 public static final String TAG = "ChromeSigninController";
17 16
18 // Used by ChromeBackupAgent and for testing. 17 // Used by ChromeBackupAgent and for testing.
19 public static final String SIGNED_IN_ACCOUNT_KEY = "google.services.username "; 18 public static final String SIGNED_IN_ACCOUNT_KEY = "google.services.username ";
20 19
21 private static final Object LOCK = new Object(); 20 private static final Object LOCK = new Object();
22 21
23 private static ChromeSigninController sChromeSigninController; 22 private static ChromeSigninController sChromeSigninController;
24 23
25 private final Context mApplicationContext; 24 private ChromeSigninController() {}
26
27 private ChromeSigninController(Context context) {
28 mApplicationContext = context.getApplicationContext();
29 }
30 25
31 /** 26 /**
32 * A factory method for the ChromeSigninController. 27 * A factory method for the ChromeSigninController.
33 * 28 *
34 * @param context the ApplicationContext is retrieved from the context used as an argument.
35 * @return a singleton instance of the ChromeSigninController 29 * @return a singleton instance of the ChromeSigninController
36 */ 30 */
37 public static ChromeSigninController get(Context context) { 31 public static ChromeSigninController get() {
38 synchronized (LOCK) { 32 synchronized (LOCK) {
39 if (sChromeSigninController == null) { 33 if (sChromeSigninController == null) {
40 sChromeSigninController = new ChromeSigninController(context); 34 sChromeSigninController = new ChromeSigninController();
41 } 35 }
42 } 36 }
43 return sChromeSigninController; 37 return sChromeSigninController;
44 } 38 }
45 39
46 public Account getSignedInUser() { 40 public Account getSignedInUser() {
47 String syncAccountName = getSignedInAccountName(); 41 String syncAccountName = getSignedInAccountName();
48 if (syncAccountName == null) { 42 if (syncAccountName == null) {
49 return null; 43 return null;
50 } 44 }
51 return AccountManagerHelper.createAccountFromName(syncAccountName); 45 return AccountManagerHelper.createAccountFromName(syncAccountName);
52 } 46 }
53 47
54 public boolean isSignedIn() { 48 public boolean isSignedIn() {
55 return getSignedInAccountName() != null; 49 return getSignedInAccountName() != null;
56 } 50 }
57 51
58 public void setSignedInAccountName(String accountName) { 52 public void setSignedInAccountName(String accountName) {
59 ContextUtils.getAppSharedPreferences() 53 ContextUtils.getAppSharedPreferences()
60 .edit() 54 .edit()
61 .putString(SIGNED_IN_ACCOUNT_KEY, accountName) 55 .putString(SIGNED_IN_ACCOUNT_KEY, accountName)
62 .apply(); 56 .apply();
63 } 57 }
64 58
65 public String getSignedInAccountName() { 59 public String getSignedInAccountName() {
66 return ContextUtils.getAppSharedPreferences().getString(SIGNED_IN_ACCOUN T_KEY, null); 60 return ContextUtils.getAppSharedPreferences().getString(SIGNED_IN_ACCOUN T_KEY, null);
67 } 61 }
68 } 62 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698