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 "chrome/browser/sync/profile_sync_service_android.h" | 5 #include "chrome/browser/sync/profile_sync_service_android.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/i18n/time_formatting.h" | 10 #include "base/i18n/time_formatting.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 FAVICON_IMAGE = 1 << 8, | 61 FAVICON_IMAGE = 1 << 8, |
62 FAVICON_TRACKING = 1 << 9, | 62 FAVICON_TRACKING = 1 << 9, |
63 NIGORI = 1 << 10, | 63 NIGORI = 1 << 10, |
64 DEVICE_INFO = 1 << 11, | 64 DEVICE_INFO = 1 << 11, |
65 EXPERIMENTS = 1 << 12, | 65 EXPERIMENTS = 1 << 12, |
66 SUPERVISED_USER_SETTING = 1 << 13, | 66 SUPERVISED_USER_SETTING = 1 << 13, |
67 SUPERVISED_USER_WHITELIST = 1 << 14, | 67 SUPERVISED_USER_WHITELIST = 1 << 14, |
68 AUTOFILL_WALLET = 1 << 15, | 68 AUTOFILL_WALLET = 1 << 15, |
69 }; | 69 }; |
70 | 70 |
| 71 // Native callback for the JNI GetAllNodes method. When |
| 72 // ProfileSyncService::GetAllNodes completes, this method is called and the |
| 73 // results are sent to the Java callback. |
| 74 void NativeGetAllNodesCallback( |
| 75 const base::android::ScopedJavaGlobalRef<jobject>& callback, |
| 76 scoped_ptr<base::ListValue> result) { |
| 77 JNIEnv* env = base::android::AttachCurrentThread(); |
| 78 std::string json_string; |
| 79 if (!result.get() || !base::JSONWriter::Write(*result, &json_string)) { |
| 80 DVLOG(1) << "Writing as JSON failed. Passing empty string to Java code."; |
| 81 json_string = std::string(); |
| 82 } |
| 83 |
| 84 ScopedJavaLocalRef<jstring> java_json_string = |
| 85 ConvertUTF8ToJavaString(env, json_string); |
| 86 Java_ProfileSyncService_onGetAllNodesResult(env, |
| 87 callback.obj(), |
| 88 java_json_string.obj()); |
| 89 } |
| 90 |
71 } // namespace | 91 } // namespace |
72 | 92 |
73 ProfileSyncServiceAndroid::ProfileSyncServiceAndroid(JNIEnv* env, jobject obj) | 93 ProfileSyncServiceAndroid::ProfileSyncServiceAndroid(JNIEnv* env, jobject obj) |
74 : profile_(NULL), | 94 : profile_(NULL), |
75 sync_service_(NULL), | 95 sync_service_(NULL), |
76 weak_java_profile_sync_service_(env, obj) { | 96 weak_java_profile_sync_service_(env, obj) { |
77 if (g_browser_process == NULL || | 97 if (g_browser_process == NULL || |
78 g_browser_process->profile_manager() == NULL) { | 98 g_browser_process->profile_manager() == NULL) { |
79 NOTREACHED() << "Browser process or profile manager not initialized"; | 99 NOTREACHED() << "Browser process or profile manager not initialized"; |
80 return; | 100 return; |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 } | 201 } |
182 | 202 |
183 ScopedJavaLocalRef<jstring> ProfileSyncServiceAndroid::QuerySyncStatusSummary( | 203 ScopedJavaLocalRef<jstring> ProfileSyncServiceAndroid::QuerySyncStatusSummary( |
184 JNIEnv* env, jobject) { | 204 JNIEnv* env, jobject) { |
185 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 205 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
186 DCHECK(profile_); | 206 DCHECK(profile_); |
187 std::string status(sync_service_->QuerySyncStatusSummaryString()); | 207 std::string status(sync_service_->QuerySyncStatusSummaryString()); |
188 return ConvertUTF8ToJavaString(env, status); | 208 return ConvertUTF8ToJavaString(env, status); |
189 } | 209 } |
190 | 210 |
| 211 void ProfileSyncServiceAndroid::GetAllNodes(JNIEnv* env, |
| 212 jobject obj, |
| 213 jobject callback) { |
| 214 base::android::ScopedJavaGlobalRef<jobject> java_callback; |
| 215 java_callback.Reset(env, callback); |
| 216 |
| 217 base::Callback<void(scoped_ptr<base::ListValue>)> native_callback = |
| 218 base::Bind(&NativeGetAllNodesCallback, java_callback); |
| 219 sync_service_->GetAllNodes(native_callback); |
| 220 } |
| 221 |
191 jboolean ProfileSyncServiceAndroid::SetSyncSessionsId( | 222 jboolean ProfileSyncServiceAndroid::SetSyncSessionsId( |
192 JNIEnv* env, jobject obj, jstring tag) { | 223 JNIEnv* env, jobject obj, jstring tag) { |
193 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 224 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
194 DCHECK(profile_); | 225 DCHECK(profile_); |
195 std::string machine_tag = ConvertJavaStringToUTF8(env, tag); | 226 std::string machine_tag = ConvertJavaStringToUTF8(env, tag); |
196 sync_prefs_->SetSyncSessionsGUID(machine_tag); | 227 sync_prefs_->SetSyncSessionsGUID(machine_tag); |
197 return true; | 228 return true; |
198 } | 229 } |
199 | 230 |
200 jint ProfileSyncServiceAndroid::GetAuthError(JNIEnv* env, jobject) { | 231 jint ProfileSyncServiceAndroid::GetAuthError(JNIEnv* env, jobject) { |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 ProfileSyncServiceAndroid* profile_sync_service_android = | 572 ProfileSyncServiceAndroid* profile_sync_service_android = |
542 new ProfileSyncServiceAndroid(env, obj); | 573 new ProfileSyncServiceAndroid(env, obj); |
543 profile_sync_service_android->Init(); | 574 profile_sync_service_android->Init(); |
544 return reinterpret_cast<intptr_t>(profile_sync_service_android); | 575 return reinterpret_cast<intptr_t>(profile_sync_service_android); |
545 } | 576 } |
546 | 577 |
547 // static | 578 // static |
548 bool ProfileSyncServiceAndroid::Register(JNIEnv* env) { | 579 bool ProfileSyncServiceAndroid::Register(JNIEnv* env) { |
549 return RegisterNativesImpl(env); | 580 return RegisterNativesImpl(env); |
550 } | 581 } |
OLD | NEW |