summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortzik@chromium.org <tzik@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-14 03:37:36 +0000
committertzik@chromium.org <tzik@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-14 03:37:36 +0000
commit5ebda57faf69cdc6b07818006e0fd677bfc97fcf (patch)
tree1f8bf4e6205dcc335b37a12e2540c7d8d86f0484
parent43d2cd6bc8712a58a6792103016b188a0242fccc (diff)
downloadchromium_src-5ebda57faf69cdc6b07818006e0fd677bfc97fcf.zip
chromium_src-5ebda57faf69cdc6b07818006e0fd677bfc97fcf.tar.gz
chromium_src-5ebda57faf69cdc6b07818006e0fd677bfc97fcf.tar.bz2
Merge 244393 "[Pepper] Use platform path for QuotaReservation::G..."
> [Pepper] Use platform path for QuotaReservation::GetOpenFileHandle > > * Pass platform file path instead of virtual path to fileapis::QuotaReservation. > * This should fix the quota leak regression. > > BUG=333150 > > Review URL: https://codereview.chromium.org/131043002 TBR=tzik@chromium.org Review URL: https://codereview.chromium.org/136843005 git-svn-id: svn://svn.chromium.org/chrome/branches/1750/src@244644 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--content/browser/renderer_host/pepper/pepper_file_io_host.cc2
-rw-r--r--content/browser/renderer_host/pepper/pepper_file_system_browser_host.cc4
-rw-r--r--content/browser/renderer_host/pepper/pepper_file_system_browser_host.h2
-rw-r--r--content/browser/renderer_host/pepper/quota_reservation.cc20
-rw-r--r--content/browser/renderer_host/pepper/quota_reservation.h7
-rw-r--r--content/browser/renderer_host/pepper/quota_reservation_unittest.cc20
-rw-r--r--webkit/browser/fileapi/quota/quota_reservation_buffer.cc7
7 files changed, 45 insertions, 17 deletions
diff --git a/content/browser/renderer_host/pepper/pepper_file_io_host.cc b/content/browser/renderer_host/pepper/pepper_file_io_host.cc
index 041a28d..66a0ad2 100644
--- a/content/browser/renderer_host/pepper/pepper_file_io_host.cc
+++ b/content/browser/renderer_host/pepper/pepper_file_io_host.cc
@@ -241,7 +241,7 @@ void PepperFileIOHost::DidOpenInternalFile(
if (check_quota_) {
file_system_host_->OpenQuotaFile(
this,
- file_system_url_.path(),
+ file_system_url_,
base::Bind(&PepperFileIOHost::DidOpenQuotaFile,
weak_factory_.GetWeakPtr(),
reply_context,
diff --git a/content/browser/renderer_host/pepper/pepper_file_system_browser_host.cc b/content/browser/renderer_host/pepper/pepper_file_system_browser_host.cc
index b95f79c..740e9b8 100644
--- a/content/browser/renderer_host/pepper/pepper_file_system_browser_host.cc
+++ b/content/browser/renderer_host/pepper/pepper_file_system_browser_host.cc
@@ -120,7 +120,7 @@ bool PepperFileSystemBrowserHost::IsFileSystemHost() {
void PepperFileSystemBrowserHost::OpenQuotaFile(
PepperFileIOHost* file_io_host,
- const base::FilePath& file_path,
+ const fileapi::FileSystemURL& url,
const OpenQuotaFileCallback& callback) {
int32_t id = file_io_host->pp_resource();
std::pair<FileMap::iterator, bool> insert_result =
@@ -132,7 +132,7 @@ void PepperFileSystemBrowserHost::OpenQuotaFile(
base::Bind(&QuotaReservation::OpenFile,
quota_reservation_,
id,
- file_path),
+ url),
callback);
} else {
NOTREACHED();
diff --git a/content/browser/renderer_host/pepper/pepper_file_system_browser_host.h b/content/browser/renderer_host/pepper/pepper_file_system_browser_host.h
index bd47a43..f97ddde 100644
--- a/content/browser/renderer_host/pepper/pepper_file_system_browser_host.h
+++ b/content/browser/renderer_host/pepper/pepper_file_system_browser_host.h
@@ -68,7 +68,7 @@ class CONTENT_EXPORT PepperFileSystemBrowserHost
// callback.
typedef base::Callback<void(int64_t)> OpenQuotaFileCallback;
void OpenQuotaFile(PepperFileIOHost* file_io_host,
- const base::FilePath& file_path,
+ const fileapi::FileSystemURL& url,
const OpenQuotaFileCallback& callback);
// Closes the file. This must be called after OpenQuotaFile and before the
// PepperFileIOHost is destroyed.
diff --git a/content/browser/renderer_host/pepper/quota_reservation.cc b/content/browser/renderer_host/pepper/quota_reservation.cc
index a512f10..221b374 100644
--- a/content/browser/renderer_host/pepper/quota_reservation.cc
+++ b/content/browser/renderer_host/pepper/quota_reservation.cc
@@ -7,6 +7,7 @@
#include "base/bind.h"
#include "base/callback.h"
#include "content/public/browser/browser_thread.h"
+#include "webkit/browser/fileapi/file_system_operation_runner.h"
#include "webkit/browser/fileapi/quota/open_file_handle.h"
#include "webkit/browser/fileapi/quota/quota_reservation.h"
#include "webkit/common/fileapi/file_system_util.h"
@@ -49,9 +50,23 @@ QuotaReservation::~QuotaReservation() {
}
int64_t QuotaReservation::OpenFile(int32_t id,
- const base::FilePath& file_path) {
+ const fileapi::FileSystemURL& url) {
+ base::FilePath platform_file_path;
+ if (file_system_context_) {
+ base::PlatformFileError error =
+ file_system_context_->operation_runner()->SyncGetPlatformPath(
+ url, &platform_file_path);
+ if (error != base::PLATFORM_FILE_OK) {
+ NOTREACHED();
+ return 0;
+ }
+ } else {
+ // For test.
+ platform_file_path = url.path();
+ }
+
scoped_ptr<fileapi::OpenFileHandle> file_handle =
- quota_reservation_->GetOpenFileHandle(file_path);
+ quota_reservation_->GetOpenFileHandle(platform_file_path);
std::pair<FileMap::iterator, bool> insert_result =
files_.insert(std::make_pair(id, file_handle.get()));
if (insert_result.second) {
@@ -68,6 +83,7 @@ void QuotaReservation::CloseFile(int32_t id,
FileMap::iterator it = files_.find(id);
if (it != files_.end()) {
it->second->UpdateMaxWrittenOffset(max_written_offset);
+ delete it->second;
files_.erase(it);
} else {
NOTREACHED();
diff --git a/content/browser/renderer_host/pepper/quota_reservation.h b/content/browser/renderer_host/pepper/quota_reservation.h
index bd7e0ea..845b868 100644
--- a/content/browser/renderer_host/pepper/quota_reservation.h
+++ b/content/browser/renderer_host/pepper/quota_reservation.h
@@ -15,11 +15,8 @@
#include "url/gurl.h"
#include "webkit/browser/fileapi/file_system_context.h"
-namespace base {
-class FilePath;
-}
-
namespace fileapi {
+class FileSystemURL;
class OpenFileHandle;
class QuotaReservation;
}
@@ -44,7 +41,7 @@ class CONTENT_EXPORT QuotaReservation
fileapi::FileSystemType file_system_type);
// Opens a file with the given id and path and returns its current size.
- int64_t OpenFile(int32_t id, const base::FilePath& file_path);
+ int64_t OpenFile(int32_t id, const fileapi::FileSystemURL& url);
// Closes the file opened by OpenFile with the given id.
void CloseFile(int32_t id, int64_t max_written_offset);
// Refreshes the quota reservation to a new amount. A map that associates file
diff --git a/content/browser/renderer_host/pepper/quota_reservation_unittest.cc b/content/browser/renderer_host/pepper/quota_reservation_unittest.cc
index a9a5f71..3f760e5 100644
--- a/content/browser/renderer_host/pepper/quota_reservation_unittest.cc
+++ b/content/browser/renderer_host/pepper/quota_reservation_unittest.cc
@@ -82,10 +82,16 @@ class QuotaReservationTest : public testing::Test {
reservation_manager_.reset();
}
- base::FilePath MakeFilePath(base::FilePath::StringType file_name) {
+ base::FilePath MakeFilePath(const base::FilePath::StringType& file_name) {
return work_dir_.path().Append(file_name);
}
+ fileapi::FileSystemURL MakeFileSystemURL(
+ const base::FilePath::StringType& file_name) {
+ return fileapi::FileSystemURL::CreateForTest(
+ GURL(kOrigin), kType, MakeFilePath(file_name));
+ }
+
scoped_refptr<QuotaReservation> CreateQuotaReservation(
scoped_refptr<fileapi::QuotaReservation> reservation,
const GURL& origin,
@@ -164,7 +170,8 @@ TEST_F(QuotaReservationTest, DISABLED_ReserveQuota) {
// Open a file, refresh the reservation, extend the file, and close it.
int64 file_size = 10;
SetFileSize(file1_name, file_size);
- int64 open_file_size = test->OpenFile(kFile1ID, MakeFilePath(file1_name));
+ int64 open_file_size = test->OpenFile(kFile1ID,
+ MakeFileSystemURL(file1_name));
EXPECT_EQ(file_size, open_file_size);
max_written_offsets[kFile1ID] = file_size; // 1 file open.
@@ -196,15 +203,18 @@ TEST_F(QuotaReservationTest, DISABLED_MultipleFiles) {
// Open some files of different sizes.
int64 file1_size = 10;
SetFileSize(file1_name, file1_size);
- int64 open_file1_size = test->OpenFile(kFile1ID, MakeFilePath(file1_name));
+ int64 open_file1_size = test->OpenFile(kFile1ID,
+ MakeFileSystemURL(file1_name));
EXPECT_EQ(file1_size, open_file1_size);
int64 file2_size = 20;
SetFileSize(file2_name, file2_size);
- int64 open_file2_size = test->OpenFile(kFile2ID, MakeFilePath(file2_name));
+ int64 open_file2_size = test->OpenFile(kFile2ID,
+ MakeFileSystemURL(file2_name));
EXPECT_EQ(file2_size, open_file2_size);
int64 file3_size = 30;
SetFileSize(file3_name, file3_size);
- int64 open_file3_size = test->OpenFile(kFile3ID, MakeFilePath(file3_name));
+ int64 open_file3_size = test->OpenFile(kFile3ID,
+ MakeFileSystemURL(file3_name));
EXPECT_EQ(file3_size, open_file3_size);
// Reserve quota.
diff --git a/webkit/browser/fileapi/quota/quota_reservation_buffer.cc b/webkit/browser/fileapi/quota/quota_reservation_buffer.cc
index 80d3699..14ea0d0 100644
--- a/webkit/browser/fileapi/quota/quota_reservation_buffer.cc
+++ b/webkit/browser/fileapi/quota/quota_reservation_buffer.cc
@@ -46,8 +46,13 @@ void QuotaReservationBuffer::CommitFileGrowth(int64 quota_consumption,
return;
reservation_manager_->CommitQuotaUsage(origin_, type_, usage_delta);
- DCHECK_LE(quota_consumption, reserved_quota_);
if (quota_consumption > 0) {
+ if (quota_consumption > reserved_quota_) {
+ LOG(ERROR) << "Detected over consumption of the storage quota beyond its"
+ << " reservation";
+ quota_consumption = reserved_quota_;
+ }
+
reserved_quota_ -= quota_consumption;
reservation_manager_->ReleaseReservedQuota(
origin_, type_, quota_consumption);