Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / base / win / scoped_handle.h
index d3f5c22..c8d0f39 100644 (file)
@@ -27,11 +27,9 @@ namespace win {
 
 // Generic wrapper for raw handles that takes care of closing handles
 // automatically. The class interface follows the style of
-// the ScopedStdioHandle class with a few additions:
+// the ScopedFILE class with one addition:
 //   - IsValid() method can tolerate multiple invalid handle values such as NULL
 //     and INVALID_HANDLE_VALUE (-1) for Win32 handles.
-//   - Receive() method allows to receive a handle value from a function that
-//     takes a raw handle pointer only.
 template <class Traits, class Verifier>
 class GenericScopedHandle {
   MOVE_ONLY_TYPE_FOR_CPP_03(GenericScopedHandle, RValue)
@@ -39,22 +37,6 @@ class GenericScopedHandle {
  public:
   typedef typename Traits::Handle Handle;
 
-  // Helper object to contain the effect of Receive() to the function that needs
-  // a pointer, and allow proper tracking of the handle.
-  class Receiver {
-   public:
-    explicit Receiver(GenericScopedHandle* owner)
-        : handle_(Traits::NullHandle()),
-          owner_(owner) {}
-    ~Receiver() { owner_->Set(handle_); }
-
-    operator Handle*() { return &handle_; }
-
-   private:
-    Handle handle_;
-    GenericScopedHandle* owner_;
-  };
-
   GenericScopedHandle() : handle_(Traits::NullHandle()) {}
 
   explicit GenericScopedHandle(Handle handle) : handle_(Traits::NullHandle()) {
@@ -102,16 +84,6 @@ class GenericScopedHandle {
     return handle_;
   }
 
-  // This method is intended to be used with functions that require a pointer to
-  // a destination handle, like so:
-  //    void CreateRequiredHandle(Handle* out_handle);
-  //    ScopedHandle a;
-  //    CreateRequiredHandle(a.Receive());
-  Receiver Receive() {
-    DCHECK(!Traits::IsHandleValid(handle_)) << "Handle must be NULL";
-    return Receiver(this);
-  }
-
   // Transfers ownership away from this object.
   Handle Take() {
     Handle temp = handle_;
@@ -129,9 +101,7 @@ class GenericScopedHandle {
       Verifier::StopTracking(handle_, this, BASE_WIN_GET_CALLER,
                              tracked_objects::GetProgramCounter());
 
-      if (!Traits::CloseHandle(handle_))
-        CHECK(false);
-
+      Traits::CloseHandle(handle_);
       handle_ = Traits::NullHandle();
     }
   }
@@ -148,9 +118,7 @@ class HandleTraits {
   typedef HANDLE Handle;
 
   // Closes the handle.
-  static bool CloseHandle(HANDLE handle) {
-    return ::CloseHandle(handle) != FALSE;
-  }
+  static bool BASE_EXPORT CloseHandle(HANDLE handle);
 
   // Returns true if the handle value is valid.
   static bool IsHandleValid(HANDLE handle) {
@@ -196,6 +164,17 @@ class BASE_EXPORT VerifierTraits {
 
 typedef GenericScopedHandle<HandleTraits, VerifierTraits> ScopedHandle;
 
+// This function may be called by the embedder to disable the use of
+// VerifierTraits at runtime. It has no effect if DummyVerifierTraits is used
+// for ScopedHandle.
+void BASE_EXPORT DisableHandleVerifier();
+
+// This should be called whenever the OS is closing a handle, if extended
+// verification of improper handle closing is desired. If |handle| is being
+// tracked by the handle verifier and ScopedHandle is not the one closing it,
+// a CHECK is generated.
+void BASE_EXPORT OnHandleBeingClosed(HANDLE handle);
+
 }  // namespace win
 }  // namespace base