Commit 874b217c authored by Xinghui Lu's avatar Xinghui Lu Committed by Commit Bot

Rename HelpAndFeedback to HelpAndFeedbackLauncherImpl.

This is a follow up CL for https://crrev.com/c/2359749. It is for
pure refactoring.

The plan for this two-sided patch is:
1) Add the new class under feedback/ and AppHooks method upstream with
no reference.
2) Extend the new class downstream and add the new AppHooks method.
3) Update upstream references to point to the new AppHooks method.
4) Cleanup.

This CL is for step 1). Step 2) will be done in
https://crrev.com/i/3227761 once this CL is landed.

Bug: 1117343
Change-Id: I312f3459360fa5e1b78f6e301b052a36bed2e9b4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2364581Reviewed-by: default avatarTommy Nyquist <nyquist@chromium.org>
Reviewed-by: default avatarNatalie Chouinard <chouinard@chromium.org>
Commit-Queue: Xinghui Lu <xinghuilu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#803360}
parent e523e463
......@@ -697,6 +697,7 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/feedback/FeedbackContextFeedbackSource.java",
"java/src/org/chromium/chrome/browser/feedback/FeedbackReporter.java",
"java/src/org/chromium/chrome/browser/feedback/FeedbackSource.java",
"java/src/org/chromium/chrome/browser/feedback/HelpAndFeedbackLauncherImpl.java",
"java/src/org/chromium/chrome/browser/feedback/HistogramFeedbackSource.java",
"java/src/org/chromium/chrome/browser/feedback/IMEFeedbackSource.java",
"java/src/org/chromium/chrome/browser/feedback/InterestFeedFeedbackSource.java",
......
......@@ -20,6 +20,8 @@ import org.chromium.chrome.browser.customtabs.CustomTabsConnection;
import org.chromium.chrome.browser.directactions.DirectActionCoordinator;
import org.chromium.chrome.browser.externalauth.ExternalAuthUtils;
import org.chromium.chrome.browser.feedback.FeedbackReporter;
import org.chromium.chrome.browser.feedback.HelpAndFeedbackLauncher;
import org.chromium.chrome.browser.feedback.HelpAndFeedbackLauncherImpl;
import org.chromium.chrome.browser.gsa.GSAHelper;
import org.chromium.chrome.browser.help.HelpAndFeedback;
import org.chromium.chrome.browser.historyreport.AppIndexingReporter;
......@@ -177,6 +179,14 @@ public abstract class AppHooks {
}
/**
* Returns a new instance of HelpAndFeedbackLauncher.
*/
public HelpAndFeedbackLauncher createHelpAndFeedbackLauncher() {
return new HelpAndFeedbackLauncherImpl();
}
/**
* TODO(crbug.com/1117343): Remove this method when downstream dependency is removed.
* Returns a new instance of HelpAndFeedback.
*/
public HelpAndFeedback createHelpAndFeedback() {
......
// 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.feedback;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.provider.Browser;
import android.text.TextUtils;
import androidx.annotation.Nullable;
import org.chromium.base.Log;
import org.chromium.base.ThreadUtils;
import org.chromium.base.metrics.RecordUserAction;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.AppHooks;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.components.embedder_support.util.UrlConstants;
import org.chromium.components.embedder_support.util.UrlUtilitiesJni;
import java.util.Map;
import javax.annotation.Nonnull;
/**
* Launches an activity that displays a relevant support page and has an option to provide feedback.
*/
public class HelpAndFeedbackLauncherImpl implements HelpAndFeedbackLauncher {
protected static final String FALLBACK_SUPPORT_URL =
"https://support.google.com/chrome/topic/6069782";
private static final String TAG = "HelpAndFeedback";
private static HelpAndFeedbackLauncher sInstance;
/**
* Returns the singleton instance of HelpAndFeedbackLauncher, creating it if needed.
*/
public static HelpAndFeedbackLauncher getInstance() {
ThreadUtils.assertOnUiThread();
if (sInstance == null) {
sInstance = AppHooks.get().createHelpAndFeedbackLauncher();
}
return sInstance;
}
/**
* Starts an activity showing a help page for the specified context ID.
*
* @param activity The activity to use for starting the help activity and to take a
* screenshot of.
* @param helpContext One of the CONTEXT_* constants. This should describe the user's current
* context and will be used to show a more relevant help page.
* @param collector the {@link FeedbackCollector} to use for extra data. Must not be null.
*/
protected void show(
Activity activity, String helpContext, @Nonnull FeedbackCollector collector) {
Log.d(TAG, "Feedback data: " + collector.getBundle());
launchFallbackSupportUri(activity);
}
/**
* Starts an activity prompting the user to enter feedback.
*
* @param activity The activity to use for starting the feedback activity and to take a
* screenshot of.
* @param collector the {@link FeedbackCollector} to use for extra data. Must not be null.
*/
protected void showFeedback(Activity activity, @Nonnull FeedbackCollector collector) {
Log.d(TAG, "Feedback data: " + collector.getBundle());
launchFallbackSupportUri(activity);
}
/**
* Starts an activity showing a help page for the specified context ID.
*
* @param activity The activity to use for starting the help activity and to take a
* screenshot of.
* @param helpContext One of the CONTEXT_* constants. This should describe the user's current
* context and will be used to show a more relevant help page.
* @param profile the current profile.
* @param url the current URL. May be null.
*/
@Override
public void show(final Activity activity, final String helpContext, Profile profile,
@Nullable String url) {
RecordUserAction.record("MobileHelpAndFeedback");
new ChromeFeedbackCollector(activity, null /* categoryTag */, null /* description */,
true /* takeScreenshot */,
new ChromeFeedbackCollector.InitParams(profile, url, helpContext),
collector -> show(activity, helpContext, collector));
}
/**
* Starts an activity prompting the user to enter feedback.
*
* @param activity The activity to use for starting the feedback activity and to take a
* screenshot of.
* @param profile the current profile.
* @param url the current URL. May be null.
* @param categoryTag The category that this feedback report falls under.
*/
@Override
public void showFeedback(final Activity activity, Profile profile, @Nullable String url,
@Nullable final String categoryTag) {
new ChromeFeedbackCollector(activity, categoryTag, null /* description */,
true /* takeScreenshot */,
new ChromeFeedbackCollector.InitParams(profile, url, null),
collector -> showFeedback(activity, collector));
}
/**
* Starts an activity prompting the user to enter feedback for the interest feed.
*
* @param activity The activity to use for starting the feedback activity and to take a
* screenshot of.
* @param profile the current profile.
* @param categoryTag The category that this feedback report falls under.
* @param feedContext Feed specific parameters (url, title, etc) to include with feedback.
* @param feedbackContext The context that describes the current feature being used.
*/
@Override
public void showFeedback(final Activity activity, Profile profile, @Nullable String url,
@Nullable final String categoryTag, @Nullable final Map<String, String> feedContext,
@Nullable final String feedbackContext) {
new FeedFeedbackCollector(activity, categoryTag, null /* description */, feedbackContext,
true /* takeScreenshot */,
new FeedFeedbackCollector.InitParams(profile, url, feedContext),
collector -> showFeedback(activity, collector));
}
/**
* Get help context ID from URL.
*
* @param url The URL to be checked.
* @param isIncognito Whether we are in incognito mode or not.
* @return Help context ID that matches the URL and incognito mode.
*/
public static String getHelpContextIdFromUrl(Context context, String url, boolean isIncognito) {
if (TextUtils.isEmpty(url)) {
return context.getString(R.string.help_context_general);
} else if (url.startsWith(UrlConstants.BOOKMARKS_URL)) {
return context.getString(R.string.help_context_bookmarks);
} else if (url.equals(UrlConstants.HISTORY_URL)) {
return context.getString(R.string.help_context_history);
}
// Note: For www.google.com the following function returns false.
else if (UrlUtilitiesJni.get().isGoogleSearchUrl(url)) {
return context.getString(R.string.help_context_search_results);
}
// For incognito NTP, we want to show incognito help.
else if (isIncognito) {
return context.getString(R.string.help_context_incognito);
} else if (url.equals(UrlConstants.NTP_URL)) {
return context.getString(R.string.help_context_new_tab);
}
return context.getString(R.string.help_context_webpage);
}
protected static void launchFallbackSupportUri(Context context) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(FALLBACK_SUPPORT_URL));
// Let Chrome know that this intent is from Chrome, so that it does not close the app when
// the user presses 'back' button.
intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
intent.putExtra(Browser.EXTRA_CREATE_NEW_TAB, true);
intent.setPackage(context.getPackageName());
context.startActivity(intent);
}
}
......@@ -31,6 +31,7 @@ import java.util.Map;
import javax.annotation.Nonnull;
/**
* TODO(crbug.com/1117343): Remove this class when downstream dependency is removed.
* Launches an activity that displays a relevant support page and has an option to provide feedback.
*/
public class HelpAndFeedback implements HelpAndFeedbackLauncher {
......@@ -149,11 +150,13 @@ public class HelpAndFeedback implements HelpAndFeedbackLauncher {
return context.getString(R.string.help_context_bookmarks);
} else if (url.equals(UrlConstants.HISTORY_URL)) {
return context.getString(R.string.help_context_history);
}
// Note: For www.google.com the following function returns false.
} else if (UrlUtilitiesJni.get().isGoogleSearchUrl(url)) {
else if (UrlUtilitiesJni.get().isGoogleSearchUrl(url)) {
return context.getString(R.string.help_context_search_results);
}
// For incognito NTP, we want to show incognito help.
} else if (isIncognito) {
else if (isIncognito) {
return context.getString(R.string.help_context_incognito);
} else if (url.equals(UrlConstants.NTP_URL)) {
return context.getString(R.string.help_context_new_tab);
......
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