summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ppapi/shared_impl/ppapi_permissions.cc60
-rw-r--r--ppapi/shared_impl/ppapi_permissions.h90
-rw-r--r--ppapi/utility/completion_callback_factory_thread_traits.h356
-rw-r--r--ppapi/utility/threading/lock.cc98
-rw-r--r--ppapi/utility/threading/lock.h168
5 files changed, 386 insertions, 386 deletions
diff --git a/ppapi/shared_impl/ppapi_permissions.cc b/ppapi/shared_impl/ppapi_permissions.cc
index bcfdd96..987fd89 100644
--- a/ppapi/shared_impl/ppapi_permissions.cc
+++ b/ppapi/shared_impl/ppapi_permissions.cc
@@ -1,30 +1,30 @@
-// Copyright (c) 2012 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 "ppapi/shared_impl/ppapi_permissions.h"
-
-#include "base/logging.h"
-
-namespace ppapi {
-
-PpapiPermissions::PpapiPermissions() : permissions_(0) {
-}
-
-PpapiPermissions::PpapiPermissions(uint32 perms) : permissions_(perms) {
-}
-
-PpapiPermissions::~PpapiPermissions() {
-}
-
-bool PpapiPermissions::HasPermission(Permission perm) const {
- // Check that "perm" is a power of two to make sure the caller didn't set
- // more than one permission bit. We may want to change how permissions are
- // represented in the future so don't want callers making assumptions about
- // bits.
- uint32 perm_int = static_cast<uint32>(perm);
- DCHECK((perm_int & (perm_int - 1)) == 0);
- return !!(permissions_ & perm_int);
-}
-
-} // namespace ppapi
+// Copyright (c) 2012 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 "ppapi/shared_impl/ppapi_permissions.h"
+
+#include "base/logging.h"
+
+namespace ppapi {
+
+PpapiPermissions::PpapiPermissions() : permissions_(0) {
+}
+
+PpapiPermissions::PpapiPermissions(uint32 perms) : permissions_(perms) {
+}
+
+PpapiPermissions::~PpapiPermissions() {
+}
+
+bool PpapiPermissions::HasPermission(Permission perm) const {
+ // Check that "perm" is a power of two to make sure the caller didn't set
+ // more than one permission bit. We may want to change how permissions are
+ // represented in the future so don't want callers making assumptions about
+ // bits.
+ uint32 perm_int = static_cast<uint32>(perm);
+ DCHECK((perm_int & (perm_int - 1)) == 0);
+ return !!(permissions_ & perm_int);
+}
+
+} // namespace ppapi
diff --git a/ppapi/shared_impl/ppapi_permissions.h b/ppapi/shared_impl/ppapi_permissions.h
index 3caa65d..94db0e6 100644
--- a/ppapi/shared_impl/ppapi_permissions.h
+++ b/ppapi/shared_impl/ppapi_permissions.h
@@ -1,45 +1,45 @@
-// Copyright (c) 2012 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.
-
-#ifndef PPAPI_SHARED_IMPL_PPAPI_PERMISSIONS_H_
-#define PPAPI_SHARED_IMPL_PPAPI_PERMISSIONS_H_
-
-#include "base/basictypes.h"
-#include "ppapi/shared_impl/ppapi_shared_export.h"
-
-namespace ppapi {
-
-enum Permission {
- // Allows access to dev interfaces.
- PERMISSION_DEV = 1 << 0,
-
- // Allows access to Browser-internal interfaces.
- PERMISSION_PRIVATE = 1 << 2,
-
- // Allows ability to bypass user-gesture checks for showing things like
- // file select dialogs.
- PERMISSION_BYPASS_USER_GESTURE = 1 << 3
-};
-
-class PPAPI_SHARED_EXPORT PpapiPermissions {
- public:
- // Initializes the permissions struct with no permissions.
- PpapiPermissions();
-
- // Initializes with the given permissions bits set.
- explicit PpapiPermissions(uint32 perms);
-
- ~PpapiPermissions();
-
- bool HasPermission(Permission perm) const;
-
- private:
- uint32 permissions_;
-
- // Note: Copy & assign supported.
-};
-
-} // namespace ppapi
-
-#endif // PPAPI_SHARED_IMPL_PPAPI_PERMISSIONS_H_
+// Copyright (c) 2012 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.
+
+#ifndef PPAPI_SHARED_IMPL_PPAPI_PERMISSIONS_H_
+#define PPAPI_SHARED_IMPL_PPAPI_PERMISSIONS_H_
+
+#include "base/basictypes.h"
+#include "ppapi/shared_impl/ppapi_shared_export.h"
+
+namespace ppapi {
+
+enum Permission {
+ // Allows access to dev interfaces.
+ PERMISSION_DEV = 1 << 0,
+
+ // Allows access to Browser-internal interfaces.
+ PERMISSION_PRIVATE = 1 << 2,
+
+ // Allows ability to bypass user-gesture checks for showing things like
+ // file select dialogs.
+ PERMISSION_BYPASS_USER_GESTURE = 1 << 3
+};
+
+class PPAPI_SHARED_EXPORT PpapiPermissions {
+ public:
+ // Initializes the permissions struct with no permissions.
+ PpapiPermissions();
+
+ // Initializes with the given permissions bits set.
+ explicit PpapiPermissions(uint32 perms);
+
+ ~PpapiPermissions();
+
+ bool HasPermission(Permission perm) const;
+
+ private:
+ uint32 permissions_;
+
+ // Note: Copy & assign supported.
+};
+
+} // namespace ppapi
+
+#endif // PPAPI_SHARED_IMPL_PPAPI_PERMISSIONS_H_
diff --git a/ppapi/utility/completion_callback_factory_thread_traits.h b/ppapi/utility/completion_callback_factory_thread_traits.h
index 2242b5c..cda3dc0 100644
--- a/ppapi/utility/completion_callback_factory_thread_traits.h
+++ b/ppapi/utility/completion_callback_factory_thread_traits.h
@@ -1,178 +1,178 @@
-// Copyright (c) 2012 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.
-
-#ifndef PPAPI_UTILITY_THREAD_SAFE_THREAD_TRAITS_H_
-#define PPAPI_UTILITY_THREAD_SAFE_THREAD_TRAITS_H_
-
-#include "ppapi/cpp/logging.h"
-#include "ppapi/cpp/module.h"
-#include "ppapi/utility/threading/lock.h"
-
-/// @file
-/// Defines the traits structures for thread-safety of a completion callback
-/// factory. We provide thread-safe and non-thread-safe version. The thread-safe
-/// version is always correct (if you follow the thread usage rules of the
-/// callback factory), but if you know your object will only be used on one
-/// thread, you can uses the non-thread-safe version.
-///
-/// The traits defines three nested classes to perform reference counting,
-/// locks, and scoped locking.
-
-namespace pp {
-
-/// The thread-safe version of thread traits. Using this class as the "traits"
-/// template argument to a completion callback factory will make it "somewhat
-/// thread-friendly." It will allow you to create completion callbacks from
-/// background threads and post them to another thread to run.
-///
-/// Care still must be taken to ensure that the completion callbacks are
-/// executed on the same thread that the factory is destroyed on to avoid a
-/// race on destruction.
-///
-/// Implementation note: this uses a lock instead of atomic add instructions.
-/// The number of platforms we need to support right now makes atomic
-/// operations unwieldy for this case that we don't actually use that often.
-/// As a further optimization, we can add support for this later.
-class ThreadSafeThreadTraits {
- public:
- class RefCount {
- public:
- /// Default constructor. In debug mode, this checks that the object is being
- /// created on the main thread.
- RefCount() : ref_(0) {
- }
-
- /// AddRef() increments the reference counter.
- ///
- /// @return An int32_t with the incremented reference counter.
- int32_t AddRef() {
- AutoLock lock(lock_);
- return ++ref_;
- }
-
- /// Release() decrements the reference counter.
- ///
- /// @return An int32_t with the decremeneted reference counter.
- int32_t Release() {
- AutoLock lock(lock_);
- PP_DCHECK(ref_ > 0);
- return --ref_;
- }
-
- private:
- Lock lock_;
- int32_t ref_;
- };
-
- typedef pp::Lock Lock;
- typedef pp::AutoLock AutoLock;
-};
-
-/// The non-thread-safe version of thread traits. Using this class as the
-/// "traits" template argument to a completion callback factory will make it
-/// not thread-safe but with potential extra performance.
-class NonThreadSafeThreadTraits {
- public:
- /// A simple reference counter that is not thread-safe.
- ///
- /// <strong>Note:</strong> in Debug mode, it checks that it is either called
- /// on the main thread, or always called on another thread.
- class RefCount {
- public:
- /// Default constructor. In debug mode, this checks that the object is being
- /// created on the main thread.
- RefCount() : ref_(0) {
-#ifndef NDEBUG
- is_main_thread_ = Module::Get()->core()->IsMainThread();
-#endif
- }
-
- /// Destructor.
- ~RefCount() {
- PP_DCHECK(is_main_thread_ == Module::Get()->core()->IsMainThread());
- }
-
- /// AddRef() increments the reference counter.
- ///
- /// @return An int32_t with the incremented reference counter.
- int32_t AddRef() {
- PP_DCHECK(is_main_thread_ == Module::Get()->core()->IsMainThread());
- return ++ref_;
- }
-
- /// Release() decrements the reference counter.
- ///
- /// @return An int32_t with the decremeneted reference counter.
- int32_t Release() {
- PP_DCHECK(is_main_thread_ == Module::Get()->core()->IsMainThread());
- return --ref_;
- }
-
- private:
- int32_t ref_;
-#ifndef NDEBUG
- bool is_main_thread_;
-#endif
- };
-
- /// A simple object that acts like a lock but does nothing.
- ///
- /// MStrong>Note:</strong> in Debug mode, it checks that it is either
- /// called on the main thread, or always called on another thread. It also
- /// asserts that the caller does not recursively lock.
- class Lock {
- public:
- Lock() {
-#ifndef NDEBUG
- is_main_thread_ = Module::Get()->core()->IsMainThread();
- lock_held_ = false;
-#endif
- }
-
- ~Lock() {
- PP_DCHECK(is_main_thread_ == Module::Get()->core()->IsMainThread());
- }
-
- /// Acquires the fake "lock". This does nothing except perform checks in
- /// debug mode.
- void Acquire() {
-#ifndef NDEBUG
- PP_DCHECK(!lock_held_);
- lock_held_ = true;
-#endif
- }
-
- /// Releases the fake "lock". This does nothing except perform checks in
- /// debug mode.
- void Release() {
-#ifndef NDEBUG
- PP_DCHECK(lock_held_);
- lock_held_ = false;
-#endif
- }
-
- private:
-#ifndef NDEBUG
- bool is_main_thread_;
- bool lock_held_;
-#endif
- };
-
- class AutoLock {
- public:
- explicit AutoLock(Lock& lock) : lock_(lock) {
- lock_.Acquire();
- }
- ~AutoLock() {
- lock_.Release();
- }
-
- private:
- Lock& lock_;
- };
-};
-
-} // namespace pp
-
-#endif // PPAPI_UTILITY_THREAD_SAFE_THREAD_TRAITS_H_
+// Copyright (c) 2012 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.
+
+#ifndef PPAPI_UTILITY_THREAD_SAFE_THREAD_TRAITS_H_
+#define PPAPI_UTILITY_THREAD_SAFE_THREAD_TRAITS_H_
+
+#include "ppapi/cpp/logging.h"
+#include "ppapi/cpp/module.h"
+#include "ppapi/utility/threading/lock.h"
+
+/// @file
+/// Defines the traits structures for thread-safety of a completion callback
+/// factory. We provide thread-safe and non-thread-safe version. The thread-safe
+/// version is always correct (if you follow the thread usage rules of the
+/// callback factory), but if you know your object will only be used on one
+/// thread, you can uses the non-thread-safe version.
+///
+/// The traits defines three nested classes to perform reference counting,
+/// locks, and scoped locking.
+
+namespace pp {
+
+/// The thread-safe version of thread traits. Using this class as the "traits"
+/// template argument to a completion callback factory will make it "somewhat
+/// thread-friendly." It will allow you to create completion callbacks from
+/// background threads and post them to another thread to run.
+///
+/// Care still must be taken to ensure that the completion callbacks are
+/// executed on the same thread that the factory is destroyed on to avoid a
+/// race on destruction.
+///
+/// Implementation note: this uses a lock instead of atomic add instructions.
+/// The number of platforms we need to support right now makes atomic
+/// operations unwieldy for this case that we don't actually use that often.
+/// As a further optimization, we can add support for this later.
+class ThreadSafeThreadTraits {
+ public:
+ class RefCount {
+ public:
+ /// Default constructor. In debug mode, this checks that the object is being
+ /// created on the main thread.
+ RefCount() : ref_(0) {
+ }
+
+ /// AddRef() increments the reference counter.
+ ///
+ /// @return An int32_t with the incremented reference counter.
+ int32_t AddRef() {
+ AutoLock lock(lock_);
+ return ++ref_;
+ }
+
+ /// Release() decrements the reference counter.
+ ///
+ /// @return An int32_t with the decremeneted reference counter.
+ int32_t Release() {
+ AutoLock lock(lock_);
+ PP_DCHECK(ref_ > 0);
+ return --ref_;
+ }
+
+ private:
+ Lock lock_;
+ int32_t ref_;
+ };
+
+ typedef pp::Lock Lock;
+ typedef pp::AutoLock AutoLock;
+};
+
+/// The non-thread-safe version of thread traits. Using this class as the
+/// "traits" template argument to a completion callback factory will make it
+/// not thread-safe but with potential extra performance.
+class NonThreadSafeThreadTraits {
+ public:
+ /// A simple reference counter that is not thread-safe.
+ ///
+ /// <strong>Note:</strong> in Debug mode, it checks that it is either called
+ /// on the main thread, or always called on another thread.
+ class RefCount {
+ public:
+ /// Default constructor. In debug mode, this checks that the object is being
+ /// created on the main thread.
+ RefCount() : ref_(0) {
+#ifndef NDEBUG
+ is_main_thread_ = Module::Get()->core()->IsMainThread();
+#endif
+ }
+
+ /// Destructor.
+ ~RefCount() {
+ PP_DCHECK(is_main_thread_ == Module::Get()->core()->IsMainThread());
+ }
+
+ /// AddRef() increments the reference counter.
+ ///
+ /// @return An int32_t with the incremented reference counter.
+ int32_t AddRef() {
+ PP_DCHECK(is_main_thread_ == Module::Get()->core()->IsMainThread());
+ return ++ref_;
+ }
+
+ /// Release() decrements the reference counter.
+ ///
+ /// @return An int32_t with the decremeneted reference counter.
+ int32_t Release() {
+ PP_DCHECK(is_main_thread_ == Module::Get()->core()->IsMainThread());
+ return --ref_;
+ }
+
+ private:
+ int32_t ref_;
+#ifndef NDEBUG
+ bool is_main_thread_;
+#endif
+ };
+
+ /// A simple object that acts like a lock but does nothing.
+ ///
+ /// MStrong>Note:</strong> in Debug mode, it checks that it is either
+ /// called on the main thread, or always called on another thread. It also
+ /// asserts that the caller does not recursively lock.
+ class Lock {
+ public:
+ Lock() {
+#ifndef NDEBUG
+ is_main_thread_ = Module::Get()->core()->IsMainThread();
+ lock_held_ = false;
+#endif
+ }
+
+ ~Lock() {
+ PP_DCHECK(is_main_thread_ == Module::Get()->core()->IsMainThread());
+ }
+
+ /// Acquires the fake "lock". This does nothing except perform checks in
+ /// debug mode.
+ void Acquire() {
+#ifndef NDEBUG
+ PP_DCHECK(!lock_held_);
+ lock_held_ = true;
+#endif
+ }
+
+ /// Releases the fake "lock". This does nothing except perform checks in
+ /// debug mode.
+ void Release() {
+#ifndef NDEBUG
+ PP_DCHECK(lock_held_);
+ lock_held_ = false;
+#endif
+ }
+
+ private:
+#ifndef NDEBUG
+ bool is_main_thread_;
+ bool lock_held_;
+#endif
+ };
+
+ class AutoLock {
+ public:
+ explicit AutoLock(Lock& lock) : lock_(lock) {
+ lock_.Acquire();
+ }
+ ~AutoLock() {
+ lock_.Release();
+ }
+
+ private:
+ Lock& lock_;
+ };
+};
+
+} // namespace pp
+
+#endif // PPAPI_UTILITY_THREAD_SAFE_THREAD_TRAITS_H_
diff --git a/ppapi/utility/threading/lock.cc b/ppapi/utility/threading/lock.cc
index 12cbd08..ee4bad7 100644
--- a/ppapi/utility/threading/lock.cc
+++ b/ppapi/utility/threading/lock.cc
@@ -1,49 +1,49 @@
-// Copyright (c) 2012 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 "ppapi/utility/threading/lock.h"
-
-namespace pp {
-
-#ifdef WIN32 // Windows implementation for native plugins.
-
-Lock::Lock() {
- // The second parameter is the spin count; for short-held locks it avoids the
- // contending thread from going to sleep which helps performance greatly.
- ::InitializeCriticalSectionAndSpinCount(&os_lock_, 2000);
-}
-
-Lock::~Lock() {
- ::DeleteCriticalSection(&os_lock_);
-}
-
-void Lock::Acquire() {
- ::EnterCriticalSection(&os_lock_);
-}
-
-void Lock::Release() {
- ::LeaveCriticalSection(&os_lock_);
-}
-
-#else // Posix implementation.
-
-Lock::Lock() {
- pthread_mutex_init(&os_lock_, NULL);
-}
-
-Lock::~Lock() {
- pthread_mutex_destroy(&os_lock_);
-}
-
-void Lock::Acquire() {
- pthread_mutex_lock(&os_lock_);
-}
-
-void Lock::Release() {
- pthread_mutex_unlock(&os_lock_);
-}
-
-#endif
-
-} // namespace pp
+// Copyright (c) 2012 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 "ppapi/utility/threading/lock.h"
+
+namespace pp {
+
+#ifdef WIN32 // Windows implementation for native plugins.
+
+Lock::Lock() {
+ // The second parameter is the spin count; for short-held locks it avoids the
+ // contending thread from going to sleep which helps performance greatly.
+ ::InitializeCriticalSectionAndSpinCount(&os_lock_, 2000);
+}
+
+Lock::~Lock() {
+ ::DeleteCriticalSection(&os_lock_);
+}
+
+void Lock::Acquire() {
+ ::EnterCriticalSection(&os_lock_);
+}
+
+void Lock::Release() {
+ ::LeaveCriticalSection(&os_lock_);
+}
+
+#else // Posix implementation.
+
+Lock::Lock() {
+ pthread_mutex_init(&os_lock_, NULL);
+}
+
+Lock::~Lock() {
+ pthread_mutex_destroy(&os_lock_);
+}
+
+void Lock::Acquire() {
+ pthread_mutex_lock(&os_lock_);
+}
+
+void Lock::Release() {
+ pthread_mutex_unlock(&os_lock_);
+}
+
+#endif
+
+} // namespace pp
diff --git a/ppapi/utility/threading/lock.h b/ppapi/utility/threading/lock.h
index 71a9876..f3bfe4a 100644
--- a/ppapi/utility/threading/lock.h
+++ b/ppapi/utility/threading/lock.h
@@ -1,84 +1,84 @@
-// Copyright (c) 2012 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.
-
-#ifndef PPAPI_UTILITY_THREADING_LOCK_H_
-#define PPAPI_UTILITY_THREADING_LOCK_H_
-
-#ifdef WIN32
-#include <windows.h>
-#else
-#include <pthread.h>
-#endif
-
-namespace pp {
-
-/// A simple wrapper around a platform-specific lock. See also AutoLock.
-class Lock {
- public:
- /// Creates a lock in the "not held" state.
- Lock();
-
- /// Destroys the lock.
- ~Lock();
-
- /// Acquires the lock, blocking if it's already held by a different thread.
- /// The lock must not already be held on the current thread (i.e. recursive
- /// locks are not supported).
- ///
- /// Most callers should consider using an AutoLock instead to automatically
- /// acquire and release the lock.
- void Acquire();
-
- /// Releases the lock. This must be paired with a call to Acquire().
- void Release();
-
- private:
-#if defined(WIN32)
- typedef CRITICAL_SECTION OSLockType;
-#else
- typedef pthread_mutex_t OSLockType;
-#endif
-
- OSLockType os_lock_;
-
- // Copy and assign not supported.
- Lock(const Lock&);
- Lock& operator=(const Lock&);
-};
-
-/// A helper class that scopes holding a lock.
-///
-/// @code
-/// class MyClass {
-/// public:
-/// void DoSomething() {
-/// pp::AutoLock lock(lock_);
-/// ...do something with the lock held...
-/// }
-///
-/// private:
-/// pp::Lock lock_;
-/// };
-/// @endcode
-class AutoLock {
- public:
- explicit AutoLock(Lock& lock) : lock_(lock) {
- lock_.Acquire();
- }
-
- ~AutoLock() {
- lock_.Release();
- }
-
- private:
- Lock& lock_;
-
- // Copy and assign not supported.
- AutoLock(const AutoLock&);
- AutoLock& operator=(const AutoLock&);
-};
-
-} // namespace pp
-
-#endif // PPAPI_UTILITY_THREADING_LOCK_H_
+// Copyright (c) 2012 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.
+
+#ifndef PPAPI_UTILITY_THREADING_LOCK_H_
+#define PPAPI_UTILITY_THREADING_LOCK_H_
+
+#ifdef WIN32
+#include <windows.h>
+#else
+#include <pthread.h>
+#endif
+
+namespace pp {
+
+/// A simple wrapper around a platform-specific lock. See also AutoLock.
+class Lock {
+ public:
+ /// Creates a lock in the "not held" state.
+ Lock();
+
+ /// Destroys the lock.
+ ~Lock();
+
+ /// Acquires the lock, blocking if it's already held by a different thread.
+ /// The lock must not already be held on the current thread (i.e. recursive
+ /// locks are not supported).
+ ///
+ /// Most callers should consider using an AutoLock instead to automatically
+ /// acquire and release the lock.
+ void Acquire();
+
+ /// Releases the lock. This must be paired with a call to Acquire().
+ void Release();
+
+ private:
+#if defined(WIN32)
+ typedef CRITICAL_SECTION OSLockType;
+#else
+ typedef pthread_mutex_t OSLockType;
+#endif
+
+ OSLockType os_lock_;
+
+ // Copy and assign not supported.
+ Lock(const Lock&);
+ Lock& operator=(const Lock&);
+};
+
+/// A helper class that scopes holding a lock.
+///
+/// @code
+/// class MyClass {
+/// public:
+/// void DoSomething() {
+/// pp::AutoLock lock(lock_);
+/// ...do something with the lock held...
+/// }
+///
+/// private:
+/// pp::Lock lock_;
+/// };
+/// @endcode
+class AutoLock {
+ public:
+ explicit AutoLock(Lock& lock) : lock_(lock) {
+ lock_.Acquire();
+ }
+
+ ~AutoLock() {
+ lock_.Release();
+ }
+
+ private:
+ Lock& lock_;
+
+ // Copy and assign not supported.
+ AutoLock(const AutoLock&);
+ AutoLock& operator=(const AutoLock&);
+};
+
+} // namespace pp
+
+#endif // PPAPI_UTILITY_THREADING_LOCK_H_