summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-24 01:28:39 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-24 01:28:39 +0000
commitb5be3f53d7af0037dbc634beb550752de56ad840 (patch)
treebad47f796066287eaa93221d864a302865698919
parent77e00d58ca90f79cd76032c94e189f1748b2769e (diff)
downloadchromium_src-b5be3f53d7af0037dbc634beb550752de56ad840.zip
chromium_src-b5be3f53d7af0037dbc634beb550752de56ad840.tar.gz
chromium_src-b5be3f53d7af0037dbc634beb550752de56ad840.tar.bz2
Clean up database files. Some changes are due to Google style guide violations, some to be consistent with prevailing team style, some merely in hopes of increasing readability.
BUG=none TEST=none Review URL: http://codereview.chromium.org/330007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29985 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/renderer_host/database_dispatcher_host.cc83
-rw-r--r--chrome/browser/renderer_host/database_dispatcher_host.h21
-rw-r--r--chrome/common/db_message_filter.cc50
-rw-r--r--chrome/common/db_message_filter.h89
-rw-r--r--webkit/database/vfs_backend.cc104
-rw-r--r--webkit/database/vfs_backend.h25
6 files changed, 158 insertions, 214 deletions
diff --git a/chrome/browser/renderer_host/database_dispatcher_host.cc b/chrome/browser/renderer_host/database_dispatcher_host.cc
index 8623a87..7b11c89 100644
--- a/chrome/browser/renderer_host/database_dispatcher_host.cc
+++ b/chrome/browser/renderer_host/database_dispatcher_host.cc
@@ -14,15 +14,10 @@
#include "third_party/sqlite/preprocessed/sqlite3.h"
#endif
-#include "base/message_loop.h"
-#include "base/platform_file.h"
-#include "base/process.h"
-#include "base/task.h"
#include "base/thread.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/renderer_host/resource_message_filter.h"
#include "chrome/common/render_messages.h"
-#include "ipc/ipc_message.h"
#include "webkit/database/vfs_backend.h"
#if defined(OS_POSIX)
@@ -72,9 +67,8 @@ static void DatabaseOpenFile(MessageLoop* io_thread_message_loop,
ResourceMessageFilter* sender) {
base::PlatformFile target_handle = base::kInvalidPlatformFileValue;
base::PlatformFile target_dir_handle = base::kInvalidPlatformFileValue;
- VfsBackend::OpenFile(
- params.file_name, params.db_dir, params.desired_flags,
- params.handle, &target_handle, &target_dir_handle);
+ VfsBackend::OpenFile(params.file_name, params.db_dir, params.desired_flags,
+ params.handle, &target_handle, &target_dir_handle);
ViewMsg_DatabaseOpenFileResponse_Params response_params;
#if defined(OS_WIN)
@@ -92,12 +86,11 @@ static void DatabaseOpenFile(MessageLoop* io_thread_message_loop,
// Deletes the given database file, then schedules
// a task on the IO thread's message loop to send an IPC back to
// corresponding renderer process with the error code.
-static void DatabaseDeleteFile(
- MessageLoop* io_thread_message_loop,
- const DeleteFileParams& params,
- int32 message_id,
- int reschedule_count,
- ResourceMessageFilter* sender) {
+static void DatabaseDeleteFile(MessageLoop* io_thread_message_loop,
+ const DeleteFileParams& params,
+ int32 message_id,
+ int reschedule_count,
+ ResourceMessageFilter* sender) {
// Return an error if the file could not be deleted
// after kNumDeleteRetries times.
if (!reschedule_count) {
@@ -108,14 +101,14 @@ static void DatabaseDeleteFile(
return;
}
- int error_code = VfsBackend::DeleteFile(
- params.file_name, params.db_dir, params.sync_dir);
+ int error_code =
+ VfsBackend::DeleteFile(params.file_name, params.db_dir, params.sync_dir);
if (error_code == SQLITE_IOERR_DELETE) {
// If the file could not be deleted, try again.
MessageLoop::current()->PostDelayedTask(FROM_HERE,
NewRunnableFunction(DatabaseDeleteFile, io_thread_message_loop,
- params, message_id, reschedule_count - 1, sender),
- kDelayDeleteRetryMs);
+ params, message_id, reschedule_count - 1, sender),
+ kDelayDeleteRetryMs);
return;
}
@@ -128,11 +121,10 @@ static void DatabaseDeleteFile(
// Gets the attributes of the given database file, then schedules
// a task on the IO thread's message loop to send an IPC back to
// corresponding renderer process.
-static void DatabaseGetFileAttributes(
- MessageLoop* io_thread_message_loop,
- const FilePath& file_name,
- int32 message_id,
- ResourceMessageFilter* sender) {
+static void DatabaseGetFileAttributes(MessageLoop* io_thread_message_loop,
+ const FilePath& file_name,
+ int32 message_id,
+ ResourceMessageFilter* sender) {
uint32 attributes = VfsBackend::GetFileAttributes(file_name);
io_thread_message_loop->PostTask(FROM_HERE,
NewRunnableFunction(SendMessage, sender,
@@ -144,11 +136,10 @@ static void DatabaseGetFileAttributes(
// Gets the size of the given file, then schedules a task
// on the IO thread's message loop to send an IPC back to
// the corresponding renderer process.
-static void DatabaseGetFileSize(
- MessageLoop* io_thread_message_loop,
- const FilePath& file_name,
- int32 message_id,
- ResourceMessageFilter* sender) {
+static void DatabaseGetFileSize(MessageLoop* io_thread_message_loop,
+ const FilePath& file_name,
+ int32 message_id,
+ ResourceMessageFilter* sender) {
int64 size = VfsBackend::GetFileSize(file_name);
io_thread_message_loop->PostTask(FROM_HERE,
NewRunnableFunction(SendMessage, sender,
@@ -158,16 +149,14 @@ static void DatabaseGetFileSize(
} // namespace
DatabaseDispatcherHost::DatabaseDispatcherHost(
- const FilePath& profile_path,
- ResourceMessageFilter* resource_message_filter)
- : profile_path_(profile_path),
- resource_message_filter_(resource_message_filter),
- file_thread_message_loop_(
+ const FilePath& profile_path,
+ ResourceMessageFilter* resource_message_filter)
+ : profile_path_(profile_path),
+ resource_message_filter_(resource_message_filter),
+ file_thread_message_loop_(
g_browser_process->file_thread()->message_loop()) {
}
-DatabaseDispatcherHost::~DatabaseDispatcherHost() {
-}
bool DatabaseDispatcherHost::IsDBMessage(const IPC::Message& message) {
switch (message.type()) {
@@ -176,15 +165,15 @@ bool DatabaseDispatcherHost::IsDBMessage(const IPC::Message& message) {
case ViewHostMsg_DatabaseGetFileAttributes::ID:
case ViewHostMsg_DatabaseGetFileSize::ID:
return true;
+ default:
+ return false;
}
- return false;
}
bool DatabaseDispatcherHost::OnMessageReceived(
const IPC::Message& message, bool* message_was_ok) {
- if (!IsDBMessage(message)) {
+ if (!IsDBMessage(message))
return false;
- }
*message_was_ok = true;
bool handled = true;
@@ -215,9 +204,9 @@ FilePath DatabaseDispatcherHost::GetDBFileFullPath(const FilePath& file_name) {
return GetDBDir().Append(file_name);
}
-void DatabaseDispatcherHost::OnDatabaseOpenFile(
- const FilePath& file_name, int desired_flags,
- int32 message_id) {
+void DatabaseDispatcherHost::OnDatabaseOpenFile(const FilePath& file_name,
+ int desired_flags,
+ int32 message_id) {
FilePath db_file_name = GetDBFileFullPath(file_name);
if (db_file_name.empty()) {
@@ -243,7 +232,7 @@ void DatabaseDispatcherHost::OnDatabaseOpenFile(
resource_message_filter_->AddRef();
file_thread_message_loop_->PostTask(FROM_HERE,
NewRunnableFunction(DatabaseOpenFile, MessageLoop::current(),
- params, message_id, resource_message_filter_));
+ params, message_id, resource_message_filter_));
}
void DatabaseDispatcherHost::OnDatabaseDeleteFile(
@@ -262,7 +251,8 @@ void DatabaseDispatcherHost::OnDatabaseDeleteFile(
resource_message_filter_->AddRef();
file_thread_message_loop_->PostTask(FROM_HERE,
NewRunnableFunction(DatabaseDeleteFile, MessageLoop::current(),
- params, message_id, kNumDeleteRetries, resource_message_filter_));
+ params, message_id, kNumDeleteRetries,
+ resource_message_filter_));
}
void DatabaseDispatcherHost::OnDatabaseGetFileAttributes(
@@ -270,15 +260,14 @@ void DatabaseDispatcherHost::OnDatabaseGetFileAttributes(
FilePath db_file_name = GetDBFileFullPath(file_name);
if (db_file_name.empty()) {
resource_message_filter_->Send(
- new ViewMsg_DatabaseGetFileAttributesResponse(
- message_id, -1));
+ new ViewMsg_DatabaseGetFileAttributesResponse(message_id, -1));
return;
}
resource_message_filter_->AddRef();
file_thread_message_loop_->PostTask(FROM_HERE,
NewRunnableFunction(DatabaseGetFileAttributes, MessageLoop::current(),
- db_file_name, message_id, resource_message_filter_));
+ db_file_name, message_id, resource_message_filter_));
}
void DatabaseDispatcherHost::OnDatabaseGetFileSize(
@@ -293,5 +282,5 @@ void DatabaseDispatcherHost::OnDatabaseGetFileSize(
resource_message_filter_->AddRef();
file_thread_message_loop_->PostTask(FROM_HERE,
NewRunnableFunction(DatabaseGetFileSize, MessageLoop::current(),
- db_file_name, message_id, resource_message_filter_));
+ db_file_name, message_id, resource_message_filter_));
}
diff --git a/chrome/browser/renderer_host/database_dispatcher_host.h b/chrome/browser/renderer_host/database_dispatcher_host.h
index 3f5302d..1b59f08 100644
--- a/chrome/browser/renderer_host/database_dispatcher_host.h
+++ b/chrome/browser/renderer_host/database_dispatcher_host.h
@@ -6,7 +6,6 @@
#define CHROME_BROWSER_RENDERER_HOST_DATABASE_DISPATCHER_HOST_H_
#include "base/file_path.h"
-#include "base/ref_counted.h"
class MessageLoop;
class ResourceMessageFilter;
@@ -18,24 +17,29 @@ class Message;
class DatabaseDispatcherHost {
public:
DatabaseDispatcherHost(const FilePath& profile_path,
- ResourceMessageFilter* resource_message_filter);
- ~DatabaseDispatcherHost();
+ ResourceMessageFilter* resource_message_filter);
+ ~DatabaseDispatcherHost() {}
// Returns true iff the message is HTML5 DB related and was processed.
bool OnMessageReceived(const IPC::Message& message, bool* message_was_ok);
// Processes the request to return a handle to the given DB file.
void OnDatabaseOpenFile(const FilePath& file_name,
- int desired_flags, int32 message_id);
+ int desired_flags,
+ int32 message_id);
+
// Processes the request to delete the given DB file.
- void OnDatabaseDeleteFile(const FilePath& file_name, const bool& sync_dir,
- int32 message_id);
+ void OnDatabaseDeleteFile(const FilePath& file_name,
+ const bool& sync_dir,
+ int32 message_id);
+
// Processes the request to return the attributes of the given DB file.
void OnDatabaseGetFileAttributes(const FilePath& file_name,
- int32 message_id);
+ int32 message_id);
+
// Processes the request to return the size of the given file.
void OnDatabaseGetFileSize(const FilePath& file_name,
- int32 message_id);
+ int32 message_id);
private:
// Determines if the message is HTML5 DB related.
@@ -43,6 +47,7 @@ class DatabaseDispatcherHost {
// Returns the directory where all DB files are stored.
FilePath GetDBDir();
+
// Returns the absolute name of the given DB file.
FilePath GetDBFileFullPath(const FilePath& file_name);
diff --git a/chrome/common/db_message_filter.cc b/chrome/common/db_message_filter.cc
index 396ca7c..3ca841b 100644
--- a/chrome/common/db_message_filter.cc
+++ b/chrome/common/db_message_filter.cc
@@ -2,37 +2,22 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "db_message_filter.h"
+#include "chrome/common/db_message_filter.h"
-#include "base/atomic_sequence_num.h"
-#include "base/id_map.h"
-#include "base/lock.h"
-#include "base/message_loop.h"
-#include "base/platform_file.h"
-#include "base/task.h"
#include "chrome/common/child_process.h"
#include "chrome/common/render_messages.h"
-#include "ipc/ipc_channel.h"
-#include "ipc/ipc_message.h"
DBMessageFilter* DBMessageFilter::instance_ = NULL;
DBMessageFilter::DBMessageFilter()
- : io_thread_message_loop_(ChildProcess::current()->io_message_loop()),
- channel_(NULL), channel_lock_(new Lock()),
- shutdown_event_(ChildProcess::current()->GetShutDownEvent()),
- messages_awaiting_replies_(new IDMap<DBMessageState>()),
- unique_id_generator_(new base::AtomicSequenceNumber()) {
- DCHECK(!instance_);
- instance_ = this;
-}
-
-DBMessageFilter::~DBMessageFilter() {
- instance_ = NULL;
-}
-
-DBMessageFilter* DBMessageFilter::GetInstance() {
- return instance_;
+ : io_thread_message_loop_(ChildProcess::current()->io_message_loop()),
+ channel_(NULL),
+ channel_lock_(new Lock()),
+ shutdown_event_(ChildProcess::current()->GetShutDownEvent()),
+ messages_awaiting_replies_(new IDMap<DBMessageState>()),
+ unique_id_generator_(new base::AtomicSequenceNumber()) {
+ DCHECK(!instance_);
+ instance_ = this;
}
int DBMessageFilter::GetUniqueID() {
@@ -43,17 +28,16 @@ static void SendMessageOnIOThread(IPC::Message* message,
IPC::Channel* channel,
Lock* channel_lock) {
AutoLock channel_auto_lock(*channel_lock);
- if (!channel) {
- delete message;
- } else {
+ if (channel)
channel->Send(message);
- }
+ else
+ delete message;
}
void DBMessageFilter::Send(IPC::Message* message) {
io_thread_message_loop_->PostTask(FROM_HERE,
- NewRunnableFunction(SendMessageOnIOThread, message,
- channel_, channel_lock_.get()));
+ NewRunnableFunction(SendMessageOnIOThread, message, channel_,
+ channel_lock_.get()));
}
void DBMessageFilter::OnFilterAdded(IPC::Channel* channel) {
@@ -76,12 +60,10 @@ bool DBMessageFilter::OnMessageReceived(const IPC::Message& message) {
IPC_BEGIN_MESSAGE_MAP(DBMessageFilter, message)
IPC_MESSAGE_HANDLER(ViewMsg_DatabaseOpenFileResponse,
OnResponse<ViewMsg_DatabaseOpenFileResponse_Params>)
- IPC_MESSAGE_HANDLER(ViewMsg_DatabaseDeleteFileResponse,
- OnResponse<int>)
+ IPC_MESSAGE_HANDLER(ViewMsg_DatabaseDeleteFileResponse, OnResponse<int>)
IPC_MESSAGE_HANDLER(ViewMsg_DatabaseGetFileAttributesResponse,
OnResponse<uint32>)
- IPC_MESSAGE_HANDLER(ViewMsg_DatabaseGetFileSizeResponse,
- OnResponse<int64>)
+ IPC_MESSAGE_HANDLER(ViewMsg_DatabaseGetFileSizeResponse, OnResponse<int64>)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
diff --git a/chrome/common/db_message_filter.h b/chrome/common/db_message_filter.h
index 1376db0..23035e9 100644
--- a/chrome/common/db_message_filter.h
+++ b/chrome/common/db_message_filter.h
@@ -5,6 +5,7 @@
#ifndef CHROME_COMMON_DB_MESSAGE_FILTER_H_
#define CHROME_COMMON_DB_MESSAGE_FILTER_H_
+#include "base/atomic_sequence_num.h"
#include "base/id_map.h"
#include "base/scoped_ptr.h"
#include "base/waitable_event.h"
@@ -13,94 +14,74 @@
class Lock;
class MessageLoop;
-namespace base {
-class AtomicSequenceNumber;
-}
-
namespace IPC {
class Channel;
}
-// A thread-safe message filter used to send IPCs from DB threads and
-// process replies from the browser process.
+// A thread-safe message filter used to send IPCs from DB threads and process
+// replies from the browser process.
//
-// This class should not be instantianted anywhere but RenderThread::Init().
-// It is meant to be a singleton in each renderer process. To get the
-// singleton, use DBMessageFilter::GetInstance().
+// This class should not be instantianted anywhere but RenderThread::Init(). It
+// is meant to be a singleton in each renderer process. To access the singleton,
+// use GetInstance().
class DBMessageFilter : public IPC::ChannelProxy::MessageFilter {
public:
// Creates a new DBMessageFilter instance.
DBMessageFilter();
// Returns the DBMessageFilter singleton created in this renderer process.
- static DBMessageFilter* GetInstance();
+ static DBMessageFilter* GetInstance() { return instance_; }
- // Returns a ID that uniquely identifies each message that will be sent
- // using the SendAndWait() method.
+ // Returns a unique ID for use when calling the SendAndWait() method.
virtual int GetUniqueID();
- // Posts a task to the IO thread to send the given message to the browser.
- //
- // message - The message.
+ // Posts a task to the IO thread to send |message| to the browser.
virtual void Send(IPC::Message* message);
- // Sends a message and blocks the current thread until a reply for that
- // message is received or the renderer process is about to be destroyed.
- //
- // Returns the result from the reply message or the default value if the
- // renderer process is being destroyed, or the message could not be sent.
- //
- // message - The message to be sent.
- // message_id - An ID that uniquely identifies this message.
- // default_result - The default value; returned when the renderer process
- // is being destroyed before the reply got back, or if
- // the message could not be sent.
+ // Sends |message| and blocks the current thread. Returns the result from the
+ // reply message, or |default_result| if the renderer process is being
+ // destroyed or the message could not be sent.
template<class ResultType>
- ResultType SendAndWait(IPC::Message* message, int message_id,
- ResultType default_result) {
+ ResultType SendAndWait(IPC::Message* message,
+ int message_id,
+ ResultType default_result) {
ResultType result;
base::WaitableEvent waitable_event(false, false);
DBMessageState state =
- { reinterpret_cast<intptr_t>(&result), &waitable_event };
+ { reinterpret_cast<intptr_t>(&result), &waitable_event };
messages_awaiting_replies_->AddWithID(&state, message_id);
Send(message);
base::WaitableEvent* events[2] = { shutdown_event_, &waitable_event };
- size_t event_index = base::WaitableEvent::WaitMany(events, 2);
- return (event_index ? result : default_result);
+ return (base::WaitableEvent::WaitMany(events, 2) ? result : default_result);
}
- // Processes the incoming message from the browser process.
- //
- // message - The message.
+ // Processes incoming message |message| from the browser process.
virtual bool OnMessageReceived(const IPC::Message& message);
private:
- // The state we store for each message we send
+ // The state we store for each message we send.
struct DBMessageState {
intptr_t result_address_;
base::WaitableEvent* waitable_event_;
};
- // This is a RefCount'ed class, do not allow anybody to destroy
- // instances of this class
- virtual ~DBMessageFilter();
+ // This is a RefCounted class, do not allow anybody to destroy it directly.
+ virtual ~DBMessageFilter() { instance_ = NULL; }
- // Invoked when this filter is added to a channel.
- //
- // channel - The channel this filter was added to.
+ // Invoked when this filter is added to |channel|.
virtual void OnFilterAdded(IPC::Channel* channel);
- // Called when the channel encounters a problem. The filter should
- // clean up its internal data and not accept any more messages.
+ // Called when the channel encounters a problem. The filter should clean up
+ // its internal data and not accept any more messages.
virtual void OnChannelError();
- // Called when the channel is closing. The filter should clean up
- // its internal data and not accept any more messages.
+ // Called when the channel is closing. The filter should clean up its internal
+ // and not accept any more messages.
virtual void OnChannelClosing();
- // Processes the reply to a DB request
+ // Processes the reply to a DB request.
template<class ResultType>
void OnResponse(int32 message_id, ResultType result) {
DBMessageState *state = messages_awaiting_replies_->Lookup(message_id);
@@ -111,26 +92,26 @@ class DBMessageFilter : public IPC::ChannelProxy::MessageFilter {
}
}
- // The message loop of the IO thread
+ // The message loop for the IO thread.
MessageLoop* io_thread_message_loop_;
- // The channel this filter was added to
+ // The channel to which this filter was added.
IPC::Channel* channel_;
- // A lock around the channel
+ // A lock around the channel.
scoped_ptr<Lock> channel_lock_;
- // The shutdown event
+ // The shutdown event.
base::WaitableEvent* shutdown_event_;
- // The list of messages awaiting replies
- // For each such message we store a DBMessageState instance
+ // The list of messages awaiting replies. For each such message we store a
+ // DBMessageState instance.
scoped_ptr<IDMap<DBMessageState> > messages_awaiting_replies_;
- // A thread-safe unique number generator
+ // A thread-safe unique number generator.
scoped_ptr<base::AtomicSequenceNumber> unique_id_generator_;
- // The singleton
+ // The singleton.
static DBMessageFilter* instance_;
};
diff --git a/webkit/database/vfs_backend.cc b/webkit/database/vfs_backend.cc
index cc06215..8d84dbd 100644
--- a/webkit/database/vfs_backend.cc
+++ b/webkit/database/vfs_backend.cc
@@ -12,12 +12,12 @@
#include "base/file_path.h"
#include "base/file_util.h"
-#include "base/process.h"
namespace webkit_database {
-bool VfsBackend::OpenFileFlagsAreConsistent(
- const FilePath& file_name, const FilePath& db_dir, int desired_flags) {
+bool VfsBackend::OpenFileFlagsAreConsistent(const FilePath& file_name,
+ const FilePath& db_dir,
+ int desired_flags) {
// Is this a request for a temp file?
// We should be able to delete temp files when they're closed
// and create them as needed
@@ -34,72 +34,58 @@ bool VfsBackend::OpenFileFlagsAreConsistent(
const bool is_read_only = (desired_flags & SQLITE_OPEN_READONLY) != 0;
const bool is_read_write = (desired_flags & SQLITE_OPEN_READWRITE) != 0;
- // All files should be opened either read-write or read-only.
- if (!(is_read_only ^ is_read_write)) {
+ // All files should be opened either read-write or read-only, but not both.
+ if (is_read_only == is_read_write)
return false;
- }
- // If a new file is created, it must also be writtable.
- if (is_create && !is_read_write) {
+ // If a new file is created, it must also be writable.
+ if (is_create && !is_read_write)
return false;
- }
-
- // We must be able to create a new file, if exclusive access is desired.
- if (is_exclusive && !is_create) {
- return false;
- }
- // We cannot delete the files that we expect to already exist.
- if (is_delete && !is_create) {
+ // If we're accessing an existing file, we cannot give exclusive access, and
+ // we can't delete it.
+ if ((is_exclusive || is_delete) && !is_create)
return false;
- }
// The main DB, main journal and master journal cannot be auto-deleted.
- if (((file_type == SQLITE_OPEN_MAIN_DB) ||
- (file_type == SQLITE_OPEN_MAIN_JOURNAL) ||
- (file_type == SQLITE_OPEN_MASTER_JOURNAL)) &&
- is_delete) {
+ if (is_delete && ((file_type == SQLITE_OPEN_MAIN_DB) ||
+ (file_type == SQLITE_OPEN_MAIN_JOURNAL) ||
+ (file_type == SQLITE_OPEN_MASTER_JOURNAL))) {
return false;
}
// Make sure we're opening the DB directory or that a file type is set.
- if ((file_type != SQLITE_OPEN_MAIN_DB) &&
- (file_type != SQLITE_OPEN_TEMP_DB) &&
- (file_type != SQLITE_OPEN_MAIN_JOURNAL) &&
- (file_type != SQLITE_OPEN_TEMP_JOURNAL) &&
- (file_type != SQLITE_OPEN_SUBJOURNAL) &&
- (file_type != SQLITE_OPEN_MASTER_JOURNAL) &&
- (file_type != SQLITE_OPEN_TRANSIENT_DB)) {
- return false;
- }
-
- return true;
+ return (file_type == SQLITE_OPEN_MAIN_DB) ||
+ (file_type == SQLITE_OPEN_TEMP_DB) ||
+ (file_type == SQLITE_OPEN_MAIN_JOURNAL) ||
+ (file_type == SQLITE_OPEN_TEMP_JOURNAL) ||
+ (file_type == SQLITE_OPEN_SUBJOURNAL) ||
+ (file_type == SQLITE_OPEN_MASTER_JOURNAL) ||
+ (file_type == SQLITE_OPEN_TRANSIENT_DB);
}
-void VfsBackend::OpenFile(
- const FilePath& file_name, const FilePath& db_dir, int desired_flags,
- base::ProcessHandle handle, base::PlatformFile* target_handle,
- base::PlatformFile* target_dir_handle) {
+void VfsBackend::OpenFile(const FilePath& file_name,
+ const FilePath& db_dir,
+ int desired_flags,
+ base::ProcessHandle handle,
+ base::PlatformFile* target_handle,
+ base::PlatformFile* target_dir_handle) {
// Verify the flags for consistency and create the database
// directory if it doesn't exist.
if (OpenFileFlagsAreConsistent(file_name, db_dir, desired_flags) &&
file_util::CreateDirectory(db_dir)) {
int flags = 0;
flags |= base::PLATFORM_FILE_READ;
- if (desired_flags & SQLITE_OPEN_READWRITE) {
+ if (desired_flags & SQLITE_OPEN_READWRITE)
flags |= base::PLATFORM_FILE_WRITE;
- }
if (!(desired_flags & SQLITE_OPEN_MAIN_DB)) {
flags |= base::PLATFORM_FILE_EXCLUSIVE_READ |
base::PLATFORM_FILE_EXCLUSIVE_WRITE;
}
- if (desired_flags & SQLITE_OPEN_CREATE) {
- flags |= base::PLATFORM_FILE_OPEN_ALWAYS;
- } else {
- flags |= base::PLATFORM_FILE_OPEN;
- }
+ flags |= ((desired_flags & SQLITE_OPEN_CREATE) ?
+ base::PLATFORM_FILE_OPEN_ALWAYS : base::PLATFORM_FILE_OPEN);
if (desired_flags & SQLITE_OPEN_EXCLUSIVE) {
flags |= base::PLATFORM_FILE_EXCLUSIVE_READ |
@@ -114,16 +100,15 @@ void VfsBackend::OpenFile(
// If this is a request for a handle to a temp file, get a unique file name
FilePath db_file_name;
if (file_name == db_dir) {
- if (!file_util::CreateTemporaryFileInDir(db_dir, &db_file_name)) {
+ if (!file_util::CreateTemporaryFileInDir(db_dir, &db_file_name))
db_file_name = FilePath();
- }
} else {
db_file_name = file_name;
}
// Try to open/create the DB file.
- base::PlatformFile file_handle =
- (db_file_name.empty() ? base::kInvalidPlatformFileValue :
+ base::PlatformFile file_handle = (db_file_name.empty() ?
+ base::kInvalidPlatformFileValue :
base::CreatePlatformFile(db_file_name.ToWStringHack(), flags, NULL));
if (file_handle != base::kInvalidPlatformFileValue) {
#if defined(OS_WIN)
@@ -157,14 +142,13 @@ void VfsBackend::OpenFile(
}
}
-int VfsBackend::DeleteFile(
- const FilePath& file_name, const FilePath& db_dir, bool sync_dir) {
- if (!file_util::PathExists(file_name)) {
+int VfsBackend::DeleteFile(const FilePath& file_name,
+ const FilePath& db_dir,
+ bool sync_dir) {
+ if (!file_util::PathExists(file_name))
return SQLITE_OK;
- }
- if (!file_util::Delete(file_name, false)) {
+ if (!file_util::Delete(file_name, false))
return SQLITE_IOERR_DELETE;
- }
int error_code = SQLITE_OK;
#if defined(OS_POSIX)
@@ -174,9 +158,8 @@ int VfsBackend::DeleteFile(
if (dir_fd == base::kInvalidPlatformFileValue) {
error_code = SQLITE_CANTOPEN;
} else {
- if (fsync(dir_fd)) {
+ if (fsync(dir_fd))
error_code = SQLITE_IOERR_DIR_FSYNC;
- }
base::ClosePlatformFile(dir_fd);
}
}
@@ -189,15 +172,12 @@ uint32 VfsBackend::GetFileAttributes(const FilePath& file_name) {
uint32 attributes = ::GetFileAttributes(file_name.value().c_str());
#elif defined(OS_POSIX)
uint32 attributes = 0;
- if (!access(file_name.value().c_str(), R_OK)) {
+ if (!access(file_name.value().c_str(), R_OK))
attributes |= static_cast<uint32>(R_OK);
- }
- if (!access(file_name.value().c_str(), W_OK)) {
+ if (!access(file_name.value().c_str(), W_OK))
attributes |= static_cast<uint32>(W_OK);
- }
- if (!attributes) {
+ if (!attributes)
attributes = -1;
- }
#endif
return attributes;
}
@@ -207,4 +187,4 @@ int64 VfsBackend::GetFileSize(const FilePath& file_name) {
return (file_util::GetFileSize(file_name, &size) ? size : 0);
}
-} // namespace database
+} // namespace webkit_database
diff --git a/webkit/database/vfs_backend.h b/webkit/database/vfs_backend.h
index 536ffd8..d57e9e2 100644
--- a/webkit/database/vfs_backend.h
+++ b/webkit/database/vfs_backend.h
@@ -14,20 +14,27 @@ namespace webkit_database {
class VfsBackend {
public:
- static void OpenFile(
- const FilePath& file_name, const FilePath& db_dir, int desired_flags,
- base::ProcessHandle handle, base::PlatformFile* target_handle,
- base::PlatformFile* target_dir_handle);
- static int DeleteFile(
- const FilePath& file_name, const FilePath& db_dir, bool sync_dir);
+ static void OpenFile(const FilePath& file_name,
+ const FilePath& db_dir,
+ int desired_flags,
+ base::ProcessHandle handle,
+ base::PlatformFile* target_handle,
+ base::PlatformFile* target_dir_handle);
+
+ static int DeleteFile(const FilePath& file_name,
+ const FilePath& db_dir,
+ bool sync_dir);
+
static uint32 GetFileAttributes(const FilePath& file_name);
+
static int64 GetFileSize(const FilePath& file_name);
private:
- static bool OpenFileFlagsAreConsistent(
- const FilePath& file_name, const FilePath& db_dir, int desired_flags);
+ static bool OpenFileFlagsAreConsistent(const FilePath& file_name,
+ const FilePath& db_dir,
+ int desired_flags);
};
-} // namespace webkit_database
+} // namespace webkit_database
#endif // WEBKIT_DATABASE_VFS_BACKEND_H_