- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / android / signin / signin_manager_android.h
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(scoped_ptr<policy::CloudPolicyClient> client);
58   void OnPolicyFetchDone(bool success);
59 #endif
60
61   void OnBrowsingDataRemoverDone();
62
63   Profile* profile_;
64
65   // Java-side SigninManager object.
66   base::android::ScopedJavaGlobalRef<jobject> java_signin_manager_;
67
68 #if defined(ENABLE_CONFIGURATION_POLICY)
69   // CloudPolicyClient stored during a pending sign-in, awaiting user
70   // confirmation before starting to fetch policies.
71   scoped_ptr<policy::CloudPolicyClient> cloud_policy_client_;
72
73   // Username that is pending sign-in. This is used to extract the domain name
74   // for the policy dialog, when |username_| corresponds to a managed account.
75   std::string username_;
76 #endif
77
78   base::WeakPtrFactory<SigninManagerAndroid> weak_factory_;
79
80   DISALLOW_COPY_AND_ASSIGN(SigninManagerAndroid);
81 };
82
83 #endif  // CHROME_BROWSER_ANDROID_SIGNIN_SIGNIN_MANAGER_ANDROID_H_