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 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 jboolean ProfileSyncServiceAndroid::IsSyncKeystoreMigrationDone( | 340 jboolean ProfileSyncServiceAndroid::IsSyncKeystoreMigrationDone( |
341 JNIEnv* env, jobject) { | 341 JNIEnv* env, jobject) { |
342 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 342 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
343 syncer::SyncStatus status; | 343 syncer::SyncStatus status; |
344 bool is_status_valid = sync_service_->QueryDetailedSyncStatus(&status); | 344 bool is_status_valid = sync_service_->QueryDetailedSyncStatus(&status); |
345 return is_status_valid && !status.keystore_migration_time.is_null(); | 345 return is_status_valid && !status.keystore_migration_time.is_null(); |
346 } | 346 } |
347 | 347 |
348 jlong ProfileSyncServiceAndroid::GetEnabledDataTypes(JNIEnv* env, | 348 jlong ProfileSyncServiceAndroid::GetEnabledDataTypes(JNIEnv* env, |
349 jobject obj) { | 349 jobject obj) { |
350 jlong model_type_selection = 0; | |
351 syncer::ModelTypeSet types = sync_service_->GetActiveDataTypes(); | 350 syncer::ModelTypeSet types = sync_service_->GetActiveDataTypes(); |
352 types.PutAll(syncer::ControlTypes()); | 351 types.PutAll(syncer::ControlTypes()); |
353 if (types.Has(syncer::BOOKMARKS)) { | 352 return ModelTypeSetToSelection(types); |
354 model_type_selection |= BOOKMARK; | |
355 } | |
356 if (types.Has(syncer::AUTOFILL)) { | |
357 model_type_selection |= AUTOFILL; | |
358 } | |
359 if (types.Has(syncer::AUTOFILL_PROFILE)) { | |
360 model_type_selection |= AUTOFILL_PROFILE; | |
361 } | |
362 if (types.Has(syncer::PASSWORDS)) { | |
363 model_type_selection |= PASSWORD; | |
364 } | |
365 if (types.Has(syncer::TYPED_URLS)) { | |
366 model_type_selection |= TYPED_URL; | |
367 } | |
368 if (types.Has(syncer::SESSIONS)) { | |
369 model_type_selection |= SESSION; | |
370 } | |
371 if (types.Has(syncer::HISTORY_DELETE_DIRECTIVES)) { | |
372 model_type_selection |= HISTORY_DELETE_DIRECTIVE; | |
373 } | |
374 if (types.Has(syncer::PROXY_TABS)) { | |
375 model_type_selection |= PROXY_TABS; | |
376 } | |
377 if (types.Has(syncer::FAVICON_IMAGES)) { | |
378 model_type_selection |= FAVICON_IMAGE; | |
379 } | |
380 if (types.Has(syncer::FAVICON_TRACKING)) { | |
381 model_type_selection |= FAVICON_TRACKING; | |
382 } | |
383 if (types.Has(syncer::DEVICE_INFO)) { | |
384 model_type_selection |= DEVICE_INFO; | |
385 } | |
386 if (types.Has(syncer::NIGORI)) { | |
387 model_type_selection |= NIGORI; | |
388 } | |
389 if (types.Has(syncer::EXPERIMENTS)) { | |
390 model_type_selection |= EXPERIMENTS; | |
391 } | |
392 return model_type_selection; | |
393 } | 353 } |
394 | 354 |
395 void ProfileSyncServiceAndroid::SetPreferredDataTypes( | 355 void ProfileSyncServiceAndroid::SetPreferredDataTypes( |
396 JNIEnv* env, jobject obj, | 356 JNIEnv* env, jobject obj, |
397 jboolean sync_everything, | 357 jboolean sync_everything, |
398 jlong model_type_selection) { | 358 jlong model_type_selection) { |
399 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 359 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
400 syncer::ModelTypeSet types; | 360 syncer::ModelTypeSet types; |
401 // Note: only user selectable types should be included here. | 361 // Note: only user selectable types should be included here. |
402 if (model_type_selection & AUTOFILL) | 362 if (model_type_selection & AUTOFILL) |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 void ProfileSyncServiceAndroid::OverrideNetworkResourcesForTest( | 439 void ProfileSyncServiceAndroid::OverrideNetworkResourcesForTest( |
480 JNIEnv* env, | 440 JNIEnv* env, |
481 jobject obj, | 441 jobject obj, |
482 jlong network_resources) { | 442 jlong network_resources) { |
483 syncer::NetworkResources* resources = | 443 syncer::NetworkResources* resources = |
484 reinterpret_cast<syncer::NetworkResources*>(network_resources); | 444 reinterpret_cast<syncer::NetworkResources*>(network_resources); |
485 sync_service_->OverrideNetworkResourcesForTest( | 445 sync_service_->OverrideNetworkResourcesForTest( |
486 make_scoped_ptr<syncer::NetworkResources>(resources)); | 446 make_scoped_ptr<syncer::NetworkResources>(resources)); |
487 } | 447 } |
488 | 448 |
| 449 // static |
| 450 jlong ProfileSyncServiceAndroid::ModelTypeSetToSelection( |
| 451 syncer::ModelTypeSet types) { |
| 452 jlong model_type_selection = 0; |
| 453 if (types.Has(syncer::BOOKMARKS)) { |
| 454 model_type_selection |= BOOKMARK; |
| 455 } |
| 456 if (types.Has(syncer::AUTOFILL)) { |
| 457 model_type_selection |= AUTOFILL; |
| 458 } |
| 459 if (types.Has(syncer::AUTOFILL_PROFILE)) { |
| 460 model_type_selection |= AUTOFILL_PROFILE; |
| 461 } |
| 462 if (types.Has(syncer::PASSWORDS)) { |
| 463 model_type_selection |= PASSWORD; |
| 464 } |
| 465 if (types.Has(syncer::TYPED_URLS)) { |
| 466 model_type_selection |= TYPED_URL; |
| 467 } |
| 468 if (types.Has(syncer::SESSIONS)) { |
| 469 model_type_selection |= SESSION; |
| 470 } |
| 471 if (types.Has(syncer::HISTORY_DELETE_DIRECTIVES)) { |
| 472 model_type_selection |= HISTORY_DELETE_DIRECTIVE; |
| 473 } |
| 474 if (types.Has(syncer::PROXY_TABS)) { |
| 475 model_type_selection |= PROXY_TABS; |
| 476 } |
| 477 if (types.Has(syncer::FAVICON_IMAGES)) { |
| 478 model_type_selection |= FAVICON_IMAGE; |
| 479 } |
| 480 if (types.Has(syncer::FAVICON_TRACKING)) { |
| 481 model_type_selection |= FAVICON_TRACKING; |
| 482 } |
| 483 if (types.Has(syncer::DEVICE_INFO)) { |
| 484 model_type_selection |= DEVICE_INFO; |
| 485 } |
| 486 if (types.Has(syncer::NIGORI)) { |
| 487 model_type_selection |= NIGORI; |
| 488 } |
| 489 if (types.Has(syncer::EXPERIMENTS)) { |
| 490 model_type_selection |= EXPERIMENTS; |
| 491 } |
| 492 if (types.Has(syncer::SUPERVISED_USER_SETTINGS)) { |
| 493 model_type_selection |= SUPERVISED_USER_SETTING; |
| 494 } |
| 495 return model_type_selection; |
| 496 } |
| 497 |
| 498 // static |
| 499 std::string ProfileSyncServiceAndroid::ModelTypeSelectionToStringForTest( |
| 500 jlong model_type_selection) { |
| 501 ScopedJavaLocalRef<jstring> string = |
| 502 Java_ProfileSyncService_modelTypeSelectionToStringForTest( |
| 503 AttachCurrentThread(), model_type_selection); |
| 504 return ConvertJavaStringToUTF8(string); |
| 505 } |
| 506 |
489 void ProfileSyncServiceAndroid::NudgeSyncer(JNIEnv* env, | 507 void ProfileSyncServiceAndroid::NudgeSyncer(JNIEnv* env, |
490 jobject obj, | 508 jobject obj, |
491 jint objectSource, | 509 jint objectSource, |
492 jstring objectId, | 510 jstring objectId, |
493 jlong version, | 511 jlong version, |
494 jstring state) { | 512 jstring state) { |
495 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 513 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
496 SendNudgeNotification(objectSource, ConvertJavaStringToUTF8(env, objectId), | 514 SendNudgeNotification(objectSource, ConvertJavaStringToUTF8(env, objectId), |
497 version, ConvertJavaStringToUTF8(env, state)); | 515 version, ConvertJavaStringToUTF8(env, state)); |
498 } | 516 } |
(...skipping 21 matching lines...) Expand all Loading... |
520 ProfileSyncServiceAndroid* profile_sync_service_android = | 538 ProfileSyncServiceAndroid* profile_sync_service_android = |
521 new ProfileSyncServiceAndroid(env, obj); | 539 new ProfileSyncServiceAndroid(env, obj); |
522 profile_sync_service_android->Init(); | 540 profile_sync_service_android->Init(); |
523 return reinterpret_cast<intptr_t>(profile_sync_service_android); | 541 return reinterpret_cast<intptr_t>(profile_sync_service_android); |
524 } | 542 } |
525 | 543 |
526 // static | 544 // static |
527 bool ProfileSyncServiceAndroid::Register(JNIEnv* env) { | 545 bool ProfileSyncServiceAndroid::Register(JNIEnv* env) { |
528 return RegisterNativesImpl(env); | 546 return RegisterNativesImpl(env); |
529 } | 547 } |
OLD | NEW |