Roll src/third_party/WebKit f298044:aa8346d (svn 202628:202629)
[chromium-blink-merge.git] / content / browser / accessibility / ax_tree_id_registry.cc
blob1b167e7e7db1af72853e613f1c1cb2c252f31864
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 #include "content/browser/accessibility/ax_tree_id_registry.h"
7 #include "base/memory/singleton.h"
9 namespace content {
11 // static
12 const AXTreeIDRegistry::AXTreeID AXTreeIDRegistry::kNoAXTreeID = -1;
14 // static
15 AXTreeIDRegistry* AXTreeIDRegistry::GetInstance() {
16 return base::Singleton<AXTreeIDRegistry>::get();
19 AXTreeIDRegistry::AXTreeID AXTreeIDRegistry::GetOrCreateAXTreeID(
20 int process_id, int routing_id) {
21 FrameID frame_id(process_id, routing_id);
22 std::map<FrameID, AXTreeID>::iterator it;
23 it = frame_to_ax_tree_id_map_.find(frame_id);
24 if (it != frame_to_ax_tree_id_map_.end())
25 return it->second;
27 AXTreeID new_id = ++ax_tree_id_counter_;
28 frame_to_ax_tree_id_map_[frame_id] = new_id;
29 ax_tree_to_frame_id_map_[new_id] = frame_id;
31 return new_id;
34 AXTreeIDRegistry::FrameID AXTreeIDRegistry::GetFrameID(
35 AXTreeIDRegistry::AXTreeID ax_tree_id) {
36 std::map<AXTreeID, FrameID>::iterator it;
37 it = ax_tree_to_frame_id_map_.find(ax_tree_id);
38 if (it != ax_tree_to_frame_id_map_.end())
39 return it->second;
41 return FrameID(-1, -1);
44 void AXTreeIDRegistry::RemoveAXTreeID(AXTreeIDRegistry::AXTreeID ax_tree_id) {
45 std::map<AXTreeID, FrameID>::iterator it;
46 it = ax_tree_to_frame_id_map_.find(ax_tree_id);
47 if (it != ax_tree_to_frame_id_map_.end()) {
48 frame_to_ax_tree_id_map_.erase(it->second);
49 ax_tree_to_frame_id_map_.erase(it);
53 AXTreeIDRegistry::AXTreeIDRegistry() : ax_tree_id_counter_(-1) {
54 // Always populate default desktop tree value (0 -> 0, 0).
55 GetOrCreateAXTreeID(0, 0);
58 AXTreeIDRegistry::~AXTreeIDRegistry() {
61 } // namespace content