#include "chrome/browser/android/profile_key_util.h"
#include "base/android/scoped_java_ref.h"
#include "chrome/browser/android/profile_key_startup_accessor.h"
#include "chrome/browser/profiles/profile_key.h"
#include "chrome/browser/profiles/profile_key_android.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/profiles/android/jni_headers/ProfileKeyUtil_jni.h"
using base::android::ScopedJavaLocalRef;
namespace android {
namespace {
Profile* GetProfile() {
Profile* profile = ProfileManager::GetLastUsedProfile();
DCHECK(profile);
return profile;
}
}
ProfileKey* GetLastUsedRegularProfileKey() {
ProfileKey* key = ProfileKeyStartupAccessor::GetInstance()->profile_key();
if (!key)
key = GetProfile()->GetProfileKey();
DCHECK(key && !key->IsOffTheRecord());
return key;
}
}
static ScopedJavaLocalRef<jobject>
JNI_ProfileKeyUtil_GetLastUsedRegularProfileKey(JNIEnv* env) {
ProfileKey* key = ::android::GetLastUsedRegularProfileKey();
if (!key) {
NOTREACHED() << "ProfileKey not found.";
}
ProfileKeyAndroid* profile_key_android = key->GetProfileKeyAndroid();
if (!profile_key_android) {
NOTREACHED() << "ProfileKeyAndroid not found.";
}
return profile_key_android->GetJavaObject();
}
DEFINE_JNI(ProfileKeyUtil)