OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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.chrome.browser.signin; | 5 package org.chromium.chrome.browser.signin; |
6 | 6 |
7 import android.accounts.Account; | 7 import android.accounts.Account; |
8 import android.annotation.TargetApi; | 8 import android.annotation.TargetApi; |
9 import android.app.Activity; | 9 import android.app.Activity; |
10 import android.app.Dialog; | 10 import android.app.Dialog; |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 public static final String PREF_SYNC_SETTINGS = "sync_settings"; | 112 public static final String PREF_SYNC_SETTINGS = "sync_settings"; |
113 | 113 |
114 private int mGaiaServiceType; | 114 private int mGaiaServiceType; |
115 | 115 |
116 private ArrayList<Preference> mAccountsListPreferences = new ArrayList<Prefe
rence>(); | 116 private ArrayList<Preference> mAccountsListPreferences = new ArrayList<Prefe
rence>(); |
117 | 117 |
118 @Override | 118 @Override |
119 public void onCreate(Bundle savedState) { | 119 public void onCreate(Bundle savedState) { |
120 super.onCreate(savedState); | 120 super.onCreate(savedState); |
121 | 121 |
| 122 // Prevent sync from starting if it hasn't already to give the user a ch
ance to change |
| 123 // their sync settings. |
| 124 ProfileSyncService syncService = ProfileSyncService.get(); |
| 125 if (syncService != null) { |
| 126 syncService.setSetupInProgress(true); |
| 127 } |
| 128 |
122 mGaiaServiceType = AccountManagementScreenHelper.GAIA_SERVICE_TYPE_NONE; | 129 mGaiaServiceType = AccountManagementScreenHelper.GAIA_SERVICE_TYPE_NONE; |
123 if (getArguments() != null) { | 130 if (getArguments() != null) { |
124 mGaiaServiceType = | 131 mGaiaServiceType = |
125 getArguments().getInt(SHOW_GAIA_SERVICE_TYPE_EXTRA, mGaiaSer
viceType); | 132 getArguments().getInt(SHOW_GAIA_SERVICE_TYPE_EXTRA, mGaiaSer
viceType); |
126 } | 133 } |
127 | 134 |
128 AccountManagementScreenHelper.logEvent( | 135 AccountManagementScreenHelper.logEvent( |
129 ProfileAccountManagementMetrics.VIEW, | 136 ProfileAccountManagementMetrics.VIEW, |
130 mGaiaServiceType); | 137 mGaiaServiceType); |
131 | 138 |
(...skipping 17 matching lines...) Expand all Loading... |
149 public void onPause() { | 156 public void onPause() { |
150 super.onPause(); | 157 super.onPause(); |
151 SigninManager.get(getActivity()).removeSignInStateObserver(this); | 158 SigninManager.get(getActivity()).removeSignInStateObserver(this); |
152 ProfileDownloader.removeObserver(this); | 159 ProfileDownloader.removeObserver(this); |
153 ProfileSyncService syncService = ProfileSyncService.get(); | 160 ProfileSyncService syncService = ProfileSyncService.get(); |
154 if (syncService != null) { | 161 if (syncService != null) { |
155 syncService.removeSyncStateChangedListener(this); | 162 syncService.removeSyncStateChangedListener(this); |
156 } | 163 } |
157 } | 164 } |
158 | 165 |
| 166 @Override |
| 167 public void onDestroy() { |
| 168 super.onDestroy(); |
| 169 |
| 170 // Allow sync to begin syncing if it hasn't yet. |
| 171 ProfileSyncService syncService = ProfileSyncService.get(); |
| 172 if (syncService != null) { |
| 173 syncService.setSetupInProgress(false); |
| 174 } |
| 175 } |
| 176 |
159 /** | 177 /** |
160 * Initiate fetching the user accounts data (images and the full name). | 178 * Initiate fetching the user accounts data (images and the full name). |
161 * Fetched data will be sent to observers of ProfileDownloader. | 179 * Fetched data will be sent to observers of ProfileDownloader. |
162 * | 180 * |
163 * @param profile Profile to use. | 181 * @param profile Profile to use. |
164 */ | 182 */ |
165 private static void startFetchingAccountsInformation(Context context, Profil
e profile) { | 183 private static void startFetchingAccountsInformation(Context context, Profil
e profile) { |
166 Account[] accounts = AccountManagerHelper.get(context).getGoogleAccounts
(); | 184 Account[] accounts = AccountManagerHelper.get(context).getGoogleAccounts
(); |
167 for (int i = 0; i < accounts.length; i++) { | 185 for (int i = 0; i < accounts.length; i++) { |
168 startFetchingAccountInformation(context, profile, accounts[i].name); | 186 startFetchingAccountInformation(context, profile, accounts[i].name); |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 ProfileAccountManagementMetrics.SIGNOUT_CANCEL, | 500 ProfileAccountManagementMetrics.SIGNOUT_CANCEL, |
483 mGaiaServiceType); | 501 mGaiaServiceType); |
484 } | 502 } |
485 } | 503 } |
486 | 504 |
487 // ProfileSyncServiceListener implementation: | 505 // ProfileSyncServiceListener implementation: |
488 | 506 |
489 @Override | 507 @Override |
490 public void syncStateChanged() { | 508 public void syncStateChanged() { |
491 SyncPreference pref = (SyncPreference) findPreference(PREF_SYNC_SETTINGS
); | 509 SyncPreference pref = (SyncPreference) findPreference(PREF_SYNC_SETTINGS
); |
492 pref.updateSyncSummaryAndIcon(); | 510 if (pref != null) { |
| 511 pref.updateSyncSummaryAndIcon(); |
| 512 } |
493 | 513 |
494 // TODO(crbug/557784): Show notification for sync error | 514 // TODO(crbug/557784): Show notification for sync error |
495 } | 515 } |
496 | 516 |
497 // SignInStateObserver implementation: | 517 // SignInStateObserver implementation: |
498 | 518 |
499 @Override | 519 @Override |
500 public void onSignedIn() { | 520 public void onSignedIn() { |
501 update(); | 521 update(); |
502 } | 522 } |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
697 * @param context A context | 717 * @param context A context |
698 * @param isAllowed True if the sign out is not disabled due to a child/EDU
account | 718 * @param isAllowed True if the sign out is not disabled due to a child/EDU
account |
699 */ | 719 */ |
700 public static void setSignOutAllowedPreferenceValue(Context context, boolean
isAllowed) { | 720 public static void setSignOutAllowedPreferenceValue(Context context, boolean
isAllowed) { |
701 ContextUtils.getAppSharedPreferences() | 721 ContextUtils.getAppSharedPreferences() |
702 .edit() | 722 .edit() |
703 .putBoolean(SIGN_OUT_ALLOWED, isAllowed) | 723 .putBoolean(SIGN_OUT_ALLOWED, isAllowed) |
704 .apply(); | 724 .apply(); |
705 } | 725 } |
706 } | 726 } |
OLD | NEW |