OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef NET_DISK_CACHE_FLASH_ENTRY_IMPL_H_ | |
6 #define NET_DISK_CACHE_FLASH_ENTRY_IMPL_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/memory/ref_counted.h" | |
11 #include "base/memory/scoped_ptr.h" | |
12 #include "net/base/net_export.h" | |
13 #include "net/disk_cache/disk_cache.h" | |
14 #include "net/disk_cache/flash/internal_entry.h" | |
15 | |
16 namespace base { | |
17 | |
18 class MessageLoopProxy; | |
19 | |
20 } // namespace base | |
21 | |
22 namespace disk_cache { | |
23 | |
24 class InternalEntry; | |
25 class IOBuffer; | |
26 class LogStore; | |
27 | |
28 // Context switches are slow on Android. In order to minimize the context | |
rvargas (doing something else)
2013/04/05 18:15:41
nit: Remove the first sentence?. It is vague and e
agayev
2013/04/05 22:26:45
Done.
| |
29 // switches between IOThread and CacheThread, this disk_cache::Entry | |
rvargas (doing something else)
2013/04/05 18:15:41
This layer doesn't know anything about IO or Cache
agayev
2013/04/05 22:26:45
Done.
| |
30 // implementation uses split objects to optimize the most common case, that is | |
31 // creating a new entry. | |
rvargas (doing something else)
2013/04/05 18:15:41
creating a new entry is the most common case? that
agayev
2013/04/05 22:26:45
Done, I think :)
| |
32 // | |
33 // All asynchronous function calls on a new entry are served from IOThread | |
rvargas (doing something else)
2013/04/05 18:15:41
nit: All calls are served synchronously.
agayev
2013/04/05 22:26:45
Done.
| |
34 // synchronously. When an object is destructed (via final Close() call), a | |
35 // message is posted to CacheThread to save the object to storage. | |
36 // | |
37 // When an entry is not new, every asynchronous call is posted to CacheThread, | |
38 // just as before; synchronous calls like GetKey() and GetDataSize() are served | |
39 // from the IOThread. | |
40 class NET_EXPORT_PRIVATE FlashEntryImpl | |
41 : public Entry, | |
42 public base::RefCountedThreadSafe<FlashEntryImpl> { | |
43 friend class base::RefCountedThreadSafe<FlashEntryImpl>; | |
44 public: | |
45 FlashEntryImpl(const std::string& key, | |
46 LogStore* store, | |
47 base::MessageLoopProxy* cache_thread); | |
48 FlashEntryImpl(int32 id, | |
49 LogStore* store, | |
50 base::MessageLoopProxy* cache_thread); | |
51 | |
52 int Init(const CompletionCallback& callback); | |
53 | |
54 // disk_cache::Entry interface. | |
55 virtual void Doom() OVERRIDE; | |
56 virtual void Close() OVERRIDE; | |
57 virtual std::string GetKey() const OVERRIDE; | |
58 virtual base::Time GetLastUsed() const OVERRIDE; | |
59 virtual base::Time GetLastModified() const OVERRIDE; | |
60 virtual int32 GetDataSize(int index) const OVERRIDE; | |
61 virtual int ReadData(int index, int offset, IOBuffer* buf, int buf_len, | |
62 const CompletionCallback& callback) OVERRIDE; | |
63 virtual int WriteData(int index, int offset, IOBuffer* buf, int buf_len, | |
64 const CompletionCallback& callback, | |
65 bool truncate) OVERRIDE; | |
66 virtual int ReadSparseData(int64 offset, IOBuffer* buf, int buf_len, | |
67 const CompletionCallback& callback) OVERRIDE; | |
68 virtual int WriteSparseData(int64 offset, IOBuffer* buf, int buf_len, | |
69 const CompletionCallback& callback) OVERRIDE; | |
70 virtual int GetAvailableRange(int64 offset, int len, int64* start, | |
71 const CompletionCallback& callback) OVERRIDE; | |
72 virtual bool CouldBeSparse() const OVERRIDE; | |
73 virtual void CancelSparseIO() OVERRIDE; | |
74 virtual int ReadyForSparseIO(const CompletionCallback& callback) OVERRIDE; | |
75 | |
76 private: | |
77 void OnInitComplete(scoped_ptr<KeyAndStreamSizes> key_and_stream_sizes); | |
78 virtual ~FlashEntryImpl(); | |
79 | |
80 bool init_; | |
81 std::string key_; | |
82 | |
83 // Used if |this| is an newly created entry. | |
84 scoped_refptr<InternalEntry> new_internal_entry_; | |
85 | |
86 // Used if |this| is an existing entry. | |
87 scoped_refptr<InternalEntry> old_internal_entry_; | |
88 | |
89 // Used if |this| is an existing entry. It is initialized once during Init(), | |
rvargas (doing something else)
2013/04/05 18:15:41
So... it is not used for new entries?. It is initi
agayev
2013/04/05 22:26:45
Done. I was going to use it for old entry only, b
| |
90 // and updated every time there is a successful WriteData() to | |
91 // |old_internal_entry_|. | |
92 int stream_sizes_[kFlashLogStoreEntryNumStreams]; | |
93 | |
94 // Copy of the callback for asynchronous calls on |old_internal_entry_|. | |
95 CompletionCallback callback_; | |
96 | |
97 scoped_refptr<base::MessageLoopProxy> cache_thread_; | |
98 | |
99 DISALLOW_COPY_AND_ASSIGN(FlashEntryImpl); | |
100 }; | |
101 | |
102 } // namespace disk_cache | |
103 | |
104 #endif // NET_DISK_CACHE_FLASH_ENTRY_IMPL_H_ | |
OLD | NEW |