Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / components / dom_distiller / core / dom_distiller_service_android.cc
blob768ade899a65517387911438bfc18bf3bc693e4e
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
3 // found in the LICENSE file.
5 #include "components/dom_distiller/core/dom_distiller_service_android.h"
7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h"
9 #include "base/android/scoped_java_ref.h"
10 #include "components/dom_distiller/core/distilled_page_prefs.h"
11 #include "components/dom_distiller/core/distilled_page_prefs_android.h"
12 #include "components/dom_distiller/core/dom_distiller_service.h"
13 #include "jni/DomDistillerService_jni.h"
15 using base::android::ConvertUTF8ToJavaString;
16 using base::android::ScopedJavaLocalRef;
18 namespace dom_distiller {
19 namespace android {
21 DomDistillerServiceAndroid::DomDistillerServiceAndroid(
22 DomDistillerService* service)
23 : service_(service) {
24 JNIEnv* env = base::android::AttachCurrentThread();
25 base::android::ScopedJavaLocalRef<jobject> local_java_ref =
26 Java_DomDistillerService_create(env, reinterpret_cast<intptr_t>(this));
27 java_ref_.Reset(env, local_java_ref.obj());
30 DomDistillerServiceAndroid::~DomDistillerServiceAndroid() {
33 bool DomDistillerServiceAndroid::HasEntry(JNIEnv* env,
34 jobject obj,
35 jstring j_entry_id) {
36 const std::string entry_id =
37 base::android::ConvertJavaStringToUTF8(env, j_entry_id);
38 return service_->HasEntry(entry_id);
41 ScopedJavaLocalRef<jstring> DomDistillerServiceAndroid::GetUrlForEntry(
42 JNIEnv* env,
43 jobject obj,
44 jstring j_entry_id) {
45 const std::string entry_id =
46 base::android::ConvertJavaStringToUTF8(env, j_entry_id);
47 return ConvertUTF8ToJavaString(env, service_->GetUrlForEntry(entry_id));
50 jlong DomDistillerServiceAndroid::GetDistilledPagePrefsPtr(JNIEnv* env,
51 jobject obj) {
52 return reinterpret_cast<intptr_t>(service_->GetDistilledPagePrefs());
55 bool DomDistillerServiceAndroid::Register(JNIEnv* env) {
56 return RegisterNativesImpl(env);
59 } // namespace android
60 } // namespace dom_distiller