OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/profiles/profile_android.h" | 5 #include "chrome/browser/profiles/profile_android.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
9 #include "chrome/browser/profiles/profile_destroyer.h" | 9 #include "chrome/browser/profiles/profile_destroyer.h" |
10 #include "chrome/browser/profiles/profile_manager.h" | 10 #include "chrome/browser/profiles/profile_manager.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 return NULL; | 41 return NULL; |
42 return profile_android->profile_; | 42 return profile_android->profile_; |
43 } | 43 } |
44 | 44 |
45 // static | 45 // static |
46 bool ProfileAndroid::RegisterProfileAndroid(JNIEnv* env) { | 46 bool ProfileAndroid::RegisterProfileAndroid(JNIEnv* env) { |
47 return RegisterNativesImpl(env); | 47 return RegisterNativesImpl(env); |
48 } | 48 } |
49 | 49 |
50 // static | 50 // static |
51 jobject ProfileAndroid::GetLastUsedProfile(JNIEnv* env, jclass clazz) { | 51 ScopedJavaLocalRef<jobject> ProfileAndroid::GetLastUsedProfile(JNIEnv* env, |
| 52 jclass clazz) { |
52 Profile* profile = ProfileManager::GetLastUsedProfile(); | 53 Profile* profile = ProfileManager::GetLastUsedProfile(); |
53 if (profile == NULL) { | 54 if (profile == NULL) { |
54 NOTREACHED() << "Profile not found."; | 55 NOTREACHED() << "Profile not found."; |
55 return NULL; | 56 return ScopedJavaLocalRef<jobject>(); |
56 } | 57 } |
57 | 58 |
58 ProfileAndroid* profile_android = ProfileAndroid::FromProfile(profile); | 59 ProfileAndroid* profile_android = ProfileAndroid::FromProfile(profile); |
59 if (profile_android == NULL) { | 60 if (profile_android == NULL) { |
60 NOTREACHED() << "ProfileAndroid not found."; | 61 NOTREACHED() << "ProfileAndroid not found."; |
61 return NULL; | 62 return ScopedJavaLocalRef<jobject>(); |
62 } | 63 } |
63 | 64 |
64 return profile_android->obj_.obj(); | 65 return ScopedJavaLocalRef<jobject>(profile_android->obj_); |
65 } | 66 } |
66 | 67 |
67 void ProfileAndroid::DestroyWhenAppropriate(JNIEnv* env, jobject obj) { | 68 void ProfileAndroid::DestroyWhenAppropriate(JNIEnv* env, jobject obj) { |
68 // Don't delete the Profile directly because the corresponding | 69 // Don't delete the Profile directly because the corresponding |
69 // RenderViewHost might not be deleted yet. | 70 // RenderViewHost might not be deleted yet. |
70 ProfileDestroyer::DestroyProfileWhenAppropriate(profile_); | 71 ProfileDestroyer::DestroyProfileWhenAppropriate(profile_); |
71 } | 72 } |
72 | 73 |
73 base::android::ScopedJavaLocalRef<jobject> ProfileAndroid::GetOriginalProfile( | 74 base::android::ScopedJavaLocalRef<jobject> ProfileAndroid::GetOriginalProfile( |
74 JNIEnv* env, jobject obj) { | 75 JNIEnv* env, jobject obj) { |
(...skipping 13 matching lines...) Expand all Loading... |
88 | 89 |
89 jboolean ProfileAndroid::HasOffTheRecordProfile(JNIEnv* env, jobject obj) { | 90 jboolean ProfileAndroid::HasOffTheRecordProfile(JNIEnv* env, jobject obj) { |
90 return profile_->HasOffTheRecordProfile(); | 91 return profile_->HasOffTheRecordProfile(); |
91 } | 92 } |
92 | 93 |
93 jboolean ProfileAndroid::IsOffTheRecord(JNIEnv* env, jobject obj) { | 94 jboolean ProfileAndroid::IsOffTheRecord(JNIEnv* env, jobject obj) { |
94 return profile_->IsOffTheRecord(); | 95 return profile_->IsOffTheRecord(); |
95 } | 96 } |
96 | 97 |
97 // static | 98 // static |
98 jobject GetLastUsedProfile(JNIEnv* env, jclass clazz) { | 99 ScopedJavaLocalRef<jobject> GetLastUsedProfile(JNIEnv* env, jclass clazz) { |
99 return ProfileAndroid::GetLastUsedProfile(env, clazz); | 100 return ProfileAndroid::GetLastUsedProfile(env, clazz); |
100 } | 101 } |
101 | 102 |
102 ProfileAndroid::ProfileAndroid(Profile* profile) | 103 ProfileAndroid::ProfileAndroid(Profile* profile) |
103 : profile_(profile) { | 104 : profile_(profile) { |
104 JNIEnv* env = AttachCurrentThread(); | 105 JNIEnv* env = AttachCurrentThread(); |
105 base::android::ScopedJavaLocalRef<jobject> jprofile = | 106 base::android::ScopedJavaLocalRef<jobject> jprofile = |
106 Java_Profile_create(env, reinterpret_cast<intptr_t>(this)); | 107 Java_Profile_create(env, reinterpret_cast<intptr_t>(this)); |
107 obj_.Reset(env, jprofile.obj()); | 108 obj_.Reset(env, jprofile.obj()); |
108 } | 109 } |
109 | 110 |
110 ProfileAndroid::~ProfileAndroid() { | 111 ProfileAndroid::~ProfileAndroid() { |
111 Java_Profile_onNativeDestroyed(AttachCurrentThread(), obj_.obj()); | 112 Java_Profile_onNativeDestroyed(AttachCurrentThread(), obj_.obj()); |
112 } | 113 } |
113 | 114 |
114 base::android::ScopedJavaLocalRef<jobject> ProfileAndroid::GetJavaObject() { | 115 base::android::ScopedJavaLocalRef<jobject> ProfileAndroid::GetJavaObject() { |
115 return base::android::ScopedJavaLocalRef<jobject>(obj_); | 116 return base::android::ScopedJavaLocalRef<jobject>(obj_); |
116 } | 117 } |
OLD | NEW |