Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2886)

Unified Diff: base/files/file_posix.cc

Issue 676873004: Intercept file Open/Close (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/files/file.cc ('k') | base/files/file_posix_hooks_internal.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/files/file_posix.cc
diff --git a/base/files/file_posix.cc b/base/files/file_posix.cc
index 43684b5dabfe3df9b2a6907cd5dfbecb8e3582c3..75c1b811b23d3c3b894a4bcd7502f22d7a4440a3 100644
--- a/base/files/file_posix.cc
+++ b/base/files/file_posix.cc
@@ -10,6 +10,7 @@
#include <unistd.h>
#include "base/files/file_path.h"
+#include "base/files/file_posix_hooks_internal.h"
#include "base/logging.h"
#include "base/metrics/sparse_histogram.h"
#include "base/posix/eintr_wrapper.h"
@@ -166,6 +167,14 @@ void File::Info::FromStat(const stat_wrapper_t& stat_info) {
Time::kNanosecondsPerMicrosecond);
}
+// Default implementations of Protect/Unprotect hooks defined as weak symbols
+// where possible.
+void ProtectFileDescriptor(int fd) {
+}
+
+void UnprotectFileDescriptor(int fd) {
+}
+
// NaCl doesn't implement system calls to open files directly.
#if !defined(OS_NACL)
// TODO(erikkay): does it make sense to support FLAG_EXCLUSIVE_* here?
@@ -252,6 +261,7 @@ void File::InitializeUnsafe(const FilePath& name, uint32 flags) {
async_ = ((flags & FLAG_ASYNC) == FLAG_ASYNC);
error_details_ = FILE_OK;
file_.reset(descriptor);
+ ProtectFileDescriptor(descriptor);
}
#endif // !defined(OS_NACL)
@@ -264,6 +274,8 @@ PlatformFile File::GetPlatformFile() const {
}
PlatformFile File::TakePlatformFile() {
+ if (IsValid())
+ UnprotectFileDescriptor(GetPlatformFile());
return file_.release();
}
@@ -272,6 +284,7 @@ void File::Close() {
return;
base::ThreadRestrictions::AssertIOAllowed();
+ UnprotectFileDescriptor(GetPlatformFile());
file_.reset();
}
@@ -484,8 +497,10 @@ File::Error File::OSErrorToFileError(int saved_errno) {
}
void File::SetPlatformFile(PlatformFile file) {
- DCHECK(!file_.is_valid());
+ CHECK(!file_.is_valid());
file_.reset(file);
+ if (file_.is_valid())
+ ProtectFileDescriptor(GetPlatformFile());
}
} // namespace base
« no previous file with comments | « base/files/file.cc ('k') | base/files/file_posix_hooks_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698