Commit f0286999 authored by nancylingwang@google.com's avatar nancylingwang@google.com Committed by Commit Bot

Create AppRegistryCacheWrapper to access AppRegistryCache.

Ash(ShelfController) should observe AppRegistryCache to get the app
notification badging information. Ash can't depend on chrome/*, so we
can't use AppServiceProxy to get AppRegistryCache, and we can't use
profile as well, because that is in chrome/browser/chromeos directory.

Create a new AppRegistryCacheWrapper to map account id to
AppRegistryCache, so that Ash or other external browser components can
access AppRegistryCache. This could help offload AppServiceProxy, extend
AppRegistryCache to be used out of chrome/browser, and benefit for the
future if we have an AppRegistryCache out of AppServiceProxy.

BUG=1068884

Change-Id: Ib5caa94d944a0d031df9dbee0e3d2c00587ab402
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2212285
Commit-Queue: Nancy Wang <nancylingwang@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#772324}
parent df0f5fb4
......@@ -4029,6 +4029,7 @@ static_library("browser") {
"//components/services/app_service/public/cpp:instance_update",
"//components/services/font:lib",
"//components/services/font/public/mojom",
"//components/user_manager",
"//ui/events/ozone",
"//ui/ozone",
]
......
......@@ -17,6 +17,7 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_features.h"
#include "components/services/app_service/app_service_impl.h"
#include "components/services/app_service/public/cpp/app_registry_cache_wrapper.h"
#include "components/services/app_service/public/cpp/intent_filter_util.h"
#include "components/services/app_service/public/cpp/intent_util.h"
#include "components/services/app_service/public/mojom/types.mojom.h"
......@@ -30,6 +31,8 @@
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/supervised_user/grit/supervised_user_unscaled_resources.h"
#include "chromeos/constants/chromeos_features.h"
#include "components/user_manager/user.h"
#include "components/user_manager/user_manager.h"
#include "extensions/common/constants.h"
#endif
......@@ -93,7 +96,11 @@ AppServiceProxy::AppServiceProxy(Profile* profile)
Initialize();
}
AppServiceProxy::~AppServiceProxy() = default;
AppServiceProxy::~AppServiceProxy() {
#if defined(OS_CHROMEOS)
AppRegistryCacheWrapper::Get().RemoveAppRegistryCache(&cache_);
#endif
}
// static
void AppServiceProxy::RegisterProfilePrefs(PrefRegistrySimple* registry) {
......@@ -122,6 +129,15 @@ void AppServiceProxy::Initialize() {
return;
}
#if defined(OS_CHROMEOS)
if (user_manager::UserManager::Get() &&
user_manager::UserManager::Get()->GetActiveUser()) {
AppRegistryCacheWrapper::Get().AddAppRegistryCache(
user_manager::UserManager::Get()->GetActiveUser()->GetAccountId(),
&cache_);
}
#endif
browser_app_launcher_ = std::make_unique<apps::BrowserAppLauncher>(profile_);
app_service_impl_ = std::make_unique<apps::AppServiceImpl>(
......
......@@ -5,6 +5,9 @@ include_rules = [
]
specific_include_rules = {
"app_registry_cache_wrapper\.cc": [
"+components/account_id/account_id.h",
],
"instance_registry\.h": [
"+ash/public/cpp/shelf_types.h",
],
......
......@@ -20,11 +20,16 @@ source_set("app_update") {
sources = [
"app_registry_cache.cc",
"app_registry_cache.h",
"app_registry_cache_wrapper.cc",
"app_registry_cache_wrapper.h",
"app_update.cc",
"app_update.h",
]
public_deps = [ "//components/services/app_service/public/mojom" ]
public_deps = [
"//components/account_id:account_id",
"//components/services/app_service/public/mojom",
]
}
if (is_chromeos) {
......
// 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.
#include "components/services/app_service/public/cpp/app_registry_cache_wrapper.h"
#include "base/no_destructor.h"
#include "components/account_id/account_id.h"
#include "components/services/app_service/public/cpp/app_registry_cache.h"
namespace apps {
// static
AppRegistryCacheWrapper& AppRegistryCacheWrapper::Get() {
static base::NoDestructor<AppRegistryCacheWrapper> instance;
return *instance;
}
AppRegistryCacheWrapper::AppRegistryCacheWrapper() = default;
AppRegistryCacheWrapper::~AppRegistryCacheWrapper() = default;
AppRegistryCache* AppRegistryCacheWrapper::GetAppRegistryCache(
const AccountId& account_id) {
auto it = app_registry_caches_.find(account_id);
if (it == app_registry_caches_.end()) {
return nullptr;
}
return it->second;
}
void AppRegistryCacheWrapper::AddAppRegistryCache(const AccountId& account_id,
AppRegistryCache* cache) {
app_registry_caches_[account_id] = cache;
}
void AppRegistryCacheWrapper::RemoveAppRegistryCache(AppRegistryCache* cache) {
for (auto& it : app_registry_caches_) {
if (it.second == cache) {
app_registry_caches_.erase(it.first);
return;
}
}
}
} // namespace apps
// 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.
#ifndef COMPONENTS_SERVICES_APP_SERVICE_PUBLIC_CPP_APP_REGISTRY_CACHE_WRAPPER_H_
#define COMPONENTS_SERVICES_APP_SERVICE_PUBLIC_CPP_APP_REGISTRY_CACHE_WRAPPER_H_
#include <map>
class AccountId;
namespace apps {
class AppRegistryCache;
// Wraps AppRegistryCache to get all AppRegistryCaches independently. Provides
// the method to get the AppRegistryCache per |account_id|.
class AppRegistryCacheWrapper {
public:
// Returns the global AppRegistryCacheWrapper object.
static AppRegistryCacheWrapper& Get();
AppRegistryCacheWrapper();
~AppRegistryCacheWrapper();
AppRegistryCacheWrapper(const AppRegistryCacheWrapper&) = delete;
AppRegistryCacheWrapper& operator=(const AppRegistryCacheWrapper&) = delete;
// Returns AppRegistryCache for the given |account_id|, or return null if
// AppRegistryCache doesn't exist.
AppRegistryCache* GetAppRegistryCache(const AccountId& account_id);
// Adds the AppRegistryCache for the given |account_id|.
void AddAppRegistryCache(const AccountId& account_id,
AppRegistryCache* cache);
// Removes the |cache| in |app_registry_caches_|.
void RemoveAppRegistryCache(AppRegistryCache* cache);
private:
std::map<AccountId, AppRegistryCache*> app_registry_caches_;
};
} // namespace apps
#endif // COMPONENTS_SERVICES_APP_SERVICE_PUBLIC_CPP_APP_REGISTRY_CACHE_WRAPPER_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