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

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: A couple GN fixes. Created 6 years, 2 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
« no previous file with comments | « chrome/browser/sync/profile_sync_service_android.h ('k') | chrome/chrome.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
19 #include "chrome/browser/profiles/profile_manager.h" 18 #include "chrome/browser/profiles/profile_manager.h"
20 #include "chrome/browser/signin/signin_manager_factory.h" 19 #include "chrome/browser/signin/signin_manager_factory.h"
21 #include "chrome/browser/sync/about_sync_util.h" 20 #include "chrome/browser/sync/about_sync_util.h"
22 #include "chrome/browser/sync/profile_sync_service.h" 21 #include "chrome/browser/sync/profile_sync_service.h"
23 #include "chrome/browser/sync/profile_sync_service_factory.h" 22 #include "chrome/browser/sync/profile_sync_service_factory.h"
24 #include "chrome/browser/sync/sync_ui_util.h" 23 #include "chrome/browser/sync/sync_ui_util.h"
25 #include "chrome/grit/generated_resources.h" 24 #include "chrome/grit/generated_resources.h"
26 #include "components/invalidation/object_id_invalidation_map.h"
27 #include "components/signin/core/browser/signin_manager.h" 25 #include "components/signin/core/browser/signin_manager.h"
28 #include "components/sync_driver/pref_names.h" 26 #include "components/sync_driver/pref_names.h"
29 #include "components/sync_driver/sync_prefs.h" 27 #include "components/sync_driver/sync_prefs.h"
30 #include "content/public/browser/browser_thread.h" 28 #include "content/public/browser/browser_thread.h"
31 #include "content/public/browser/notification_service.h"
32 #include "content/public/browser/notification_source.h"
33 #include "google/cacheinvalidation/types.pb.h" 29 #include "google/cacheinvalidation/types.pb.h"
34 #include "google_apis/gaia/gaia_constants.h" 30 #include "google_apis/gaia/gaia_constants.h"
35 #include "google_apis/gaia/google_service_auth_error.h" 31 #include "google_apis/gaia/google_service_auth_error.h"
36 #include "jni/ProfileSyncService_jni.h" 32 #include "jni/ProfileSyncService_jni.h"
37 #include "sync/internal_api/public/network_resources.h" 33 #include "sync/internal_api/public/network_resources.h"
38 #include "sync/internal_api/public/read_transaction.h" 34 #include "sync/internal_api/public/read_transaction.h"
39 #include "ui/base/l10n/l10n_util.h" 35 #include "ui/base/l10n/l10n_util.h"
40 36
41 using base::android::AttachCurrentThread; 37 using base::android::AttachCurrentThread;
42 using base::android::CheckException; 38 using base::android::CheckException;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 void ProfileSyncServiceAndroid::RemoveObserver() { 81 void ProfileSyncServiceAndroid::RemoveObserver() {
86 if (sync_service_->HasObserver(this)) { 82 if (sync_service_->HasObserver(this)) {
87 sync_service_->RemoveObserver(this); 83 sync_service_->RemoveObserver(this);
88 } 84 }
89 } 85 }
90 86
91 ProfileSyncServiceAndroid::~ProfileSyncServiceAndroid() { 87 ProfileSyncServiceAndroid::~ProfileSyncServiceAndroid() {
92 RemoveObserver(); 88 RemoveObserver();
93 } 89 }
94 90
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() { 91 void ProfileSyncServiceAndroid::OnStateChanged() {
132 // Notify the java world that our sync state has changed. 92 // Notify the java world that our sync state has changed.
133 JNIEnv* env = AttachCurrentThread(); 93 JNIEnv* env = AttachCurrentThread();
134 Java_ProfileSyncService_syncStateChanged( 94 Java_ProfileSyncService_syncStateChanged(
135 env, weak_java_profile_sync_service_.get(env).obj()); 95 env, weak_java_profile_sync_service_.get(env).obj());
136 } 96 }
137 97
138 void ProfileSyncServiceAndroid::EnableSync(JNIEnv* env, jobject) { 98 void ProfileSyncServiceAndroid::EnableSync(JNIEnv* env, jobject) {
139 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 99 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
140 // Don't need to do anything if we're already enabled. 100 // Don't need to do anything if we're already enabled.
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 457
498 // static 458 // static
499 std::string ProfileSyncServiceAndroid::ModelTypeSelectionToStringForTest( 459 std::string ProfileSyncServiceAndroid::ModelTypeSelectionToStringForTest(
500 jlong model_type_selection) { 460 jlong model_type_selection) {
501 ScopedJavaLocalRef<jstring> string = 461 ScopedJavaLocalRef<jstring> string =
502 Java_ProfileSyncService_modelTypeSelectionToStringForTest( 462 Java_ProfileSyncService_modelTypeSelectionToStringForTest(
503 AttachCurrentThread(), model_type_selection); 463 AttachCurrentThread(), model_type_selection);
504 return ConvertJavaStringToUTF8(string); 464 return ConvertJavaStringToUTF8(string);
505 } 465 }
506 466
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 467 // static
530 ProfileSyncServiceAndroid* 468 ProfileSyncServiceAndroid*
531 ProfileSyncServiceAndroid::GetProfileSyncServiceAndroid() { 469 ProfileSyncServiceAndroid::GetProfileSyncServiceAndroid() {
532 return reinterpret_cast<ProfileSyncServiceAndroid*>( 470 return reinterpret_cast<ProfileSyncServiceAndroid*>(
533 Java_ProfileSyncService_getProfileSyncServiceAndroid( 471 Java_ProfileSyncService_getProfileSyncServiceAndroid(
534 AttachCurrentThread(), base::android::GetApplicationContext())); 472 AttachCurrentThread(), base::android::GetApplicationContext()));
535 } 473 }
536 474
537 static jlong Init(JNIEnv* env, jobject obj) { 475 static jlong Init(JNIEnv* env, jobject obj) {
538 ProfileSyncServiceAndroid* profile_sync_service_android = 476 ProfileSyncServiceAndroid* profile_sync_service_android =
539 new ProfileSyncServiceAndroid(env, obj); 477 new ProfileSyncServiceAndroid(env, obj);
540 profile_sync_service_android->Init(); 478 profile_sync_service_android->Init();
541 return reinterpret_cast<intptr_t>(profile_sync_service_android); 479 return reinterpret_cast<intptr_t>(profile_sync_service_android);
542 } 480 }
543 481
544 // static 482 // static
545 bool ProfileSyncServiceAndroid::Register(JNIEnv* env) { 483 bool ProfileSyncServiceAndroid::Register(JNIEnv* env) {
546 return RegisterNativesImpl(env); 484 return RegisterNativesImpl(env);
547 } 485 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/profile_sync_service_android.h ('k') | chrome/chrome.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698