| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/plugins/ppapi/quota_file_io.h" | 5 #include "webkit/plugins/ppapi/quota_file_io.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/memory/scoped_callback_factory.h" |
| 11 #include "base/message_loop_proxy.h" |
| 10 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 11 #include "base/message_loop_proxy.h" | |
| 12 #include "base/task.h" | 13 #include "base/task.h" |
| 13 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 14 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
| 14 #include "webkit/plugins/ppapi/resource_helper.h" | 15 #include "webkit/plugins/ppapi/resource_helper.h" |
| 15 #include "webkit/plugins/ppapi/resource_tracker.h" | 16 #include "webkit/plugins/ppapi/resource_tracker.h" |
| 16 | 17 |
| 17 using base::PlatformFile; | 18 using base::PlatformFile; |
| 18 using base::PlatformFileError; | 19 using base::PlatformFileError; |
| 19 using quota::StorageType; | 20 using quota::StorageType; |
| 20 | 21 |
| 21 namespace webkit { | 22 namespace webkit { |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 : pp_instance_(instance), | 218 : pp_instance_(instance), |
| 218 file_(file), | 219 file_(file), |
| 219 file_url_(file_url), | 220 file_url_(file_url), |
| 220 storage_type_(PPFileSystemTypeToQuotaStorageType(type)), | 221 storage_type_(PPFileSystemTypeToQuotaStorageType(type)), |
| 221 cached_file_size_(0), | 222 cached_file_size_(0), |
| 222 cached_available_space_(0), | 223 cached_available_space_(0), |
| 223 outstanding_quota_queries_(0), | 224 outstanding_quota_queries_(0), |
| 224 outstanding_errors_(0), | 225 outstanding_errors_(0), |
| 225 max_written_offset_(0), | 226 max_written_offset_(0), |
| 226 inflight_operations_(0), | 227 inflight_operations_(0), |
| 227 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 228 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
| 228 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | |
| 229 DCHECK_NE(base::kInvalidPlatformFileValue, file_); | 229 DCHECK_NE(base::kInvalidPlatformFileValue, file_); |
| 230 DCHECK_NE(quota::kStorageTypeUnknown, storage_type_); | 230 DCHECK_NE(quota::kStorageTypeUnknown, storage_type_); |
| 231 } | 231 } |
| 232 | 232 |
| 233 QuotaFileIO::~QuotaFileIO() { | 233 QuotaFileIO::~QuotaFileIO() { |
| 234 // Note that this doesn't dispatch pending callbacks. | 234 // Note that this doesn't dispatch pending callbacks. |
| 235 STLDeleteContainerPointers(pending_operations_.begin(), | 235 STLDeleteContainerPointers(pending_operations_.begin(), |
| 236 pending_operations_.end()); | 236 pending_operations_.end()); |
| 237 STLDeleteContainerPointers(pending_callbacks_.begin(), | 237 STLDeleteContainerPointers(pending_callbacks_.begin(), |
| 238 pending_callbacks_.end()); | 238 pending_callbacks_.end()); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 outstanding_errors_ = 0; | 287 outstanding_errors_ = 0; |
| 288 | 288 |
| 289 PluginDelegate* plugin_delegate = GetPluginDelegate(); | 289 PluginDelegate* plugin_delegate = GetPluginDelegate(); |
| 290 if (!plugin_delegate) | 290 if (!plugin_delegate) |
| 291 return false; | 291 return false; |
| 292 | 292 |
| 293 // Query the file size. | 293 // Query the file size. |
| 294 ++outstanding_quota_queries_; | 294 ++outstanding_quota_queries_; |
| 295 if (!base::FileUtilProxy::GetFileInfoFromPlatformFile( | 295 if (!base::FileUtilProxy::GetFileInfoFromPlatformFile( |
| 296 plugin_delegate->GetFileThreadMessageLoopProxy(), file_, | 296 plugin_delegate->GetFileThreadMessageLoopProxy(), file_, |
| 297 callback_factory_.NewCallback( | 297 base::Bind(&QuotaFileIO::DidQueryInfoForQuota, |
| 298 &QuotaFileIO::DidQueryInfoForQuota))) { | 298 weak_factory_.GetWeakPtr()))) { |
| 299 // This makes the call fail synchronously; we do not fire the callback | 299 // This makes the call fail synchronously; we do not fire the callback |
| 300 // here but just delete the operation and return false. | 300 // here but just delete the operation and return false. |
| 301 return false; | 301 return false; |
| 302 } | 302 } |
| 303 | 303 |
| 304 // Query the current available space. | 304 // Query the current available space. |
| 305 ++outstanding_quota_queries_; | 305 ++outstanding_quota_queries_; |
| 306 plugin_delegate->QueryAvailableSpace( | 306 plugin_delegate->QueryAvailableSpace( |
| 307 GURL(file_url_.path()).GetOrigin(), storage_type_, | 307 GURL(file_url_.path()).GetOrigin(), storage_type_, |
| 308 base::Bind(&QuotaFileIO::DidQueryAvailableSpace, | 308 base::Bind(&QuotaFileIO::DidQueryAvailableSpace, |
| 309 weak_ptr_factory_.GetWeakPtr())); | 309 weak_factory_.GetWeakPtr())); |
| 310 } | 310 } |
| 311 pending_operations_.push_back(op.release()); | 311 pending_operations_.push_back(op.release()); |
| 312 return true; | 312 return true; |
| 313 } | 313 } |
| 314 | 314 |
| 315 void QuotaFileIO::DidQueryInfoForQuota( | 315 void QuotaFileIO::DidQueryInfoForQuota( |
| 316 base::PlatformFileError error_code, | 316 base::PlatformFileError error_code, |
| 317 const base::PlatformFileInfo& file_info) { | 317 const base::PlatformFileInfo& file_info) { |
| 318 if (error_code != base::PLATFORM_FILE_OK) | 318 if (error_code != base::PLATFORM_FILE_OK) |
| 319 ++outstanding_errors_; | 319 ++outstanding_errors_; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 | 397 |
| 398 | 398 |
| 399 PluginDelegate* plugin_delegate = GetPluginDelegate(); | 399 PluginDelegate* plugin_delegate = GetPluginDelegate(); |
| 400 if (plugin_delegate) | 400 if (plugin_delegate) |
| 401 plugin_delegate->DidUpdateFile(file_url_, delta); | 401 plugin_delegate->DidUpdateFile(file_url_, delta); |
| 402 inflight_operations_ = 0; | 402 inflight_operations_ = 0; |
| 403 } | 403 } |
| 404 | 404 |
| 405 } // namespace ppapi | 405 } // namespace ppapi |
| 406 } // namespace webkit | 406 } // namespace webkit |
| OLD | NEW |