OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef WEBKIT_QUOTA_QUOTA_TEMPORARY_STORAGE_EVICTOR_H_ |
| 6 #define WEBKIT_QUOTA_QUOTA_TEMPORARY_STORAGE_EVICTOR_H_ |
| 7 #pragma once |
| 8 |
| 9 #include "base/message_loop_proxy.h" |
| 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_callback_factory.h" |
| 12 #include "webkit/quota/quota_database.h" |
| 13 #include "webkit/quota/quota_manager.h" |
| 14 #include "webkit/quota/quota_task.h" |
| 15 #include "webkit/quota/quota_types.h" |
| 16 |
| 17 class GURL; |
| 18 |
| 19 namespace quota { |
| 20 |
| 21 struct QuotaTemporaryStorageEvictorDeleter; |
| 22 |
| 23 class QuotaTemporaryStorageEvictor |
| 24 : public base::RefCountedThreadSafe<QuotaTemporaryStorageEvictor, |
| 25 QuotaTemporaryStorageEvictorDeleter> { |
| 26 public: |
| 27 // Constructed on the io_thread. |
| 28 QuotaTemporaryStorageEvictor( |
| 29 int64 target_available_space, |
| 30 int64 delay_ms, |
| 31 scoped_refptr<base::MessageLoopProxy> io_message_loop); |
| 32 virtual ~QuotaTemporaryStorageEvictor(); |
| 33 |
| 34 // TODO(dmikurube): Make it a private friend of QuotaManager ? |
| 35 void RegisterQuotaManagerOnIOThread(QuotaEvictionHandler* quota_manager); |
| 36 |
| 37 // It can be called from any thread. |
| 38 // It posts a task to the io_thread internally. |
| 39 void Start(); |
| 40 |
| 41 // It must be called on the io_thread. |
| 42 void OnQuotaManagerDestroyedOnIOThread(); |
| 43 |
| 44 bool repeated_eviction() const { return repeated_eviction_; } |
| 45 void set_repeated_eviction(bool repeated_eviction) { |
| 46 repeated_eviction_ = repeated_eviction; |
| 47 } |
| 48 |
| 49 static const double kUsageRatioToBeEvicted; |
| 50 const int64 physical_available_space_to_be_evicted; |
| 51 |
| 52 private: |
| 53 friend struct QuotaTemporaryStorageEvictorDeleter; |
| 54 friend class QuotaTemporaryStorageEvictorTest; |
| 55 |
| 56 void Evict(bool delete_immediately); |
| 57 |
| 58 // They must be called-back from the io_thread. |
| 59 void OnGottenUsageAndQuotaOnIOThread( |
| 60 QuotaStatusCode status, |
| 61 int64 usage, |
| 62 int64 quota, |
| 63 int64 physical_available_space); |
| 64 void OnEvictionCompletedOnIOThread( |
| 65 QuotaStatusCode status); |
| 66 |
| 67 // They must be called on the io_thread. |
| 68 void CallEvictOriginOnIOThread(const GURL& origin); |
| 69 void CallGetUsageAndQuotaOnIOThread(); |
| 70 |
| 71 void DeleteOnCorrectThread() const; |
| 72 |
| 73 // This pointer must be accessed in the io_thread. |
| 74 QuotaEvictionHandler* quota_manager_; |
| 75 |
| 76 int64 target_available_space_; |
| 77 int64 delay_ms_; |
| 78 bool repeated_eviction_; |
| 79 scoped_refptr<base::MessageLoopProxy> io_message_loop_; |
| 80 |
| 81 base::ScopedCallbackFactory<QuotaTemporaryStorageEvictor> callback_factory_; |
| 82 |
| 83 DISALLOW_COPY_AND_ASSIGN(QuotaTemporaryStorageEvictor); |
| 84 }; |
| 85 |
| 86 struct QuotaTemporaryStorageEvictorDeleter { |
| 87 static void Destruct(const QuotaTemporaryStorageEvictor* evictor) { |
| 88 LOG(ERROR) << "Deleter::Destruct"; |
| 89 evictor->DeleteOnCorrectThread(); |
| 90 } |
| 91 }; |
| 92 |
| 93 } // namespace quota |
| 94 |
| 95 #endif // WEBKIT_QUOTA_QUOTA_TEMPORARY_STORAGE_EVICTOR_H_ |
OLD | NEW |