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 #ifndef CHROME_BROWSER_ANDROID_SIGNIN_SIGNIN_MANAGER_ANDROID_H_ 6 #define CHROME_BROWSER_ANDROID_SIGNIN_SIGNIN_MANAGER_ANDROID_H_ 7 8 #include <jni.h> 9 10 #include <string> 11 12 #include "base/android/scoped_java_ref.h" 13 #include "base/basictypes.h" 14 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/weak_ptr.h" 16 #include "google_apis/gaia/merge_session_helper.h" 17 18 class GoogleServiceAuthError; 19 class Profile; 20 21 namespace policy { 22 class CloudPolicyClient; 23 } 24 25 // Android wrapper of the SigninManager which provides access from the Java 26 // layer. Note that on Android, there's only a single profile, and therefore 27 // a single instance of this wrapper. The name of the Java class is 28 // SigninManager. 29 // This class should only be accessed from the UI thread. 30 // 31 // This class implements parts of the sign-in flow, to make sure that policy 32 // is available before sign-in completes. 33 class SigninManagerAndroid : public MergeSessionHelper::Observer { 34 public: 35 SigninManagerAndroid(JNIEnv* env, jobject obj); 36 37 // Registers the SigninManagerAndroid's native methods through JNI. 38 static bool Register(JNIEnv* env); 39 40 void CheckPolicyBeforeSignIn(JNIEnv* env, jobject obj, jstring username); 41 42 void FetchPolicyBeforeSignIn(JNIEnv* env, jobject obj); 43 44 void OnSignInCompleted(JNIEnv* env, jobject obj, jstring username); 45 46 void SignOut(JNIEnv* env, jobject obj); 47 48 base::android::ScopedJavaLocalRef<jstring> GetManagementDomain(JNIEnv* env, 49 jobject obj); 50 51 void WipeProfileData(JNIEnv* env, jobject obj); 52 53 void LogInSignedInUser(JNIEnv* env, jobject obj); 54 55 void ClearLastSignedInUser(JNIEnv* env, jobject obj); 56 57 private: 58 virtual ~SigninManagerAndroid(); 59 60 #if defined(ENABLE_CONFIGURATION_POLICY) 61 void OnPolicyRegisterDone(const std::string& dm_token, 62 const std::string& client_id); 63 void OnPolicyFetchDone(bool success); 64 #endif 65 66 void OnBrowsingDataRemoverDone(); 67 68 void ClearLastSignedInUser(); 69 70 // MergeSessionHelper::Observer implementation. 71 virtual void MergeSessionCompleted( 72 const std::string& account_id, 73 const GoogleServiceAuthError& error) OVERRIDE; 74 75 Profile* profile_; 76 77 // Java-side SigninManager object. 78 base::android::ScopedJavaGlobalRef<jobject> java_signin_manager_; 79 80 #if defined(ENABLE_CONFIGURATION_POLICY) 81 // CloudPolicy credentials stored during a pending sign-in, awaiting user 82 // confirmation before starting to fetch policies. 83 std::string dm_token_; 84 std::string client_id_; 85 86 // Username that is pending sign-in. This is used to extract the domain name 87 // for the policy dialog, when |username_| corresponds to a managed account. 88 std::string username_; 89 #endif 90 91 // Helper to merge the signed into account into the cookie jar session. 92 scoped_ptr<MergeSessionHelper> merge_session_helper_; 93 94 base::WeakPtrFactory<SigninManagerAndroid> weak_factory_; 95 96 DISALLOW_COPY_AND_ASSIGN(SigninManagerAndroid); 97 }; 98 99 #endif // CHROME_BROWSER_ANDROID_SIGNIN_SIGNIN_MANAGER_ANDROID_H_ 100