1 // Copyright 2014 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_VIEWS_ACCESSIBILITY_AX_AURA_OBJ_CACHE_H_
6 #define UI_VIEWS_ACCESSIBILITY_AX_AURA_OBJ_CACHE_H_
10 #include "base/basictypes.h"
11 #include "ui/views/views_export.h"
13 template <typename T
> struct DefaultSingletonTraits
;
20 class AXAuraObjWrapper
;
24 // A cache responsible for assigning id's to a set of interesting Aura views.
25 class VIEWS_EXPORT AXAuraObjCache
{
27 // Get the single instance of this class.
28 static AXAuraObjCache
* GetInstance();
30 // Get or create an entry in the cache based on an Aura view.
31 AXAuraObjWrapper
* GetOrCreate(View
* view
);
32 AXAuraObjWrapper
* GetOrCreate(Widget
* widget
);
33 AXAuraObjWrapper
* GetOrCreate(aura::Window
* window
);
35 // Gets an id given an Aura view.
36 int32
GetID(View
* view
);
37 int32
GetID(Widget
* widget
);
38 int32
GetID(aura::Window
* window
);
40 // Gets the next unique id for this cache. Useful for non-Aura view backed
42 int32
GetNextID() { return current_id_
++; }
44 // Removes an entry from this cache based on an Aura view.
45 void Remove(View
* view
);
46 void Remove(Widget
* widget
);
47 void Remove(aura::Window
* window
);
49 // Lookup a cached entry based on an id.
50 AXAuraObjWrapper
* Get(int32 id
);
52 // Remove a cached entry based on an id.
53 void Remove(int32 id
);
55 // Indicates if this object's currently being destroyed.
56 bool is_destroying() { return is_destroying_
; }
59 friend struct DefaultSingletonTraits
<AXAuraObjCache
>;
62 virtual ~AXAuraObjCache();
64 template <typename AuraViewWrapper
, typename AuraView
>
65 AXAuraObjWrapper
* CreateInternal(
66 AuraView
* aura_view
, std::map
<AuraView
*, int32
>& aura_view_to_id_map
);
68 template<typename AuraView
> int32
GetIDInternal(
69 AuraView
* aura_view
, std::map
<AuraView
*, int32
>& aura_view_to_id_map
);
71 template<typename AuraView
> void RemoveInternal(
72 AuraView
* aura_view
, std::map
<AuraView
*, int32
>& aura_view_to_id_map
);
74 std::map
<views::View
*, int32
> view_to_id_map_
;
75 std::map
<views::Widget
*, int32
> widget_to_id_map_
;
76 std::map
<aura::Window
*, int32
> window_to_id_map_
;
78 std::map
<int32
, AXAuraObjWrapper
*> cache_
;
81 // True immediately when entering this object's destructor.
84 DISALLOW_COPY_AND_ASSIGN(AXAuraObjCache
);
89 #endif // UI_VIEWS_ACCESSIBILITY_AX_AURA_OBJ_CACHE_H_