Upstream version 5.34.92.0
[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 #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  private:
56   virtual ~SigninManagerAndroid();
57
58 #if defined(ENABLE_CONFIGURATION_POLICY)
59   void OnPolicyRegisterDone(const std::string& dm_token,
60                             const std::string& client_id);
61   void OnPolicyFetchDone(bool success);
62 #endif
63
64   void OnBrowsingDataRemoverDone();
65
66   // MergeSessionHelper::Observer implementation.
67   virtual void MergeSessionCompleted(
68       const std::string& account_id,
69       const GoogleServiceAuthError& error) OVERRIDE;
70
71   Profile* profile_;
72
73   // Java-side SigninManager object.
74   base::android::ScopedJavaGlobalRef<jobject> java_signin_manager_;
75
76 #if defined(ENABLE_CONFIGURATION_POLICY)
77   // CloudPolicy credentials stored during a pending sign-in, awaiting user
78   // confirmation before starting to fetch policies.
79   std::string dm_token_;
80   std::string client_id_;
81
82   // Username that is pending sign-in. This is used to extract the domain name
83   // for the policy dialog, when |username_| corresponds to a managed account.
84   std::string username_;
85 #endif
86
87   // Helper to merge the signed into account into the cookie jar session.
88   scoped_ptr<MergeSessionHelper> merge_session_helper_;
89
90   base::WeakPtrFactory<SigninManagerAndroid> weak_factory_;
91
92   DISALLOW_COPY_AND_ASSIGN(SigninManagerAndroid);
93 };
94
95 #endif  // CHROME_BROWSER_ANDROID_SIGNIN_SIGNIN_MANAGER_ANDROID_H_