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 ScopedJavaLocalRef<jobject> ProfileAndroid::GetLastUsedProfile(JNIEnv* env, | 51 jobject ProfileAndroid::GetLastUsedProfile(JNIEnv* env, jclass clazz) { |
52 jclass clazz) { | |
53 Profile* profile = ProfileManager::GetLastUsedProfile(); | 52 Profile* profile = ProfileManager::GetLastUsedProfile(); |
54 if (profile == NULL) { | 53 if (profile == NULL) { |
55 NOTREACHED() << "Profile not found."; | 54 NOTREACHED() << "Profile not found."; |
56 return ScopedJavaLocalRef<jobject>(); | 55 return NULL; |
57 } | 56 } |
58 | 57 |
59 ProfileAndroid* profile_android = ProfileAndroid::FromProfile(profile); | 58 ProfileAndroid* profile_android = ProfileAndroid::FromProfile(profile); |
60 if (profile_android == NULL) { | 59 if (profile_android == NULL) { |
61 NOTREACHED() << "ProfileAndroid not found."; | 60 NOTREACHED() << "ProfileAndroid not found."; |
62 return ScopedJavaLocalRef<jobject>(); | 61 return NULL; |
63 } | 62 } |
64 | 63 |
65 return ScopedJavaLocalRef<jobject>(profile_android->obj_); | 64 return profile_android->obj_.obj(); |
66 } | 65 } |
67 | 66 |
68 void ProfileAndroid::DestroyWhenAppropriate(JNIEnv* env, jobject obj) { | 67 void ProfileAndroid::DestroyWhenAppropriate(JNIEnv* env, jobject obj) { |
69 // Don't delete the Profile directly because the corresponding | 68 // Don't delete the Profile directly because the corresponding |
70 // RenderViewHost might not be deleted yet. | 69 // RenderViewHost might not be deleted yet. |
71 ProfileDestroyer::DestroyProfileWhenAppropriate(profile_); | 70 ProfileDestroyer::DestroyProfileWhenAppropriate(profile_); |
72 } | 71 } |
73 | 72 |
74 base::android::ScopedJavaLocalRef<jobject> ProfileAndroid::GetOriginalProfile( | 73 base::android::ScopedJavaLocalRef<jobject> ProfileAndroid::GetOriginalProfile( |
75 JNIEnv* env, jobject obj) { | 74 JNIEnv* env, jobject obj) { |
(...skipping 13 matching lines...) Expand all Loading... |
89 | 88 |
90 jboolean ProfileAndroid::HasOffTheRecordProfile(JNIEnv* env, jobject obj) { | 89 jboolean ProfileAndroid::HasOffTheRecordProfile(JNIEnv* env, jobject obj) { |
91 return profile_->HasOffTheRecordProfile(); | 90 return profile_->HasOffTheRecordProfile(); |
92 } | 91 } |
93 | 92 |
94 jboolean ProfileAndroid::IsOffTheRecord(JNIEnv* env, jobject obj) { | 93 jboolean ProfileAndroid::IsOffTheRecord(JNIEnv* env, jobject obj) { |
95 return profile_->IsOffTheRecord(); | 94 return profile_->IsOffTheRecord(); |
96 } | 95 } |
97 | 96 |
98 // static | 97 // static |
99 ScopedJavaLocalRef<jobject> GetLastUsedProfile(JNIEnv* env, jclass clazz) { | 98 jobject GetLastUsedProfile(JNIEnv* env, jclass clazz) { |
100 return ProfileAndroid::GetLastUsedProfile(env, clazz); | 99 return ProfileAndroid::GetLastUsedProfile(env, clazz); |
101 } | 100 } |
102 | 101 |
103 ProfileAndroid::ProfileAndroid(Profile* profile) | 102 ProfileAndroid::ProfileAndroid(Profile* profile) |
104 : profile_(profile) { | 103 : profile_(profile) { |
105 JNIEnv* env = AttachCurrentThread(); | 104 JNIEnv* env = AttachCurrentThread(); |
106 base::android::ScopedJavaLocalRef<jobject> jprofile = | 105 base::android::ScopedJavaLocalRef<jobject> jprofile = |
107 Java_Profile_create(env, reinterpret_cast<intptr_t>(this)); | 106 Java_Profile_create(env, reinterpret_cast<intptr_t>(this)); |
108 obj_.Reset(env, jprofile.obj()); | 107 obj_.Reset(env, jprofile.obj()); |
109 } | 108 } |
110 | 109 |
111 ProfileAndroid::~ProfileAndroid() { | 110 ProfileAndroid::~ProfileAndroid() { |
112 Java_Profile_onNativeDestroyed(AttachCurrentThread(), obj_.obj()); | 111 Java_Profile_onNativeDestroyed(AttachCurrentThread(), obj_.obj()); |
113 } | 112 } |
114 | 113 |
115 base::android::ScopedJavaLocalRef<jobject> ProfileAndroid::GetJavaObject() { | 114 base::android::ScopedJavaLocalRef<jobject> ProfileAndroid::GetJavaObject() { |
116 return base::android::ScopedJavaLocalRef<jobject>(obj_); | 115 return base::android::ScopedJavaLocalRef<jobject>(obj_); |
117 } | 116 } |
OLD | NEW |