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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 std::unique_ptr<base::ListValue> result) { | 60 std::unique_ptr<base::ListValue> result) { |
61 JNIEnv* env = base::android::AttachCurrentThread(); | 61 JNIEnv* env = base::android::AttachCurrentThread(); |
62 std::string json_string; | 62 std::string json_string; |
63 if (!result.get() || !base::JSONWriter::Write(*result, &json_string)) { | 63 if (!result.get() || !base::JSONWriter::Write(*result, &json_string)) { |
64 DVLOG(1) << "Writing as JSON failed. Passing empty string to Java code."; | 64 DVLOG(1) << "Writing as JSON failed. Passing empty string to Java code."; |
65 json_string = std::string(); | 65 json_string = std::string(); |
66 } | 66 } |
67 | 67 |
68 ScopedJavaLocalRef<jstring> java_json_string = | 68 ScopedJavaLocalRef<jstring> java_json_string = |
69 ConvertUTF8ToJavaString(env, json_string); | 69 ConvertUTF8ToJavaString(env, json_string); |
70 Java_ProfileSyncService_onGetAllNodesResult(env, | 70 Java_ProfileSyncService_onGetAllNodesResult(env, callback, java_json_string); |
71 callback.obj(), | |
72 java_json_string.obj()); | |
73 } | 71 } |
74 | 72 |
75 ScopedJavaLocalRef<jintArray> ModelTypeSetToJavaIntArray( | 73 ScopedJavaLocalRef<jintArray> ModelTypeSetToJavaIntArray( |
76 JNIEnv* env, | 74 JNIEnv* env, |
77 syncer::ModelTypeSet types) { | 75 syncer::ModelTypeSet types) { |
78 std::vector<int> type_vector; | 76 std::vector<int> type_vector; |
79 for (syncer::ModelTypeSet::Iterator it = types.First(); it.Good(); it.Inc()) { | 77 for (syncer::ModelTypeSet::Iterator it = types.First(); it.Good(); it.Inc()) { |
80 type_vector.push_back(it.Get()); | 78 type_vector.push_back(it.Get()); |
81 } | 79 } |
82 return base::android::ToJavaIntArray(env, type_vector); | 80 return base::android::ToJavaIntArray(env, type_vector); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 sync_service_->RemoveObserver(this); | 121 sync_service_->RemoveObserver(this); |
124 sync_service_->SetPlatformSyncAllowedProvider( | 122 sync_service_->SetPlatformSyncAllowedProvider( |
125 ProfileSyncService::PlatformSyncAllowedProvider()); | 123 ProfileSyncService::PlatformSyncAllowedProvider()); |
126 } | 124 } |
127 } | 125 } |
128 | 126 |
129 void ProfileSyncServiceAndroid::OnStateChanged() { | 127 void ProfileSyncServiceAndroid::OnStateChanged() { |
130 // Notify the java world that our sync state has changed. | 128 // Notify the java world that our sync state has changed. |
131 JNIEnv* env = AttachCurrentThread(); | 129 JNIEnv* env = AttachCurrentThread(); |
132 Java_ProfileSyncService_syncStateChanged( | 130 Java_ProfileSyncService_syncStateChanged( |
133 env, weak_java_profile_sync_service_.get(env).obj()); | 131 env, weak_java_profile_sync_service_.get(env)); |
134 } | 132 } |
135 | 133 |
136 bool ProfileSyncServiceAndroid::IsSyncAllowedByAndroid() const { | 134 bool ProfileSyncServiceAndroid::IsSyncAllowedByAndroid() const { |
137 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 135 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
138 JNIEnv* env = AttachCurrentThread(); | 136 JNIEnv* env = AttachCurrentThread(); |
139 return Java_ProfileSyncService_isMasterSyncEnabled( | 137 return Java_ProfileSyncService_isMasterSyncEnabled( |
140 env, weak_java_profile_sync_service_.get(env).obj()); | 138 env, weak_java_profile_sync_service_.get(env)); |
141 } | 139 } |
142 | 140 |
143 // Pure ProfileSyncService calls. | 141 // Pure ProfileSyncService calls. |
144 | 142 |
145 jboolean ProfileSyncServiceAndroid::IsSyncRequested( | 143 jboolean ProfileSyncServiceAndroid::IsSyncRequested( |
146 JNIEnv* env, | 144 JNIEnv* env, |
147 const JavaParamRef<jobject>& obj) { | 145 const JavaParamRef<jobject>& obj) { |
148 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 146 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
149 return sync_service_->IsSyncRequested(); | 147 return sync_service_->IsSyncRequested(); |
150 } | 148 } |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 504 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
507 ProfileSyncServiceAndroid* profile_sync_service_android = | 505 ProfileSyncServiceAndroid* profile_sync_service_android = |
508 new ProfileSyncServiceAndroid(env, obj); | 506 new ProfileSyncServiceAndroid(env, obj); |
509 if (profile_sync_service_android->Init()) { | 507 if (profile_sync_service_android->Init()) { |
510 return reinterpret_cast<intptr_t>(profile_sync_service_android); | 508 return reinterpret_cast<intptr_t>(profile_sync_service_android); |
511 } else { | 509 } else { |
512 delete profile_sync_service_android; | 510 delete profile_sync_service_android; |
513 return 0; | 511 return 0; |
514 } | 512 } |
515 } | 513 } |
OLD | NEW |