Rebase webrtc/base 6129:6163 (svn diff -r 6129:6163 http://webrtc.googlecode.com/svn/trunk/talk/base apply diff manually)

BUG=N/A
R=andrew@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/15519004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@6175 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/webrtc/base/cpumonitor.cc b/webrtc/base/cpumonitor.cc
index f5c0d06..c881b48 100644
--- a/webrtc/base/cpumonitor.cc
+++ b/webrtc/base/cpumonitor.cc
@@ -31,6 +31,7 @@
 #if defined(WEBRTC_MAC)
 #include <mach/mach_host.h>
 #include <mach/mach_init.h>
+#include <mach/mach_port.h>
 #include <mach/host_info.h>
 #include <mach/task.h>
 #endif  // defined(WEBRTC_MAC)
@@ -224,11 +225,14 @@
 #endif  // WEBRTC_WIN 
 
 #if defined(WEBRTC_MAC)
+  mach_port_t mach_host = mach_host_self();
   host_cpu_load_info_data_t cpu_info;
   mach_msg_type_number_t info_count = HOST_CPU_LOAD_INFO_COUNT;
-  if (KERN_SUCCESS != host_statistics(mach_host_self(), HOST_CPU_LOAD_INFO,
-                                      reinterpret_cast<host_info_t>(&cpu_info),
-                                      &info_count)) {
+  kern_return_t kr = host_statistics(mach_host, HOST_CPU_LOAD_INFO,
+                                     reinterpret_cast<host_info_t>(&cpu_info),
+                                     &info_count);
+  mach_port_deallocate(mach_task_self(), mach_host);
+  if (KERN_SUCCESS != kr) {
     LOG(LS_ERROR) << "::host_statistics() failed";
     return 0.f;
   }
diff --git a/webrtc/base/gunit.h b/webrtc/base/gunit.h
index 9766c2c..6d9c06f 100644
--- a/webrtc/base/gunit.h
+++ b/webrtc/base/gunit.h
@@ -19,11 +19,6 @@
 #include "testing/base/public/gunit.h"
 #endif
 
-// forward declarations
-namespace rtc {
-class Pathname;
-}
-
 // Wait until "ex" is true, or "timeout" expires.
 #define WAIT(ex, timeout) \
   for (uint32 start = rtc::Time(); \
@@ -90,6 +85,4 @@
     } \
   } while (0);
 
-rtc::Pathname GetTalkDirectory();
-
 #endif  // WEBRTC_BASE_GUNIT_H_
diff --git a/webrtc/base/testutils.h b/webrtc/base/testutils.h
index a148d91..74fed45 100644
--- a/webrtc/base/testutils.h
+++ b/webrtc/base/testutils.h
@@ -28,6 +28,7 @@
 #include "webrtc/base/common.h"
 #include "webrtc/base/gunit.h"
 #include "webrtc/base/nethelpers.h"
+#include "webrtc/base/pathutils.h"
 #include "webrtc/base/stream.h"
 #include "webrtc/base/stringencode.h"
 #include "webrtc/base/stringutils.h"
@@ -434,6 +435,30 @@
   return success;
 }
 
+// Look in parent dir for parallel directory.
+inline rtc::Pathname GetSiblingDirectory(
+    const std::string& parallel_dir) {
+  rtc::Pathname path = rtc::Filesystem::GetCurrentDirectory();
+  while (!path.empty()) {
+    rtc::Pathname potential_parallel_dir = path;
+    potential_parallel_dir.AppendFolder(parallel_dir);
+    if (rtc::Filesystem::IsFolder(potential_parallel_dir)) {
+      return potential_parallel_dir;
+    }
+
+    path.SetFolder(path.parent_folder());
+  }
+  return path;
+}
+
+inline rtc::Pathname GetGoogle3Directory() {
+  return GetSiblingDirectory("google3");
+}
+
+inline rtc::Pathname GetTalkDirectory() {
+  return GetSiblingDirectory("talk");
+}
+
 ///////////////////////////////////////////////////////////////////////////////
 // Unittest predicates which are similar to STREQ, but for raw memory
 ///////////////////////////////////////////////////////////////////////////////
diff --git a/webrtc/base/unittest_main.cc b/webrtc/base/unittest_main.cc
index 7c4630e..5d412d5 100644
--- a/webrtc/base/unittest_main.cc
+++ b/webrtc/base/unittest_main.cc
@@ -18,7 +18,6 @@
 #include "webrtc/base/fileutils.h"
 #include "webrtc/base/gunit.h"
 #include "webrtc/base/logging.h"
-#include "webrtc/base/pathutils.h"
 
 DEFINE_bool(help, false, "prints this message");
 DEFINE_string(log, "", "logging options to use");
@@ -53,28 +52,6 @@
 }
 #endif  // WEBRTC_WIN 
 
-rtc::Pathname GetTalkDirectory() {
-  // Locate talk directory.
-  rtc::Pathname path = rtc::Filesystem::GetCurrentDirectory();
-  std::string talk_folder_name("talk");
-  talk_folder_name += path.folder_delimiter();
-  while (path.folder_name() != talk_folder_name && !path.empty()) {
-    path.SetFolder(path.parent_folder());
-  }
-
-  // If not running inside "talk" folder, then assume running in its parent
-  // folder.
-  if (path.empty()) {
-    path = rtc::Filesystem::GetCurrentDirectory();
-    path.AppendFolder("talk");
-    // Make sure the folder exist.
-    if (!rtc::Filesystem::IsFolder(path)) {
-      path.clear();
-    }
-  }
-  return path;
-}
-
 int main(int argc, char** argv) {
   testing::InitGoogleTest(&argc, argv);
   rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, false);