Move thread local stuff from base to base/threading and consistently use the
base namespace. This also fixes references to TLSSlot to
base::ThreadLocalStorage::Slot.

TEST=it compiles
BUG=none
Review URL: http://codereview.chromium.org/5986012

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@70322 0039d316-1c4b-4281-b951-d872f2087c98


CrOS-Libchrome-Original-Commit: 1357c32474af4190d22ccca26bf414443252784b
diff --git a/base/base.gyp b/base/base.gyp
index 7637284..1c82964 100644
--- a/base/base.gyp
+++ b/base/base.gyp
@@ -141,13 +141,13 @@
         'task_queue_unittest.cc',
         'task_unittest.cc',
         'threading/simple_thread_unittest.cc',
+        'threading/thread_local_storage_unittest.cc',
+        'threading/thread_local_unittest.cc',
         'threading/watchdog_unittest.cc',
         'threading/worker_pool_posix_unittest.cc',
         'threading/worker_pool_unittest.cc',
         'thread_checker_unittest.cc',
         'thread_collision_warner_unittest.cc',
-        'thread_local_storage_unittest.cc',
-        'thread_local_unittest.cc',
         'thread_unittest.cc',
         'time_unittest.cc',
         'time_win_unittest.cc',
diff --git a/base/base.gypi b/base/base.gypi
index e969149..7b6d50b 100644
--- a/base/base.gypi
+++ b/base/base.gypi
@@ -245,6 +245,12 @@
           'template_util.h',
           'threading/simple_thread.cc',
           'threading/simple_thread.h',
+          'threading/thread_local.h',
+          'threading/thread_local_posix.cc',
+          'threading/thread_local_storage.h',
+          'threading/thread_local_storage_posix.cc',
+          'threading/thread_local_storage_win.cc',
+          'threading/thread_local_win.cc',
           'threading/watchdog.cc',
           'threading/watchdog.h',
           'threading/worker_pool.h',
@@ -257,12 +263,6 @@
           'thread_checker.h',
           'thread_collision_warner.cc',
           'thread_collision_warner.h',
-          'thread_local.h',
-          'thread_local_posix.cc',
-          'thread_local_storage.h',
-          'thread_local_storage_posix.cc',
-          'thread_local_storage_win.cc',
-          'thread_local_win.cc',
           'thread_restrictions.h',
           'thread_restrictions.cc',
           'time.cc',
diff --git a/base/message_loop.cc b/base/message_loop.cc
index 49d76a0..0e0572a 100644
--- a/base/message_loop.cc
+++ b/base/message_loop.cc
@@ -11,7 +11,7 @@
 #include "base/logging.h"
 #include "base/message_pump_default.h"
 #include "base/metrics/histogram.h"
-#include "base/thread_local.h"
+#include "base/threading/thread_local.h"
 
 #if defined(OS_MACOSX)
 #include "base/message_pump_mac.h"
diff --git a/base/metrics/stats_table.cc b/base/metrics/stats_table.cc
index 82d6a25..a5e85c9 100644
--- a/base/metrics/stats_table.cc
+++ b/base/metrics/stats_table.cc
@@ -11,7 +11,7 @@
 #include "base/shared_memory.h"
 #include "base/string_piece.h"
 #include "base/string_util.h"
-#include "base/thread_local_storage.h"
+#include "base/threading/thread_local_storage.h"
 #include "base/utf_string_conversions.h"
 
 #if defined(OS_POSIX)
diff --git a/base/metrics/stats_table.h b/base/metrics/stats_table.h
index e83039c..2a4f266 100644
--- a/base/metrics/stats_table.h
+++ b/base/metrics/stats_table.h
@@ -26,7 +26,7 @@
 #include "base/basictypes.h"
 #include "base/hash_tables.h"
 #include "base/lock.h"
