[email protected] | 9049a7b | 2013-03-07 22:22:03 | [diff] [blame] | 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 | #include "chrome/browser/sync/profile_sync_service_android.h" |
| 6 | |
| 7 | #include "base/android/jni_android.h" |
maxbogue | 47c7504 | 2015-08-12 18:05:01 | [diff] [blame] | 8 | #include "base/android/jni_array.h" |
[email protected] | 9049a7b | 2013-03-07 22:22:03 | [diff] [blame] | 9 | #include "base/android/jni_string.h" |
| 10 | #include "base/bind.h" |
| 11 | #include "base/i18n/time_formatting.h" |
| 12 | #include "base/json/json_writer.h" |
| 13 | #include "base/logging.h" |
| 14 | #include "base/memory/scoped_ptr.h" |
[email protected] | 34ee051 | 2013-03-12 17:49:54 | [diff] [blame] | 15 | #include "base/prefs/pref_service.h" |
[email protected] | e309f31 | 2013-06-07 21:50:08 | [diff] [blame] | 16 | #include "base/strings/utf_string_conversions.h" |
[email protected] | cc86ccfe | 2013-06-28 00:10:50 | [diff] [blame] | 17 | #include "base/time/time.h" |
[email protected] | 9049a7b | 2013-03-07 22:22:03 | [diff] [blame] | 18 | #include "chrome/browser/browser_process.h" |
| 19 | #include "chrome/browser/profiles/profile_manager.h" |
[email protected] | 9049a7b | 2013-03-07 22:22:03 | [diff] [blame] | 20 | #include "chrome/browser/signin/signin_manager_factory.h" |
[email protected] | 9049a7b | 2013-03-07 22:22:03 | [diff] [blame] | 21 | #include "chrome/browser/sync/profile_sync_service_factory.h" |
[email protected] | 9049a7b | 2013-03-07 22:22:03 | [diff] [blame] | 22 | #include "chrome/browser/sync/sync_ui_util.h" |
maxbogue | 93150a5d | 2015-08-31 21:08:32 | [diff] [blame] | 23 | #include "chrome/common/channel_info.h" |
[email protected] | af39f00 | 2014-08-22 10:18:18 | [diff] [blame] | 24 | #include "chrome/grit/generated_resources.h" |
blundell | 7282b51 | 2015-11-09 07:21:11 | [diff] [blame] | 25 | #include "components/browser_sync/browser/profile_sync_service.h" |
[email protected] | 7fbd3b1 | 2014-04-01 11:19:16 | [diff] [blame] | 26 | #include "components/signin/core/browser/signin_manager.h" |
maxbogue | 93150a5d | 2015-08-31 21:08:32 | [diff] [blame] | 27 | #include "components/sync_driver/about_sync_util.h" |
[email protected] | 34f5405 | 2014-03-20 21:33:40 | [diff] [blame] | 28 | #include "components/sync_driver/pref_names.h" |
| 29 | #include "components/sync_driver/sync_prefs.h" |
[email protected] | dfe6a9b | 2014-01-31 21:37:55 | [diff] [blame] | 30 | #include "content/public/browser/browser_thread.h" |
[email protected] | 9049a7b | 2013-03-07 22:22:03 | [diff] [blame] | 31 | #include "google/cacheinvalidation/types.pb.h" |
| 32 | #include "google_apis/gaia/gaia_constants.h" |
| 33 | #include "google_apis/gaia/google_service_auth_error.h" |
[email protected] | 9049a7b | 2013-03-07 22:22:03 | [diff] [blame] | 34 | #include "jni/ProfileSyncService_jni.h" |
[email protected] | be21aaa | 2014-08-21 21:26:38 | [diff] [blame] | 35 | #include "sync/internal_api/public/network_resources.h" |
[email protected] | 9049a7b | 2013-03-07 22:22:03 | [diff] [blame] | 36 | #include "sync/internal_api/public/read_transaction.h" |
| 37 | #include "ui/base/l10n/l10n_util.h" |
| 38 | |
| 39 | using base::android::AttachCurrentThread; |
| 40 | using base::android::CheckException; |
| 41 | using base::android::ConvertJavaStringToUTF8; |
| 42 | using base::android::ConvertUTF8ToJavaString; |
| 43 | using base::android::ScopedJavaLocalRef; |
| 44 | using content::BrowserThread; |
| 45 | |
| 46 | namespace { |
[email protected] | 9049a7b | 2013-03-07 22:22:03 | [diff] [blame] | 47 | |
pvalenzuela | ff27ca20 | 2015-05-20 23:34:21 | [diff] [blame] | 48 | // Native callback for the JNI GetAllNodes method. When |
| 49 | // ProfileSyncService::GetAllNodes completes, this method is called and the |
| 50 | // results are sent to the Java callback. |
| 51 | void NativeGetAllNodesCallback( |
| 52 | const base::android::ScopedJavaGlobalRef<jobject>& callback, |
| 53 | scoped_ptr<base::ListValue> result) { |
| 54 | JNIEnv* env = base::android::AttachCurrentThread(); |
| 55 | std::string json_string; |
| 56 | if (!result.get() || !base::JSONWriter::Write(*result, &json_string)) { |
| 57 | DVLOG(1) << "Writing as JSON failed. Passing empty string to Java code."; |
| 58 | json_string = std::string(); |
| 59 | } |
| 60 | |
| 61 | ScopedJavaLocalRef<jstring> java_json_string = |
| 62 | ConvertUTF8ToJavaString(env, json_string); |
| 63 | Java_ProfileSyncService_onGetAllNodesResult(env, |
| 64 | callback.obj(), |
| 65 | java_json_string.obj()); |
| 66 | } |
| 67 | |
maxbogue | 28baa96 | 2015-10-01 17:21:38 | [diff] [blame] | 68 | ScopedJavaLocalRef<jintArray> ModelTypeSetToJavaIntArray( |
| 69 | JNIEnv* env, |
| 70 | syncer::ModelTypeSet types) { |
| 71 | std::vector<int> type_vector; |
| 72 | for (syncer::ModelTypeSet::Iterator it = types.First(); it.Good(); it.Inc()) { |
| 73 | type_vector.push_back(it.Get()); |
| 74 | } |
| 75 | return base::android::ToJavaIntArray(env, type_vector); |
| 76 | } |
| 77 | |
[email protected] | 9049a7b | 2013-03-07 22:22:03 | [diff] [blame] | 78 | } // namespace |
| 79 | |
| 80 | ProfileSyncServiceAndroid::ProfileSyncServiceAndroid(JNIEnv* env, jobject obj) |
| 81 | : profile_(NULL), |
| 82 | sync_service_(NULL), |
| 83 | weak_java_profile_sync_service_(env, obj) { |
| 84 | if (g_browser_process == NULL || |
| 85 | g_browser_process->profile_manager() == NULL) { |
| 86 | NOTREACHED() << "Browser process or profile manager not initialized"; |
| 87 | return; |
| 88 | } |
| 89 | |
[email protected] | dd547a2 | 2013-12-12 18:37:41 | [diff] [blame] | 90 | profile_ = ProfileManager::GetActiveUserProfile(); |
[email protected] | 9049a7b | 2013-03-07 22:22:03 | [diff] [blame] | 91 | if (profile_ == NULL) { |
| 92 | NOTREACHED() << "Sync Init: Profile not found."; |
| 93 | return; |
| 94 | } |
| 95 | |
[email protected] | 34f5405 | 2014-03-20 21:33:40 | [diff] [blame] | 96 | sync_prefs_.reset(new sync_driver::SyncPrefs(profile_->GetPrefs())); |
[email protected] | aa5b2ece | 2013-05-17 00:37:36 | [diff] [blame] | 97 | |
[email protected] | 9049a7b | 2013-03-07 22:22:03 | [diff] [blame] | 98 | sync_service_ = |
| 99 | ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_); |
| 100 | DCHECK(sync_service_); |
| 101 | } |
| 102 | |
| 103 | void ProfileSyncServiceAndroid::Init() { |
| 104 | sync_service_->AddObserver(this); |
[email protected] | 9049a7b | 2013-03-07 22:22:03 | [diff] [blame] | 105 | } |
| 106 | |
maxbogue | 28baa96 | 2015-10-01 17:21:38 | [diff] [blame] | 107 | ProfileSyncServiceAndroid::~ProfileSyncServiceAndroid() { |
[email protected] | 9049a7b | 2013-03-07 22:22:03 | [diff] [blame] | 108 | if (sync_service_->HasObserver(this)) { |
| 109 | sync_service_->RemoveObserver(this); |
| 110 | } |
| 111 | } |
| 112 | |
[email protected] | 9049a7b | 2013-03-07 22:22:03 | [diff] [blame] | 113 | void ProfileSyncServiceAndroid::OnStateChanged() { |
[email protected] | 9049a7b | 2013-03-07 22:22:03 | [diff] [blame] | 114 | // Notify the java world that our sync state has changed. |
| 115 | JNIEnv* env = AttachCurrentThread(); |
| 116 | Java_ProfileSyncService_syncStateChanged( |
| 117 | env, weak_java_profile_sync_service_.get(env).obj()); |
| 118 | } |
| 119 | |
maxbogue | 28baa96 | 2015-10-01 17:21:38 | [diff] [blame] | 120 | // Pure ProfileSyncService calls. |
zea | b1b09b7 | 2015-05-01 17:56:40 | [diff] [blame] | 121 | |
maxbogue | 28baa96 | 2015-10-01 17:21:38 | [diff] [blame] | 122 | jboolean ProfileSyncServiceAndroid::IsSyncRequested( |
| 123 | JNIEnv* env, jobject obj) { |
| 124 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 125 | return sync_service_->IsSyncRequested(); |
zea | b1b09b7 | 2015-05-01 17:56:40 | [diff] [blame] | 126 | } |
| 127 | |
maxbogue | f5c53a2d | 2015-07-08 20:47:29 | [diff] [blame] | 128 | void ProfileSyncServiceAndroid::RequestStart(JNIEnv* env, jobject) { |
anujk.sharma | 8619448 | 2015-04-23 06:38:23 | [diff] [blame] | 129 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
maxbogue | cd3fad6b | 2015-06-09 00:44:53 | [diff] [blame] | 130 | sync_service_->RequestStart(); |
[email protected] | 9049a7b | 2013-03-07 22:22:03 | [diff] [blame] | 131 | } |
| 132 | |
maxbogue | f5c53a2d | 2015-07-08 20:47:29 | [diff] [blame] | 133 | void ProfileSyncServiceAndroid::RequestStop(JNIEnv* env, jobject) { |
| 134 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 135 | sync_service_->RequestStop(ProfileSyncService::KEEP_DATA); |
| 136 | } |
| 137 | |
[email protected] | 9049a7b | 2013-03-07 22:22:03 | [diff] [blame] | 138 | void ProfileSyncServiceAndroid::SignOutSync(JNIEnv* env, jobject) { |
anujk.sharma | 8619448 | 2015-04-23 06:38:23 | [diff] [blame] | 139 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | 9049a7b | 2013-03-07 22:22:03 | [diff] [blame] | 140 | DCHECK(profile_); |
maxbogue | 699262c9 | 2015-06-19 19:24:58 | [diff] [blame] | 141 | sync_service_->RequestStop(ProfileSyncService::CLEAR_DATA); |
[email protected] | 9049a7b | 2013-03-07 22:22:03 | [diff] [blame] | 142 | } |
| 143 | |
maxbogue | 28baa96 | 2015-10-01 17:21:38 | [diff] [blame] | 144 | jboolean ProfileSyncServiceAndroid::IsSyncActive(JNIEnv* env, jobject obj) { |
| 145 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 146 | return sync_service_->IsSyncActive(); |
| 147 | } |
| 148 | |
| 149 | jboolean ProfileSyncServiceAndroid::IsBackendInitialized(JNIEnv* env, jobject) { |
| 150 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 151 | return sync_service_->IsBackendInitialized(); |
| 152 | } |
| 153 | |
| 154 | jboolean ProfileSyncServiceAndroid::IsFirstSetupInProgress( |
| 155 | JNIEnv* env, jobject) { |
| 156 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 157 | return sync_service_->IsFirstSetupInProgress(); |
| 158 | } |
| 159 | |
| 160 | void ProfileSyncServiceAndroid::SetSetupInProgress( |
| 161 | JNIEnv* env, jobject obj, jboolean in_progress) { |
| 162 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 163 | sync_service_->SetSetupInProgress(in_progress); |
| 164 | } |
| 165 | |
| 166 | jboolean ProfileSyncServiceAndroid::HasSyncSetupCompleted( |
| 167 | JNIEnv* env, jobject obj) { |
| 168 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 169 | return sync_service_->HasSyncSetupCompleted(); |
| 170 | } |
| 171 | |
| 172 | void ProfileSyncServiceAndroid::SetSyncSetupCompleted( |
| 173 | JNIEnv* env, jobject obj) { |
| 174 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 175 | sync_service_->SetSyncSetupCompleted(); |
| 176 | } |
| 177 | |
| 178 | ScopedJavaLocalRef<jintArray> ProfileSyncServiceAndroid::GetActiveDataTypes( |
| 179 | JNIEnv* env, jobject obj) { |
| 180 | syncer::ModelTypeSet types = sync_service_->GetActiveDataTypes(); |
| 181 | return ModelTypeSetToJavaIntArray(env, types); |
| 182 | } |
| 183 | |
| 184 | ScopedJavaLocalRef<jintArray> ProfileSyncServiceAndroid::GetPreferredDataTypes( |
| 185 | JNIEnv* env, jobject obj) { |
| 186 | syncer::ModelTypeSet types = sync_service_->GetPreferredDataTypes(); |
| 187 | return ModelTypeSetToJavaIntArray(env, types); |
| 188 | } |
| 189 | |
| 190 | void ProfileSyncServiceAndroid::SetPreferredDataTypes( |
| 191 | JNIEnv* env, jobject obj, |
| 192 | jboolean sync_everything, |
| 193 | jintArray model_type_array) { |
| 194 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 195 | std::vector<int> types_vector; |
| 196 | base::android::JavaIntArrayToIntVector(env, model_type_array, &types_vector); |
| 197 | syncer::ModelTypeSet types; |
| 198 | for (size_t i = 0; i < types_vector.size(); i++) { |
| 199 | types.Put(static_cast<syncer::ModelType>(types_vector[i])); |
| 200 | } |
| 201 | sync_service_->OnUserChoseDatatypes(sync_everything, types); |
| 202 | } |
| 203 | |
| 204 | jboolean ProfileSyncServiceAndroid::IsCryptographerReady(JNIEnv* env, jobject) { |
| 205 | syncer::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
| 206 | return sync_service_->IsCryptographerReady(&trans); |
| 207 | } |
| 208 | |
| 209 | jboolean ProfileSyncServiceAndroid::IsEncryptEverythingAllowed( |
| 210 | JNIEnv* env, jobject obj) { |
| 211 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 212 | return sync_service_->IsEncryptEverythingAllowed(); |
| 213 | } |
| 214 | |
| 215 | jboolean ProfileSyncServiceAndroid::IsEncryptEverythingEnabled( |
| 216 | JNIEnv* env, jobject) { |
| 217 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 218 | return sync_service_->IsEncryptEverythingEnabled(); |
| 219 | } |
| 220 | |
| 221 | void ProfileSyncServiceAndroid::EnableEncryptEverything( |
| 222 | JNIEnv* env, jobject obj) { |
| 223 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 224 | sync_service_->EnableEncryptEverything(); |
| 225 | } |
| 226 | |
| 227 | jboolean ProfileSyncServiceAndroid::IsPassphraseRequired(JNIEnv* env, jobject) { |
| 228 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 229 | return sync_service_->IsPassphraseRequired(); |
| 230 | } |
| 231 | |
| 232 | jboolean ProfileSyncServiceAndroid::IsPassphraseRequiredForDecryption( |
| 233 | JNIEnv* env, jobject obj) { |
| 234 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 235 | return sync_service_->IsPassphraseRequiredForDecryption(); |
| 236 | } |
| 237 | |
| 238 | jboolean ProfileSyncServiceAndroid::IsUsingSecondaryPassphrase( |
| 239 | JNIEnv* env, jobject) { |
| 240 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 241 | return sync_service_->IsUsingSecondaryPassphrase(); |
| 242 | } |
| 243 | |
maxbogue | 774f317 | 2015-11-18 16:26:58 | [diff] [blame^] | 244 | ScopedJavaLocalRef<jbyteArray> |
| 245 | ProfileSyncServiceAndroid::GetCustomPassphraseKey(JNIEnv* env, jobject obj) { |
| 246 | std::string key = sync_service_->GetCustomPassphraseKey(); |
| 247 | return base::android::ToJavaByteArray( |
| 248 | env, reinterpret_cast<const uint8_t*>(key.data()), key.size()); |
| 249 | } |
| 250 | |
maxbogue | 28baa96 | 2015-10-01 17:21:38 | [diff] [blame] | 251 | jint ProfileSyncServiceAndroid::GetPassphraseType(JNIEnv* env, jobject) { |
| 252 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 253 | return sync_service_->GetPassphraseType(); |
| 254 | } |
| 255 | |
| 256 | void ProfileSyncServiceAndroid::SetEncryptionPassphrase( |
| 257 | JNIEnv* env, jobject obj, jstring passphrase) { |
| 258 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 259 | std::string key = ConvertJavaStringToUTF8(env, passphrase); |
| 260 | sync_service_->SetEncryptionPassphrase(key, ProfileSyncService::EXPLICIT); |
| 261 | } |
| 262 | |
| 263 | jboolean ProfileSyncServiceAndroid::SetDecryptionPassphrase( |
| 264 | JNIEnv* env, jobject obj, jstring passphrase) { |
| 265 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 266 | std::string key = ConvertJavaStringToUTF8(env, passphrase); |
| 267 | return sync_service_->SetDecryptionPassphrase(key); |
| 268 | } |
| 269 | |
| 270 | jboolean ProfileSyncServiceAndroid::HasExplicitPassphraseTime( |
| 271 | JNIEnv* env, jobject) { |
| 272 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 273 | base::Time passphrase_time = sync_service_->GetExplicitPassphraseTime(); |
| 274 | return !passphrase_time.is_null(); |
| 275 | } |
| 276 | |
| 277 | jlong ProfileSyncServiceAndroid::GetExplicitPassphraseTime( |
| 278 | JNIEnv* env, jobject) { |
| 279 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 280 | base::Time passphrase_time = sync_service_->GetExplicitPassphraseTime(); |
| 281 | return passphrase_time.ToJavaTime(); |
| 282 | } |
| 283 | |
maxbogue | d4470ca | 2014-09-30 23:38:11 | [diff] [blame] | 284 | void ProfileSyncServiceAndroid::FlushDirectory(JNIEnv* env, jobject) { |
anujk.sharma | 8619448 | 2015-04-23 06:38:23 | [diff] [blame] | 285 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
maxbogue | d4470ca | 2014-09-30 23:38:11 | [diff] [blame] | 286 | sync_service_->FlushDirectory(); |
| 287 | } |
| 288 | |
[email protected] | 9049a7b | 2013-03-07 22:22:03 | [diff] [blame] | 289 | ScopedJavaLocalRef<jstring> ProfileSyncServiceAndroid::QuerySyncStatusSummary( |
| 290 | JNIEnv* env, jobject) { |
anujk.sharma | 8619448 | 2015-04-23 06:38:23 | [diff] [blame] | 291 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | 9049a7b | 2013-03-07 22:22:03 | [diff] [blame] | 292 | DCHECK(profile_); |
[email protected] | 9e8df05 | 2013-09-18 10:47:18 | [diff] [blame] | 293 | std::string status(sync_service_->QuerySyncStatusSummaryString()); |
[email protected] | 9049a7b | 2013-03-07 22:22:03 | [diff] [blame] | 294 | return ConvertUTF8ToJavaString(env, status); |
| 295 | } |
| 296 | |
pvalenzuela | ff27ca20 | 2015-05-20 23:34:21 | [diff] [blame] | 297 | void ProfileSyncServiceAndroid::GetAllNodes(JNIEnv* env, |
| 298 | jobject obj, |
| 299 | jobject callback) { |
| 300 | base::android::ScopedJavaGlobalRef<jobject> java_callback; |
| 301 | java_callback.Reset(env, callback); |
| 302 | |
| 303 | base::Callback<void(scoped_ptr<base::ListValue>)> native_callback = |
| 304 | base::Bind(&NativeGetAllNodesCallback, java_callback); |
| 305 | sync_service_->GetAllNodes(native_callback); |
| 306 | } |
| 307 | |
maxbogue | 28baa96 | 2015-10-01 17:21:38 | [diff] [blame] | 308 | jint ProfileSyncServiceAndroid::GetAuthError(JNIEnv* env, jobject) { |
| 309 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 310 | return sync_service_->GetAuthError().state(); |
| 311 | } |
| 312 | |
| 313 | jboolean ProfileSyncServiceAndroid::HasUnrecoverableError( |
| 314 | JNIEnv* env, jobject) { |
| 315 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 316 | return sync_service_->HasUnrecoverableError(); |
| 317 | } |
| 318 | |
| 319 | // Pure SyncPrefs calls. |
| 320 | |
| 321 | jboolean ProfileSyncServiceAndroid::IsPassphrasePrompted(JNIEnv* env, |
| 322 | jobject obj) { |
| 323 | return sync_prefs_->IsPassphrasePrompted(); |
| 324 | } |
| 325 | |
| 326 | void ProfileSyncServiceAndroid::SetPassphrasePrompted(JNIEnv* env, |
| 327 | jobject obj, |
| 328 | jboolean prompted) { |
| 329 | sync_prefs_->SetPassphrasePrompted(prompted); |
| 330 | } |
| 331 | |
maxbogue | c7f232d | 2015-07-29 19:25:40 | [diff] [blame] | 332 | void ProfileSyncServiceAndroid::SetSyncSessionsId( |
[email protected] | 9049a7b | 2013-03-07 22:22:03 | [diff] [blame] | 333 | JNIEnv* env, jobject obj, jstring tag) { |
anujk.sharma | 8619448 | 2015-04-23 06:38:23 | [diff] [blame] | 334 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | 9049a7b | 2013-03-07 22:22:03 | [diff] [blame] | 335 | DCHECK(profile_); |
| 336 | std::string machine_tag = ConvertJavaStringToUTF8(env, tag); |
[email protected] | aa5b2ece | 2013-05-17 00:37:36 | [diff] [blame] | 337 | sync_prefs_->SetSyncSessionsGUID(machine_tag); |
[email protected] | 9049a7b | 2013-03-07 22:22:03 | [diff] [blame] | 338 | } |
| 339 | |
maxbogue | 28baa96 | 2015-10-01 17:21:38 | [diff] [blame] | 340 | jboolean ProfileSyncServiceAndroid::HasKeepEverythingSynced( |
[email protected] | 9049a7b | 2013-03-07 22:22:03 | [diff] [blame] | 341 | JNIEnv* env, jobject) { |
anujk.sharma | 8619448 | 2015-04-23 06:38:23 | [diff] [blame] | 342 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
maxbogue | 28baa96 | 2015-10-01 17:21:38 | [diff] [blame] | 343 | return sync_prefs_->HasKeepEverythingSynced(); |
[email protected] | 9049a7b | 2013-03-07 22:22:03 | [diff] [blame] | 344 | } |
| 345 | |
maxbogue | 28baa96 | 2015-10-01 17:21:38 | [diff] [blame] | 346 | // UI string getters. |
maxbogue | c021ddcc | 2014-10-09 16:21:24 | [diff] [blame] | 347 | |
[email protected] | 9049a7b | 2013-03-07 22:22:03 | [diff] [blame] | 348 | ScopedJavaLocalRef<jstring> |
| 349 | ProfileSyncServiceAndroid::GetSyncEnterGooglePassphraseBodyWithDateText( |
| 350 | JNIEnv* env, jobject) { |
anujk.sharma | 8619448 | 2015-04-23 06:38:23 | [diff] [blame] | 351 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | 9049a7b | 2013-03-07 22:22:03 | [diff] [blame] | 352 | base::Time passphrase_time = sync_service_->GetExplicitPassphraseTime(); |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 353 | base::string16 passphrase_time_str = |
| 354 | base::TimeFormatShortDate(passphrase_time); |
[email protected] | 9049a7b | 2013-03-07 22:22:03 | [diff] [blame] | 355 | return base::android::ConvertUTF16ToJavaString(env, |
| 356 | l10n_util::GetStringFUTF16( |
| 357 | IDS_SYNC_ENTER_GOOGLE_PASSPHRASE_BODY_WITH_DATE, |
| 358 | passphrase_time_str)); |
| 359 | } |
| 360 | |
| 361 | ScopedJavaLocalRef<jstring> |
| 362 | ProfileSyncServiceAndroid::GetSyncEnterCustomPassphraseBodyWithDateText( |
| 363 | JNIEnv* env, jobject) { |
anujk.sharma | 8619448 | 2015-04-23 06:38:23 | [diff] [blame] | 364 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | 9049a7b | 2013-03-07 22:22:03 | [diff] [blame] | 365 | base::Time passphrase_time = sync_service_->GetExplicitPassphraseTime(); |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 366 | base::string16 passphrase_time_str = |
| 367 | base::TimeFormatShortDate(passphrase_time); |
[email protected] | 9049a7b | 2013-03-07 22:22:03 | [diff] [blame] | 368 | return base::android::ConvertUTF16ToJavaString(env, |
| 369 | l10n_util::GetStringFUTF16(IDS_SYNC_ENTER_PASSPHRASE_BODY_WITH_DATE, |
| 370 | passphrase_time_str)); |
| 371 | } |
| 372 | |
| 373 | ScopedJavaLocalRef<jstring> |
[email protected] | 4faa9de0 | 2013-03-26 10:17:20 | [diff] [blame] | 374 | ProfileSyncServiceAndroid::GetCurrentSignedInAccountText( |
| 375 | JNIEnv* env, jobject) { |
anujk.sharma | 8619448 | 2015-04-23 06:38:23 | [diff] [blame] | 376 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | 4faa9de0 | 2013-03-26 10:17:20 | [diff] [blame] | 377 | const std::string& sync_username = |
bzanotti | 1b5be290 | 2015-08-31 12:10:05 | [diff] [blame] | 378 | SigninManagerFactory::GetForProfile(profile_) |
| 379 | ->GetAuthenticatedAccountInfo() |
| 380 | .email; |
[email protected] | 4faa9de0 | 2013-03-26 10:17:20 | [diff] [blame] | 381 | return base::android::ConvertUTF16ToJavaString(env, |
| 382 | l10n_util::GetStringFUTF16( |
| 383 | IDS_SYNC_ACCOUNT_SYNCING_TO_USER, |
[email protected] | f911df5 | 2013-12-24 23:24:23 | [diff] [blame] | 384 | base::ASCIIToUTF16(sync_username))); |
[email protected] | 4faa9de0 | 2013-03-26 10:17:20 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | ScopedJavaLocalRef<jstring> |
[email protected] | 9049a7b | 2013-03-07 22:22:03 | [diff] [blame] | 388 | ProfileSyncServiceAndroid::GetSyncEnterCustomPassphraseBodyText( |
| 389 | JNIEnv* env, jobject) { |
anujk.sharma | 8619448 | 2015-04-23 06:38:23 | [diff] [blame] | 390 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | 9049a7b | 2013-03-07 22:22:03 | [diff] [blame] | 391 | return ConvertUTF8ToJavaString( |
| 392 | env, l10n_util::GetStringUTF8(IDS_SYNC_ENTER_PASSPHRASE_BODY)); |
| 393 | } |
| 394 | |
maxbogue | 28baa96 | 2015-10-01 17:21:38 | [diff] [blame] | 395 | // Functionality only available for testing purposes. |
[email protected] | 9049a7b | 2013-03-07 22:22:03 | [diff] [blame] | 396 | |
| 397 | ScopedJavaLocalRef<jstring> ProfileSyncServiceAndroid::GetAboutInfoForTest( |
| 398 | JNIEnv* env, jobject) { |
anujk.sharma | 8619448 | 2015-04-23 06:38:23 | [diff] [blame] | 399 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | 9049a7b | 2013-03-07 22:22:03 | [diff] [blame] | 400 | |
[email protected] | dbb9aa4 | 2013-12-23 20:08:21 | [diff] [blame] | 401 | scoped_ptr<base::DictionaryValue> about_info = |
droger | 5144c43 | 2015-09-17 10:53:11 | [diff] [blame] | 402 | sync_driver::sync_ui_util::ConstructAboutInformation( |
| 403 | sync_service_, sync_service_->signin(), chrome::GetChannel()); |
[email protected] | 9049a7b | 2013-03-07 22:22:03 | [diff] [blame] | 404 | std::string about_info_json; |
estade | 8d04646 | 2015-05-16 01:02:34 | [diff] [blame] | 405 | base::JSONWriter::Write(*about_info, &about_info_json); |
[email protected] | 9049a7b | 2013-03-07 22:22:03 | [diff] [blame] | 406 | |
| 407 | return ConvertUTF8ToJavaString(env, about_info_json); |
| 408 | } |
| 409 | |
[email protected] | ed4d705 | 2013-09-04 19:01:37 | [diff] [blame] | 410 | jlong ProfileSyncServiceAndroid::GetLastSyncedTimeForTest( |
| 411 | JNIEnv* env, jobject obj) { |
| 412 | // Use profile preferences here instead of SyncPrefs to avoid an extra |
| 413 | // conversion, since SyncPrefs::GetLastSyncedTime() converts the stored value |
| 414 | // to to base::Time. |
| 415 | return static_cast<jlong>( |
[email protected] | 34f5405 | 2014-03-20 21:33:40 | [diff] [blame] | 416 | profile_->GetPrefs()->GetInt64(sync_driver::prefs::kSyncLastSyncedTime)); |
[email protected] | ed4d705 | 2013-09-04 19:01:37 | [diff] [blame] | 417 | } |
| 418 | |
[email protected] | be21aaa | 2014-08-21 21:26:38 | [diff] [blame] | 419 | void ProfileSyncServiceAndroid::OverrideNetworkResourcesForTest( |
| 420 | JNIEnv* env, |
| 421 | jobject obj, |
| 422 | jlong network_resources) { |
| 423 | syncer::NetworkResources* resources = |
| 424 | reinterpret_cast<syncer::NetworkResources*>(network_resources); |
| 425 | sync_service_->OverrideNetworkResourcesForTest( |
| 426 | make_scoped_ptr<syncer::NetworkResources>(resources)); |
| 427 | } |
| 428 | |
bauerb | dab6c6f | 2014-08-28 09:20:23 | [diff] [blame] | 429 | // static |
[email protected] | 332a8336 | 2013-03-26 08:45:55 | [diff] [blame] | 430 | ProfileSyncServiceAndroid* |
| 431 | ProfileSyncServiceAndroid::GetProfileSyncServiceAndroid() { |
| 432 | return reinterpret_cast<ProfileSyncServiceAndroid*>( |
maxbogue | 89bee1d86 | 2015-08-26 21:00:07 | [diff] [blame] | 433 | Java_ProfileSyncService_getProfileSyncServiceAndroid( |
| 434 | AttachCurrentThread())); |
[email protected] | 332a8336 | 2013-03-26 08:45:55 | [diff] [blame] | 435 | } |
| 436 | |
maxbogue | 28baa96 | 2015-10-01 17:21:38 | [diff] [blame] | 437 | // static |
| 438 | bool ProfileSyncServiceAndroid::Register(JNIEnv* env) { |
| 439 | return RegisterNativesImpl(env); |
| 440 | } |
| 441 | |
torne | 89cc5d9 | 2015-09-04 11:16:35 | [diff] [blame] | 442 | static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
[email protected] | 9049a7b | 2013-03-07 22:22:03 | [diff] [blame] | 443 | ProfileSyncServiceAndroid* profile_sync_service_android = |
| 444 | new ProfileSyncServiceAndroid(env, obj); |
| 445 | profile_sync_service_android->Init(); |
[email protected] | d557b604 | 2013-11-21 16:34:31 | [diff] [blame] | 446 | return reinterpret_cast<intptr_t>(profile_sync_service_android); |
[email protected] | 9049a7b | 2013-03-07 22:22:03 | [diff] [blame] | 447 | } |