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/file_system_operation_runner.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 } else { | 63 } else { |
64 // For test. | 64 // For test. |
65 platform_file_path = url.path(); | 65 platform_file_path = url.path(); |
66 } | 66 } |
67 | 67 |
68 scoped_ptr<fileapi::OpenFileHandle> file_handle = | 68 scoped_ptr<fileapi::OpenFileHandle> file_handle = |
69 quota_reservation_->GetOpenFileHandle(platform_file_path); | 69 quota_reservation_->GetOpenFileHandle(platform_file_path); |
70 std::pair<FileMap::iterator, bool> insert_result = | 70 std::pair<FileMap::iterator, bool> insert_result = |
71 files_.insert(std::make_pair(id, file_handle.get())); | 71 files_.insert(std::make_pair(id, file_handle.get())); |
72 if (insert_result.second) { | 72 if (insert_result.second) { |
73 int64_t max_written_offset = file_handle->base_file_size(); | 73 int64_t max_written_offset = file_handle->GetEstimatedFileSize(); |
74 ignore_result(file_handle.release()); | 74 ignore_result(file_handle.release()); |
75 return max_written_offset; | 75 return max_written_offset; |
76 } | 76 } |
77 NOTREACHED(); | 77 NOTREACHED(); |
78 return 0; | 78 return 0; |
79 } | 79 } |
80 | 80 |
81 void QuotaReservation::CloseFile(int32_t id, | 81 void QuotaReservation::CloseFile(int32_t id, |
82 int64_t max_written_offset) { | 82 int64_t max_written_offset) { |
83 FileMap::iterator it = files_.find(id); | 83 FileMap::iterator it = files_.find(id); |
(...skipping 28 matching lines...) Expand all Loading... |
112 void QuotaReservation::OnClientCrash() { | 112 void QuotaReservation::OnClientCrash() { |
113 quota_reservation_->OnClientCrash(); | 113 quota_reservation_->OnClientCrash(); |
114 } | 114 } |
115 | 115 |
116 void QuotaReservation::GotReservedQuota( | 116 void QuotaReservation::GotReservedQuota( |
117 const ReserveQuotaCallback& callback, | 117 const ReserveQuotaCallback& callback, |
118 base::PlatformFileError error) { | 118 base::PlatformFileError error) { |
119 OffsetMap max_written_offsets; | 119 OffsetMap max_written_offsets; |
120 for (FileMap::iterator it = files_.begin(); it != files_.end(); ++ it) { | 120 for (FileMap::iterator it = files_.begin(); it != files_.end(); ++ it) { |
121 max_written_offsets.insert( | 121 max_written_offsets.insert( |
122 std::make_pair(it->first, it->second->base_file_size())); | 122 std::make_pair(it->first, it->second->GetEstimatedFileSize())); |
123 } | 123 } |
124 | 124 |
125 if (file_system_context_) { | 125 if (file_system_context_) { |
126 BrowserThread::PostTask( | 126 BrowserThread::PostTask( |
127 BrowserThread::IO, | 127 BrowserThread::IO, |
128 FROM_HERE, | 128 FROM_HERE, |
129 base::Bind(callback, | 129 base::Bind(callback, |
130 quota_reservation_->remaining_quota(), | 130 quota_reservation_->remaining_quota(), |
131 max_written_offsets)); | 131 max_written_offsets)); |
132 } else { | 132 } else { |
133 // Unit testing code path. | 133 // Unit testing code path. |
134 callback.Run(quota_reservation_->remaining_quota(), max_written_offsets); | 134 callback.Run(quota_reservation_->remaining_quota(), max_written_offsets); |
135 } | 135 } |
136 } | 136 } |
137 | 137 |
138 void QuotaReservation::DeleteOnCorrectThread() const { | 138 void QuotaReservation::DeleteOnCorrectThread() const { |
139 if (file_system_context_ && | 139 if (file_system_context_ && |
140 !file_system_context_-> | 140 !file_system_context_-> |
141 default_file_task_runner()->RunsTasksOnCurrentThread()) { | 141 default_file_task_runner()->RunsTasksOnCurrentThread()) { |
142 file_system_context_->default_file_task_runner()->DeleteSoon( | 142 file_system_context_->default_file_task_runner()->DeleteSoon( |
143 FROM_HERE, | 143 FROM_HERE, |
144 this); | 144 this); |
145 } else { | 145 } else { |
146 // We're on the right thread to delete, or unit test. | 146 // We're on the right thread to delete, or unit test. |
147 delete this; | 147 delete this; |
148 } | 148 } |
149 } | 149 } |
150 | 150 |
151 } // namespace content | 151 } // namespace content |
OLD | NEW |