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

Side by Side Diff: components/invalidation/impl/invalidation_service_android.cc

Issue 2909113002: Deprecate NonThreadSafe in components/invalidation in favor of SequenceChecker. (Closed)
Patch Set: Created 3 years, 6 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/invalidation/impl/invalidation_service_android.h" 5 #include "components/invalidation/impl/invalidation_service_android.h"
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/android/jni_array.h" 8 #include "base/android/jni_array.h"
9 #include "base/android/jni_string.h" 9 #include "base/android/jni_string.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "components/invalidation/public/object_id_invalidation_map.h" 11 #include "components/invalidation/public/object_id_invalidation_map.h"
12 #include "google/cacheinvalidation/types.pb.h" 12 #include "google/cacheinvalidation/types.pb.h"
13 #include "jni/InvalidationService_jni.h" 13 #include "jni/InvalidationService_jni.h"
14 14
15 using base::android::ConvertJavaStringToUTF8; 15 using base::android::ConvertJavaStringToUTF8;
16 using base::android::ConvertUTF8ToJavaString; 16 using base::android::ConvertUTF8ToJavaString;
17 using base::android::JavaRef; 17 using base::android::JavaRef;
18 using base::android::JavaParamRef; 18 using base::android::JavaParamRef;
19 19
20 namespace invalidation { 20 namespace invalidation {
21 21
22 InvalidationServiceAndroid::InvalidationServiceAndroid() 22 InvalidationServiceAndroid::InvalidationServiceAndroid()
23 : invalidator_state_(syncer::INVALIDATIONS_ENABLED), logger_() { 23 : invalidator_state_(syncer::INVALIDATIONS_ENABLED), logger_() {
24 DCHECK(CalledOnValidThread()); 24 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
25 JNIEnv* env = base::android::AttachCurrentThread(); 25 JNIEnv* env = base::android::AttachCurrentThread();
26 base::android::ScopedJavaLocalRef<jobject> local_java_ref = 26 base::android::ScopedJavaLocalRef<jobject> local_java_ref =
27 Java_InvalidationService_create(env, reinterpret_cast<intptr_t>(this)); 27 Java_InvalidationService_create(env, reinterpret_cast<intptr_t>(this));
28 java_ref_.Reset(env, local_java_ref.obj()); 28 java_ref_.Reset(env, local_java_ref.obj());
29 logger_.OnStateChange(invalidator_state_); 29 logger_.OnStateChange(invalidator_state_);
30 } 30 }
31 31
32 InvalidationServiceAndroid::~InvalidationServiceAndroid() { } 32 InvalidationServiceAndroid::~InvalidationServiceAndroid() {
33 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
34 }
33 35
34 void InvalidationServiceAndroid::RegisterInvalidationHandler( 36 void InvalidationServiceAndroid::RegisterInvalidationHandler(
35 syncer::InvalidationHandler* handler) { 37 syncer::InvalidationHandler* handler) {
36 DCHECK(CalledOnValidThread()); 38 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
37 invalidator_registrar_.RegisterHandler(handler); 39 invalidator_registrar_.RegisterHandler(handler);
38 logger_.OnRegistration(handler->GetOwnerName()); 40 logger_.OnRegistration(handler->GetOwnerName());
39 } 41 }
40 42
41 bool InvalidationServiceAndroid::UpdateRegisteredInvalidationIds( 43 bool InvalidationServiceAndroid::UpdateRegisteredInvalidationIds(
42 syncer::InvalidationHandler* handler, 44 syncer::InvalidationHandler* handler,
43 const syncer::ObjectIdSet& ids) { 45 const syncer::ObjectIdSet& ids) {
44 DCHECK(CalledOnValidThread()); 46 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
45 JNIEnv* env = base::android::AttachCurrentThread(); 47 JNIEnv* env = base::android::AttachCurrentThread();
46 DCHECK(env); 48 DCHECK(env);
47 49
48 if (!invalidator_registrar_.UpdateRegisteredIds(handler, ids)) 50 if (!invalidator_registrar_.UpdateRegisteredIds(handler, ids))
49 return false; 51 return false;
50 const syncer::ObjectIdSet& registered_ids = 52 const syncer::ObjectIdSet& registered_ids =
51 invalidator_registrar_.GetAllRegisteredIds(); 53 invalidator_registrar_.GetAllRegisteredIds();
52 54
53 // To call the corresponding method on the Java invalidation service, split 55 // To call the corresponding method on the Java invalidation service, split
54 // the object ids into object source and object name arrays. 56 // the object ids into object source and object name arrays.
55 std::vector<int> sources; 57 std::vector<int> sources;
56 std::vector<std::string> names; 58 std::vector<std::string> names;
57 syncer::ObjectIdSet::const_iterator id; 59 syncer::ObjectIdSet::const_iterator id;
58 for (id = registered_ids.begin(); id != registered_ids.end(); ++id) { 60 for (id = registered_ids.begin(); id != registered_ids.end(); ++id) {
59 sources.push_back(id->source()); 61 sources.push_back(id->source());
60 names.push_back(id->name()); 62 names.push_back(id->name());
61 } 63 }
62 64
63 Java_InvalidationService_setRegisteredObjectIds( 65 Java_InvalidationService_setRegisteredObjectIds(
64 env, java_ref_, base::android::ToJavaIntArray(env, sources), 66 env, java_ref_, base::android::ToJavaIntArray(env, sources),
65 base::android::ToJavaArrayOfStrings(env, names)); 67 base::android::ToJavaArrayOfStrings(env, names));
66 68
67 logger_.OnUpdateIds(invalidator_registrar_.GetSanitizedHandlersIdsMap()); 69 logger_.OnUpdateIds(invalidator_registrar_.GetSanitizedHandlersIdsMap());
68 return true; 70 return true;
69 } 71 }
70 72
71 void InvalidationServiceAndroid::UnregisterInvalidationHandler( 73 void InvalidationServiceAndroid::UnregisterInvalidationHandler(
72 syncer::InvalidationHandler* handler) { 74 syncer::InvalidationHandler* handler) {
73 DCHECK(CalledOnValidThread()); 75 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
74 invalidator_registrar_.UnregisterHandler(handler); 76 invalidator_registrar_.UnregisterHandler(handler);
75 logger_.OnUnregistration(handler->GetOwnerName()); 77 logger_.OnUnregistration(handler->GetOwnerName());
76 } 78 }
77 79
78 syncer::InvalidatorState 80 syncer::InvalidatorState
79 InvalidationServiceAndroid::GetInvalidatorState() const { 81 InvalidationServiceAndroid::GetInvalidatorState() const {
80 DCHECK(CalledOnValidThread()); 82 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
81 return invalidator_state_; 83 return invalidator_state_;
82 } 84 }
83 85
84 std::string InvalidationServiceAndroid::GetInvalidatorClientId() const { 86 std::string InvalidationServiceAndroid::GetInvalidatorClientId() const {
85 DCHECK(CalledOnValidThread()); 87 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
86 JNIEnv* env = base::android::AttachCurrentThread(); 88 JNIEnv* env = base::android::AttachCurrentThread();
87 DCHECK(env); 89 DCHECK(env);
88 90
89 // Ask the Java code to for the invalidator ID it's currently using. 91 // Ask the Java code to for the invalidator ID it's currently using.
90 base::android::ScopedJavaLocalRef<_jbyteArray*> id_bytes_java = 92 base::android::ScopedJavaLocalRef<_jbyteArray*> id_bytes_java =
91 Java_InvalidationService_getInvalidatorClientId(env, java_ref_); 93 Java_InvalidationService_getInvalidatorClientId(env, java_ref_);
92 94
93 // Convert it into a more convenient format for C++. 95 // Convert it into a more convenient format for C++.
94 std::vector<uint8_t> id_bytes; 96 std::vector<uint8_t> id_bytes;
95 base::android::JavaByteArrayToByteVector(env, id_bytes_java.obj(), &id_bytes); 97 base::android::JavaByteArrayToByteVector(env, id_bytes_java.obj(), &id_bytes);
96 std::string id(id_bytes.begin(), id_bytes.end()); 98 std::string id(id_bytes.begin(), id_bytes.end());
97 99
98 return id; 100 return id;
99 } 101 }
100 102
101 InvalidationLogger* InvalidationServiceAndroid::GetInvalidationLogger() { 103 InvalidationLogger* InvalidationServiceAndroid::GetInvalidationLogger() {
102 return &logger_; 104 return &logger_;
103 } 105 }
104 106
105 void InvalidationServiceAndroid::RequestDetailedStatus( 107 void InvalidationServiceAndroid::RequestDetailedStatus(
106 base::Callback<void(const base::DictionaryValue&)> return_callback) const { 108 base::Callback<void(const base::DictionaryValue&)> return_callback) const {
107 } 109 }
108 110
109 IdentityProvider* InvalidationServiceAndroid::GetIdentityProvider() { 111 IdentityProvider* InvalidationServiceAndroid::GetIdentityProvider() {
110 return NULL; 112 return NULL;
111 } 113 }
112 114
113 void InvalidationServiceAndroid::TriggerStateChangeForTest( 115 void InvalidationServiceAndroid::TriggerStateChangeForTest(
114 syncer::InvalidatorState state) { 116 syncer::InvalidatorState state) {
115 DCHECK(CalledOnValidThread()); 117 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
116 invalidator_state_ = state; 118 invalidator_state_ = state;
117 invalidator_registrar_.UpdateInvalidatorState(invalidator_state_); 119 invalidator_registrar_.UpdateInvalidatorState(invalidator_state_);
118 } 120 }
119 121
120 void InvalidationServiceAndroid::Invalidate( 122 void InvalidationServiceAndroid::Invalidate(
121 JNIEnv* env, 123 JNIEnv* env,
122 const JavaParamRef<jobject>& obj, 124 const JavaParamRef<jobject>& obj,
123 jint object_source, 125 jint object_source,
124 const JavaParamRef<jstring>& java_object_id, 126 const JavaParamRef<jstring>& java_object_id,
125 jlong version, 127 jlong version,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 object_invalidation_map); 167 object_invalidation_map);
166 logger_.OnInvalidation(object_invalidation_map); 168 logger_.OnInvalidation(object_invalidation_map);
167 } 169 }
168 170
169 // static 171 // static
170 bool InvalidationServiceAndroid::RegisterJni(JNIEnv* env) { 172 bool InvalidationServiceAndroid::RegisterJni(JNIEnv* env) {
171 return RegisterNativesImpl(env); 173 return RegisterNativesImpl(env);
172 } 174 }
173 175
174 } // namespace invalidation 176 } // namespace invalidation
OLDNEW
« no previous file with comments | « components/invalidation/impl/invalidation_service_android.h ('k') | components/invalidation/impl/p2p_invalidation_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698