Chromium Code Reviews| 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 "content/browser/renderer_host/pepper/quota_reservation.h" | 5 #include "content/browser/renderer_host/pepper/quota_reservation.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
| 10 #include "webkit/browser/fileapi/file_system_operation_runner.h" | |
| 10 #include "webkit/browser/fileapi/quota/open_file_handle.h" | 11 #include "webkit/browser/fileapi/quota/open_file_handle.h" |
| 11 #include "webkit/browser/fileapi/quota/quota_reservation.h" | 12 #include "webkit/browser/fileapi/quota/quota_reservation.h" |
| 12 #include "webkit/common/fileapi/file_system_util.h" | 13 #include "webkit/common/fileapi/file_system_util.h" |
| 13 | 14 |
| 14 namespace content { | 15 namespace content { |
| 15 | 16 |
| 16 // static | 17 // static |
| 17 scoped_refptr<QuotaReservation> QuotaReservation::Create( | 18 scoped_refptr<QuotaReservation> QuotaReservation::Create( |
| 18 scoped_refptr<fileapi::FileSystemContext> file_system_context, | 19 scoped_refptr<fileapi::FileSystemContext> file_system_context, |
| 19 const GURL& origin_url, | 20 const GURL& origin_url, |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 42 } | 43 } |
| 43 | 44 |
| 44 QuotaReservation::~QuotaReservation() { | 45 QuotaReservation::~QuotaReservation() { |
| 45 // We should have no open files at this point. | 46 // We should have no open files at this point. |
| 46 DCHECK(files_.size() == 0); | 47 DCHECK(files_.size() == 0); |
| 47 for (FileMap::iterator it = files_.begin(); it != files_.end(); ++ it) | 48 for (FileMap::iterator it = files_.begin(); it != files_.end(); ++ it) |
| 48 delete it->second; | 49 delete it->second; |
| 49 } | 50 } |
| 50 | 51 |
| 51 int64_t QuotaReservation::OpenFile(int32_t id, | 52 int64_t QuotaReservation::OpenFile(int32_t id, |
| 52 const base::FilePath& file_path) { | 53 const fileapi::FileSystemURL& url) { |
| 54 base::FilePath platform_file_path; | |
| 55 if (file_system_context_) { | |
| 56 base::PlatformFileError error = | |
| 57 file_system_context_->operation_runner()->SyncGetPlatformPath( | |
| 58 url, &platform_file_path); | |
| 59 if (error != base::PLATFORM_FILE_OK) { | |
| 60 NOTREACHED(); | |
| 61 return 0; | |
| 62 } | |
| 63 } else { | |
| 64 // For test. | |
| 65 platform_file_path = url.path(); | |
| 66 } | |
| 67 | |
| 53 scoped_ptr<fileapi::OpenFileHandle> file_handle = | 68 scoped_ptr<fileapi::OpenFileHandle> file_handle = |
| 54 quota_reservation_->GetOpenFileHandle(file_path); | 69 quota_reservation_->GetOpenFileHandle(platform_file_path); |
| 55 std::pair<FileMap::iterator, bool> insert_result = | 70 std::pair<FileMap::iterator, bool> insert_result = |
| 56 files_.insert(std::make_pair(id, file_handle.get())); | 71 files_.insert(std::make_pair(id, file_handle.get())); |
| 57 if (insert_result.second) { | 72 if (insert_result.second) { |
| 58 int64_t max_written_offset = file_handle->base_file_size(); | 73 int64_t max_written_offset = file_handle->base_file_size(); |
| 59 ignore_result(file_handle.release()); | 74 ignore_result(file_handle.release()); |
| 60 return max_written_offset; | 75 return max_written_offset; |
| 61 } | 76 } |
| 62 NOTREACHED(); | 77 NOTREACHED(); |
| 63 return 0; | 78 return 0; |
| 64 } | 79 } |
| 65 | 80 |
| 66 void QuotaReservation::CloseFile(int32_t id, | 81 void QuotaReservation::CloseFile(int32_t id, |
| 67 int64_t max_written_offset) { | 82 int64_t max_written_offset) { |
| 68 FileMap::iterator it = files_.find(id); | 83 FileMap::iterator it = files_.find(id); |
| 69 if (it != files_.end()) { | 84 if (it != files_.end()) { |
| 70 it->second->UpdateMaxWrittenOffset(max_written_offset); | 85 it->second->UpdateMaxWrittenOffset(max_written_offset); |
| 86 delete it->second; | |
|
bbudge
2014/01/10 06:03:13
Whoa, nice catch.
| |
| 71 files_.erase(it); | 87 files_.erase(it); |
| 72 } else { | 88 } else { |
| 73 NOTREACHED(); | 89 NOTREACHED(); |
| 74 } | 90 } |
| 75 } | 91 } |
| 76 | 92 |
| 77 void QuotaReservation::ReserveQuota( | 93 void QuotaReservation::ReserveQuota( |
| 78 int64_t amount, | 94 int64_t amount, |
| 79 const OffsetMap& max_written_offsets, | 95 const OffsetMap& max_written_offsets, |
| 80 const ReserveQuotaCallback& callback) { | 96 const ReserveQuotaCallback& callback) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 file_system_context_->default_file_task_runner()->DeleteSoon( | 142 file_system_context_->default_file_task_runner()->DeleteSoon( |
| 127 FROM_HERE, | 143 FROM_HERE, |
| 128 this); | 144 this); |
| 129 } else { | 145 } else { |
| 130 // We're on the right thread to delete, or unit test. | 146 // We're on the right thread to delete, or unit test. |
| 131 delete this; | 147 delete this; |
| 132 } | 148 } |
| 133 } | 149 } |
| 134 | 150 |
| 135 } // namespace content | 151 } // namespace content |
| OLD | NEW |