| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 QuotaReservation::~QuotaReservation() { | 44 QuotaReservation::~QuotaReservation() { |
| 45 // We should have no open files at this point. | 45 // We should have no open files at this point. |
| 46 DCHECK(files_.size() == 0); | 46 DCHECK(files_.size() == 0); |
| 47 for (FileMap::iterator it = files_.begin(); it != files_.end(); ++it) | 47 for (FileMap::iterator it = files_.begin(); it != files_.end(); ++it) |
| 48 delete it->second; | 48 delete it->second; |
| 49 } | 49 } |
| 50 | 50 |
| 51 int64_t QuotaReservation::OpenFile(int32_t id, | 51 int64_t QuotaReservation::OpenFile(int32_t id, |
| 52 const storage::FileSystemURL& url) { | 52 const storage::FileSystemURL& url) { |
| 53 base::FilePath platform_file_path; | 53 base::FilePath platform_file_path; |
| 54 if (file_system_context_) { | 54 if (file_system_context_.get()) { |
| 55 base::File::Error error = | 55 base::File::Error error = |
| 56 file_system_context_->operation_runner()->SyncGetPlatformPath( | 56 file_system_context_->operation_runner()->SyncGetPlatformPath( |
| 57 url, &platform_file_path); | 57 url, &platform_file_path); |
| 58 if (error != base::File::FILE_OK) { | 58 if (error != base::File::FILE_OK) { |
| 59 NOTREACHED(); | 59 NOTREACHED(); |
| 60 return 0; | 60 return 0; |
| 61 } | 61 } |
| 62 } else { | 62 } else { |
| 63 // For test. | 63 // For test. |
| 64 platform_file_path = url.path(); | 64 platform_file_path = url.path(); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 } | 110 } |
| 111 | 111 |
| 112 void QuotaReservation::OnClientCrash() { quota_reservation_->OnClientCrash(); } | 112 void QuotaReservation::OnClientCrash() { quota_reservation_->OnClientCrash(); } |
| 113 | 113 |
| 114 void QuotaReservation::GotReservedQuota(const ReserveQuotaCallback& callback, | 114 void QuotaReservation::GotReservedQuota(const ReserveQuotaCallback& callback, |
| 115 base::File::Error error) { | 115 base::File::Error error) { |
| 116 ppapi::FileSizeMap file_sizes; | 116 ppapi::FileSizeMap file_sizes; |
| 117 for (FileMap::iterator it = files_.begin(); it != files_.end(); ++it) | 117 for (FileMap::iterator it = files_.begin(); it != files_.end(); ++it) |
| 118 file_sizes[it->first] = it->second->GetMaxWrittenOffset(); | 118 file_sizes[it->first] = it->second->GetMaxWrittenOffset(); |
| 119 | 119 |
| 120 if (file_system_context_) { | 120 if (file_system_context_.get()) { |
| 121 BrowserThread::PostTask( | 121 BrowserThread::PostTask( |
| 122 BrowserThread::IO, | 122 BrowserThread::IO, |
| 123 FROM_HERE, | 123 FROM_HERE, |
| 124 base::Bind( | 124 base::Bind( |
| 125 callback, quota_reservation_->remaining_quota(), file_sizes)); | 125 callback, quota_reservation_->remaining_quota(), file_sizes)); |
| 126 } else { | 126 } else { |
| 127 // Unit testing code path. | 127 // Unit testing code path. |
| 128 callback.Run(quota_reservation_->remaining_quota(), file_sizes); | 128 callback.Run(quota_reservation_->remaining_quota(), file_sizes); |
| 129 } | 129 } |
| 130 } | 130 } |
| 131 | 131 |
| 132 void QuotaReservation::DeleteOnCorrectThread() const { | 132 void QuotaReservation::DeleteOnCorrectThread() const { |
| 133 if (file_system_context_ && !file_system_context_->default_file_task_runner() | 133 if (file_system_context_.get() && |
| 134 ->RunsTasksOnCurrentThread()) { | 134 !file_system_context_->default_file_task_runner() |
| 135 ->RunsTasksOnCurrentThread()) { |
| 135 file_system_context_->default_file_task_runner()->DeleteSoon(FROM_HERE, | 136 file_system_context_->default_file_task_runner()->DeleteSoon(FROM_HERE, |
| 136 this); | 137 this); |
| 137 } else { | 138 } else { |
| 138 // We're on the right thread to delete, or unit test. | 139 // We're on the right thread to delete, or unit test. |
| 139 delete this; | 140 delete this; |
| 140 } | 141 } |
| 141 } | 142 } |
| 142 | 143 |
| 143 } // namespace content | 144 } // namespace content |
| OLD | NEW |