Fix --trace-shutdown with thread-local tracing.

With thread-local tracing (r221766), TraceLog::Flush() is async and
needs to be called from a thread having a message loop. It also requires
that tracing has been stopped.

BrowserShutdownProfileDumper is a special caller that TraceLog::Flush()
was originally called from a thread without message loop.

Now start another thread for flushing, and call TraceLog::SetDisabled()
before TraceLog::Flush().

The calling thread needs to wait for the completion of the flush,
otherwise the browser may shutdown before all trace events written.
Temporarily allow the thread to wait in ThreadRestrictions.

BUG=none
TEST=manual run chrome with --trace-shutdown. Should not assert. Should generate correct trace file.

Review URL: https://chromiumcodereview.appspot.com/24047007

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


CrOS-Libchrome-Original-Commit: f9be1053de943283ec72f4dbf2e6fce78fd2fea1
diff --git a/base/debug/trace_event_impl.cc b/base/debug/trace_event_impl.cc
index 39d23dd..fd68350 100644
--- a/base/debug/trace_event_impl.cc
+++ b/base/debug/trace_event_impl.cc
@@ -1334,6 +1334,7 @@
     scoped_refptr<RefCountedString> empty_result = new RefCountedString;
     if (!cb.is_null())
       cb.Run(empty_result, false);
+    LOG(WARNING) << "Ignored TraceLog::Flush called when tracing is enabled";
     return;
   }
 
diff --git a/base/threading/thread_restrictions.h b/base/threading/thread_restrictions.h
index bc25d6a..f52e64c 100644
--- a/base/threading/thread_restrictions.h
+++ b/base/threading/thread_restrictions.h
@@ -42,6 +42,7 @@
 }
 namespace content {
 class BrowserGpuChannelHostFactory;
+class BrowserShutdownProfileDumper;
 class BrowserTestBase;
 class GLHelper;
 class GpuChannelHost;
@@ -176,6 +177,7 @@
  private:
   // DO NOT ADD ANY OTHER FRIEND STATEMENTS, talk to jam or brettw first.
   // BEGIN ALLOWED USAGE.
+  friend class content::BrowserShutdownProfileDumper;
   friend class content::BrowserTestBase;
   friend class content::NestedMessagePumpAndroid;
   friend class content::RenderWidgetHelper;