15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef BASE_THREADING_THREAD_RESTRICTIONS_H_
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define BASE_THREADING_THREAD_RESTRICTIONS_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/base_export.h"
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/basictypes.h"
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// See comment at top of thread_checker.h
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON))
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define ENABLE_THREAD_RESTRICTIONS 1
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#else
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define ENABLE_THREAD_RESTRICTIONS 0
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class AcceleratedPresenter;
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class BrowserProcessImpl;
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class HistogramSynchronizer;
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class NativeBackendKWallet;
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ScopedAllowWaitForLegacyWebViewApi;
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class TestingAutomationProvider;
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace browser_sync {
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class NonFrontendDataTypeController;
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class UIModelWorker;
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace cc {
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class CompletionEvent;
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace chromeos {
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class AudioMixerAlsa;
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class BlockingMethodCaller;
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace system {
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class StatisticsProviderImpl;
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace chrome_browser_net {
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Predictor;
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace content {
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class BrowserGpuChannelHostFactory;
44d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)class BrowserShutdownProfileDumper;
452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class BrowserTestBase;
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class GLHelper;
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class GpuChannelHost;
4858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)class NestedMessagePumpAndroid;
49116680a4aac90f2aa7413d9095a592090648e557Ben Murdochclass RenderWidgetResizeHelper;
50eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochclass ScopedAllowWaitForAndroidLayoutTests;
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class TextInputClientMac;
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace dbus {
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Bus;
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace disk_cache {
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class BackendImpl;
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class InFlightIO;
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace media {
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class AudioOutputController;
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
631320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccinamespace metrics {
641320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciclass MetricsService;
651320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci}
665f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)namespace mojo {
675f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)namespace common {
685f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)class WatcherThreadManager;
695f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)}
705f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)}
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace net {
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class FileStreamPosix;
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class FileStreamWin;
742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace internal {
752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class AddressTrackerLinux;
762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace remoting {
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class AutoThread;
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace base {
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdochnamespace android {
86bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdochclass JavaHandlerThread;
87bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch}
88bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class SequencedWorkerPool;
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class SimpleThread;
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Thread;
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ThreadTestHelper;
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Certain behavior is disallowed on certain threads.  ThreadRestrictions helps
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// enforce these rules.  Examples of such rules:
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// * Do not do blocking IO (makes the thread janky)
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// * Do not access Singleton/LazyInstance (may lead to shutdown crashes)
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Here's more about how the protection works:
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 1) If a thread should not be allowed to make IO calls, mark it:
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//      base::ThreadRestrictions::SetIOAllowed(false);
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//    By default, threads *are* allowed to make IO calls.
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//    In Chrome browser code, IO calls should be proxied to the File thread.
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 2) If a function makes a call that will go out to disk, check whether the
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//    current thread is allowed:
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//      base::ThreadRestrictions::AssertIOAllowed();
1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Style tip: where should you put AssertIOAllowed checks?  It's best
1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// if you put them as close to the disk access as possible, at the
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// lowest level.  This rule is simple to follow and helps catch all
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// callers.  For example, if your function GoDoSomeBlockingDiskCall()
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// only calls other functions in Chrome and not fopen(), you should go
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// add the AssertIOAllowed checks in the helper functions.
1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class BASE_EXPORT ThreadRestrictions {
1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Constructing a ScopedAllowIO temporarily allows IO for the current
1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // thread.  Doing this is almost certainly always incorrect.
1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  class BASE_EXPORT ScopedAllowIO {
1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   public:
1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ScopedAllowIO() { previous_value_ = SetIOAllowed(true); }
1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ~ScopedAllowIO() { SetIOAllowed(previous_value_); }
1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   private:
1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Whether IO is allowed when the ScopedAllowIO was constructed.
1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    bool previous_value_;
1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DISALLOW_COPY_AND_ASSIGN(ScopedAllowIO);
1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Constructing a ScopedAllowSingleton temporarily allows accessing for the
1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // current thread.  Doing this is almost always incorrect.
1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  class BASE_EXPORT ScopedAllowSingleton {
1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   public:
1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ScopedAllowSingleton() { previous_value_ = SetSingletonAllowed(true); }
1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ~ScopedAllowSingleton() { SetSingletonAllowed(previous_value_); }
1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   private:
1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Whether singleton use is allowed when the ScopedAllowSingleton was
1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // constructed.
1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    bool previous_value_;
1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DISALLOW_COPY_AND_ASSIGN(ScopedAllowSingleton);
1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if ENABLE_THREAD_RESTRICTIONS
1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Set whether the current thread to make IO calls.
1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Threads start out in the *allowed* state.
1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the previous value.
1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool SetIOAllowed(bool allowed);
1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Check whether the current thread is allowed to make IO calls,
1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // and DCHECK if not.  See the block comment above the class for
1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // a discussion of where to add these checks.
1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static void AssertIOAllowed();
1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Set whether the current thread can use singletons.  Returns the previous
1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // value.
1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool SetSingletonAllowed(bool allowed);
1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Check whether the current thread is allowed to use singletons (Singleton /
1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // LazyInstance).  DCHECKs if not.
1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static void AssertSingletonAllowed();
1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Disable waiting on the current thread. Threads start out in the *allowed*
1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // state. Returns the previous value.
1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static void DisallowWaiting();
1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Check whether the current thread is allowed to wait, and DCHECK if not.
1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static void AssertWaitAllowed();
1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#else
1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Inline the empty definitions of these functions so that they can be
1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // compiled out.
1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool SetIOAllowed(bool allowed) { return true; }
1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static void AssertIOAllowed() {}
1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool SetSingletonAllowed(bool allowed) { return true; }
1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static void AssertSingletonAllowed() {}
1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static void DisallowWaiting() {}
1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static void AssertWaitAllowed() {}
1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // DO NOT ADD ANY OTHER FRIEND STATEMENTS, talk to jam or brettw first.
1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // BEGIN ALLOWED USAGE.
187d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  friend class content::BrowserShutdownProfileDumper;
1882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  friend class content::BrowserTestBase;
18958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  friend class content::NestedMessagePumpAndroid;
190116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  friend class content::RenderWidgetResizeHelper;
191eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  friend class content::ScopedAllowWaitForAndroidLayoutTests;
1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class ::HistogramSynchronizer;
1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class ::ScopedAllowWaitForLegacyWebViewApi;
1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class ::TestingAutomationProvider;
1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class cc::CompletionEvent;
1965f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  friend class mojo::common::WatcherThreadManager;
1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class remoting::AutoThread;
1982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  friend class MessagePumpDefault;
1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class SequencedWorkerPool;
2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class SimpleThread;
2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class Thread;
2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class ThreadTestHelper;
20390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  friend class PlatformThread;
204bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch  friend class android::JavaHandlerThread;
2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // END ALLOWED USAGE.
2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // BEGIN USAGE THAT NEEDS TO BE FIXED.
2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class ::chromeos::AudioMixerAlsa;        // http://crbug.com/125206
2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class ::chromeos::BlockingMethodCaller;  // http://crbug.com/125360
2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class ::chromeos::system::StatisticsProviderImpl;  // http://crbug.com/125385
2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class browser_sync::NonFrontendDataTypeController;  // http://crbug.com/19757
2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class browser_sync::UIModelWorker;       // http://crbug.com/19757
2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class chrome_browser_net::Predictor;     // http://crbug.com/78451
2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class
2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      content::BrowserGpuChannelHostFactory;      // http://crbug.com/125248
2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class content::GLHelper;                 // http://crbug.com/125415
2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class content::GpuChannelHost;           // http://crbug.com/125264
2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class content::TextInputClientMac;       // http://crbug.com/121917
2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class dbus::Bus;                         // http://crbug.com/125222
2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class disk_cache::BackendImpl;           // http://crbug.com/74623
2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class disk_cache::InFlightIO;            // http://crbug.com/74623
2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class media::AudioOutputController;      // http://crbug.com/120973
2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class net::FileStreamPosix;              // http://crbug.com/115067
2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class net::FileStreamWin;                // http://crbug.com/115067
2252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  friend class net::internal::AddressTrackerLinux;  // http://crbug.com/125097
2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class ::AcceleratedPresenter;            // http://crbug.com/125391
2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class ::BrowserProcessImpl;              // http://crbug.com/125207
2281320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  friend class metrics::MetricsService;           // http://crbug.com/124954
2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class ::NativeBackendKWallet;            // http://crbug.com/125331
2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // END USAGE THAT NEEDS TO BE FIXED.
2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if ENABLE_THREAD_RESTRICTIONS
2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool SetWaitAllowed(bool allowed);
2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#else
2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool SetWaitAllowed(bool allowed) { return true; }
2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Constructing a ScopedAllowWait temporarily allows waiting on the current
2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // thread.  Doing this is almost always incorrect, which is why we limit who
2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // can use this through friend. If you find yourself needing to use this, find
2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // another way. Talk to jam or brettw.
2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  class BASE_EXPORT ScopedAllowWait {
2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   public:
2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ScopedAllowWait() { previous_value_ = SetWaitAllowed(true); }
2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ~ScopedAllowWait() { SetWaitAllowed(previous_value_); }
2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   private:
2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Whether singleton use is allowed when the ScopedAllowWait was
2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // constructed.
2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    bool previous_value_;
2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DISALLOW_COPY_AND_ASSIGN(ScopedAllowWait);
2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DISALLOW_IMPLICIT_CONSTRUCTORS(ThreadRestrictions);
2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace base
2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // BASE_THREADING_THREAD_RESTRICTIONS_H_
260