Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2623)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/notifications/ChannelsUpdater.java

Issue 2863623002: [Android] Refactor: move files to chrome/browser/notifications/channels (Closed)
Patch Set: rebase Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/notifications/ChannelsUpdater.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/notifications/ChannelsUpdater.java b/chrome/android/java/src/org/chromium/chrome/browser/notifications/ChannelsUpdater.java
deleted file mode 100644
index 8a7a1a95eceb3acdf8c70d5c9811495737877357..0000000000000000000000000000000000000000
--- a/chrome/android/java/src/org/chromium/chrome/browser/notifications/ChannelsUpdater.java
+++ /dev/null
@@ -1,71 +0,0 @@
-// Copyright 2017 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;
-
-import android.app.NotificationManager;
-import android.content.Context;
-import android.content.SharedPreferences;
-
-import org.chromium.base.BuildInfo;
-import org.chromium.base.ContextUtils;
-import org.chromium.base.VisibleForTesting;
-
-/**
- * Contains helper methods for checking if we should update channels and updating them if so.
- */
-public class ChannelsUpdater {
- @VisibleForTesting
- static final String CHANNELS_VERSION_KEY = "channels_version_key";
-
- private final ChannelsInitializer mChannelsInitializer;
- private final SharedPreferences mSharedPreferences;
- private final boolean mIsAtLeastO;
- private final int mChannelsVersion;
-
- public static ChannelsUpdater getInstance() {
- return LazyHolder.INSTANCE;
- }
-
- private static class LazyHolder {
- // If pre-O, initialize with nulls as a small optimization to avoid getting AppContext etc
- // when we won't need it. It's ok for these parameters to be null when mIsAtLeastO is false.
- public static final ChannelsUpdater INSTANCE = !BuildInfo.isAtLeastO()
- ? new ChannelsUpdater(false /* isAtLeastO */, null, null, -1)
- : new ChannelsUpdater(true /* isAtLeastO */, ContextUtils.getAppSharedPreferences(),
- new ChannelsInitializer(
- new NotificationManagerProxyImpl(
- (NotificationManager) ContextUtils.getApplicationContext()
- .getSystemService(Context.NOTIFICATION_SERVICE)),
- new ChannelDefinitions()),
- ChannelDefinitions.CHANNELS_VERSION);
- }
-
- @VisibleForTesting
- ChannelsUpdater(boolean isAtLeastO, SharedPreferences sharedPreferences,
- ChannelsInitializer channelsInitializer, int channelsVersion) {
- mIsAtLeastO = isAtLeastO;
- mSharedPreferences = sharedPreferences;
- mChannelsInitializer = channelsInitializer;
- mChannelsVersion = channelsVersion;
- }
-
- public boolean shouldUpdateChannels() {
- return mIsAtLeastO
- && mSharedPreferences.getInt(CHANNELS_VERSION_KEY, -1) != mChannelsVersion;
- }
-
- public void updateChannels() {
- if (!mIsAtLeastO) return;
- assert mChannelsInitializer != null;
- mChannelsInitializer.deleteLegacyChannels();
- mChannelsInitializer.initializeStartupChannels();
- storeChannelVersionInPrefs();
- }
-
- private void storeChannelVersionInPrefs() {
- assert mSharedPreferences != null;
- mSharedPreferences.edit().putInt(CHANNELS_VERSION_KEY, mChannelsVersion).apply();
- }
-}

Powered by Google App Engine
This is Rietveld 408576698