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 #include "net/disk_cache/simple/simple_entry_operation.h"
7 #include "base/logging.h"
8 #include "net/base/io_buffer.h"
9 #include "net/disk_cache/disk_cache.h"
10 #include "net/disk_cache/simple/simple_entry_impl.h"
12 namespace disk_cache
{
14 SimpleEntryOperation::SimpleEntryOperation(const SimpleEntryOperation
& other
)
15 : entry_(other
.entry_
.get()),
17 callback_(other
.callback_
),
18 out_entry_(other
.out_entry_
),
19 offset_(other
.offset_
),
20 length_(other
.length_
),
22 have_index_(other
.have_index_
),
24 truncate_(other
.truncate_
),
25 optimistic_(other
.optimistic_
),
26 alone_in_queue_(other
.alone_in_queue_
) {
29 SimpleEntryOperation::~SimpleEntryOperation() {}
32 SimpleEntryOperation
SimpleEntryOperation::OpenOperation(
33 SimpleEntryImpl
* entry
,
35 const CompletionCallback
& callback
,
37 return SimpleEntryOperation(entry
,
52 SimpleEntryOperation
SimpleEntryOperation::CreateOperation(
53 SimpleEntryImpl
* entry
,
55 const CompletionCallback
& callback
,
57 return SimpleEntryOperation(entry
,
72 SimpleEntryOperation
SimpleEntryOperation::CloseOperation(
73 SimpleEntryImpl
* entry
) {
74 return SimpleEntryOperation(entry
,
89 SimpleEntryOperation
SimpleEntryOperation::ReadOperation(
90 SimpleEntryImpl
* entry
,
95 const CompletionCallback
& callback
,
96 bool alone_in_queue
) {
97 return SimpleEntryOperation(entry
,
112 SimpleEntryOperation
SimpleEntryOperation::WriteOperation(
113 SimpleEntryImpl
* entry
,
120 const CompletionCallback
& callback
) {
121 return SimpleEntryOperation(entry
,
135 bool SimpleEntryOperation::ConflictsWith(
136 const SimpleEntryOperation
& other_op
) const {
137 if (type_
!= TYPE_READ
&& type_
!= TYPE_WRITE
)
139 if (other_op
.type() != TYPE_READ
&& other_op
.type() != TYPE_WRITE
)
141 if (type() == TYPE_READ
&& other_op
.type() == TYPE_READ
)
143 if (index_
!= other_op
.index_
)
145 int end
= (type_
== TYPE_WRITE
&& truncate_
) ? INT_MAX
: offset_
+ length_
;
146 int other_op_end
= (other_op
.type() == TYPE_WRITE
&& other_op
.truncate())
148 : other_op
.offset() + other_op
.length();
149 return (offset_
< other_op_end
&& other_op
.offset() < end
);
152 void SimpleEntryOperation::ReleaseReferences() {
153 callback_
= CompletionCallback();
158 SimpleEntryOperation::SimpleEntryOperation(SimpleEntryImpl
* entry
,
160 const CompletionCallback
& callback
,
164 EntryOperationType type
,
173 out_entry_(out_entry
),
177 have_index_(have_index
),
180 optimistic_(optimistic
),
181 alone_in_queue_(alone_in_queue
) {
184 } // namespace disk_cache