Chromium Code Reviews| OLD | NEW | 
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #ifndef UI_GFX_X_X11_ATOM_CACHE_H_ | 5 #ifndef UI_GFX_X_X11_ATOM_CACHE_H_ | 
| 6 #define UI_GFX_X_X11_ATOM_CACHE_H_ | 6 #define UI_GFX_X_X11_ATOM_CACHE_H_ | 
| 7 | 7 | 
| 8 #include <map> | 8 #include <map> | 
| 9 #include <string> | 9 #include <string> | 
| 10 | 10 | 
| 11 #include "base/macros.h" | 11 #include "base/macros.h" | 
| 12 #include "ui/gfx/gfx_export.h" | 12 #include "ui/gfx/gfx_export.h" | 
| 13 #include "ui/gfx/x/x11_types.h" | 13 #include "ui/gfx/x/x11_types.h" | 
| 14 | 14 | 
| 15 namespace base { | |
| 16 template <typename T> | |
| 17 struct DefaultSingletonTraits; | |
| 18 } | |
| 19 | |
| 15 namespace ui { | 20 namespace ui { | 
| 
 
sadrul
2017/06/01 20:45:31
OK, I think my bad, but this should be gfx :(
Som
 
Tom Anderson
2017/06/01 21:20:42
Acknowledged.
 
 | |
| 16 | 21 | 
| 17 // Pre-caches all Atoms on first use to minimize roundtrips to the X11 | 22 // Pre-caches all Atoms on first use to minimize roundtrips to the X11 | 
| 18 // server. By default, GetAtom() will CHECK() that atoms accessed through | 23 // server. By default, GetAtom() will CHECK() that atoms accessed through | 
| 19 // GetAtom() were passed to the constructor, but this behaviour can be changed | 24 // GetAtom() were passed to the constructor, but this behaviour can be changed | 
| 20 // with allow_uncached_atoms(). | 25 // with allow_uncached_atoms(). | 
| 21 class GFX_EXPORT X11AtomCache { | 26 class GFX_EXPORT X11AtomCache { | 
| 22 public: | 27 public: | 
| 23 // Preinterns the NULL terminated list of string |to_cache| on |xdisplay|. | 28 static X11AtomCache* GetInstance(); | 
| 24 X11AtomCache(XDisplay* xdisplay, const char* const* to_cache); | |
| 25 ~X11AtomCache(); | |
| 26 | 29 | 
| 27 // Returns the pre-interned Atom without having to go to the x server. | 30 // Returns the pre-interned Atom without having to go to the x server. | 
| 28 XAtom GetAtom(const char*) const; | 31 XAtom GetAtom(const char*) const; | 
| 29 | 32 | 
| 30 // When an Atom isn't in the list of items we've cached, we should look it | 33 private: | 
| 31 // up, cache it locally, and then return the result. | 34 friend struct base::DefaultSingletonTraits<X11AtomCache>; | 
| 32 void allow_uncached_atoms() { uncached_atoms_allowed_ = true; } | |
| 33 | 35 | 
| 34 private: | 36 X11AtomCache(); | 
| 37 ~X11AtomCache(); | |
| 38 | |
| 35 XDisplay* xdisplay_; | 39 XDisplay* xdisplay_; | 
| 36 | 40 | 
| 37 bool uncached_atoms_allowed_; | |
| 38 | |
| 39 mutable std::map<std::string, XAtom> cached_atoms_; | 41 mutable std::map<std::string, XAtom> cached_atoms_; | 
| 40 | 42 | 
| 41 DISALLOW_COPY_AND_ASSIGN(X11AtomCache); | 43 DISALLOW_COPY_AND_ASSIGN(X11AtomCache); | 
| 42 }; | 44 }; | 
| 43 | 45 | 
| 44 } // namespace ui | 46 } // namespace ui | 
| 45 | 47 | 
| 46 #endif // UI_GFX_X_X11_ATOM_CACHE_H_ | 48 #endif // UI_GFX_X_X11_ATOM_CACHE_H_ | 
| OLD | NEW |