[SyncFS] Build indexes from FileTracker entries on disk.
[chromium-blink-merge.git] / ui / gfx / x / x11_atom_cache.h
blob92d4db799b06ed8912248bee025a30306ee459c0
1 // Copyright (c) 2012 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.
5 #ifndef UI_GFX_X_X11_ATOM_CACHE_H_
6 #define UI_GFX_X_X11_ATOM_CACHE_H_
8 #include <map>
9 #include <string>
11 #include "base/basictypes.h"
12 #include "ui/gfx/gfx_export.h"
13 #include "ui/gfx/x/x11_types.h"
15 namespace ui {
17 // Pre-caches all Atoms on first use to minimize roundtrips to the X11
18 // server. By default, GetAtom() will CHECK() that atoms accessed through
19 // GetAtom() were passed to the constructor, but this behaviour can be changed
20 // with allow_uncached_atoms().
21 class GFX_EXPORT X11AtomCache {
22 public:
23 // Preinterns the NULL terminated list of string |to_cache_ on |xdisplay|.
24 X11AtomCache(XDisplay* xdisplay, const char** to_cache);
25 ~X11AtomCache();
27 // Returns the pre-interned Atom without having to go to the x server.
28 XAtom GetAtom(const char*) const;
30 // When an Atom isn't in the list of items we've cached, we should look it
31 // up, cache it locally, and then return the result.
32 void allow_uncached_atoms() { uncached_atoms_allowed_ = true; }
34 private:
35 XDisplay* xdisplay_;
37 bool uncached_atoms_allowed_;
39 mutable std::map<std::string, XAtom> cached_atoms_;
41 DISALLOW_COPY_AND_ASSIGN(X11AtomCache);
44 } // namespace ui
46 #endif // UI_GFX_X_X11_ATOM_CACHE_H_