Windows should animate when they are about to get docked at screen edges.
[chromium-blink-merge.git] / net / disk_cache / simple / simple_entry_operation.h
blobacdd60a3207e59324432e650e94a11905a930d0c
1 // Copyright 2013 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.
5 #ifndef NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_OPERATION_H_
6 #define NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_OPERATION_H_
8 #include "base/memory/ref_counted.h"
9 #include "net/base/completion_callback.h"
10 #include "net/base/net_log.h"
12 namespace net {
13 class IOBuffer;
16 namespace disk_cache {
18 class Entry;
19 class SimpleEntryImpl;
21 // SimpleEntryOperation stores the information regarding operations in
22 // SimpleEntryImpl, between the moment they are issued by users of the backend,
23 // and the moment when they are executed.
24 class SimpleEntryOperation {
25 public:
26 typedef net::CompletionCallback CompletionCallback;
28 enum EntryOperationType {
29 TYPE_OPEN = 0,
30 TYPE_CREATE = 1,
31 TYPE_CLOSE = 2,
32 TYPE_READ = 3,
33 TYPE_WRITE = 4,
36 SimpleEntryOperation(const SimpleEntryOperation& other);
37 ~SimpleEntryOperation();
39 static SimpleEntryOperation OpenOperation(SimpleEntryImpl* entry,
40 bool have_index,
41 const CompletionCallback& callback,
42 Entry** out_entry);
43 static SimpleEntryOperation CreateOperation(
44 SimpleEntryImpl* entry,
45 bool have_index,
46 const CompletionCallback& callback,
47 Entry** out_entry);
48 static SimpleEntryOperation CloseOperation(SimpleEntryImpl* entry);
49 static SimpleEntryOperation ReadOperation(SimpleEntryImpl* entry,
50 int index,
51 int offset,
52 int length,
53 net::IOBuffer* buf,
54 const CompletionCallback& callback,
55 bool alone_in_queue);
56 static SimpleEntryOperation WriteOperation(
57 SimpleEntryImpl* entry,
58 int index,
59 int offset,
60 int length,
61 net::IOBuffer* buf,
62 bool truncate,
63 bool optimistic,
64 const CompletionCallback& callback);
66 bool ConflictsWith(const SimpleEntryOperation& other_op) const;
67 // Releases all references. After calling this operation, SimpleEntryOperation
68 // will only hold POD members.
69 void ReleaseReferences();
71 EntryOperationType type() const {
72 return static_cast<EntryOperationType>(type_);
74 const CompletionCallback& callback() const { return callback_; }
75 Entry** out_entry() { return out_entry_; }
76 bool have_index() const { return have_index_; }
77 int index() const { return index_; }
78 int offset() const { return offset_; }
79 int length() const { return length_; }
80 net::IOBuffer* buf() { return buf_.get(); }
81 bool truncate() const { return truncate_; }
82 bool optimistic() const { return optimistic_; }
83 bool alone_in_queue() const { return alone_in_queue_; }
85 private:
86 SimpleEntryOperation(SimpleEntryImpl* entry,
87 net::IOBuffer* buf,
88 const CompletionCallback& callback,
89 Entry** out_entry,
90 int offset,
91 int length,
92 EntryOperationType type,
93 bool have_index,
94 int index,
95 bool truncate,
96 bool optimistic,
97 bool alone_in_queue);
99 // This ensures entry will not be deleted until the operation has ran.
100 scoped_refptr<SimpleEntryImpl> entry_;
101 scoped_refptr<net::IOBuffer> buf_;
102 CompletionCallback callback_;
104 // Used in open and create operations.
105 Entry** out_entry_;
107 // Used in write and read operations.
108 const int offset_;
109 const int length_;
111 const unsigned int type_ : 3; /* 3 */
112 // Used in open and create operations.
113 const unsigned int have_index_ : 1; /* 4 */
114 // Used in write and read operations.
115 const unsigned int index_ : 2; /* 6 */
116 // Used only in write operations.
117 const unsigned int truncate_ : 1; /* 7 */
118 const unsigned int optimistic_ : 1; /* 8 */
119 // Used only in SimpleCache.ReadIsParallelizable histogram.
120 const unsigned int alone_in_queue_ : 1; /* 9 */
123 } // namespace disk_cache
125 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_OPERATION_H_