Commit 8a33ab1d authored by Mohamed Heikal's avatar Mohamed Heikal Committed by Commit Bot

Migrate chime init code downstream

needed in preparation to moving the chime DFM definition downstream.
followup cl downstream crrev.com/i/3364724

Bug: 1142775
Change-Id: I2b07234fdba5dc2fa49632d5710f5ebedf48439f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2501667
Commit-Queue: Mohamed Heikal <mheikal@chromium.org>
Reviewed-by: default avatarHenrique Nakashima <hnakashima@chromium.org>
Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Reviewed-by: default avatarXing Liu <xingliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#822165}
parent 5dad049a
...@@ -29,6 +29,7 @@ import org.chromium.chrome.browser.instantapps.InstantAppsHandler; ...@@ -29,6 +29,7 @@ import org.chromium.chrome.browser.instantapps.InstantAppsHandler;
import org.chromium.chrome.browser.lens.LensController; import org.chromium.chrome.browser.lens.LensController;
import org.chromium.chrome.browser.locale.LocaleManager; import org.chromium.chrome.browser.locale.LocaleManager;
import org.chromium.chrome.browser.metrics.VariationsSession; import org.chromium.chrome.browser.metrics.VariationsSession;
import org.chromium.chrome.browser.notifications.chime.ChimeDelegate;
import org.chromium.chrome.browser.omaha.RequestGenerator; import org.chromium.chrome.browser.omaha.RequestGenerator;
import org.chromium.chrome.browser.partnerbookmarks.PartnerBookmark; import org.chromium.chrome.browser.partnerbookmarks.PartnerBookmark;
import org.chromium.chrome.browser.partnerbookmarks.PartnerBookmarksProviderIterator; import org.chromium.chrome.browser.partnerbookmarks.PartnerBookmarksProviderIterator;
...@@ -358,4 +359,11 @@ public abstract class AppHooks { ...@@ -358,4 +359,11 @@ public abstract class AppHooks {
public String getWebApkServerUrl() { public String getWebApkServerUrl() {
return ""; return "";
} }
/**
* Returns a Chime Delegate if the chime module is defined.
*/
public @Nullable ChimeDelegate getChimeDelegate() {
return null;
}
} }
...@@ -28,7 +28,6 @@ import org.chromium.chrome.browser.browsing_data.TimePeriod; ...@@ -28,7 +28,6 @@ import org.chromium.chrome.browser.browsing_data.TimePeriod;
import org.chromium.chrome.browser.metrics.UmaUtils; import org.chromium.chrome.browser.metrics.UmaUtils;
import org.chromium.chrome.browser.metrics.VariationsSession; import org.chromium.chrome.browser.metrics.VariationsSession;
import org.chromium.chrome.browser.notifications.NotificationPlatformBridge; import org.chromium.chrome.browser.notifications.NotificationPlatformBridge;
import org.chromium.chrome.browser.notifications.chime.ChimeSession;
import org.chromium.chrome.browser.partnercustomizations.PartnerBrowserCustomizations; import org.chromium.chrome.browser.partnercustomizations.PartnerBrowserCustomizations;
import org.chromium.chrome.browser.preferences.ChromePreferenceKeys; import org.chromium.chrome.browser.preferences.ChromePreferenceKeys;
import org.chromium.chrome.browser.preferences.Pref; import org.chromium.chrome.browser.preferences.Pref;
...@@ -140,7 +139,9 @@ public class ChromeActivitySessionTracker { ...@@ -140,7 +139,9 @@ public class ChromeActivitySessionTracker {
updateAcceptLanguages(); updateAcceptLanguages();
mVariationsSession.start(); mVariationsSession.start();
mPowerBroadcastReceiver.onForegroundSessionStart(); mPowerBroadcastReceiver.onForegroundSessionStart();
ChimeSession.start(); if (AppHooks.get().getChimeDelegate() != null) {
AppHooks.get().getChimeDelegate().startSession();
}
// Track the ratio of Chrome startups that are caused by notification clicks. // Track the ratio of Chrome startups that are caused by notification clicks.
// TODO(johnme): Add other reasons (and switch to recordEnumeratedHistogram). // TODO(johnme): Add other reasons (and switch to recordEnumeratedHistogram).
......
...@@ -73,7 +73,8 @@ public class ChromeCachedFlags { ...@@ -73,7 +73,8 @@ public class ChromeCachedFlags {
ChromeFeatureList.TAB_TO_GTS_ANIMATION, ChromeFeatureList.TAB_TO_GTS_ANIMATION,
ChromeFeatureList.TABBED_APP_OVERFLOW_MENU_ICONS, ChromeFeatureList.TABBED_APP_OVERFLOW_MENU_ICONS,
ChromeFeatureList.TABBED_APP_OVERFLOW_MENU_REGROUP, ChromeFeatureList.TABBED_APP_OVERFLOW_MENU_REGROUP,
ChromeFeatureList.TABBED_APP_OVERFLOW_MENU_THREE_BUTTON_ACTIONBAR); ChromeFeatureList.TABBED_APP_OVERFLOW_MENU_THREE_BUTTON_ACTIONBAR,
ChromeFeatureList.USE_CHIME_ANDROID_SDK);
// clang-format on // clang-format on
CachedFeatureFlags.cacheNativeFlags(featuresToCache); CachedFeatureFlags.cacheNativeFlags(featuresToCache);
CachedFeatureFlags.cacheAdditionalNativeFlags(); CachedFeatureFlags.cacheAdditionalNativeFlags();
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "base/metrics/field_trial_params.h" #include "base/metrics/field_trial_params.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "chrome/browser/flags/jni_headers/ChromeFeatureList_jni.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/performance_hints/performance_hints_features.h"
#include "chrome/browser/share/features.h" #include "chrome/browser/share/features.h"
#include "chrome/browser/sharing/shared_clipboard/feature_flags.h" #include "chrome/browser/sharing/shared_clipboard/feature_flags.h"
...@@ -225,6 +226,7 @@ const base::Feature* kFeaturesExposedToJava[] = { ...@@ -225,6 +226,7 @@ const base::Feature* kFeaturesExposedToJava[] = {
&features::kDnsOverHttps, &features::kDnsOverHttps,
&net::features::kSameSiteByDefaultCookies, &net::features::kSameSiteByDefaultCookies,
&net::features::kCookiesWithoutSameSiteMustBeSecure, &net::features::kCookiesWithoutSameSiteMustBeSecure,
&notifications::features::kUseChimeAndroidSdk,
&paint_preview::kPaintPreviewDemo, &paint_preview::kPaintPreviewDemo,
&paint_preview::kPaintPreviewShowOnStartup, &paint_preview::kPaintPreviewShowOnStartup,
&language::kDetailedLanguageSettings, &language::kDetailedLanguageSettings,
......
...@@ -79,6 +79,7 @@ public class CachedFeatureFlags { ...@@ -79,6 +79,7 @@ public class CachedFeatureFlags {
put(ChromeFeatureList.TABBED_APP_OVERFLOW_MENU_ICONS, false); put(ChromeFeatureList.TABBED_APP_OVERFLOW_MENU_ICONS, false);
put(ChromeFeatureList.TABBED_APP_OVERFLOW_MENU_REGROUP, false); put(ChromeFeatureList.TABBED_APP_OVERFLOW_MENU_REGROUP, false);
put(ChromeFeatureList.TABBED_APP_OVERFLOW_MENU_THREE_BUTTON_ACTIONBAR, false); put(ChromeFeatureList.TABBED_APP_OVERFLOW_MENU_THREE_BUTTON_ACTIONBAR, false);
put(ChromeFeatureList.USE_CHIME_ANDROID_SDK, false);
} }
}; };
......
...@@ -444,6 +444,7 @@ public abstract class ChromeFeatureList { ...@@ -444,6 +444,7 @@ public abstract class ChromeFeatureList {
public static final String UPDATE_NOTIFICATION_IMMEDIATE_SHOW_OPTION = public static final String UPDATE_NOTIFICATION_IMMEDIATE_SHOW_OPTION =
"UpdateNotificationScheduleServiceImmediateShowOption"; "UpdateNotificationScheduleServiceImmediateShowOption";
public static final String USAGE_STATS = "UsageStats"; 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 VR_BROWSING_FEEDBACK = "VrBrowsingFeedback";
public static final String WEBAPK_ADAPTIVE_ICON = "WebApkAdaptiveIcon"; public static final String WEBAPK_ADAPTIVE_ICON = "WebApkAdaptiveIcon";
public static final String WEB_AUTH = "WebAuthentication"; public static final String WEB_AUTH = "WebAuthentication";
......
...@@ -5,15 +5,7 @@ ...@@ -5,15 +5,7 @@
import("//build/config/android/rules.gni") import("//build/config/android/rules.gni")
android_library("java") { android_library("java") {
sources = [ "java/src/org/chromium/chrome/browser/notifications/chime/ChimeSession.java" ] sources = [ "java/src/org/chromium/chrome/browser/notifications/chime/ChimeDelegate.java" ]
annotation_processor_deps = [ "//base/android/jni_generator:jni_processor" ]
deps = [
"//base:base_java",
"//base:jni_java",
"//chrome/android/modules/chime/public:java",
]
} }
source_set("android") { source_set("android") {
...@@ -22,14 +14,5 @@ source_set("android") { ...@@ -22,14 +14,5 @@ source_set("android") {
"features.h", "features.h",
] ]
deps = [ deps = [ "//base" ]
":jni_headers",
"//base",
]
}
generate_jni("jni_headers") {
visibility = [ ":*" ]
sources = [ "java/src/org/chromium/chrome/browser/notifications/chime/ChimeSession.java" ]
} }
...@@ -3,12 +3,6 @@ ...@@ -3,12 +3,6 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/browser/notifications/chime/android/features.h" #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 notifications {
namespace features { namespace features {
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.notifications.chime;
/**
* Chime interface.
*/
public interface ChimeDelegate {
/*
* Start a chime session.
*/
public default void startSession() {}
}
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.notifications.chime;
import org.chromium.base.annotations.NativeMethods;
import org.chromium.chrome.modules.chime.ChimeModule;
/**
* Used to register to Chime notification platform.
*/
public class ChimeSession {
private static boolean sRegistered;
/**
* Registers to Chime and start to receive notifications.
*/
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;
// Install the DFM and then reigster.
if (ChimeModule.isInstalled()) {
registerChimeInternal();
return;
}
ChimeModule.install((success) -> {
if (success) registerChimeInternal();
});
}
private static void registerChimeInternal() {
assert (ChimeModule.isInstalled());
sRegistered = true;
ChimeModule.getImpl().register();
}
@NativeMethods
interface Natives {
/**
* @return Whether Chime is enabled.
*/
boolean isEnabled();
}
}
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