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
3 // found in the LICENSE file.
5 #include "chrome/browser/profiles/profile_android.h"
7 #include "base/android/jni_android.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "jni/Profile_jni.h"
11 using base::android::AttachCurrentThread
;
14 const char kProfileAndroidKey
[] = "profile_android";
18 ProfileAndroid
* ProfileAndroid::FromProfile(Profile
* profile
) {
22 ProfileAndroid
* profile_android
= static_cast<ProfileAndroid
*>(
23 profile
->GetUserData(kProfileAndroidKey
));
24 if (!profile_android
) {
25 profile_android
= new ProfileAndroid(profile
);
26 profile
->SetUserData(kProfileAndroidKey
, profile_android
);
28 return profile_android
;
32 Profile
* ProfileAndroid::FromProfileAndroid(jobject obj
) {
36 ProfileAndroid
* profile_android
= reinterpret_cast<ProfileAndroid
*>(
37 Java_Profile_getNativePointer(AttachCurrentThread(), obj
));
40 return profile_android
->profile_
;
44 bool ProfileAndroid::RegisterProfileAndroid(JNIEnv
* env
) {
45 return RegisterNativesImpl(env
);
48 ProfileAndroid::ProfileAndroid(Profile
* profile
)
50 JNIEnv
* env
= AttachCurrentThread();
51 base::android::ScopedJavaLocalRef
<jobject
> jprofile
=
52 Java_Profile_create(env
, reinterpret_cast<int>(this));
53 obj_
.Reset(env
, jprofile
.obj());
57 ProfileAndroid::~ProfileAndroid() {
58 Java_Profile_destroy(AttachCurrentThread(), obj_
.obj());
61 base::android::ScopedJavaLocalRef
<jobject
> ProfileAndroid::GetJavaObject() {
62 return base::android::ScopedJavaLocalRef
<jobject
>(obj_
);