Commit bbf2c994 authored by Maggie Cai's avatar Maggie Cai Committed by Commit Bot

[IntentHandling] Add preferred apps class in App Service.

This CL adds preferred apps class that contains preferred apps storage
struct, and add and find methods for the struct. Unit tests are also
included.

BUG=853604

Change-Id: I0c2c6c219720da5b56b1f1ed5e3818c760566487
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1864495
Commit-Queue: Maggie Cai <mxcai@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Reviewed-by: default avatarNancy Wang <nancylingwang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#708490}
parent 54d46c60
......@@ -3563,6 +3563,7 @@ jumbo_static_library("browser") {
"//chrome/services/app_service/public/cpp:app_update",
"//chrome/services/app_service/public/cpp:icon_loader",
"//chrome/services/app_service/public/cpp:intents",
"//chrome/services/app_service/public/cpp:preferred_apps",
"//components/feedback",
"//components/image_fetcher/core",
"//components/keep_alive_registry",
......
......@@ -53,6 +53,21 @@ source_set("intents") {
"//base",
"//chrome/services/app_service/public/mojom",
"//components/services/app_service/public/cpp:intent_util",
"//url",
]
}
source_set("preferred_apps") {
sources = [
"preferred_apps.cc",
"preferred_apps.h",
]
deps = [
":intents",
"//base",
"//chrome/services/app_service/public/mojom",
"//url",
]
}
......@@ -65,6 +80,7 @@ source_set("unit_tests") {
"icon_cache_unittest.cc",
"icon_coalescer_unittest.cc",
"intent_util_unittest.cc",
"preferred_apps_unittest.cc",
]
deps = [
......
This diff is collapsed.
// 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.
#ifndef CHROME_SERVICES_APP_SERVICE_PUBLIC_CPP_PREFERRED_APPS_H_
#define CHROME_SERVICES_APP_SERVICE_PUBLIC_CPP_PREFERRED_APPS_H_
#include <memory>
#include <string>
#include "base/optional.h"
#include "chrome/services/app_service/public/mojom/types.mojom.h"
class GURL;
namespace base {
class Value;
}
namespace apps {
// The preferred apps set by the user. The preferred apps is stored as
// base::DictionaryValue. It is a nested map that maps the intent filter
// condition type and value to app id. For example, to represent a
// preferred app for an intent filter that handles https://www.google.com,
// and a preferred app for an intent filter that handles tel:// link,
// the preferred_apps dictionary will look like:
// {“scheme”: {
// "https”: {
// “host”: {
// “www.google.com”: {
// "app_id": <app_id>
// },
// },
// },
// "tel": {
// "app_id": <app_id>
// },
// },
// }
class PreferredApps {
public:
PreferredApps();
~PreferredApps();
static bool VerifyPreferredApps(base::Value* dict);
void Init(std::unique_ptr<base::Value> preferred_apps);
// Add a preferred app for an |intent_filter|.
bool AddPreferredApp(const std::string& app_id,
const apps::mojom::IntentFilterPtr& intent_filter);
// Find preferred app id for an |intent|.
base::Optional<std::string> FindPreferredAppForIntent(
const apps::mojom::IntentPtr& intent);
// Find preferred app id for an |url|.
base::Optional<std::string> FindPreferredAppForUrl(const GURL& url);
private:
std::unique_ptr<base::Value> preferred_apps_;
DISALLOW_COPY_AND_ASSIGN(PreferredApps);
};
} // namespace apps
#endif // CHROME_SERVICES_APP_SERVICE_PUBLIC_CPP_PREFERRED_APPS_H_
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