2009-10-03 03:36:52 +02:00
|
|
|
// Copyright (c) 2009 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 _BROWSER_DATABASE_SYSTEM_H
|
|
|
|
#define _BROWSER_DATABASE_SYSTEM_H
|
|
|
|
|
|
|
|
#include "base/file_path.h"
|
2010-01-12 02:37:00 +01:00
|
|
|
#include "base/hash_tables.h"
|
|
|
|
#include "base/lock.h"
|
2009-10-03 03:36:52 +02:00
|
|
|
#include "base/platform_file.h"
|
2010-01-12 02:37:00 +01:00
|
|
|
#include "base/ref_counted.h"
|
2009-10-03 03:36:52 +02:00
|
|
|
#include "base/scoped_temp_dir.h"
|
2010-01-12 02:37:00 +01:00
|
|
|
#include "base/string16.h"
|
|
|
|
#include "third_party/WebKit/WebKit/chromium/public/WebDatabaseObserver.h"
|
|
|
|
#include "webkit/database/database_connections.h"
|
|
|
|
#include "webkit/database/database_tracker.h"
|
2009-10-03 03:36:52 +02:00
|
|
|
|
2010-01-12 02:37:00 +01:00
|
|
|
class BrowserDatabaseSystem : public webkit_database::DatabaseTracker::Observer,
|
|
|
|
public WebKit::WebDatabaseObserver {
|
2009-10-03 03:36:52 +02:00
|
|
|
public:
|
|
|
|
static BrowserDatabaseSystem* GetInstance();
|
|
|
|
BrowserDatabaseSystem();
|
|
|
|
~BrowserDatabaseSystem();
|
|
|
|
|
2010-01-12 02:37:00 +01:00
|
|
|
// VFS functions
|
|
|
|
base::PlatformFile OpenFile(const string16& vfs_file_name,
|
|
|
|
int desired_flags,
|
|
|
|
base::PlatformFile* dir_handle);
|
|
|
|
int DeleteFile(const string16& vfs_file_name, bool sync_dir);
|
|
|
|
long GetFileAttributes(const string16& vfs_file_name);
|
|
|
|
long long GetFileSize(const string16& vfs_file_name);
|
|
|
|
|
|
|
|
// database tracker functions
|
|
|
|
void DatabaseOpened(const string16& origin_identifier,
|
|
|
|
const string16& database_name,
|
|
|
|
const string16& description,
|
|
|
|
int64 estimated_size);
|
|
|
|
void DatabaseModified(const string16& origin_identifier,
|
|
|
|
const string16& database_name);
|
|
|
|
void DatabaseClosed(const string16& origin_identifier,
|
|
|
|
const string16& database_name);
|
|
|
|
|
|
|
|
// DatabaseTracker::Observer implementation
|
|
|
|
virtual void OnDatabaseSizeChanged(const string16& origin_identifier,
|
|
|
|
const string16& database_name,
|
|
|
|
int64 database_size,
|
|
|
|
int64 space_available);
|
|
|
|
|
|
|
|
// WebDatabaseObserver implementation
|
|
|
|
virtual void databaseOpened(const WebKit::WebDatabase& database);
|
|
|
|
virtual void databaseModified(const WebKit::WebDatabase& database);
|
|
|
|
virtual void databaseClosed(const WebKit::WebDatabase& database);
|
|
|
|
|
2009-10-03 03:36:52 +02:00
|
|
|
void ClearAllDatabases();
|
|
|
|
|
|
|
|
private:
|
2010-01-12 02:37:00 +01:00
|
|
|
// The calls that come from the database tracker run on the main thread.
|
|
|
|
// Therefore, we can only call DatabaseUtil::GetFullFilePathForVfsFile()
|
|
|
|
// on the main thread. However, the VFS calls run on the DB thread and
|
|
|
|
// they need to crack VFS file paths. To resolve this problem, we store
|
|
|
|
// a map of vfs_file_names to file_paths. The map is updated on the main
|
|
|
|
// thread on each DatabaseOpened() call that comes from the database
|
|
|
|
// tracker, and is read on the DB thread by each VFS call.
|
|
|
|
void SetFullFilePathsForVfsFile(const string16& origin_identifier,
|
|
|
|
const string16& database_name);
|
|
|
|
FilePath GetFullFilePathForVfsFile(const string16& vfs_file_name);
|
2009-10-03 03:36:52 +02:00
|
|
|
|
|
|
|
static BrowserDatabaseSystem* instance_;
|
|
|
|
|
|
|
|
ScopedTempDir temp_dir_;
|
|
|
|
|
2010-01-12 02:37:00 +01:00
|
|
|
scoped_refptr<webkit_database::DatabaseTracker> db_tracker_;
|
|
|
|
|
|
|
|
Lock file_names_lock_;
|
|
|
|
base::hash_map<string16, FilePath> file_names_;
|
|
|
|
|
|
|
|
webkit_database::DatabaseConnections database_connections_;
|
2009-10-03 03:36:52 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // _BROWSER_DATABASE_SYSTEM_H
|