Move Webstore URL concepts to //extensions and out
[chromium-blink-merge.git] / chrome / browser / android / signin / signin_manager_android.h
blob28ee6e99b7225faef3652fa02a79217ff1ca7202
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.
5 #ifndef CHROME_BROWSER_ANDROID_SIGNIN_SIGNIN_MANAGER_ANDROID_H_
6 #define CHROME_BROWSER_ANDROID_SIGNIN_SIGNIN_MANAGER_ANDROID_H_
8 #include <jni.h>
10 #include <string>
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 "base/prefs/pref_change_registrar.h"
17 #include "google_apis/gaia/merge_session_helper.h"
19 class GoogleServiceAuthError;
20 class Profile;
22 namespace policy {
23 class CloudPolicyClient;
26 // Android wrapper of the SigninManager which provides access from the Java
27 // layer. Note that on Android, there's only a single profile, and therefore
28 // a single instance of this wrapper. The name of the Java class is
29 // SigninManager.
30 // This class should only be accessed from the UI thread.
32 // This class implements parts of the sign-in flow, to make sure that policy
33 // is available before sign-in completes.
34 class SigninManagerAndroid : public MergeSessionHelper::Observer {
35 public:
36 SigninManagerAndroid(JNIEnv* env, jobject obj);
38 // Registers the SigninManagerAndroid's native methods through JNI.
39 static bool Register(JNIEnv* env);
41 void CheckPolicyBeforeSignIn(JNIEnv* env, jobject obj, jstring username);
43 void FetchPolicyBeforeSignIn(JNIEnv* env, jobject obj);
45 void OnSignInCompleted(JNIEnv* env, jobject obj, jstring username);
47 void SignOut(JNIEnv* env, jobject obj);
49 base::android::ScopedJavaLocalRef<jstring> GetManagementDomain(JNIEnv* env,
50 jobject obj);
52 void WipeProfileData(JNIEnv* env, jobject obj);
54 void LogInSignedInUser(JNIEnv* env, jobject obj);
56 void ClearLastSignedInUser(JNIEnv* env, jobject obj);
58 jboolean IsSigninAllowedByPolicy(JNIEnv* env, jobject obj);
60 private:
61 virtual ~SigninManagerAndroid();
63 #if defined(ENABLE_CONFIGURATION_POLICY)
64 void OnPolicyRegisterDone(const std::string& dm_token,
65 const std::string& client_id);
66 void OnPolicyFetchDone(bool success);
67 #endif
69 void OnBrowsingDataRemoverDone();
71 void ClearLastSignedInUser();
73 void OnSigninAllowedPrefChanged();
75 // MergeSessionHelper::Observer implementation.
76 virtual void MergeSessionCompleted(
77 const std::string& account_id,
78 const GoogleServiceAuthError& error) OVERRIDE;
80 Profile* profile_;
82 // Java-side SigninManager object.
83 base::android::ScopedJavaGlobalRef<jobject> java_signin_manager_;
85 #if defined(ENABLE_CONFIGURATION_POLICY)
86 // CloudPolicy credentials stored during a pending sign-in, awaiting user
87 // confirmation before starting to fetch policies.
88 std::string dm_token_;
89 std::string client_id_;
91 // Username that is pending sign-in. This is used to extract the domain name
92 // for the policy dialog, when |username_| corresponds to a managed account.
93 std::string username_;
94 #endif
96 // Helper to merge the signed into account into the cookie jar session.
97 scoped_ptr<MergeSessionHelper> merge_session_helper_;
99 PrefChangeRegistrar pref_change_registrar_;
101 base::WeakPtrFactory<SigninManagerAndroid> weak_factory_;
103 DISALLOW_COPY_AND_ASSIGN(SigninManagerAndroid);
106 #endif // CHROME_BROWSER_ANDROID_SIGNIN_SIGNIN_MANAGER_ANDROID_H_