OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/invalidation/invalidation_controller_android.h" | |
6 | |
7 #include <string> | |
8 #include <vector> | |
9 | |
10 #include "base/android/jni_array.h" | |
11 #include "google/cacheinvalidation/include/types.h" | |
12 #include "sync/jni/InvalidationController_jni.h" | |
13 | |
14 namespace invalidation { | |
15 | |
16 InvalidationControllerAndroid::InvalidationControllerAndroid() {} | |
17 | |
18 InvalidationControllerAndroid::~InvalidationControllerAndroid() {} | |
19 | |
20 void InvalidationControllerAndroid::SetRegisteredObjectIds( | |
21 const syncer::ObjectIdSet& ids) { | |
22 // Get a reference to the Java invalidation controller. | |
23 JNIEnv* env = base::android::AttachCurrentThread(); | |
24 DCHECK(env); | |
25 if (invalidation_controller_.is_null()) { | |
nyquist
2013/09/10 01:42:49
Could this be done in the constructor instead?
nyquist
2013/09/10 09:48:05
Disregard this since this is not always called. Do
Steve Condie
2013/09/10 17:49:54
Ok, I will leave as is.
| |
26 invalidation_controller_.Reset(Java_InvalidationController_get( | |
27 env, | |
28 base::android::GetApplicationContext())); | |
29 } | |
30 | |
31 // To call the corresponding method on the Java invalidation controller, split | |
32 // the object ids into object source and object name arrays. | |
33 std::vector<int> sources; | |
34 std::vector<std::string> names; | |
35 syncer::ObjectIdSet::const_iterator id; | |
36 for (id = ids.begin(); id != ids.end(); ++id) { | |
37 sources.push_back(id->source()); | |
38 names.push_back(id->name()); | |
39 } | |
40 | |
41 Java_InvalidationController_setRegisteredObjectIds( | |
42 env, | |
43 invalidation_controller_.obj(), | |
44 base::android::ToJavaIntArray(env, sources).obj(), | |
45 base::android::ToJavaArrayOfStrings(env, names).obj()); | |
46 } | |
47 | |
48 bool RegisterInvalidationController(JNIEnv* env) { | |
49 return RegisterNativesImpl(env); | |
50 } | |
51 | |
52 } // namespace invalidation | |
OLD | NEW |