Commit 65967617 authored by Xing Liu's avatar Xing Liu Committed by Commit Bot

Chime: Add an initialize method.

Chime needs to be initialized during ChromeApplication.java's startup
code.

This CL adds ChimeSession.initialize() entry point API, and a upstream
placeholder function for Chime DFM.

Also clean up the feature flag JNI call for Chime, now it can directly
depends on chrome/browser/flags:java.

Bug: 1136305
Change-Id: Id8424fc22d2f419860318b12bd8753da448cd50b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2466897Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Commit-Queue: Xing Liu <xingliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#818755}
parent 38f96591
......@@ -140,7 +140,7 @@ public class ChromeActivitySessionTracker {
updateAcceptLanguages();
mVariationsSession.start();
mPowerBroadcastReceiver.onForegroundSessionStart();
ChimeSession.start();
ChimeSession.register();
// Track the ratio of Chrome startups that are caused by notification clicks.
// TODO(johnme): Add other reasons (and switch to recordEnumeratedHistogram).
......
......@@ -12,6 +12,9 @@ import org.chromium.base.annotations.UsedByReflection;
*/
@UsedByReflection("ChimeModule")
public class ChimeModuleEntryImpl implements ChimeModuleEntry {
@Override
public void initialize() {}
@Override
public void register() {}
}
......@@ -12,7 +12,12 @@ import org.chromium.components.module_installer.builder.ModuleInterface;
@ModuleInterface(module = "chime", impl = "org.chromium.chrome.modules.chime.ChimeModuleEntryImpl")
public interface ChimeModuleEntry {
/**
* Registers the Chime notification SDK to the server.
* Initializes the Chime component.
*/
void initialize();
/**
* Registers the Chime notification and starts to get notification payloads from servers.
*/
void register();
}
......@@ -13,6 +13,7 @@
#include "base/metrics/field_trial_params.h"
#include "base/stl_util.h"
#include "chrome/browser/flags/jni_headers/ChromeFeatureList_jni.h"
#include "chrome/browser/notifications/chime/android/features.h"
#include "chrome/browser/performance_hints/performance_hints_features.h"
#include "chrome/browser/share/features.h"
#include "chrome/browser/sharing/shared_clipboard/feature_flags.h"
......@@ -228,6 +229,7 @@ const base::Feature* kFeaturesExposedToJava[] = {
&language::kExplicitLanguageAsk,
&language::kTranslateIntent,
&messages::kMessagesForAndroidInfrastructure,
&notifications::features::kUseChimeAndroidSdk,
&offline_pages::kOfflineIndicatorFeature,
&offline_pages::kOfflineIndicatorAlwaysHttpProbeFeature,
&offline_pages::kOfflinePagesCTFeature, // See crbug.com/620421.
......
......@@ -79,6 +79,7 @@ public class CachedFeatureFlags {
put(ChromeFeatureList.TABBED_APP_OVERFLOW_MENU_REGROUP, false);
put(ChromeFeatureList.MESSAGES_FOR_ANDROID_INFRASTRUCTURE, false);
put(ChromeFeatureList.TABBED_APP_OVERFLOW_MENU_THREE_BUTTON_ACTIONBAR, false);
put(ChromeFeatureList.USE_CHIME_ANDROID_SDK, false);
}
};
......
......@@ -438,6 +438,7 @@ public abstract class ChromeFeatureList {
public static final String UPDATE_NOTIFICATION_IMMEDIATE_SHOW_OPTION =
"UpdateNotificationScheduleServiceImmediateShowOption";
public static final String USAGE_STATS = "UsageStats";
public static final String USE_CHIME_ANDROID_SDK = "UseChimeAndroidSdk";
public static final String VR_BROWSING_FEEDBACK = "VrBrowsingFeedback";
public static final String WEBAPK_ADAPTIVE_ICON = "WebApkAdaptiveIcon";
public static final String WEB_AUTH = "WebAuthentication";
......
......@@ -13,6 +13,7 @@ android_library("java") {
"//base:base_java",
"//base:jni_java",
"//chrome/android/modules/chime/public:java",
"//chrome/browser/flags:java",
]
}
......@@ -22,14 +23,5 @@ source_set("android") {
"features.h",
]
deps = [
":jni_headers",
"//base",
]
}
generate_jni("jni_headers") {
visibility = [ ":*" ]
sources = [ "java/src/org/chromium/chrome/browser/notifications/chime/ChimeSession.java" ]
deps = [ "//base" ]
}
......@@ -3,12 +3,6 @@
// found in the LICENSE file.
#include "chrome/browser/notifications/chime/android/features.h"
#include "chrome/browser/notifications/chime/android/jni_headers/ChimeSession_jni.h"
jboolean JNI_ChimeSession_IsEnabled(JNIEnv* env) {
return base::FeatureList::IsEnabled(
notifications::features::kUseChimeAndroidSdk);
}
namespace notifications {
namespace features {
......
......@@ -4,7 +4,8 @@
package org.chromium.chrome.browser.notifications.chime;
import org.chromium.base.annotations.NativeMethods;
import org.chromium.chrome.browser.flags.CachedFeatureFlags;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.modules.chime.ChimeModule;
/**
......@@ -14,12 +15,23 @@ public class ChimeSession {
private static boolean sRegistered;
/**
* Registers to Chime and start to receive notifications.
* Initializes the Chime component. If the DFM is not installed or the feature flag is not
* enabled, do nothing.
*/
public static void start() {
// TODO(xingliu): Find a better way to access feature in Java code.
// https://crbug.com/1017860.
if (!ChimeSessionJni.get().isEnabled() || sRegistered) return;
public static void init() {
// Don't init if we don't install DFM yet or the feature is not enabled. The DFM install
// happens during the first time registration.
if (!ChimeModule.isInstalled() || !isEnabled()) return;
ChimeModule.getImpl().initialize();
}
/**
* Registers to Chime and start to receive notifications. Internally it will install the DFM
* first.
*/
public static void register() {
if (!isEnabled() || sRegistered) return;
// Install the DFM and then reigster.
if (ChimeModule.isInstalled()) {
......@@ -38,11 +50,7 @@ public class ChimeSession {
ChimeModule.getImpl().register();
}
@NativeMethods
interface Natives {
/**
* @return Whether Chime is enabled.
*/
boolean isEnabled();
private static boolean isEnabled() {
return CachedFeatureFlags.isEnabled(ChromeFeatureList.USE_CHIME_ANDROID_SDK);
}
}
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