17dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// Copyright 2013 The Chromium Authors. All rights reserved.
27dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// Use of this source code is governed by a BSD-style license that can be
37dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// found in the LICENSE file.
47dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
57dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#ifndef CHROME_BROWSER_ANDROID_SIGNIN_SIGNIN_MANAGER_ANDROID_H_
67dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#define CHROME_BROWSER_ANDROID_SIGNIN_SIGNIN_MANAGER_ANDROID_H_
77dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
87dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include <jni.h>
97dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
109ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch#include <string>
119ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch
127dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "base/android/scoped_java_ref.h"
137dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "base/basictypes.h"
147dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "base/memory/scoped_ptr.h"
15558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch#include "base/memory/weak_ptr.h"
165f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "base/prefs/pref_change_registrar.h"
175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "google_apis/gaia/merge_session_helper.h"
187dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class GoogleServiceAuthError;
207dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochclass Profile;
217dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
227dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochnamespace policy {
237dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochclass CloudPolicyClient;
247dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch}
257dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
267dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// Android wrapper of the SigninManager which provides access from the Java
277dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// layer. Note that on Android, there's only a single profile, and therefore
287dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// a single instance of this wrapper. The name of the Java class is
297dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// SigninManager.
307dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// This class should only be accessed from the UI thread.
317dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch//
327dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// This class implements parts of the sign-in flow, to make sure that policy
337dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// is available before sign-in completes.
345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class SigninManagerAndroid : public MergeSessionHelper::Observer {
357dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch public:
367dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  SigninManagerAndroid(JNIEnv* env, jobject obj);
377dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
387dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // Registers the SigninManagerAndroid's native methods through JNI.
397dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  static bool Register(JNIEnv* env);
407dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
417dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  void CheckPolicyBeforeSignIn(JNIEnv* env, jobject obj, jstring username);
427dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
437dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  void FetchPolicyBeforeSignIn(JNIEnv* env, jobject obj);
447dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
457dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  void OnSignInCompleted(JNIEnv* env, jobject obj, jstring username);
467dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
477dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  void SignOut(JNIEnv* env, jobject obj);
487dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
49558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  base::android::ScopedJavaLocalRef<jstring> GetManagementDomain(JNIEnv* env,
50558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch                                                                 jobject obj);
51558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch
52558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  void WipeProfileData(JNIEnv* env, jobject obj);
53558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch
543551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  void LogInSignedInUser(JNIEnv* env, jobject obj);
553551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
565c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  void ClearLastSignedInUser(JNIEnv* env, jobject obj);
575c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
585f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  jboolean IsSigninAllowedByPolicy(JNIEnv* env, jobject obj);
595f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
607dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch private:
617dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  virtual ~SigninManagerAndroid();
627dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
637dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#if defined(ENABLE_CONFIGURATION_POLICY)
64f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  void OnPolicyRegisterDone(const std::string& dm_token,
65f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                            const std::string& client_id);
667dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  void OnPolicyFetchDone(bool success);
677dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#endif
687dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
69558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  void OnBrowsingDataRemoverDone();
70558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch
715c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  void ClearLastSignedInUser();
725c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
735f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  void OnSigninAllowedPrefChanged();
745f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // MergeSessionHelper::Observer implementation.
765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void MergeSessionCompleted(
775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      const std::string& account_id,
785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      const GoogleServiceAuthError& error) OVERRIDE;
795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
807dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  Profile* profile_;
817dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
827dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // Java-side SigninManager object.
837dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  base::android::ScopedJavaGlobalRef<jobject> java_signin_manager_;
847dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
857dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#if defined(ENABLE_CONFIGURATION_POLICY)
86f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // CloudPolicy credentials stored during a pending sign-in, awaiting user
877dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // confirmation before starting to fetch policies.
88f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  std::string dm_token_;
89f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  std::string client_id_;
909ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch
919ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch  // Username that is pending sign-in. This is used to extract the domain name
929ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch  // for the policy dialog, when |username_| corresponds to a managed account.
939ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch  std::string username_;
947dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#endif
957dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Helper to merge the signed into account into the cookie jar session.
975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  scoped_ptr<MergeSessionHelper> merge_session_helper_;
985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
995f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  PrefChangeRegistrar pref_change_registrar_;
1005f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
101558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  base::WeakPtrFactory<SigninManagerAndroid> weak_factory_;
102558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch
1037dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  DISALLOW_COPY_AND_ASSIGN(SigninManagerAndroid);
1047dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch};
1057dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
1067dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#endif  // CHROME_BROWSER_ANDROID_SIGNIN_SIGNIN_MANAGER_ANDROID_H_
107