Disable the new avatar menu in a test.
[chromium-blink-merge.git] / base / threading / thread_id_name_manager.h
blob0ea59df6572cfcdf03c68fe8dac06c0792a51c2f
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
3 // found in the LICENSE file.
5 #ifndef BASE_THREADING_THREAD_ID_NAME_MANAGER_H_
6 #define BASE_THREADING_THREAD_ID_NAME_MANAGER_H_
8 #include <map>
9 #include <string>
11 #include "base/base_export.h"
12 #include "base/basictypes.h"
13 #include "base/synchronization/lock.h"
14 #include "base/threading/platform_thread.h"
16 template <typename T> struct DefaultSingletonTraits;
18 namespace base {
20 class BASE_EXPORT ThreadIdNameManager {
21 public:
22 static ThreadIdNameManager* GetInstance();
24 static const char* GetDefaultInternedString();
26 // Register the mapping between a thread |id| and |handle|.
27 void RegisterThread(PlatformThreadHandle::Handle handle, PlatformThreadId id);
29 // Set the name for the given id.
30 void SetName(PlatformThreadId id, const char* name);
32 // Get the name for the given id.
33 const char* GetName(PlatformThreadId id);
35 // Remove the name for the given id.
36 void RemoveName(PlatformThreadHandle::Handle handle, PlatformThreadId id);
38 private:
39 friend struct DefaultSingletonTraits<ThreadIdNameManager>;
41 typedef std::map<PlatformThreadId, PlatformThreadHandle::Handle>
42 ThreadIdToHandleMap;
43 typedef std::map<PlatformThreadHandle::Handle, std::string*>
44 ThreadHandleToInternedNameMap;
45 typedef std::map<std::string, std::string*> NameToInternedNameMap;
47 ThreadIdNameManager();
48 ~ThreadIdNameManager();
50 // lock_ protects the name_to_interned_name_, thread_id_to_handle_ and
51 // thread_handle_to_interned_name_ maps.
52 Lock lock_;
54 NameToInternedNameMap name_to_interned_name_;
55 ThreadIdToHandleMap thread_id_to_handle_;
56 ThreadHandleToInternedNameMap thread_handle_to_interned_name_;
58 // Treat the main process specially as there is no PlatformThreadHandle.
59 std::string* main_process_name_;
60 PlatformThreadId main_process_id_;
62 DISALLOW_COPY_AND_ASSIGN(ThreadIdNameManager);
65 } // namespace base
67 #endif // BASE_THREADING_THREAD_ID_NAME_MANAGER_H_