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> { | |
michaeln
2011/05/17 00:19:03
I don't understand why this is refcounted much les
Dai Mikurube (NOT FULLTIME)
2011/05/17 05:02:13
In the previous version, it was running on the db_
| |
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 // It must be called-back from the io_thread. | |
59 void OnDeletionCompletedOnIOThread( | |
60 QuotaStatusCode status, | |
61 int64 usage, | |
62 int64 quota, | |
63 int64 physical_available_space); | |
64 | |
65 // They must be called on the io_thread. | |
66 void CallDeleteOriginOnIOThread(const GURL& origin); | |
67 void CallGetUsageAndQuotaOnIOThread(); | |
68 | |
69 void DeleteOnCorrectThread() const; | |
70 | |
71 // This pointer must be accessed in the io_thread. | |
72 QuotaEvictionHandler* quota_manager_; | |
73 | |
74 int64 target_available_space_; | |
75 int64 delay_ms_; | |
76 bool repeated_eviction_; | |
77 scoped_refptr<base::MessageLoopProxy> io_message_loop_; | |
78 | |
79 base::ScopedCallbackFactory<QuotaTemporaryStorageEvictor> callback_factory_; | |
80 | |
81 DISALLOW_COPY_AND_ASSIGN(QuotaTemporaryStorageEvictor); | |
82 }; | |
83 | |
84 struct QuotaTemporaryStorageEvictorDeleter { | |
85 static void Destruct(const QuotaTemporaryStorageEvictor* evictor) { | |
86 LOG(ERROR) << "Deleter::Destruct"; | |
87 evictor->DeleteOnCorrectThread(); | |
88 } | |
89 }; | |
90 | |
91 } // namespace quota | |
92 | |
93 #endif // WEBKIT_QUOTA_QUOTA_TEMPORARY_STORAGE_EVICTOR_H_ | |
OLD | NEW |