Commit c89adc7b authored by kinuko@chromium.org's avatar kinuko@chromium.org

Adding thread assertions in FileAPIMessageFilter

Chromeos folks once encountered a bug introduced by calling UnregisterOperation on a wrong thread-- adding assertions should help avoid introducing such bugs.

BUG=none
TEST=none


Review URL: http://codereview.chromium.org/9568028

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@124551 0039d316-1c4b-4281-b951-d872f2087c98
parent b80ac4bd
...@@ -168,6 +168,7 @@ bool FileAPIMessageFilter::OnMessageReceived( ...@@ -168,6 +168,7 @@ bool FileAPIMessageFilter::OnMessageReceived(
void FileAPIMessageFilter::OnOpen( void FileAPIMessageFilter::OnOpen(
int request_id, const GURL& origin_url, fileapi::FileSystemType type, int request_id, const GURL& origin_url, fileapi::FileSystemType type,
int64 requested_size, bool create) { int64 requested_size, bool create) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
if (type == fileapi::kFileSystemTypeTemporary) { if (type == fileapi::kFileSystemTypeTemporary) {
content::RecordAction(UserMetricsAction("OpenFileSystemTemporary")); content::RecordAction(UserMetricsAction("OpenFileSystemTemporary"));
} else if (type == fileapi::kFileSystemTypePersistent) { } else if (type == fileapi::kFileSystemTypePersistent) {
...@@ -179,6 +180,7 @@ void FileAPIMessageFilter::OnOpen( ...@@ -179,6 +180,7 @@ void FileAPIMessageFilter::OnOpen(
void FileAPIMessageFilter::OnMove( void FileAPIMessageFilter::OnMove(
int request_id, const GURL& src_path, const GURL& dest_path) { int request_id, const GURL& src_path, const GURL& dest_path) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
base::PlatformFileError error; base::PlatformFileError error;
const int src_permissions = kReadFilePermissions | kWriteFilePermissions; const int src_permissions = kReadFilePermissions | kWriteFilePermissions;
if (!HasPermissionsForFile(src_path, src_permissions, &error) || if (!HasPermissionsForFile(src_path, src_permissions, &error) ||
...@@ -194,6 +196,7 @@ void FileAPIMessageFilter::OnMove( ...@@ -194,6 +196,7 @@ void FileAPIMessageFilter::OnMove(
void FileAPIMessageFilter::OnCopy( void FileAPIMessageFilter::OnCopy(
int request_id, const GURL& src_path, const GURL& dest_path) { int request_id, const GURL& src_path, const GURL& dest_path) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
base::PlatformFileError error; base::PlatformFileError error;
if (!HasPermissionsForFile(src_path, kReadFilePermissions, &error) || if (!HasPermissionsForFile(src_path, kReadFilePermissions, &error) ||
!HasPermissionsForFile(dest_path, kCreateFilePermissions, &error)) { !HasPermissionsForFile(dest_path, kCreateFilePermissions, &error)) {
...@@ -208,6 +211,7 @@ void FileAPIMessageFilter::OnCopy( ...@@ -208,6 +211,7 @@ void FileAPIMessageFilter::OnCopy(
void FileAPIMessageFilter::OnRemove( void FileAPIMessageFilter::OnRemove(
int request_id, const GURL& path, bool recursive) { int request_id, const GURL& path, bool recursive) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
base::PlatformFileError error; base::PlatformFileError error;
if (!HasPermissionsForFile(path, kWriteFilePermissions, &error)) { if (!HasPermissionsForFile(path, kWriteFilePermissions, &error)) {
Send(new FileSystemMsg_DidFail(request_id, error)); Send(new FileSystemMsg_DidFail(request_id, error));
...@@ -221,6 +225,7 @@ void FileAPIMessageFilter::OnRemove( ...@@ -221,6 +225,7 @@ void FileAPIMessageFilter::OnRemove(
void FileAPIMessageFilter::OnReadMetadata( void FileAPIMessageFilter::OnReadMetadata(
int request_id, const GURL& path) { int request_id, const GURL& path) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
base::PlatformFileError error; base::PlatformFileError error;
if (!HasPermissionsForFile(path, kReadFilePermissions, &error)) { if (!HasPermissionsForFile(path, kReadFilePermissions, &error)) {
Send(new FileSystemMsg_DidFail(request_id, error)); Send(new FileSystemMsg_DidFail(request_id, error));
...@@ -235,6 +240,7 @@ void FileAPIMessageFilter::OnReadMetadata( ...@@ -235,6 +240,7 @@ void FileAPIMessageFilter::OnReadMetadata(
void FileAPIMessageFilter::OnCreate( void FileAPIMessageFilter::OnCreate(
int request_id, const GURL& path, bool exclusive, int request_id, const GURL& path, bool exclusive,
bool is_directory, bool recursive) { bool is_directory, bool recursive) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
base::PlatformFileError error; base::PlatformFileError error;
if (!HasPermissionsForFile(path, kCreateFilePermissions, &error)) { if (!HasPermissionsForFile(path, kCreateFilePermissions, &error)) {
Send(new FileSystemMsg_DidFail(request_id, error)); Send(new FileSystemMsg_DidFail(request_id, error));
...@@ -254,6 +260,7 @@ void FileAPIMessageFilter::OnCreate( ...@@ -254,6 +260,7 @@ void FileAPIMessageFilter::OnCreate(
void FileAPIMessageFilter::OnExists( void FileAPIMessageFilter::OnExists(
int request_id, const GURL& path, bool is_directory) { int request_id, const GURL& path, bool is_directory) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
base::PlatformFileError error; base::PlatformFileError error;
if (!HasPermissionsForFile(path, kReadFilePermissions, &error)) { if (!HasPermissionsForFile(path, kReadFilePermissions, &error)) {
Send(new FileSystemMsg_DidFail(request_id, error)); Send(new FileSystemMsg_DidFail(request_id, error));
...@@ -273,6 +280,7 @@ void FileAPIMessageFilter::OnExists( ...@@ -273,6 +280,7 @@ void FileAPIMessageFilter::OnExists(
void FileAPIMessageFilter::OnReadDirectory( void FileAPIMessageFilter::OnReadDirectory(
int request_id, const GURL& path) { int request_id, const GURL& path) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
base::PlatformFileError error; base::PlatformFileError error;
if (!HasPermissionsForFile(path, kReadFilePermissions, &error)) { if (!HasPermissionsForFile(path, kReadFilePermissions, &error)) {
Send(new FileSystemMsg_DidFail(request_id, error)); Send(new FileSystemMsg_DidFail(request_id, error));
...@@ -289,6 +297,7 @@ void FileAPIMessageFilter::OnWrite( ...@@ -289,6 +297,7 @@ void FileAPIMessageFilter::OnWrite(
const GURL& path, const GURL& path,
const GURL& blob_url, const GURL& blob_url,
int64 offset) { int64 offset) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
if (!request_context_) { if (!request_context_) {
// We can't write w/o a request context, trying to do so will crash. // We can't write w/o a request context, trying to do so will crash.
NOTREACHED(); NOTREACHED();
...@@ -326,6 +335,7 @@ void FileAPIMessageFilter::OnTouchFile( ...@@ -326,6 +335,7 @@ void FileAPIMessageFilter::OnTouchFile(
const GURL& path, const GURL& path,
const base::Time& last_access_time, const base::Time& last_access_time,
const base::Time& last_modified_time) { const base::Time& last_modified_time) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
base::PlatformFileError error; base::PlatformFileError error;
if (!HasPermissionsForFile(path, kCreateFilePermissions, &error)) { if (!HasPermissionsForFile(path, kCreateFilePermissions, &error)) {
Send(new FileSystemMsg_DidFail(request_id, error)); Send(new FileSystemMsg_DidFail(request_id, error));
...@@ -340,6 +350,7 @@ void FileAPIMessageFilter::OnTouchFile( ...@@ -340,6 +350,7 @@ void FileAPIMessageFilter::OnTouchFile(
void FileAPIMessageFilter::OnCancel( void FileAPIMessageFilter::OnCancel(
int request_id, int request_id,
int request_id_to_cancel) { int request_id_to_cancel) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
FileSystemOperationInterface* write = operations_.Lookup( FileSystemOperationInterface* write = operations_.Lookup(
request_id_to_cancel); request_id_to_cancel);
if (write) { if (write) {
...@@ -356,6 +367,7 @@ void FileAPIMessageFilter::OnCancel( ...@@ -356,6 +367,7 @@ void FileAPIMessageFilter::OnCancel(
void FileAPIMessageFilter::OnOpenFile( void FileAPIMessageFilter::OnOpenFile(
int request_id, const GURL& path, int file_flags) { int request_id, const GURL& path, int file_flags) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
base::PlatformFileError error; base::PlatformFileError error;
const int open_permissions = base::PLATFORM_FILE_OPEN | const int open_permissions = base::PLATFORM_FILE_OPEN |
(file_flags & kOpenFilePermissions); (file_flags & kOpenFilePermissions);
...@@ -371,6 +383,7 @@ void FileAPIMessageFilter::OnOpenFile( ...@@ -371,6 +383,7 @@ void FileAPIMessageFilter::OnOpenFile(
void FileAPIMessageFilter::OnWillUpdate(const GURL& path) { void FileAPIMessageFilter::OnWillUpdate(const GURL& path) {
GURL origin_url; GURL origin_url;
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
fileapi::FileSystemType type; fileapi::FileSystemType type;
if (!CrackFileSystemURL(path, &origin_url, &type, NULL)) if (!CrackFileSystemURL(path, &origin_url, &type, NULL))
return; return;
...@@ -381,6 +394,7 @@ void FileAPIMessageFilter::OnWillUpdate(const GURL& path) { ...@@ -381,6 +394,7 @@ void FileAPIMessageFilter::OnWillUpdate(const GURL& path) {
} }
void FileAPIMessageFilter::OnDidUpdate(const GURL& path, int64 delta) { void FileAPIMessageFilter::OnDidUpdate(const GURL& path, int64 delta) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
GURL origin_url; GURL origin_url;
fileapi::FileSystemType type; fileapi::FileSystemType type;
if (!CrackFileSystemURL(path, &origin_url, &type, NULL)) if (!CrackFileSystemURL(path, &origin_url, &type, NULL))
...@@ -497,6 +511,7 @@ void FileAPIMessageFilter::DidFinish(int request_id, ...@@ -497,6 +511,7 @@ void FileAPIMessageFilter::DidFinish(int request_id,
void FileAPIMessageFilter::DidCancel(int request_id, void FileAPIMessageFilter::DidCancel(int request_id,
base::PlatformFileError result) { base::PlatformFileError result) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
if (result == base::PLATFORM_FILE_OK) if (result == base::PLATFORM_FILE_OK)
Send(new FileSystemMsg_DidSucceed(request_id)); Send(new FileSystemMsg_DidSucceed(request_id));
else else
...@@ -562,6 +577,7 @@ void FileAPIMessageFilter::DidOpenFileSystem(int request_id, ...@@ -562,6 +577,7 @@ void FileAPIMessageFilter::DidOpenFileSystem(int request_id,
base::PlatformFileError result, base::PlatformFileError result,
const std::string& name, const std::string& name,
const GURL& root) { const GURL& root) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
if (result == base::PLATFORM_FILE_OK) { if (result == base::PLATFORM_FILE_OK) {
DCHECK(root.is_valid()); DCHECK(root.is_valid());
Send(new FileSystemMsg_DidOpenFileSystem(request_id, name, root)); Send(new FileSystemMsg_DidOpenFileSystem(request_id, name, root));
...@@ -578,6 +594,7 @@ void FileAPIMessageFilter::DidCreateSnapshot( ...@@ -578,6 +594,7 @@ void FileAPIMessageFilter::DidCreateSnapshot(
const base::PlatformFileInfo& info, const base::PlatformFileInfo& info,
const FilePath& platform_path, const FilePath& platform_path,
const scoped_refptr<webkit_blob::ShareableFileReference>& unused) { const scoped_refptr<webkit_blob::ShareableFileReference>& unused) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
if (result != base::PLATFORM_FILE_OK) { if (result != base::PLATFORM_FILE_OK) {
Send(new FileSystemMsg_DidFail(request_id, result)); Send(new FileSystemMsg_DidFail(request_id, result));
return; return;
...@@ -657,6 +674,7 @@ FileSystemOperationInterface* FileAPIMessageFilter::GetNewOperation( ...@@ -657,6 +674,7 @@ FileSystemOperationInterface* FileAPIMessageFilter::GetNewOperation(
} }
void FileAPIMessageFilter::UnregisterOperation(int request_id) { void FileAPIMessageFilter::UnregisterOperation(int request_id) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
DCHECK(operations_.Lookup(request_id)); DCHECK(operations_.Lookup(request_id));
operations_.Remove(request_id); operations_.Remove(request_id);
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment