Give names to all utility processes.
[chromium-blink-merge.git] / chrome / browser / accessibility / ax_tree_id_registry.cc
blob4314ea415076b6ab6c6e245a2e99805e43db4cd6
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 "chrome/browser/accessibility/ax_tree_id_registry.h"
7 #include "base/memory/singleton.h"
9 // static
10 AXTreeIDRegistry* AXTreeIDRegistry::GetInstance() {
11 return Singleton<AXTreeIDRegistry>::get();
14 int AXTreeIDRegistry::GetOrCreateAXTreeID(int process_id, int routing_id) {
15 FrameID frame_id(process_id, routing_id);
16 std::map<FrameID, AXTreeID>::iterator it;
17 it = frame_to_ax_tree_id_map_.find(frame_id);
18 if (it != frame_to_ax_tree_id_map_.end())
19 return it->second;
21 int new_id = ++ax_tree_id_counter_;
22 frame_to_ax_tree_id_map_[frame_id] = new_id;
23 ax_tree_to_frame_id_map_[new_id] = frame_id;
25 return new_id;
28 AXTreeIDRegistry::FrameID AXTreeIDRegistry::GetFrameID(int ax_tree_id) {
29 std::map<AXTreeID, FrameID>::iterator it;
30 it = ax_tree_to_frame_id_map_.find(ax_tree_id);
31 if (it != ax_tree_to_frame_id_map_.end())
32 return it->second;
34 return FrameID(-1, -1);
37 void AXTreeIDRegistry::RemoveAXTreeID(int ax_tree_id) {
38 std::map<AXTreeID, FrameID>::iterator it;
39 it = ax_tree_to_frame_id_map_.find(ax_tree_id);
40 if (it != ax_tree_to_frame_id_map_.end()) {
41 frame_to_ax_tree_id_map_.erase(it->second);
42 ax_tree_to_frame_id_map_.erase(it);
46 AXTreeIDRegistry::AXTreeIDRegistry() : ax_tree_id_counter_(-1) {
47 // Always populate default desktop tree value (0 -> 0, 0).
48 GetOrCreateAXTreeID(0, 0);
51 AXTreeIDRegistry::~AXTreeIDRegistry() {