Commit bfa6245c authored by Nigel Tao's avatar Nigel Tao Committed by Commit Bot

Don't add default apps for non-standard profiles

On Chrome OS, such profiles include the Lock Screen App Profile and the
Sign-in Profile.

Change-Id: Ia373979d377e3b11729ca1036f4f8d12dc824271
Reviewed-on: https://chromium-review.googlesource.com/1166265
Commit-Queue: Nigel Tao <nigeltao@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#584965}
parent a9ed1fd3
...@@ -19,6 +19,10 @@ ...@@ -19,6 +19,10 @@
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "url/gurl.h" #include "url/gurl.h"
#if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#endif
namespace { namespace {
constexpr char kWebAppManifestUrl[] = "web_app_manifest_url"; constexpr char kWebAppManifestUrl[] = "web_app_manifest_url";
...@@ -81,6 +85,34 @@ std::vector<web_app::PendingAppManager::AppInfo> ScanDir(base::FilePath dir) { ...@@ -81,6 +85,34 @@ std::vector<web_app::PendingAppManager::AppInfo> ScanDir(base::FilePath dir) {
return app_infos; return app_infos;
} }
base::FilePath DetermineScanDir(Profile* profile) {
base::FilePath dir;
#if defined(OS_CHROMEOS)
// As of mid 2018, only Chrome OS has default/external web apps, and
// chrome::DIR_STANDALONE_EXTERNAL_EXTENSIONS is only defined for OS_LINUX,
// which includes OS_CHROMEOS.
if (chromeos::ProfileHelper::IsPrimaryProfile(profile)) {
// For manual testing, you can change s/STANDALONE/USER/, as writing to
// "$HOME/.config/chromium/test-user/.config/chromium/External Extensions"
// does not require root ACLs, unlike "/usr/share/chromium/extensions".
//
// TODO(nigeltao): do we want to append a sub-directory name, analogous to
// the "arc" in "/usr/share/chromium/extensions/arc" as per
// chrome/browser/ui/app_list/arc/arc_default_app_list.cc? Or should we not
// sort "system apps" into directories based on their platform (e.g. ARC,
// PWA, etc.), and instead examine the JSON contents (e.g. an "activity"
// key means ARC, "web_app_start_url" key means PWA, etc.)?
if (!base::PathService::Get(chrome::DIR_STANDALONE_EXTERNAL_EXTENSIONS,
&dir)) {
LOG(ERROR) << "ScanForExternalWebApps: base::PathService::Get failed";
}
}
#endif
return dir;
}
} // namespace } // namespace
namespace web_app { namespace web_app {
...@@ -90,49 +122,28 @@ ScanDirForExternalWebAppsForTesting(base::FilePath dir) { ...@@ -90,49 +122,28 @@ ScanDirForExternalWebAppsForTesting(base::FilePath dir) {
return ScanDir(dir); return ScanDir(dir);
} }
void ScanForExternalWebApps(ScanForExternalWebAppsCallback callback) { void ScanForExternalWebApps(Profile* profile,
ScanForExternalWebAppsCallback callback) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
#if !defined(OS_CHROMEOS) base::FilePath dir = DetermineScanDir(profile);
// As of mid 2018, only Chrome OS has default/external web apps, and if (dir.empty()) {
// chrome::DIR_STANDALONE_EXTERNAL_EXTENSIONS is only defined for OS_LINUX, std::move(callback).Run(std::vector<web_app::PendingAppManager::AppInfo>());
// which includes OS_CHROMEOS. } else {
// // Do a two-part callback dance, across different TaskRunners.
// In the future we may have default/external web apps for other platforms, //
// but for now run the callback with an empty vector. // 1. Schedule ScanDir to happen on a background thread, so that we don't
std::move(callback).Run(std::vector<web_app::PendingAppManager::AppInfo>()); // block the UI thread. When that's done,
#else // base::PostTaskWithTraitsAndReplyWithResult will bounce us back to the
// For manual testing, it can be useful to s/STANDALONE/USER/, as writing to // originating thread (the UI thread).
// "$HOME/.config/chromium/test-user/.config/chromium/External Extensions" //
// does not require root ACLs, unlike "/usr/share/chromium/extensions". // 2. In |callback|, forward the vector of AppInfo's on to the
// // pending_app_manager_, which can only be called on the UI thread.
// TODO(nigeltao): do we want to append a sub-directory name, analogous to base::PostTaskWithTraitsAndReplyWithResult(
// the "arc" in "/usr/share/chromium/extensions/arc" as per FROM_HERE,
// chrome/browser/ui/app_list/arc/arc_default_app_list.cc? Or should we not {base::MayBlock(), base::TaskPriority::BEST_EFFORT,
// sort "system apps" into directories based on their platform (e.g. ARC, base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN},
// PWA, etc.), and instead examine the JSON contents (e.g. an "activity" base::BindOnce(&ScanDir, dir), std::move(callback));
// key means ARC, "web_app_start_url" key means PWA, etc.)?
base::FilePath dir;
if (!base::PathService::Get(chrome::DIR_STANDALONE_EXTERNAL_EXTENSIONS,
&dir)) {
LOG(ERROR) << "ScanForExternalWebApps: base::PathService::Get failed";
return;
} }
// Do a two-part callback dance, across different TaskRunners.
//
// 1. Schedule ScanDir to happen on a background thread, so that we don't
// block the UI thread. When that's done
// , base::PostTaskWithTraitsAndReplyWithResult will bounce us back to the
// originating thread (the UI thread).
//
// 2. In |callback|, forward the vector of AppInfo's on to the
// pending_app_manager_, which can only be called on the UI thread.
base::PostTaskWithTraitsAndReplyWithResult(
FROM_HERE,
{base::MayBlock(), base::TaskPriority::BEST_EFFORT,
base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN},
base::BindOnce(&ScanDir, dir), std::move(callback));
#endif
} }
} // namespace web_app } // namespace web_app
...@@ -11,12 +11,15 @@ ...@@ -11,12 +11,15 @@
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "chrome/browser/web_applications/components/pending_app_manager.h" #include "chrome/browser/web_applications/components/pending_app_manager.h"
class Profile;
namespace web_app { namespace web_app {
using ScanForExternalWebAppsCallback = using ScanForExternalWebAppsCallback =
base::OnceCallback<void(std::vector<web_app::PendingAppManager::AppInfo>)>; base::OnceCallback<void(std::vector<web_app::PendingAppManager::AppInfo>)>;
void ScanForExternalWebApps(ScanForExternalWebAppsCallback callback); void ScanForExternalWebApps(Profile* profile,
ScanForExternalWebAppsCallback callback);
// Scans the given directory (non-recursively) for *.json files that define // Scans the given directory (non-recursively) for *.json files that define
// "external web apps", the Web App analogs of "external extensions", described // "external web apps", the Web App analogs of "external extensions", described
......
...@@ -27,8 +27,8 @@ WebAppProvider::WebAppProvider(Profile* profile) ...@@ -27,8 +27,8 @@ WebAppProvider::WebAppProvider(Profile* profile)
std::make_unique<WebAppPolicyManager>(profile->GetPrefs(), std::make_unique<WebAppPolicyManager>(profile->GetPrefs(),
pending_app_manager_.get())) { pending_app_manager_.get())) {
web_app::ScanForExternalWebApps( web_app::ScanForExternalWebApps(
base::BindOnce(&WebAppProvider::OnScanForExternalWebApps, profile, base::BindOnce(&WebAppProvider::OnScanForExternalWebApps,
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
} }
WebAppProvider::~WebAppProvider() = default; WebAppProvider::~WebAppProvider() = default;
......
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