Handle account removal correctly on all platforms.
[chromium-blink-merge.git] / gpu / command_buffer / service / id_manager.cc
blobbe60d7b2cb7f9d5eb4ffe2a5ea0a623ed9592274
1 // Copyright (c) 2010 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 "gpu/command_buffer/service/id_manager.h"
6 #include "base/logging.h"
8 namespace gpu {
9 namespace gles2 {
11 IdManager::IdManager() {}
13 IdManager::~IdManager() {}
15 bool IdManager::AddMapping(GLuint client_id, GLuint service_id) {
16 std::pair<MapType::iterator, bool> result = id_map_.insert(
17 std::make_pair(client_id, service_id));
18 return result.second;
21 bool IdManager::RemoveMapping(GLuint client_id, GLuint service_id) {
22 MapType::iterator iter = id_map_.find(client_id);
23 if (iter != id_map_.end() && iter->second == service_id) {
24 id_map_.erase(iter);
25 return true;
27 return false;
30 bool IdManager::GetServiceId(GLuint client_id, GLuint* service_id) {
31 DCHECK(service_id);
32 MapType::iterator iter = id_map_.find(client_id);
33 if (iter != id_map_.end()) {
34 *service_id = iter->second;
35 return true;
37 return false;
40 bool IdManager::GetClientId(GLuint service_id, GLuint* client_id) {
41 DCHECK(client_id);
42 MapType::iterator end(id_map_.end());
43 for (MapType::iterator iter(id_map_.begin());
44 iter != end;
45 ++iter) {
46 if (iter->second == service_id) {
47 *client_id = iter->first;
48 return true;
51 return false;
54 } // namespace gles2
55 } // namespace gpu