| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/android/data_usage/data_use_tab_ui_manager_android.h" | 5 #include "chrome/browser/android/data_usage/data_use_tab_ui_manager_android.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
| 10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
| 11 #include "chrome/browser/android/data_usage/data_use_ui_tab_model.h" | 11 #include "chrome/browser/android/data_usage/data_use_ui_tab_model.h" |
| 12 #include "chrome/browser/android/data_usage/data_use_ui_tab_model_factory.h" | 12 #include "chrome/browser/android/data_usage/data_use_ui_tab_model_factory.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/profiles/profile_android.h" | 14 #include "chrome/browser/profiles/profile_android.h" |
| 15 #include "components/sessions/core/session_id.h" |
| 15 #include "jni/DataUseTabUIManager_jni.h" | 16 #include "jni/DataUseTabUIManager_jni.h" |
| 16 | 17 |
| 17 // static | 18 // static |
| 18 jboolean CheckDataUseTrackingStarted(JNIEnv* env, | 19 jboolean CheckDataUseTrackingStarted(JNIEnv* env, |
| 19 const JavaParamRef<jclass>& clazz, | 20 const JavaParamRef<jclass>& clazz, |
| 20 jint tab_id, | 21 jint tab_id, |
| 21 const JavaParamRef<jobject>& jprofile) { | 22 const JavaParamRef<jobject>& jprofile) { |
| 22 Profile* profile = ProfileAndroid::FromProfileAndroid(jprofile); | 23 Profile* profile = ProfileAndroid::FromProfileAndroid(jprofile); |
| 23 chrome::android::DataUseUITabModel* data_use_ui_tab_model = | 24 chrome::android::DataUseUITabModel* data_use_ui_tab_model = |
| 24 chrome::android::DataUseUITabModelFactory::GetForBrowserContext(profile); | 25 chrome::android::DataUseUITabModelFactory::GetForBrowserContext(profile); |
| 25 if (data_use_ui_tab_model) | 26 DCHECK_LE(0, static_cast<SessionID::id_type>(tab_id)); |
| 26 return data_use_ui_tab_model->HasDataUseTrackingStarted(tab_id); | 27 if (data_use_ui_tab_model) { |
| 28 return data_use_ui_tab_model->HasDataUseTrackingStarted( |
| 29 static_cast<SessionID::id_type>(tab_id)); |
| 30 } |
| 27 return false; | 31 return false; |
| 28 } | 32 } |
| 29 | 33 |
| 30 // static | 34 // static |
| 31 jboolean CheckDataUseTrackingEnded(JNIEnv* env, | 35 jboolean CheckDataUseTrackingEnded(JNIEnv* env, |
| 32 const JavaParamRef<jclass>& clazz, | 36 const JavaParamRef<jclass>& clazz, |
| 33 jint tab_id, | 37 jint tab_id, |
| 34 const JavaParamRef<jobject>& jprofile) { | 38 const JavaParamRef<jobject>& jprofile) { |
| 35 Profile* profile = ProfileAndroid::FromProfileAndroid(jprofile); | 39 Profile* profile = ProfileAndroid::FromProfileAndroid(jprofile); |
| 36 chrome::android::DataUseUITabModel* data_use_ui_tab_model = | 40 chrome::android::DataUseUITabModel* data_use_ui_tab_model = |
| 37 chrome::android::DataUseUITabModelFactory::GetForBrowserContext(profile); | 41 chrome::android::DataUseUITabModelFactory::GetForBrowserContext(profile); |
| 38 if (data_use_ui_tab_model) | 42 DCHECK_LE(0, static_cast<SessionID::id_type>(tab_id)); |
| 39 return data_use_ui_tab_model->HasDataUseTrackingEnded(tab_id); | 43 if (data_use_ui_tab_model) { |
| 44 return data_use_ui_tab_model->HasDataUseTrackingEnded( |
| 45 static_cast<SessionID::id_type>(tab_id)); |
| 46 } |
| 40 return false; | 47 return false; |
| 41 } | 48 } |
| 42 | 49 |
| 43 // static | 50 // static |
| 44 void OnCustomTabInitialNavigation(JNIEnv* env, | 51 void OnCustomTabInitialNavigation(JNIEnv* env, |
| 45 const JavaParamRef<jclass>& clazz, | 52 const JavaParamRef<jclass>& clazz, |
| 46 jint tab_id, | 53 jint tab_id, |
| 47 const JavaParamRef<jstring>& url, | 54 const JavaParamRef<jstring>& url, |
| 48 const JavaParamRef<jstring>& package_name, | 55 const JavaParamRef<jstring>& package_name, |
| 49 const JavaParamRef<jobject>& jprofile) { | 56 const JavaParamRef<jobject>& jprofile) { |
| 50 Profile* profile = ProfileAndroid::FromProfileAndroid(jprofile); | 57 Profile* profile = ProfileAndroid::FromProfileAndroid(jprofile); |
| 51 chrome::android::DataUseUITabModel* data_use_ui_tab_model = | 58 chrome::android::DataUseUITabModel* data_use_ui_tab_model = |
| 52 chrome::android::DataUseUITabModelFactory::GetForBrowserContext(profile); | 59 chrome::android::DataUseUITabModelFactory::GetForBrowserContext(profile); |
| 60 DCHECK_LE(0, static_cast<SessionID::id_type>(tab_id)); |
| 53 if (data_use_ui_tab_model) { | 61 if (data_use_ui_tab_model) { |
| 54 data_use_ui_tab_model->ReportCustomTabInitialNavigation( | 62 data_use_ui_tab_model->ReportCustomTabInitialNavigation( |
| 55 tab_id, ConvertJavaStringToUTF8(env, url), | 63 static_cast<SessionID::id_type>(tab_id), |
| 64 ConvertJavaStringToUTF8(env, url), |
| 56 ConvertJavaStringToUTF8(env, package_name)); | 65 ConvertJavaStringToUTF8(env, package_name)); |
| 57 } | 66 } |
| 58 } | 67 } |
| 59 | 68 |
| 60 bool RegisterDataUseTabUIManager(JNIEnv* env) { | 69 bool RegisterDataUseTabUIManager(JNIEnv* env) { |
| 61 return RegisterNativesImpl(env); | 70 return RegisterNativesImpl(env); |
| 62 } | 71 } |
| OLD | NEW |