// Copyright 2019 The Chromium Authors // 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_ICON_COALESCER_H_ #define COMPONENTS_SERVICES_APP_SERVICE_PUBLIC_CPP_ICON_COALESCER_H_ #include <map> #include <memory> #include <set> #include <string> #include <utility> #include "base/memory/raw_ptr.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_refptr.h" #include "base/memory/weak_ptr.h" #include "base/sequence_checker.h" #include "components/services/app_service/public/cpp/icon_loader.h" namespace apps { // An IconLoader that coalesces the apps::mojom::IconType::kUncompressed // results of another (wrapped) IconLoader. // // This is similar to, but different from, an IconCache. Both types are related // to the LoadIconFromIconKey Mojo call (the request and response), both reduce // the number of requests made, and both re-use the response for requests with // the same IconLoader::Key. // // An IconCache (another class) applies when the second request is sent *after* // the first response is received. An IconCoalescer (this class) applies when // the second request is sent *before* the first response is received (but // after the first request is sent, obviously). // // Caching means that the second (and subsequent) requests can be satisfied // immediately, sharing the previous response. Coalescing means that the second // (and subsequent) requests are paused, and when the first request's response // is finally received, those other requests are un-paused and share the same // response. // // When there are no in-flight requests, a (memory-backed) cache can still have // a significant memory cost, depending on how aggressive its cache eviction // policy is, but a (memory-backed) coalescer will have a trivial memory cost. // Much of its internal state (e.g. maps and multimaps) will be empty. class IconCoalescer : public IconLoader { … }; } // namespace apps #endif // COMPONENTS_SERVICES_APP_SERVICE_PUBLIC_CPP_ICON_COALESCER_H_