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 17 class Profile; 18 19 namespace policy { 20 class CloudPolicyClient; 21 } 22 23 // Android wrapper of the SigninManager which provides access from the Java 24 // layer. Note that on Android, there's only a single profile, and therefore 25 // a single instance of this wrapper. The name of the Java class is 26 // SigninManager. 27 // This class should only be accessed from the UI thread. 28 // 29 // This class implements parts of the sign-in flow, to make sure that policy 30 // is available before sign-in completes. 31 class SigninManagerAndroid { 32 public: 33 SigninManagerAndroid(JNIEnv* env, jobject obj); 34 35 // Registers the SigninManagerAndroid's native methods through JNI. 36 static bool Register(JNIEnv* env); 37 38 void CheckPolicyBeforeSignIn(JNIEnv* env, jobject obj, jstring username); 39 40 void FetchPolicyBeforeSignIn(JNIEnv* env, jobject obj); 41 42 void OnSignInCompleted(JNIEnv* env, jobject obj, jstring username); 43 44 void SignOut(JNIEnv* env, jobject obj); 45 46 base::android::ScopedJavaLocalRef<jstring> GetManagementDomain(JNIEnv* env, 47 jobject obj); 48 49 void WipeProfileData(JNIEnv* env, jobject obj); 50 51 void LogInSignedInUser(JNIEnv* env, jobject obj); 52 53 private: 54 virtual ~SigninManagerAndroid(); 55 56 #if defined(ENABLE_CONFIGURATION_POLICY) 57 void OnPolicyRegisterDone(const std::string& dm_token, 58 const std::string& client_id); 59 void OnPolicyFetchDone(bool success); 60 #endif 61 62 void OnBrowsingDataRemoverDone(); 63 64 Profile* profile_; 65 66 // Java-side SigninManager object. 67 base::android::ScopedJavaGlobalRef<jobject> java_signin_manager_; 68 69 #if defined(ENABLE_CONFIGURATION_POLICY) 70 // CloudPolicy credentials stored during a pending sign-in, awaiting user 71 // confirmation before starting to fetch policies. 72 std::string dm_token_; 73 std::string client_id_; 74 75 // Username that is pending sign-in. This is used to extract the domain name 76 // for the policy dialog, when |username_| corresponds to a managed account. 77 std::string username_; 78 #endif 79 80 base::WeakPtrFactory<SigninManagerAndroid> weak_factory_; 81 82 DISALLOW_COPY_AND_ASSIGN(SigninManagerAndroid); 83 }; 84 85 #endif // CHROME_BROWSER_ANDROID_SIGNIN_SIGNIN_MANAGER_ANDROID_H_ 86