Commit dfc20cf1 authored by Evan Stade's avatar Evan Stade Committed by Chromium LUCI CQ

Android: Streamline some infobars code.

1. Don't null-check after pointer cast, because it will never be null
   (unless the DCHECK on the previous line had already failed, however
   this clearly never happens because the same pointer is de-reffed on
   the next line, so we'd have seen crashes)

2. Combine two methods instead of having one method thunk to the other.

Bug: none
Change-Id: Id67f5cf04fda40ec694689452c403601402cc306
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2575892
Commit-Queue: Colin Blundell <blundell@chromium.org>
Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#835607}
parent cb100bca
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#include "base/android/jni_android.h" #include "base/android/jni_android.h"
#include "base/check.h" #include "base/check.h"
#include "base/metrics/histogram_functions.h" #include "base/metrics/histogram_functions.h"
#include "base/notreached.h"
#include "chrome/android/chrome_jni_headers/InfoBarContainer_jni.h" #include "chrome/android/chrome_jni_headers/InfoBarContainer_jni.h"
#include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/infobars/infobar_service.h"
#include "components/infobars/android/infobar_android.h" #include "components/infobars/android/infobar_android.h"
...@@ -45,24 +44,15 @@ void InfoBarContainerAndroid::Destroy(JNIEnv* env, ...@@ -45,24 +44,15 @@ void InfoBarContainerAndroid::Destroy(JNIEnv* env,
delete this; delete this;
} }
// Creates the Java equivalent of |android_bar| and add it to the java
// container.
void InfoBarContainerAndroid::PlatformSpecificAddInfoBar( void InfoBarContainerAndroid::PlatformSpecificAddInfoBar(
infobars::InfoBar* infobar, infobars::InfoBar* infobar,
size_t position) { size_t position) {
DCHECK(infobar); DCHECK(infobar);
infobars::InfoBarAndroid* android_bar = infobars::InfoBarAndroid* android_bar =
static_cast<infobars::InfoBarAndroid*>(infobar); static_cast<infobars::InfoBarAndroid*>(infobar);
if (!android_bar) {
// TODO(bulach): CLANK: implement other types of InfoBars.
NOTIMPLEMENTED() << "CLANK: infobar identifier "
<< infobar->delegate()->GetIdentifier();
return;
}
AttachJavaInfoBar(android_bar);
}
void InfoBarContainerAndroid::AttachJavaInfoBar(
infobars::InfoBarAndroid* android_bar) {
if (android_bar->HasSetJavaInfoBar()) if (android_bar->HasSetJavaInfoBar())
return; return;
JNIEnv* env = base::android::AttachCurrentThread(); JNIEnv* env = base::android::AttachCurrentThread();
......
...@@ -16,10 +16,6 @@ ...@@ -16,10 +16,6 @@
#include "base/macros.h" #include "base/macros.h"
#include "components/infobars/core/infobar_container.h" #include "components/infobars/core/infobar_container.h"
namespace infobars {
class InfoBarAndroid;
}
class InfoBarContainerAndroid : public infobars::InfoBarContainer { class InfoBarContainerAndroid : public infobars::InfoBarContainer {
public: public:
InfoBarContainerAndroid(JNIEnv* env, InfoBarContainerAndroid(JNIEnv* env,
...@@ -43,10 +39,6 @@ class InfoBarContainerAndroid : public infobars::InfoBarContainer { ...@@ -43,10 +39,6 @@ class InfoBarContainerAndroid : public infobars::InfoBarContainer {
void PlatformSpecificReplaceInfoBar(infobars::InfoBar* old_infobar, void PlatformSpecificReplaceInfoBar(infobars::InfoBar* old_infobar,
infobars::InfoBar* new_infobar) override; infobars::InfoBar* new_infobar) override;
// Create the Java equivalent of |android_bar| and add it to the java
// container.
void AttachJavaInfoBar(infobars::InfoBarAndroid* android_bar);
// We're owned by the java infobar, need to use a weak ref so it can destroy // We're owned by the java infobar, need to use a weak ref so it can destroy
// us. // us.
JavaObjectWeakGlobalRef weak_java_infobar_container_; JavaObjectWeakGlobalRef weak_java_infobar_container_;
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#include "base/android/jni_android.h" #include "base/android/jni_android.h"
#include "base/check.h" #include "base/check.h"
#include "base/metrics/histogram_functions.h" #include "base/metrics/histogram_functions.h"
#include "base/notreached.h"
#include "components/infobars/android/infobar_android.h" #include "components/infobars/android/infobar_android.h"
#include "components/infobars/core/infobar.h" #include "components/infobars/core/infobar.h"
#include "components/infobars/core/infobar_delegate.h" #include "components/infobars/core/infobar_delegate.h"
...@@ -46,24 +45,15 @@ void InfoBarContainerAndroid::Destroy(JNIEnv* env, ...@@ -46,24 +45,15 @@ void InfoBarContainerAndroid::Destroy(JNIEnv* env,
delete this; delete this;
} }
// Creates the Java equivalent of |android_bar| and add it to the java
// container.
void InfoBarContainerAndroid::PlatformSpecificAddInfoBar( void InfoBarContainerAndroid::PlatformSpecificAddInfoBar(
infobars::InfoBar* infobar, infobars::InfoBar* infobar,
size_t position) { size_t position) {
DCHECK(infobar); DCHECK(infobar);
infobars::InfoBarAndroid* android_bar = infobars::InfoBarAndroid* android_bar =
static_cast<infobars::InfoBarAndroid*>(infobar); static_cast<infobars::InfoBarAndroid*>(infobar);
if (!android_bar) {
// TODO(bulach): CLANK: implement other types of InfoBars.
NOTIMPLEMENTED() << "CLANK: infobar identifier "
<< infobar->delegate()->GetIdentifier();
return;
}
AttachJavaInfoBar(android_bar);
}
void InfoBarContainerAndroid::AttachJavaInfoBar(
infobars::InfoBarAndroid* android_bar) {
if (android_bar->HasSetJavaInfoBar()) if (android_bar->HasSetJavaInfoBar())
return; return;
JNIEnv* env = base::android::AttachCurrentThread(); JNIEnv* env = base::android::AttachCurrentThread();
......
...@@ -16,10 +16,6 @@ ...@@ -16,10 +16,6 @@
#include "base/macros.h" #include "base/macros.h"
#include "components/infobars/core/infobar_container.h" #include "components/infobars/core/infobar_container.h"
namespace infobars {
class InfoBarAndroid;
}
namespace weblayer { namespace weblayer {
class InfoBarContainerAndroid : public infobars::InfoBarContainer { class InfoBarContainerAndroid : public infobars::InfoBarContainer {
...@@ -44,10 +40,6 @@ class InfoBarContainerAndroid : public infobars::InfoBarContainer { ...@@ -44,10 +40,6 @@ class InfoBarContainerAndroid : public infobars::InfoBarContainer {
void PlatformSpecificReplaceInfoBar(infobars::InfoBar* old_infobar, void PlatformSpecificReplaceInfoBar(infobars::InfoBar* old_infobar,
infobars::InfoBar* new_infobar) override; infobars::InfoBar* new_infobar) override;
// Create the Java equivalent of |android_bar| and add it to the java
// container.
void AttachJavaInfoBar(infobars::InfoBarAndroid* android_bar);
// We're owned by the java infobar, need to use a weak ref so it can destroy // We're owned by the java infobar, need to use a weak ref so it can destroy
// us. // us.
JavaObjectWeakGlobalRef weak_java_infobar_container_; JavaObjectWeakGlobalRef weak_java_infobar_container_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment