Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(366)

Side by Side Diff: chrome/browser/sync/profile_sync_service_android.cc

Issue 459513002: Massive refactor of the Android invalidation code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "base/json/json_writer.h" 11 #include "base/json/json_writer.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/prefs/pref_service.h" 14 #include "base/prefs/pref_service.h"
15 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "base/time/time.h" 16 #include "base/time/time.h"
17 #include "chrome/browser/browser_process.h" 17 #include "chrome/browser/browser_process.h"
18 #include "chrome/browser/chrome_notification_types.h" 18 #include "chrome/browser/chrome_notification_types.h"
19 #include "chrome/browser/profiles/profile_manager.h" 19 #include "chrome/browser/profiles/profile_manager.h"
20 #include "chrome/browser/signin/signin_manager_factory.h" 20 #include "chrome/browser/signin/signin_manager_factory.h"
21 #include "chrome/browser/sync/about_sync_util.h" 21 #include "chrome/browser/sync/about_sync_util.h"
22 #include "chrome/browser/sync/profile_sync_service.h" 22 #include "chrome/browser/sync/profile_sync_service.h"
23 #include "chrome/browser/sync/profile_sync_service_factory.h" 23 #include "chrome/browser/sync/profile_sync_service_factory.h"
24 #include "chrome/browser/sync/sync_ui_util.h" 24 #include "chrome/browser/sync/sync_ui_util.h"
25 #include "chrome/grit/generated_resources.h" 25 #include "chrome/grit/generated_resources.h"
26 #include "components/invalidation/object_id_invalidation_map.h" 26 #include "components/invalidation/object_id_invalidation_map.h"
nyquist 2014/09/04 09:01:56 remove? could there also be other related includes
maxbogue 2014/09/05 16:42:45 Done.
27 #include "components/signin/core/browser/signin_manager.h" 27 #include "components/signin/core/browser/signin_manager.h"
28 #include "components/sync_driver/pref_names.h" 28 #include "components/sync_driver/pref_names.h"
29 #include "components/sync_driver/sync_prefs.h" 29 #include "components/sync_driver/sync_prefs.h"
30 #include "content/public/browser/browser_thread.h" 30 #include "content/public/browser/browser_thread.h"
31 #include "content/public/browser/notification_service.h" 31 #include "content/public/browser/notification_service.h"
32 #include "content/public/browser/notification_source.h" 32 #include "content/public/browser/notification_source.h"
33 #include "google/cacheinvalidation/types.pb.h" 33 #include "google/cacheinvalidation/types.pb.h"
34 #include "google_apis/gaia/gaia_constants.h" 34 #include "google_apis/gaia/gaia_constants.h"
35 #include "google_apis/gaia/google_service_auth_error.h" 35 #include "google_apis/gaia/google_service_auth_error.h"
36 #include "jni/ProfileSyncService_jni.h" 36 #include "jni/ProfileSyncService_jni.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 void ProfileSyncServiceAndroid::RemoveObserver() { 85 void ProfileSyncServiceAndroid::RemoveObserver() {
86 if (sync_service_->HasObserver(this)) { 86 if (sync_service_->HasObserver(this)) {
87 sync_service_->RemoveObserver(this); 87 sync_service_->RemoveObserver(this);
88 } 88 }
89 } 89 }
90 90
91 ProfileSyncServiceAndroid::~ProfileSyncServiceAndroid() { 91 ProfileSyncServiceAndroid::~ProfileSyncServiceAndroid() {
92 RemoveObserver(); 92 RemoveObserver();
93 } 93 }
94 94
95 void ProfileSyncServiceAndroid::SendNudgeNotification(
96 int object_source,
97 const std::string& str_object_id,
98 int64 version,
99 const std::string& state) {
100 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
101
102 // TODO(nileshagrawal): Merge this with ChromeInvalidationClient::Invalidate.
103 // Construct the ModelTypeStateMap and send it over with the notification.
104 invalidation::ObjectId object_id(
105 object_source,
106 str_object_id);
107 syncer::ObjectIdInvalidationMap object_ids_with_states;
108 if (version == ipc::invalidation::Constants::UNKNOWN) {
109 object_ids_with_states.Insert(
110 syncer::Invalidation::InitUnknownVersion(object_id));
111 } else {
112 ObjectIdVersionMap::iterator it =
113 max_invalidation_versions_.find(object_id);
114 if ((it != max_invalidation_versions_.end()) &&
115 (version <= it->second)) {
116 DVLOG(1) << "Dropping redundant invalidation with version " << version;
117 return;
118 }
119 max_invalidation_versions_[object_id] = version;
120 object_ids_with_states.Insert(
121 syncer::Invalidation::Init(object_id, version, state));
122 }
123
124 content::NotificationService::current()->Notify(
125 chrome::NOTIFICATION_SYNC_REFRESH_REMOTE,
126 content::Source<Profile>(profile_),
127 content::Details<const syncer::ObjectIdInvalidationMap>(
128 &object_ids_with_states));
129 }
130
131 void ProfileSyncServiceAndroid::OnStateChanged() { 95 void ProfileSyncServiceAndroid::OnStateChanged() {
132 // Notify the java world that our sync state has changed. 96 // Notify the java world that our sync state has changed.
133 JNIEnv* env = AttachCurrentThread(); 97 JNIEnv* env = AttachCurrentThread();
134 Java_ProfileSyncService_syncStateChanged( 98 Java_ProfileSyncService_syncStateChanged(
135 env, weak_java_profile_sync_service_.get(env).obj()); 99 env, weak_java_profile_sync_service_.get(env).obj());
136 } 100 }
137 101
138 void ProfileSyncServiceAndroid::EnableSync(JNIEnv* env, jobject) { 102 void ProfileSyncServiceAndroid::EnableSync(JNIEnv* env, jobject) {
139 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 103 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
140 // Don't need to do anything if we're already enabled. 104 // Don't need to do anything if we're already enabled.
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 461
498 // static 462 // static
499 std::string ProfileSyncServiceAndroid::ModelTypeSelectionToStringForTest( 463 std::string ProfileSyncServiceAndroid::ModelTypeSelectionToStringForTest(
500 jlong model_type_selection) { 464 jlong model_type_selection) {
501 ScopedJavaLocalRef<jstring> string = 465 ScopedJavaLocalRef<jstring> string =
502 Java_ProfileSyncService_modelTypeSelectionToStringForTest( 466 Java_ProfileSyncService_modelTypeSelectionToStringForTest(
503 AttachCurrentThread(), model_type_selection); 467 AttachCurrentThread(), model_type_selection);
504 return ConvertJavaStringToUTF8(string); 468 return ConvertJavaStringToUTF8(string);
505 } 469 }
506 470
507 void ProfileSyncServiceAndroid::NudgeSyncer(JNIEnv* env,
508 jobject obj,
509 jint objectSource,
510 jstring objectId,
511 jlong version,
512 jstring state) {
513 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
514 SendNudgeNotification(objectSource, ConvertJavaStringToUTF8(env, objectId),
515 version, ConvertJavaStringToUTF8(env, state));
516 }
517
518 void ProfileSyncServiceAndroid::NudgeSyncerForAllTypes(JNIEnv* env,
519 jobject obj) {
520 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
521 syncer::ObjectIdInvalidationMap object_ids_with_states;
522 content::NotificationService::current()->Notify(
523 chrome::NOTIFICATION_SYNC_REFRESH_REMOTE,
524 content::Source<Profile>(profile_),
525 content::Details<const syncer::ObjectIdInvalidationMap>(
526 &object_ids_with_states));
527 }
528
529 // static 471 // static
530 ProfileSyncServiceAndroid* 472 ProfileSyncServiceAndroid*
531 ProfileSyncServiceAndroid::GetProfileSyncServiceAndroid() { 473 ProfileSyncServiceAndroid::GetProfileSyncServiceAndroid() {
532 return reinterpret_cast<ProfileSyncServiceAndroid*>( 474 return reinterpret_cast<ProfileSyncServiceAndroid*>(
533 Java_ProfileSyncService_getProfileSyncServiceAndroid( 475 Java_ProfileSyncService_getProfileSyncServiceAndroid(
534 AttachCurrentThread(), base::android::GetApplicationContext())); 476 AttachCurrentThread(), base::android::GetApplicationContext()));
535 } 477 }
536 478
537 static jlong Init(JNIEnv* env, jobject obj) { 479 static jlong Init(JNIEnv* env, jobject obj) {
538 ProfileSyncServiceAndroid* profile_sync_service_android = 480 ProfileSyncServiceAndroid* profile_sync_service_android =
539 new ProfileSyncServiceAndroid(env, obj); 481 new ProfileSyncServiceAndroid(env, obj);
540 profile_sync_service_android->Init(); 482 profile_sync_service_android->Init();
541 return reinterpret_cast<intptr_t>(profile_sync_service_android); 483 return reinterpret_cast<intptr_t>(profile_sync_service_android);
542 } 484 }
543 485
544 // static 486 // static
545 bool ProfileSyncServiceAndroid::Register(JNIEnv* env) { 487 bool ProfileSyncServiceAndroid::Register(JNIEnv* env) {
546 return RegisterNativesImpl(env); 488 return RegisterNativesImpl(env);
547 } 489 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698