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

Chime: Add chrome layer code to register to Chime SDK.

This CL adds chrome layer code to register to Chime. The actual
implementation is in an Android DFM in downstream.

The code is set up according to new modulization effort, that
chrome/browser/notifications/chime/android is self contained.

Bug: 1013386
Change-Id: Iafc4269e1597af30af624e9772c6a38edcb4e5a9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1874576
Commit-Queue: Xing Liu <xingliu@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709605}
parent bf91b8b9
...@@ -295,6 +295,7 @@ android_library("chrome_java") { ...@@ -295,6 +295,7 @@ android_library("chrome_java") {
"//chrome/browser/android/thin_webview:java", "//chrome/browser/android/thin_webview:java",
"//chrome/browser/download/android:java", "//chrome/browser/download/android:java",
"//chrome/browser/image_fetcher:java", "//chrome/browser/image_fetcher:java",
"//chrome/browser/notifications/chime/android:java",
"//chrome/browser/share/android:java_resources", "//chrome/browser/share/android:java_resources",
"//chrome/browser/ui/android/styles:java", "//chrome/browser/ui/android/styles:java",
"//chrome/browser/ui/android/widget:java", "//chrome/browser/ui/android/widget:java",
......
include_rules = [ include_rules = [
"+chrome/browser/notifications",
"+components/content_capture", "+components/content_capture",
"+components/download", "+components/download",
"+components/favicon_base", "+components/favicon_base",
......
...@@ -28,6 +28,7 @@ import org.chromium.chrome.browser.flags.FeatureUtilities; ...@@ -28,6 +28,7 @@ import org.chromium.chrome.browser.flags.FeatureUtilities;
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.PrefServiceBridge; import org.chromium.chrome.browser.preferences.PrefServiceBridge;
import org.chromium.chrome.browser.preferences.privacy.BrowsingDataBridge; import org.chromium.chrome.browser.preferences.privacy.BrowsingDataBridge;
...@@ -138,6 +139,7 @@ public class ChromeActivitySessionTracker { ...@@ -138,6 +139,7 @@ public class ChromeActivitySessionTracker {
updateAcceptLanguages(); updateAcceptLanguages();
mVariationsSession.start(); mVariationsSession.start();
mPowerBroadcastReceiver.onForegroundSessionStart(); mPowerBroadcastReceiver.onForegroundSessionStart();
ChimeSession.start();
// 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).
......
...@@ -2880,6 +2880,7 @@ jumbo_static_library("browser") { ...@@ -2880,6 +2880,7 @@ jumbo_static_library("browser") {
"//chrome/android/modules/extra_icu/provider:native", "//chrome/android/modules/extra_icu/provider:native",
"//chrome/browser/android/thin_webview/internal", "//chrome/browser/android/thin_webview/internal",
"//chrome/browser/android/webapk:proto", "//chrome/browser/android/webapk:proto",
"//chrome/browser/notifications/chime/android",
"//chrome/browser/notifications/scheduler/public", "//chrome/browser/notifications/scheduler/public",
"//chrome/browser/share", "//chrome/browser/share",
"//chrome/services/media_gallery_util/public/cpp", "//chrome/services/media_gallery_util/public/cpp",
......
# 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.
import("//build/config/android/rules.gni")
android_library("java") {
java_files = [ "java/src/org/chromium/chrome/browser/notifications/chime/ChimeSession.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") {
sources = [
"features.cc",
"features.h",
]
deps = [
":jni_headers",
"//base",
]
}
generate_jni("jni_headers") {
visibility = [ ":*" ]
sources = [
"java/src/org/chromium/chrome/browser/notifications/chime/ChimeSession.java",
]
}
dtrainor@chromium.org
hesen@chromium.org
xingliu@chromium.org
// 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.
#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::kChimeNotificationPlatform);
}
namespace notifications {
namespace features {
const base::Feature kChimeNotificationPlatform{
"ChimeNotificationPlatform", base::FEATURE_DISABLED_BY_DEFAULT};
} // namespace features
} // namespace notifications
// 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.
#ifndef CHROME_BROWSER_NOTIFICATIONS_CHIME_ANDROID_FEATURES_H_
#define CHROME_BROWSER_NOTIFICATIONS_CHIME_ANDROID_FEATURES_H_
#include "base/feature_list.h"
namespace notifications {
namespace features {
// The feature flag to determine whether to use Chime notification platform.
extern const base::Feature kChimeNotificationPlatform;
} // namespace features
} // namespace notifications
#endif // CHROME_BROWSER_NOTIFICATIONS_CHIME_ANDROID_FEATURES_H_
// 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