| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "webkit/browser/fileapi/quota/open_file_handle_context.h" | 5 #include "webkit/browser/fileapi/quota/open_file_handle_context.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "webkit/browser/fileapi/quota/quota_reservation_buffer.h" | 8 #include "webkit/browser/fileapi/quota/quota_reservation_buffer.h" |
| 9 | 9 |
| 10 namespace fileapi { | 10 namespace fileapi { |
| 11 | 11 |
| 12 OpenFileHandleContext::OpenFileHandleContext( | 12 OpenFileHandleContext::OpenFileHandleContext( |
| 13 const base::FilePath& platform_path, | 13 const base::FilePath& platform_path, |
| 14 QuotaReservationBuffer* reservation_buffer) | 14 QuotaReservationBuffer* reservation_buffer) |
| 15 : initial_file_size_(0), | 15 : initial_file_size_(0), |
| 16 maximum_written_offset_(0), | 16 maximum_written_offset_(0), |
| 17 platform_path_(platform_path), | 17 platform_path_(platform_path), |
| 18 reservation_buffer_(reservation_buffer) { | 18 reservation_buffer_(reservation_buffer) { |
| 19 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); | 19 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); |
| 20 | 20 |
| 21 file_util::GetFileSize(platform_path, &initial_file_size_); | 21 base::GetFileSize(platform_path, &initial_file_size_); |
| 22 maximum_written_offset_ = initial_file_size_; | 22 maximum_written_offset_ = initial_file_size_; |
| 23 } | 23 } |
| 24 | 24 |
| 25 void OpenFileHandleContext::UpdateMaxWrittenOffset( | 25 void OpenFileHandleContext::UpdateMaxWrittenOffset( |
| 26 int64 offset, | 26 int64 offset, |
| 27 int64* new_file_size, | 27 int64* new_file_size, |
| 28 int64* growth) { | 28 int64* growth) { |
| 29 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); | 29 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); |
| 30 if (offset > maximum_written_offset_) { | 30 if (offset > maximum_written_offset_) { |
| 31 *growth = offset - maximum_written_offset_; | 31 *growth = offset - maximum_written_offset_; |
| 32 maximum_written_offset_ = offset; | 32 maximum_written_offset_ = offset; |
| 33 } else { | 33 } else { |
| 34 *growth = 0; | 34 *growth = 0; |
| 35 } | 35 } |
| 36 | 36 |
| 37 *new_file_size = maximum_written_offset_; | 37 *new_file_size = maximum_written_offset_; |
| 38 } | 38 } |
| 39 | 39 |
| 40 OpenFileHandleContext::~OpenFileHandleContext() { | 40 OpenFileHandleContext::~OpenFileHandleContext() { |
| 41 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); | 41 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); |
| 42 | 42 |
| 43 // TODO(tzik): Optimize this for single operation. | 43 // TODO(tzik): Optimize this for single operation. |
| 44 | 44 |
| 45 int64 file_size = 0; | 45 int64 file_size = 0; |
| 46 file_util::GetFileSize(platform_path_, &file_size); | 46 base::GetFileSize(platform_path_, &file_size); |
| 47 int64 usage_delta = file_size - initial_file_size_; | 47 int64 usage_delta = file_size - initial_file_size_; |
| 48 | 48 |
| 49 // |quota_consumption| may be greater than the recorded file growth when a | 49 // |quota_consumption| may be greater than the recorded file growth when a |
| 50 // plugin crashed before reporting its consumption. | 50 // plugin crashed before reporting its consumption. |
| 51 // In this case, the reserved quota for the plugin should be handled as | 51 // In this case, the reserved quota for the plugin should be handled as |
| 52 // consumed quota. | 52 // consumed quota. |
| 53 int64 quota_consumption = | 53 int64 quota_consumption = |
| 54 std::max(maximum_written_offset_, file_size) - initial_file_size_; | 54 std::max(maximum_written_offset_, file_size) - initial_file_size_; |
| 55 | 55 |
| 56 reservation_buffer_->CommitFileGrowth(quota_consumption, usage_delta); | 56 reservation_buffer_->CommitFileGrowth(quota_consumption, usage_delta); |
| 57 reservation_buffer_->DetachOpenFileHandleContext(this); | 57 reservation_buffer_->DetachOpenFileHandleContext(this); |
| 58 } | 58 } |
| 59 | 59 |
| 60 } // namespace fileapi | 60 } // namespace fileapi |
| OLD | NEW |