| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/file_system_usage_cache.h" | 5 #include "webkit/browser/fileapi/file_system_usage_cache.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 bool FileSystemUsageCache::FlushFile(const base::FilePath& file_path) { | 282 bool FileSystemUsageCache::FlushFile(const base::FilePath& file_path) { |
| 283 TRACE_EVENT0("FileSystem", "UsageCache::FlushFile"); | 283 TRACE_EVENT0("FileSystem", "UsageCache::FlushFile"); |
| 284 DCHECK(CalledOnValidThread()); | 284 DCHECK(CalledOnValidThread()); |
| 285 base::PlatformFile file = base::kInvalidPlatformFileValue; | 285 base::PlatformFile file = base::kInvalidPlatformFileValue; |
| 286 return GetPlatformFile(file_path, &file) && base::FlushPlatformFile(file); | 286 return GetPlatformFile(file_path, &file) && base::FlushPlatformFile(file); |
| 287 } | 287 } |
| 288 | 288 |
| 289 void FileSystemUsageCache::ScheduleCloseTimer() { | 289 void FileSystemUsageCache::ScheduleCloseTimer() { |
| 290 DCHECK(CalledOnValidThread()); | 290 DCHECK(CalledOnValidThread()); |
| 291 if (!timer_) | 291 if (!timer_) |
| 292 timer_.reset(new TimedTaskHelper(task_runner_)); | 292 timer_.reset(new TimedTaskHelper(task_runner_.get())); |
| 293 | 293 |
| 294 if (timer_->IsRunning()) { | 294 if (timer_->IsRunning()) { |
| 295 timer_->Reset(); | 295 timer_->Reset(); |
| 296 return; | 296 return; |
| 297 } | 297 } |
| 298 | 298 |
| 299 timer_->Start(FROM_HERE, | 299 timer_->Start(FROM_HERE, |
| 300 base::TimeDelta::FromSeconds(kCloseDelaySeconds), | 300 base::TimeDelta::FromSeconds(kCloseDelaySeconds), |
| 301 base::Bind(&FileSystemUsageCache::CloseCacheFiles, | 301 base::Bind(&FileSystemUsageCache::CloseCacheFiles, |
| 302 weak_factory_.GetWeakPtr())); | 302 weak_factory_.GetWeakPtr())); |
| 303 } | 303 } |
| 304 | 304 |
| 305 bool FileSystemUsageCache::CalledOnValidThread() { | 305 bool FileSystemUsageCache::CalledOnValidThread() { |
| 306 return !task_runner_.get() || task_runner_->RunsTasksOnCurrentThread(); | 306 return !task_runner_.get() || task_runner_->RunsTasksOnCurrentThread(); |
| 307 } | 307 } |
| 308 | 308 |
| 309 bool FileSystemUsageCache::HasCacheFileHandle(const base::FilePath& file_path) { | 309 bool FileSystemUsageCache::HasCacheFileHandle(const base::FilePath& file_path) { |
| 310 DCHECK(CalledOnValidThread()); | 310 DCHECK(CalledOnValidThread()); |
| 311 DCHECK_LE(cache_files_.size(), kMaxHandleCacheSize); | 311 DCHECK_LE(cache_files_.size(), kMaxHandleCacheSize); |
| 312 return ContainsKey(cache_files_, file_path); | 312 return ContainsKey(cache_files_, file_path); |
| 313 } | 313 } |
| 314 | 314 |
| 315 } // namespace fileapi | 315 } // namespace fileapi |
| OLD | NEW |