summaryrefslogtreecommitdiffstats
path: root/chrome/browser/invalidation/invalidation_service_factory_android.cc
blob: 4f6b55cd98c7cd7181945c1897b07b5c080be878 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/invalidation/invalidation_service_factory_android.h"

#include "base/android/jni_android.h"
#include "chrome/browser/invalidation/profile_invalidation_provider_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_android.h"
#include "components/invalidation/invalidation_service_android.h"
#include "components/invalidation/profile_invalidation_provider.h"
#include "jni/InvalidationServiceFactory_jni.h"

using base::android::ScopedJavaLocalRef;

namespace invalidation {

jobject InvalidationServiceFactoryAndroid::GetForProfile(JNIEnv* env,
                                                         jclass clazz,
                                                         jobject j_profile) {
  Profile* profile = ProfileAndroid::FromProfileAndroid(j_profile);
  invalidation::ProfileInvalidationProvider* provider =
      ProfileInvalidationProviderFactory::GetForProfile(profile);
  InvalidationServiceAndroid* service_android =
      static_cast<InvalidationServiceAndroid*>(
          provider->GetInvalidationService());
  return service_android->java_ref_.obj();
}

jobject InvalidationServiceFactoryAndroid::GetForTest(JNIEnv* env,
                                                      jclass clazz,
                                                      jobject j_context) {
  InvalidationServiceAndroid* service_android =
      new InvalidationServiceAndroid(j_context);
  return service_android->java_ref_.obj();
}

jobject GetForProfile(JNIEnv* env, jclass clazz, jobject j_profile) {
  return InvalidationServiceFactoryAndroid::GetForProfile(
      env, clazz, j_profile);
}

jobject GetForTest(JNIEnv* env, jclass clazz, jobject j_context) {
  return InvalidationServiceFactoryAndroid::GetForTest(
      env, clazz, j_context);
}

bool InvalidationServiceFactoryAndroid::Register(JNIEnv* env) {
  return RegisterNativesImpl(env);
}

}  // namespace invalidation