OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <vector> | 5 #include <vector> |
6 | 6 |
7 #include "chrome/browser/android/signin/signin_manager_android.h" | 7 #include "chrome/browser/android/signin/signin_manager_android.h" |
8 | 8 |
| 9 #include "base/android/callback_android.h" |
9 #include "base/android/jni_android.h" | 10 #include "base/android/jni_android.h" |
10 #include "base/android/jni_array.h" | 11 #include "base/android/jni_array.h" |
11 #include "base/android/jni_string.h" | 12 #include "base/android/jni_string.h" |
12 #include "base/bind.h" | 13 #include "base/bind.h" |
13 #include "base/bind_helpers.h" | 14 #include "base/bind_helpers.h" |
14 #include "base/macros.h" | 15 #include "base/macros.h" |
15 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
16 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" |
17 #include "base/threading/thread_task_runner_handle.h" | 18 #include "base/threading/thread_task_runner_handle.h" |
18 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 19 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 } | 72 } |
72 | 73 |
73 private: | 74 private: |
74 base::Closure callback_; | 75 base::Closure callback_; |
75 scoped_refptr<base::SingleThreadTaskRunner> origin_runner_; | 76 scoped_refptr<base::SingleThreadTaskRunner> origin_runner_; |
76 BrowsingDataRemover* remover_; | 77 BrowsingDataRemover* remover_; |
77 | 78 |
78 DISALLOW_COPY_AND_ASSIGN(ProfileDataRemover); | 79 DISALLOW_COPY_AND_ASSIGN(ProfileDataRemover); |
79 }; | 80 }; |
80 | 81 |
| 82 void UserManagementDomainFetched( |
| 83 base::android::ScopedJavaGlobalRef<jobject> callback, |
| 84 const std::string& dm_token, const std::string& client_id) { |
| 85 base::android::RunCallbackAndroid(callback, !dm_token.empty()); |
| 86 } |
| 87 |
81 } // namespace | 88 } // namespace |
82 | 89 |
83 SigninManagerAndroid::SigninManagerAndroid(JNIEnv* env, jobject obj) | 90 SigninManagerAndroid::SigninManagerAndroid(JNIEnv* env, jobject obj) |
84 : profile_(NULL), | 91 : profile_(NULL), |
85 weak_factory_(this) { | 92 weak_factory_(this) { |
86 java_signin_manager_.Reset(env, obj); | 93 java_signin_manager_.Reset(env, obj); |
87 profile_ = ProfileManager::GetActiveUserProfile(); | 94 profile_ = ProfileManager::GetActiveUserProfile(); |
88 DCHECK(profile_); | 95 DCHECK(profile_); |
89 SigninManagerFactory::GetForProfile(profile_)->AddObserver(this); | 96 SigninManagerFactory::GetForProfile(profile_)->AddObserver(this); |
90 pref_change_registrar_.Init(profile_->GetPrefs()); | 97 pref_change_registrar_.Init(profile_->GetPrefs()); |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 } | 298 } |
292 | 299 |
293 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 300 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
294 SigninManagerAndroid* signin_manager_android = | 301 SigninManagerAndroid* signin_manager_android = |
295 new SigninManagerAndroid(env, obj); | 302 new SigninManagerAndroid(env, obj); |
296 return reinterpret_cast<intptr_t>(signin_manager_android); | 303 return reinterpret_cast<intptr_t>(signin_manager_android); |
297 } | 304 } |
298 | 305 |
299 static jboolean ShouldLoadPolicyForUser( | 306 static jboolean ShouldLoadPolicyForUser( |
300 JNIEnv* env, | 307 JNIEnv* env, |
301 const JavaParamRef<jobject>& obj, | 308 const JavaParamRef<jclass>& clazz, |
302 const JavaParamRef<jstring>& j_username) { | 309 const JavaParamRef<jstring>& j_username) { |
303 std::string username = | 310 std::string username = |
304 base::android::ConvertJavaStringToUTF8(env, j_username); | 311 base::android::ConvertJavaStringToUTF8(env, j_username); |
305 return !policy::BrowserPolicyConnector::IsNonEnterpriseUser(username); | 312 return !policy::BrowserPolicyConnector::IsNonEnterpriseUser(username); |
306 } | 313 } |
307 | 314 |
| 315 static void IsUserManaged( |
| 316 JNIEnv* env, |
| 317 const JavaParamRef<jclass>& clazz, |
| 318 const JavaParamRef<jstring>& j_username, |
| 319 const JavaParamRef<jobject>& j_callback) { |
| 320 base::android::ScopedJavaGlobalRef<jobject> callback(env, j_callback); |
| 321 |
| 322 Profile* profile = ProfileManager::GetActiveUserProfile(); |
| 323 std::string username = |
| 324 base::android::ConvertJavaStringToUTF8(env, j_username); |
| 325 policy::UserPolicySigninService* service = |
| 326 policy::UserPolicySigninServiceFactory::GetForProfile(profile); |
| 327 service->RegisterForPolicy( |
| 328 username, AccountTrackerServiceFactory::GetForProfile(profile) |
| 329 ->FindAccountInfoByEmail(username) |
| 330 .account_id, |
| 331 base::Bind(&UserManagementDomainFetched, callback)); |
| 332 } |
| 333 |
| 334 base::android::ScopedJavaLocalRef<jstring> |
| 335 ExtractDomainName( |
| 336 JNIEnv *env, |
| 337 const JavaParamRef<jclass>& clazz, |
| 338 const JavaParamRef<jstring>& j_email) { |
| 339 std::string email = base::android::ConvertJavaStringToUTF8(env, j_email); |
| 340 std::string domain = gaia::ExtractDomainName(email); |
| 341 return base::android::ConvertUTF8ToJavaString(env, domain); |
| 342 } |
| 343 |
308 // static | 344 // static |
309 bool SigninManagerAndroid::Register(JNIEnv* env) { | 345 bool SigninManagerAndroid::Register(JNIEnv* env) { |
310 return RegisterNativesImpl(env); | 346 return RegisterNativesImpl(env); |
311 } | 347 } |
OLD | NEW |