Commit 2b74c450 authored by Hesen Zhang's avatar Hesen Zhang Committed by Commit Bot

Add UpdateNotificationController interface and factory.

- This CL added a interface for controllers and use factory
to create the instance based on the feature flag.
- Registered this client into system.
- Added UpdateNotificaitonScheduleCoordinator in Java side.
- In Java side, moved all notifications related code under
omaha/notifications.


Bug: 1013685
Change-Id: I791d590e9c3b5d03a842e818e902ee630f588031
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1888115Reviewed-by: default avatarHesen Zhang <hesen@chromium.org>
Reviewed-by: default avatarTommy Nyquist <nyquist@chromium.org>
Reviewed-by: default avatarXing Liu <xingliu@chromium.org>
Commit-Queue: Hesen Zhang <hesen@chromium.org>
Auto-Submit: Hesen Zhang <hesen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#711537}
parent 856b8913
......@@ -1083,7 +1083,10 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/omaha/UpdateConfigs.java",
"java/src/org/chromium/chrome/browser/omaha/UpdateInfoBarController.java",
"java/src/org/chromium/chrome/browser/omaha/UpdateMenuItemHelper.java",
"java/src/org/chromium/chrome/browser/omaha/UpdateNotificationController.java",
"java/src/org/chromium/chrome/browser/omaha/notification/UpdateNotificationController.java",
"java/src/org/chromium/chrome/browser/omaha/notification/UpdateNotificationControllerFactory.java",
"java/src/org/chromium/chrome/browser/omaha/notification/UpdateNotificationControllerImpl.java",
"java/src/org/chromium/chrome/browser/omaha/notification/UpdateNotificationScheduleCoordinator.java",
"java/src/org/chromium/chrome/browser/omaha/UpdateStatusProvider.java",
"java/src/org/chromium/chrome/browser/omaha/VersionNumber.java",
"java/src/org/chromium/chrome/browser/omaha/VersionNumberGetter.java",
......
......@@ -117,7 +117,8 @@ import org.chromium.chrome.browser.offlinepages.indicator.OfflineIndicatorContro
import org.chromium.chrome.browser.omaha.UpdateInfoBarController;
import org.chromium.chrome.browser.omaha.UpdateMenuItemHelper;
import org.chromium.chrome.browser.omaha.UpdateMenuItemHelper.MenuButtonState;
import org.chromium.chrome.browser.omaha.UpdateNotificationController;
import org.chromium.chrome.browser.omaha.notification.UpdateNotificationController;
import org.chromium.chrome.browser.omaha.notification.UpdateNotificationControllerFactory;
import org.chromium.chrome.browser.page_info.PageInfoController;
import org.chromium.chrome.browser.partnercustomizations.PartnerBrowserCustomizations;
import org.chromium.chrome.browser.preferences.Pref;
......@@ -1038,7 +1039,7 @@ public abstract class ChromeActivity<C extends ChromeActivityComponent>
VrModuleProvider.getDelegate().onNewIntentWithNative(this, intent);
mIntentHandler.onNewIntent(intent);
if (mUpdateNotificationController == null) {
mUpdateNotificationController = new UpdateNotificationController(this);
mUpdateNotificationController = UpdateNotificationControllerFactory.create(this);
}
mUpdateNotificationController.onNewIntent(intent);
}
......@@ -1087,7 +1088,7 @@ public abstract class ChromeActivity<C extends ChromeActivityComponent>
UpdateInfoBarController.createInstance(ChromeActivity.this);
if (mUpdateNotificationController == null) {
mUpdateNotificationController =
new UpdateNotificationController(ChromeActivity.this);
UpdateNotificationControllerFactory.create(ChromeActivity.this);
}
mUpdateNotificationController.onNewIntent(getIntent());
UpdateMenuItemHelper.getInstance().registerObserver(mUpdateStateChangedListener);
......
......@@ -368,6 +368,8 @@ public abstract class ChromeFeatureList {
"ServiceManagerForBackgroundPrefetch";
public static final String SPLIT_CACHE_BY_NETWORK_ISOLATION_KEY =
"SplitCacheByNetworkIsolationKey";
public static final String UPDATE_NOTIFICATION_SCHEDULING_INTEGRATION =
"UpdateNotificationSchedulingIntegration";
@NativeMethods
interface Natives {
......
// 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.omaha.notification;
import android.content.Intent;
/**
* Helper for gluing different implementations of UpdateNotificationController.
*/
public interface UpdateNotificationController {
/**
* Receives and handles intent.
* @param intent A {@link Intent} could contain an extra that helpful for controller.
*/
void onNewIntent(Intent intent);
}
// 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.omaha.notification;
import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.ChromeFeatureList;
/**
* A factory that creates an {@link UpdateNotificationController} instance.
*/
public class UpdateNotificationControllerFactory {
/**
* @param activity A {@link ChromeActivity} instance the notification will be shown in.
* @return a new {@link UpdateNotificationController} to use.
*/
public static UpdateNotificationController create(ChromeActivity activity) {
if (ChromeFeatureList.isEnabled(
ChromeFeatureList.UPDATE_NOTIFICATION_SCHEDULING_INTEGRATION)) {
return new UpdateNotificationScheduleCoordinator(activity);
}
return new UpdateNotificationControllerImpl(activity);
}
}
// 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.omaha;
package org.chromium.chrome.browser.omaha.notification;
import static org.chromium.chrome.browser.omaha.UpdateConfigs.getUpdateNotificationInterval;
import static org.chromium.chrome.browser.omaha.UpdateConfigs.getUpdateNotificationTextBody;
......@@ -41,6 +42,8 @@ import org.chromium.chrome.browser.notifications.NotificationMetadata;
import org.chromium.chrome.browser.notifications.NotificationUmaTracker;
import org.chromium.chrome.browser.notifications.PendingIntentProvider;
import org.chromium.chrome.browser.notifications.channels.ChannelDefinitions;
import org.chromium.chrome.browser.omaha.OmahaBase;
import org.chromium.chrome.browser.omaha.UpdateStatusProvider;
import org.chromium.chrome.browser.omaha.UpdateStatusProvider.UpdateInteractionSource;
import org.chromium.chrome.browser.omaha.UpdateStatusProvider.UpdateState;
import org.chromium.chrome.browser.omaha.UpdateStatusProvider.UpdateStatus;
......@@ -52,8 +55,8 @@ import java.lang.annotation.RetentionPolicy;
* Class supports to build and to send update notification every three weeks if new Chrome version
* is available. It listens to {@link UpdateStatusProvider}, and handle the intent to start update
* flow.
* */
public class UpdateNotificationController implements Destroyable {
*/
public class UpdateNotificationControllerImpl implements UpdateNotificationController, Destroyable {
private static final String TAG = "UpdateNotif";
private static final String INLINE_UPDATE_NOTIFICATION_RECEIVED_EXTRA =
"org.chromium.chrome.browser.omaha.inline_update_notification_received_extra";
......@@ -75,18 +78,17 @@ public class UpdateNotificationController implements Destroyable {
/**
* @param activity A {@link ChromeActivity} instance the notification will be shown in.
*/
public UpdateNotificationController(ChromeActivity activity) {
public UpdateNotificationControllerImpl(ChromeActivity activity) {
mActivity = activity;
UpdateStatusProvider.getInstance().addObserver(mObserver);
mActivity.getLifecycleDispatcher().register(this);
}
/**Controller received intent, extract info from intent and handle the status change.
* @param intent A {@link Intent} contains extra to update the controller.
*/
// UpdateNotificationController implementation.
@Override
public void onNewIntent(Intent intent) {
mShouldStartInlineUpdate = intent.getBooleanExtra(
UpdateNotificationController.INLINE_UPDATE_NOTIFICATION_RECEIVED_EXTRA, false);
mShouldStartInlineUpdate =
intent.getBooleanExtra(INLINE_UPDATE_NOTIFICATION_RECEIVED_EXTRA, false);
processUpdateStatus();
}
......
// 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.omaha.notification;
import android.content.Intent;
import androidx.annotation.Nullable;
import org.chromium.base.Callback;
import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.lifecycle.Destroyable;
import org.chromium.chrome.browser.omaha.UpdateStatusProvider;
/**
* Class supports to build and to send update notification per certain duration if new Chrome
* version is available. It listens to {@link UpdateStatusProvider}, and coordinates with the
* backend notification scheduling system.
*/
public class UpdateNotificationScheduleCoordinator
implements UpdateNotificationController, Destroyable {
private final Callback<UpdateStatusProvider.UpdateStatus> mObserver = status -> {
mUpdateStatus = status;
// TODO(hesen): process UpdateStatus.
};
private ChromeActivity mActivity;
private @Nullable UpdateStatusProvider.UpdateStatus mUpdateStatus;
/**
* @param activity A {@link ChromeActivity} instance the notification will be shown in.
*/
public UpdateNotificationScheduleCoordinator(ChromeActivity activity) {
mActivity = activity;
UpdateStatusProvider.getInstance().addObserver(mObserver);
mActivity.getLifecycleDispatcher().register(this);
}
// UpdateNotificationController implementation.
@Override
public void onNewIntent(Intent intent) {
// TODO(hesen): process UpdateStatus.
return;
}
// Destroyable implementation.
@Override
public void destroy() {
UpdateStatusProvider.getInstance().removeObserver(mObserver);
mActivity.getLifecycleDispatcher().unregister(this);
mActivity = null;
}
}
......@@ -22,7 +22,8 @@
#if defined(OS_ANDROID)
#include "chrome/browser/notifications/scheduler/display_agent_android.h"
#include "chrome/browser/notifications/scheduler/notification_background_task_scheduler_android.h"
#endif
#include "chrome/browser/updates/update_notification_client.h"
#endif // defined(OS_ANDROID)
namespace {
std::unique_ptr<notifications::NotificationSchedulerClientRegistrar>
......@@ -30,6 +31,14 @@ RegisterClients() {
auto client_registrar =
std::make_unique<notifications::NotificationSchedulerClientRegistrar>();
// TODO(xingliu): Register clients here.
#if defined(OS_ANDROID)
// Register UpdateNotificationClient.
auto chrome_update_client =
std::make_unique<updates::UpdateNotificationClient>();
client_registrar->RegisterClient(
notifications::SchedulerClientType::kChromeUpdate,
std::move(chrome_update_client));
#endif // defined(OS_ANDROID)
return client_registrar;
}
......@@ -72,7 +81,7 @@ KeyedService* NotificationScheduleServiceFactory::BuildServiceInstanceFor(
auto display_agent = notifications::DisplayAgent::Create();
auto background_task_scheduler =
std::make_unique<NotificationBackgroundTaskSchedulerImpl>();
#endif
#endif // defined(OS_ANDROID)
auto* db_provider =
content::BrowserContext::GetDefaultStoragePartition(profile)
->GetProtoDatabaseProvider();
......
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