| 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 if (sync_service_->HasObserver(this)) { | 87 if (sync_service_->HasObserver(this)) { |
| 88 sync_service_->RemoveObserver(this); | 88 sync_service_->RemoveObserver(this); |
| 89 } | 89 } |
| 90 } | 90 } |
| 91 | 91 |
| 92 ProfileSyncServiceAndroid::~ProfileSyncServiceAndroid() { | 92 ProfileSyncServiceAndroid::~ProfileSyncServiceAndroid() { |
| 93 RemoveObserver(); | 93 RemoveObserver(); |
| 94 } | 94 } |
| 95 | 95 |
| 96 void ProfileSyncServiceAndroid::SendNudgeNotification( | 96 void ProfileSyncServiceAndroid::SendNudgeNotification( |
| 97 int object_source, |
| 97 const std::string& str_object_id, | 98 const std::string& str_object_id, |
| 98 int64 version, | 99 int64 version, |
| 99 const std::string& state) { | 100 const std::string& state) { |
| 100 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 101 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 101 | 102 |
| 102 // TODO(nileshagrawal): Merge this with ChromeInvalidationClient::Invalidate. | 103 // TODO(nileshagrawal): Merge this with ChromeInvalidationClient::Invalidate. |
| 103 // Construct the ModelTypeStateMap and send it over with the notification. | 104 // Construct the ModelTypeStateMap and send it over with the notification. |
| 104 invalidation::ObjectId object_id( | 105 invalidation::ObjectId object_id( |
| 105 ipc::invalidation::ObjectSource::CHROME_SYNC, | 106 object_source, |
| 106 str_object_id); | 107 str_object_id); |
| 107 if (version != ipc::invalidation::Constants::UNKNOWN) { | 108 if (version == ipc::invalidation::Constants::UNKNOWN) { |
| 109 version = syncer::Invalidation::kUnknownVersion; |
| 110 } else { |
| 108 ObjectIdVersionMap::iterator it = | 111 ObjectIdVersionMap::iterator it = |
| 109 max_invalidation_versions_.find(object_id); | 112 max_invalidation_versions_.find(object_id); |
| 110 if ((it != max_invalidation_versions_.end()) && | 113 if ((it != max_invalidation_versions_.end()) && |
| 111 (version <= it->second)) { | 114 (version <= it->second)) { |
| 112 DVLOG(1) << "Dropping redundant invalidation with version " << version; | 115 DVLOG(1) << "Dropping redundant invalidation with version " << version; |
| 113 return; | 116 return; |
| 114 } | 117 } |
| 115 max_invalidation_versions_[object_id] = version; | 118 max_invalidation_versions_[object_id] = version; |
| 116 } | 119 } |
| 117 | 120 |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 JNIEnv* env, jobject obj) { | 478 JNIEnv* env, jobject obj) { |
| 476 // Use profile preferences here instead of SyncPrefs to avoid an extra | 479 // Use profile preferences here instead of SyncPrefs to avoid an extra |
| 477 // conversion, since SyncPrefs::GetLastSyncedTime() converts the stored value | 480 // conversion, since SyncPrefs::GetLastSyncedTime() converts the stored value |
| 478 // to to base::Time. | 481 // to to base::Time. |
| 479 return static_cast<jlong>( | 482 return static_cast<jlong>( |
| 480 profile_->GetPrefs()->GetInt64(prefs::kSyncLastSyncedTime)); | 483 profile_->GetPrefs()->GetInt64(prefs::kSyncLastSyncedTime)); |
| 481 } | 484 } |
| 482 | 485 |
| 483 void ProfileSyncServiceAndroid::NudgeSyncer(JNIEnv* env, | 486 void ProfileSyncServiceAndroid::NudgeSyncer(JNIEnv* env, |
| 484 jobject obj, | 487 jobject obj, |
| 488 jint objectSource, |
| 485 jstring objectId, | 489 jstring objectId, |
| 486 jlong version, | 490 jlong version, |
| 487 jstring state) { | 491 jstring state) { |
| 488 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 492 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 489 SendNudgeNotification(ConvertJavaStringToUTF8(env, objectId), version, | 493 SendNudgeNotification(objectSource, ConvertJavaStringToUTF8(env, objectId), |
| 490 ConvertJavaStringToUTF8(env, state)); | 494 version, ConvertJavaStringToUTF8(env, state)); |
| 491 } | 495 } |
| 492 | 496 |
| 493 void ProfileSyncServiceAndroid::NudgeSyncerForAllTypes(JNIEnv* env, | 497 void ProfileSyncServiceAndroid::NudgeSyncerForAllTypes(JNIEnv* env, |
| 494 jobject obj) { | 498 jobject obj) { |
| 495 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 499 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 496 syncer::ObjectIdInvalidationMap object_ids_with_states; | 500 syncer::ObjectIdInvalidationMap object_ids_with_states; |
| 497 content::NotificationService::current()->Notify( | 501 content::NotificationService::current()->Notify( |
| 498 chrome::NOTIFICATION_SYNC_REFRESH_REMOTE, | 502 chrome::NOTIFICATION_SYNC_REFRESH_REMOTE, |
| 499 content::Source<Profile>(profile_), | 503 content::Source<Profile>(profile_), |
| 500 content::Details<const syncer::ObjectIdInvalidationMap>( | 504 content::Details<const syncer::ObjectIdInvalidationMap>( |
| (...skipping 12 matching lines...) Expand all Loading... |
| 513 ProfileSyncServiceAndroid* profile_sync_service_android = | 517 ProfileSyncServiceAndroid* profile_sync_service_android = |
| 514 new ProfileSyncServiceAndroid(env, obj); | 518 new ProfileSyncServiceAndroid(env, obj); |
| 515 profile_sync_service_android->Init(); | 519 profile_sync_service_android->Init(); |
| 516 return reinterpret_cast<jint>(profile_sync_service_android); | 520 return reinterpret_cast<jint>(profile_sync_service_android); |
| 517 } | 521 } |
| 518 | 522 |
| 519 // static | 523 // static |
| 520 bool ProfileSyncServiceAndroid::Register(JNIEnv* env) { | 524 bool ProfileSyncServiceAndroid::Register(JNIEnv* env) { |
| 521 return RegisterNativesImpl(env); | 525 return RegisterNativesImpl(env); |
| 522 } | 526 } |
| OLD | NEW |