Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(387)

Side by Side Diff: services/catalog/entry_cache.h

Issue 2611183006: Service Manager: Miscellaneous catalog cleanup (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef SERVICES_CATALOG_ENTRY_CACHE_H_
6 #define SERVICES_CATALOG_ENTRY_CACHE_H_
7
8 #include <map>
9 #include <memory>
10 #include <string>
11
12 #include "base/macros.h"
13
14 namespace catalog {
15
16 class Entry;
17
18 // Indexed storage for all existing service catalog entries.
19 class EntryCache {
20 public:
21 EntryCache();
22 ~EntryCache();
23
24 // All entries in the cache, including non-root entries.
25 const std::map<std::string, const Entry*>& entries() const {
26 return entries_;
27 }
28
29 // Adds a new root entry to the cache. If a root entry already exists
30 // corresponding to the new entry's name, the old root entry is removed first,
31 // along with its children.
32 //
33 // If a non-root entry already exists corresponding to the new entry's name,
34 // the new entry is ignored.
35 //
36 // Returns |true| if the entry was added and |false| otherwise.
37 //
38 // TODO(rockot): Duplicate entries should be treated as an error, but for now
39 // we tolerate them because of some remaining dependency on Package directory
40 // scanning, which in turn has some unpredictable behavior with respect to
41 // Entry registration.
42 bool AddRootEntry(std::unique_ptr<Entry> entry);
43
44 // Queries the cache for an entry corresponding to |name|. Returns null if
45 // such an entry is not found.
46 const Entry* GetEntry(const std::string& name);
47
48 private:
49 // Adds and entry and its children to |entries_|. Returns |true| if the Entry
50 // was successfully added and |false| otherwise.
51 bool AddEntry(const Entry* entry);
52
53 // Removes an entry and its children from |entries_|.
54 void RemoveEntry(const Entry* entry);
55
56 // Map of top-level service entries. This transitively owns all existing
57 // Entry objects.
58 std::map<std::string, std::unique_ptr<Entry>> root_entries_;
59
60 // Map of service name to Entry. Each value points to an Entry owned either
61 // directly or indirectly by |entries_| above. This is essentially a flattened
62 // version of |entries_| with no ownership.
63 std::map<std::string, const Entry*> entries_;
64
65 DISALLOW_COPY_AND_ASSIGN(EntryCache);
66 };
67
68 } // namespace catalog
69
70 #endif // SERVICES_CATALOG_ENTRY_CACHE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698