Fix build break
[chromium-blink-merge.git] / chrome / browser / profiles / profile_android.cc
blob71df3812154defc03d445515fb9e2e6afda5b0f3
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;
13 namespace {
14 const char kProfileAndroidKey[] = "profile_android";
15 } // namespace
17 // static
18 ProfileAndroid* ProfileAndroid::FromProfile(Profile* profile) {
19 if (!profile)
20 return NULL;
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;
31 // static
32 Profile* ProfileAndroid::FromProfileAndroid(jobject obj) {
33 if (!obj)
34 return NULL;
36 ProfileAndroid* profile_android = reinterpret_cast<ProfileAndroid*>(
37 Java_Profile_getNativePointer(AttachCurrentThread(), obj));
38 if (!profile_android)
39 return NULL;
40 return profile_android->profile_;
43 // static
44 bool ProfileAndroid::RegisterProfileAndroid(JNIEnv* env) {
45 return RegisterNativesImpl(env);
48 ProfileAndroid::ProfileAndroid(Profile* profile)
49 : 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_);