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_
11 #include "base/basictypes.h"
12 #include "ui/gfx/gfx_export.h"
14 typedef unsigned long Atom
;
15 typedef struct _XDisplay XDisplay
;
19 // Pre-caches all Atoms on first use to minimize roundtrips to the X11
20 // server. By default, GetAtom() will CHECK() that atoms accessed through
21 // GetAtom() were passed to the constructor, but this behaviour can be changed
22 // with allow_uncached_atoms().
23 class GFX_EXPORT X11AtomCache
{
25 // Preinterns the NULL terminated list of string |to_cache_ on |xdisplay|.
26 X11AtomCache(XDisplay
* xdisplay
, const char** to_cache
);
29 // Returns the pre-interned Atom without having to go to the x server.
30 Atom
GetAtom(const char*) const;
32 // When an Atom isn't in the list of items we've cached, we should look it
33 // up, cache it locally, and then return the result.
34 void allow_uncached_atoms() { uncached_atoms_allowed_
= true; }
39 bool uncached_atoms_allowed_
;
41 mutable std::map
<std::string
, Atom
> cached_atoms_
;
43 DISALLOW_COPY_AND_ASSIGN(X11AtomCache
);
48 #endif // UI_GFX_X_X11_ATOM_CACHE_H_