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

Side by Side Diff: sync/android/java/src/org/chromium/sync/signin/ChromeSigninController.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.signin;
6
7 import android.accounts.Account;
8 import android.content.Context;
9
10 import org.chromium.base.ContextUtils;
11 import org.chromium.sync.AndroidSyncSettings;
12
13 /**
14 * Caches the signed-in username in the app prefs.
15 */
16 public class ChromeSigninController {
17
18 public static final String TAG = "ChromeSigninController";
19
20 // Used by ChromeBackupAgent and for testing.
21 public static final String SIGNED_IN_ACCOUNT_KEY = "google.services.username ";
22
23 private static final Object LOCK = new Object();
24
25 private static ChromeSigninController sChromeSigninController;
26
27 private final Context mApplicationContext;
28
29 private ChromeSigninController(Context context) {
30 mApplicationContext = context.getApplicationContext();
31 AndroidSyncSettings.updateAccount(context, getSignedInUser());
32 }
33
34 /**
35 * A factory method for the ChromeSigninController.
36 *
37 * @param context the ApplicationContext is retrieved from the context used as an argument.
38 * @return a singleton instance of the ChromeSigninController
39 */
40 public static ChromeSigninController get(Context context) {
41 synchronized (LOCK) {
42 if (sChromeSigninController == null) {
43 sChromeSigninController = new ChromeSigninController(context);
44 }
45 }
46 return sChromeSigninController;
47 }
48
49 public Account getSignedInUser() {
50 String syncAccountName = getSignedInAccountName();
51 if (syncAccountName == null) {
52 return null;
53 }
54 return AccountManagerHelper.createAccountFromName(syncAccountName);
55 }
56
57 public boolean isSignedIn() {
58 return getSignedInAccountName() != null;
59 }
60
61 public void setSignedInAccountName(String accountName) {
62 ContextUtils.getAppSharedPreferences().edit()
63 .putString(SIGNED_IN_ACCOUNT_KEY, accountName)
64 .apply();
65 // TODO(maxbogue): Move this to SigninManager.
66 AndroidSyncSettings.updateAccount(mApplicationContext, getSignedInUser() );
67 }
68
69 public String getSignedInAccountName() {
70 return ContextUtils.getAppSharedPreferences().getString(SIGNED_IN_ACCOUN T_KEY, null);
71 }
72 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698