Commit 89803769 authored by Aga Wronska's avatar Aga Wronska Committed by Chromium LUCI CQ

Handle invalid arc prefs gracefully

There is a crash in ArcPackageNameToAppId. Handle the situation
when prefs are invalid and return empty string. Add DCHECK for
profile passed by pointer.

Bug: 1163362
Change-Id: Icb107de221eaa4e75cc5576eee81dcfd72f47be1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2625154Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Aga Wronska <agawronska@chromium.org>
Cr-Commit-Position: refs/heads/master@{#842738}
parent c9fffd7b
......@@ -10,6 +10,7 @@
#include <tuple>
#include <utility>
#include "base/check.h"
#include "base/containers/contains.h"
#include "base/json/json_writer.h"
#include "base/metrics/histogram_macros.h"
......@@ -705,8 +706,10 @@ std::string AppIdToArcPackageName(const std::string& app_id, Profile* profile) {
std::string ArcPackageNameToAppId(const std::string& package_name,
Profile* profile) {
DCHECK(profile);
ArcAppListPrefs* arc_prefs = ArcAppListPrefs::Get(profile);
return arc_prefs->GetAppIdByPackageName(package_name);
return arc_prefs ? arc_prefs->GetAppIdByPackageName(package_name)
: std::string();
}
void AddAppLaunchObserver(content::BrowserContext* context,
......
......@@ -206,7 +206,7 @@ void GetAndroidId(
std::string AppIdToArcPackageName(const std::string& app_id, Profile* profile);
// Returns the AppID for the specified package_name, which must be the package
// name of an ARC app.
// name of an ARC app or an empty string if name not found.
std::string ArcPackageNameToAppId(const std::string& package_name,
Profile* profile);
......
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