-#include "base/thread_local_storage.h"
+#include "base/threading/thread_local_storage.h"
 
 namespace base {
 
@@ -184,7 +184,7 @@
   // we don't have a counter in our hash table, another process may
   // have created it.
   CountersMap counters_;
-  TLSSlot tls_index_;
+  ThreadLocalStorage::Slot tls_index_;
 
   static StatsTable* global_table_;
 
diff --git a/base/thread.cc b/base/thread.cc
index bc715f0..3b170ef 100644
--- a/base/thread.cc
+++ b/base/thread.cc
@@ -6,7 +6,7 @@
 
 #include "base/lazy_instance.h"
 #include "base/third_party/dynamic_annotations/dynamic_annotations.h"
-#include "base/thread_local.h"
+#include "base/threading/thread_local.h"
 #include "base/waitable_event.h"
 
 namespace base {
diff --git a/base/thread_restrictions.cc b/base/thread_restrictions.cc
index 6767d80..6a7c60a 100644
--- a/base/thread_restrictions.cc
+++ b/base/thread_restrictions.cc
@@ -9,7 +9,7 @@
 
 #include "base/lazy_instance.h"
 #include "base/logging.h"
-#include "base/thread_local.h"
+#include "base/threading/thread_local.h"
 
 namespace base {
 
diff --git a/base/thread_local.h b/base/threading/thread_local.h
similarity index 96%
rename from base/thread_local.h
rename to base/threading/thread_local.h
index eba48d2..069543f 100644
--- a/base/thread_local.h
+++ b/base/threading/thread_local.h
@@ -45,8 +45,8 @@
 //     return Singleton<ThreadLocalPointer<MyClass> >::get()->Get();
 //   }
 
-#ifndef BASE_THREAD_LOCAL_H_
-#define BASE_THREAD_LOCAL_H_
+#ifndef BASE_THREADING_THREAD_LOCAL_H_
+#define BASE_THREADING_THREAD_LOCAL_H_
 #pragma once
 
 #include "base/basictypes.h"
@@ -124,4 +124,4 @@
 
 }  // namespace base
 
-#endif  // BASE_THREAD_LOCAL_H_
+#endif  // BASE_THREADING_THREAD_LOCAL_H_
diff --git a/base/thread_local_posix.cc b/base/threading/thread_local_posix.cc
similarity index 87%
rename from base/thread_local_posix.cc
rename to base/threading/thread_local_posix.cc
index 4d03403..568fa4b 100644
--- a/base/thread_local_posix.cc
+++ b/base/threading/thread_local_posix.cc
@@ -1,8 +1,8 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "base/thread_local.h"
+#include "base/threading/thread_local.h"
 
 #include <pthread.h>
 
diff --git a/base/thread_local_storage.h b/base/threading/thread_local_storage.h
similarity index 91%
rename from base/thread_local_storage.h
rename to base/threading/thread_local_storage.h
index b37a53c..204b653 100644
--- a/base/thread_local_storage.h
+++ b/base/threading/thread_local_storage.h
@@ -2,8 +2,8 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#ifndef BASE_THREAD_LOCAL_STORAGE_H_
-#define BASE_THREAD_LOCAL_STORAGE_H_
+#ifndef BASE_THREADING_THREAD_LOCAL_STORAGE_H_
+#define BASE_THREADING_THREAD_LOCAL_STORAGE_H_
 #pragma once
 
 #include "base/basictypes.h"
@@ -12,6 +12,8 @@
 #include <pthread.h>
 #endif
 
+namespace base {
+
 // Wrapper for thread local storage.  This class doesn't do much except provide
 // an API for portability.
 class ThreadLocalStorage {
@@ -88,8 +90,6 @@
   DISALLOW_COPY_AND_ASSIGN(ThreadLocalStorage);
 };
 
-// Temporary backwards-compatible name.
-// TODO(evanm): replace all usage of TLSSlot.
-typedef ThreadLocalStorage::Slot TLSSlot;
+}  // namespace base
 
-#endif  // BASE_THREAD_LOCAL_STORAGE_H_
+#endif  // BASE_THREADING_THREAD_LOCAL_STORAGE_H_
diff --git a/base/thread_local_storage_posix.cc b/base/threading/thread_local_storage_posix.cc
similarity index 85%
rename from base/thread_local_storage_posix.cc
rename to base/threading/thread_local_storage_posix.cc
index eac74fd..81b7332 100644
--- a/base/thread_local_storage_posix.cc
+++ b/base/threading/thread_local_storage_posix.cc
@@ -1,11 +1,13 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "base/thread_local_storage.h"
+#include "base/threading/thread_local_storage.h"
 
 #include "base/logging.h"
 
+namespace base {
+
 ThreadLocalStorage::Slot::Slot(TLSDestructorFunc destructor)
     : initialized_(false) {
   Initialize(destructor);
@@ -42,3 +44,5 @@
   if (error)
     NOTREACHED();
 }
+
+}  // namespace base
diff --git a/base/thread_local_storage_unittest.cc b/base/threading/thread_local_storage_unittest.cc
similarity index 82%
rename from base/thread_local_storage_unittest.cc
rename to base/threading/thread_local_storage_unittest.cc
index dc82c53..216e650 100644
--- a/base/thread_local_storage_unittest.cc
+++ b/base/threading/thread_local_storage_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
@@ -8,7 +8,7 @@
 #endif
 
 #include "base/threading/simple_thread.h"
-#include "base/thread_local_storage.h"
+#include "base/threading/thread_local_storage.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
 #if defined(OS_WIN)
@@ -17,11 +17,14 @@
 #pragma warning(disable : 4311 4312)
 #endif
 
+namespace base {
+
+namespace {
+
 const int kInitialTlsValue = 0x5555;
-static ThreadLocalStorage::Slot tls_slot(base::LINKER_INITIALIZED);
+static ThreadLocalStorage::Slot tls_slot(LINKER_INITIALIZED);
 
-
-class ThreadLocalStorageRunner : public base::DelegateSimpleThread::Delegate {
+class ThreadLocalStorageRunner : public DelegateSimpleThread::Delegate {
  public:
   explicit ThreadLocalStorageRunner(int* tls_value_ptr)
       : tls_value_ptr_(tls_value_ptr) {}
@@ -54,6 +57,7 @@
     *ptr = kInitialTlsValue;
 }
 
+}  // namespace
 
 TEST(ThreadLocalStorageTest, Basics) {
   ThreadLocalStorage::Slot slot;
@@ -69,7 +73,7 @@
   const int kNumThreads = 5;
   int values[kNumThreads];
   ThreadLocalStorageRunner* thread_delegates[kNumThreads];
-  base::DelegateSimpleThread* threads[kNumThreads];
+  DelegateSimpleThread* threads[kNumThreads];
 
   tls_slot.Initialize(ThreadLocalStorageCleanup);
 
@@ -77,8 +81,8 @@
   for (int index = 0; index < kNumThreads; index++) {
     values[index] = kInitialTlsValue;
     thread_delegates[index] = new ThreadLocalStorageRunner(&values[index]);
-    threads[index] = new base::DelegateSimpleThread(thread_delegates[index],
-                                                    "tls thread");
+    threads[index] = new DelegateSimpleThread(thread_delegates[index],
+                                              "tls thread");
     threads[index]->Start();
   }
 
@@ -92,3 +96,5 @@
     EXPECT_EQ(values[index], kInitialTlsValue);
   }
 }
+
+}  // namespace base
diff --git a/base/thread_local_unittest.cc b/base/threading/thread_local_unittest.cc
similarity index 97%
rename from base/thread_local_unittest.cc
rename to base/threading/thread_local_unittest.cc
index a155ca2..f6bdd78 100644
--- a/base/thread_local_unittest.cc
+++ b/base/threading/thread_local_unittest.cc
@@ -4,10 +4,12 @@
 
 #include "base/logging.h"
 #include "base/threading/simple_thread.h"
-#include "base/thread_local.h"
+#include "base/threading/thread_local.h"
 #include "base/waitable_event.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
+namespace base {
+
 namespace {
 
 class ThreadLocalTesterBase : public base::DelegateSimpleThreadPool::Delegate {
@@ -157,3 +159,5 @@
     EXPECT_FALSE(tlb.Get());
   }
 }
+
+}  // namespace base
diff --git a/base/tracked_objects.cc b/base/tracked_objects.cc
index 9db25ff..1d04b12 100644
--- a/base/tracked_objects.cc
+++ b/base/tracked_objects.cc
@@ -18,7 +18,7 @@
 
 // A TLS slot to the TrackRegistry for the current thread.
 // static
-TLSSlot ThreadData::tls_index_(base::LINKER_INITIALIZED);
+base::ThreadLocalStorage::Slot ThreadData::tls_index_(base::LINKER_INITIALIZED);
 
 // A global state variable to prevent repeated initialization during tests.
 // static
diff --git a/base/tracked_objects.h b/base/tracked_objects.h
index 8590a8c..3fe2837 100644
--- a/base/tracked_objects.h
+++ b/base/tracked_objects.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
@@ -11,8 +11,8 @@
 #include <vector>
 
 #include "base/lock.h"
-#include "base/thread_local_storage.h"
 #include "base/tracked.h"
+#include "base/threading/thread_local_storage.h"
 
 // TrackedObjects provides a database of stats about objects (generally Tasks)
 // that are tracked.  Tracking means their birth, death, duration, birth thread,
@@ -571,7 +571,7 @@
   static void ShutdownDisablingFurtherTracking();
 
   // We use thread local store to identify which ThreadData to interact with.
-  static TLSSlot tls_index_;
+  static base::ThreadLocalStorage::Slot tls_index_;
 
   // Link to the most recently created instance (starts a null terminated list).
   static ThreadData* first_;
diff --git a/ipc/ipc_sync_channel.cc b/ipc/ipc_sync_channel.cc
index 79b1e60..1382cf5 100644
--- a/ipc/ipc_sync_channel.cc
+++ b/ipc/ipc_sync_channel.cc
@@ -6,8 +6,8 @@
 
 #include "base/lazy_instance.h"
 #include "base/logging.h"
-#include "base/thread_local.h"
 #include "base/message_loop.h"
+#include "base/threading/thread_local.h"
 #include "base/waitable_event.h"
 #include "base/waitable_event_watcher.h"
 #include "ipc/ipc_sync_message.h"