| 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 if (sync_service_->HasObserver(this)) { | 88 if (sync_service_->HasObserver(this)) { |
| 89 sync_service_->RemoveObserver(this); | 89 sync_service_->RemoveObserver(this); |
| 90 } | 90 } |
| 91 } | 91 } |
| 92 | 92 |
| 93 ProfileSyncServiceAndroid::~ProfileSyncServiceAndroid() { | 93 ProfileSyncServiceAndroid::~ProfileSyncServiceAndroid() { |
| 94 RemoveObserver(); | 94 RemoveObserver(); |
| 95 } | 95 } |
| 96 | 96 |
| 97 void ProfileSyncServiceAndroid::SendNudgeNotification( | 97 void ProfileSyncServiceAndroid::SendNudgeNotification( |
| 98 int object_source, |
| 98 const std::string& str_object_id, | 99 const std::string& str_object_id, |
| 99 int64 version, | 100 int64 version, |
| 100 const std::string& state) { | 101 const std::string& state) { |
| 101 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 102 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 102 | 103 |
| 103 // TODO(nileshagrawal): Merge this with ChromeInvalidationClient::Invalidate. | 104 // TODO(nileshagrawal): Merge this with ChromeInvalidationClient::Invalidate. |
| 104 // Construct the ModelTypeStateMap and send it over with the notification. | 105 // Construct the ModelTypeStateMap and send it over with the notification. |
| 105 invalidation::ObjectId object_id( | 106 invalidation::ObjectId object_id( |
| 106 ipc::invalidation::ObjectSource::CHROME_SYNC, | 107 object_source, |
| 107 str_object_id); | 108 str_object_id); |
| 108 if (version != ipc::invalidation::Constants::UNKNOWN) { | 109 if (version == ipc::invalidation::Constants::UNKNOWN) { |
| 110 version = syncer::Invalidation::kUnknownVersion; |
| 111 } else { |
| 109 ObjectIdVersionMap::iterator it = | 112 ObjectIdVersionMap::iterator it = |
| 110 max_invalidation_versions_.find(object_id); | 113 max_invalidation_versions_.find(object_id); |
| 111 if ((it != max_invalidation_versions_.end()) && | 114 if ((it != max_invalidation_versions_.end()) && |
| 112 (version <= it->second)) { | 115 (version <= it->second)) { |
| 113 DVLOG(1) << "Dropping redundant invalidation with version " << version; | 116 DVLOG(1) << "Dropping redundant invalidation with version " << version; |
| 114 return; | 117 return; |
| 115 } | 118 } |
| 116 max_invalidation_versions_[object_id] = version; | 119 max_invalidation_versions_[object_id] = version; |
| 117 } | 120 } |
| 118 | 121 |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 scoped_ptr<DictionaryValue> about_info = | 470 scoped_ptr<DictionaryValue> about_info = |
| 468 sync_ui_util::ConstructAboutInformation(sync_service_); | 471 sync_ui_util::ConstructAboutInformation(sync_service_); |
| 469 std::string about_info_json; | 472 std::string about_info_json; |
| 470 base::JSONWriter::Write(about_info.get(), &about_info_json); | 473 base::JSONWriter::Write(about_info.get(), &about_info_json); |
| 471 | 474 |
| 472 return ConvertUTF8ToJavaString(env, about_info_json); | 475 return ConvertUTF8ToJavaString(env, about_info_json); |
| 473 } | 476 } |
| 474 | 477 |
| 475 void ProfileSyncServiceAndroid::NudgeSyncer(JNIEnv* env, | 478 void ProfileSyncServiceAndroid::NudgeSyncer(JNIEnv* env, |
| 476 jobject obj, | 479 jobject obj, |
| 480 jint objectSource, |
| 477 jstring objectId, | 481 jstring objectId, |
| 478 jlong version, | 482 jlong version, |
| 479 jstring state) { | 483 jstring state) { |
| 480 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 484 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 481 SendNudgeNotification(ConvertJavaStringToUTF8(env, objectId), version, | 485 SendNudgeNotification(objectSource, ConvertJavaStringToUTF8(env, objectId), |
| 482 ConvertJavaStringToUTF8(env, state)); | 486 version, ConvertJavaStringToUTF8(env, state)); |
| 483 } | 487 } |
| 484 | 488 |
| 485 void ProfileSyncServiceAndroid::NudgeSyncerForAllTypes(JNIEnv* env, | 489 void ProfileSyncServiceAndroid::NudgeSyncerForAllTypes(JNIEnv* env, |
| 486 jobject obj) { | 490 jobject obj) { |
| 487 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 491 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 488 syncer::ObjectIdInvalidationMap object_ids_with_states; | 492 syncer::ObjectIdInvalidationMap object_ids_with_states; |
| 489 content::NotificationService::current()->Notify( | 493 content::NotificationService::current()->Notify( |
| 490 chrome::NOTIFICATION_SYNC_REFRESH_REMOTE, | 494 chrome::NOTIFICATION_SYNC_REFRESH_REMOTE, |
| 491 content::Source<Profile>(profile_), | 495 content::Source<Profile>(profile_), |
| 492 content::Details<const syncer::ObjectIdInvalidationMap>( | 496 content::Details<const syncer::ObjectIdInvalidationMap>( |
| (...skipping 12 matching lines...) Expand all Loading... |
| 505 ProfileSyncServiceAndroid* profile_sync_service_android = | 509 ProfileSyncServiceAndroid* profile_sync_service_android = |
| 506 new ProfileSyncServiceAndroid(env, obj); | 510 new ProfileSyncServiceAndroid(env, obj); |
| 507 profile_sync_service_android->Init(); | 511 profile_sync_service_android->Init(); |
| 508 return reinterpret_cast<jint>(profile_sync_service_android); | 512 return reinterpret_cast<jint>(profile_sync_service_android); |
| 509 } | 513 } |
| 510 | 514 |
| 511 // static | 515 // static |
| 512 bool ProfileSyncServiceAndroid::Register(JNIEnv* env) { | 516 bool ProfileSyncServiceAndroid::Register(JNIEnv* env) { |
| 513 return RegisterNativesImpl(env); | 517 return RegisterNativesImpl(env); |
| 514 } | 518 } |
| OLD | NEW |