OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/child/fileapi/webfilewriter_base.h" | 5 #include "content/child/fileapi/webfilewriter_base.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "third_party/WebKit/public/platform/WebFileError.h" | 8 #include "third_party/WebKit/public/platform/WebFileError.h" |
9 #include "third_party/WebKit/public/platform/WebFileWriterClient.h" | 9 #include "third_party/WebKit/public/platform/WebFileWriterClient.h" |
10 #include "third_party/WebKit/public/platform/WebURL.h" | 10 #include "third_party/WebKit/public/platform/WebURL.h" |
11 #include "webkit/common/fileapi/file_system_util.h" | 11 #include "webkit/common/fileapi/file_system_util.h" |
12 | 12 |
13 using fileapi::PlatformFileErrorToWebFileError; | 13 using fileapi::FileErrorToWebFileError; |
14 | 14 |
15 namespace content { | 15 namespace content { |
16 | 16 |
17 WebFileWriterBase::WebFileWriterBase(const GURL& path, | 17 WebFileWriterBase::WebFileWriterBase(const GURL& path, |
18 blink::WebFileWriterClient* client) | 18 blink::WebFileWriterClient* client) |
19 : path_(path), | 19 : path_(path), |
20 client_(client), | 20 client_(client), |
21 operation_(kOperationNone), | 21 operation_(kOperationNone), |
22 cancel_state_(kCancelNotInProgress) {} | 22 cancel_state_(kCancelNotInProgress) {} |
23 | 23 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 void WebFileWriterBase::cancel() { | 56 void WebFileWriterBase::cancel() { |
57 // Check for the cancel passing the previous operation's return in-flight. | 57 // Check for the cancel passing the previous operation's return in-flight. |
58 if (kOperationWrite != operation_ && kOperationTruncate != operation_) | 58 if (kOperationWrite != operation_ && kOperationTruncate != operation_) |
59 return; | 59 return; |
60 if (kCancelNotInProgress != cancel_state_) | 60 if (kCancelNotInProgress != cancel_state_) |
61 return; | 61 return; |
62 cancel_state_ = kCancelSent; | 62 cancel_state_ = kCancelSent; |
63 DoCancel(); | 63 DoCancel(); |
64 } | 64 } |
65 | 65 |
66 void WebFileWriterBase::DidFinish(base::PlatformFileError error_code) { | 66 void WebFileWriterBase::DidFinish(base::File::Error error_code) { |
67 if (error_code == base::PLATFORM_FILE_OK) | 67 if (error_code == base::File::FILE_OK) |
68 DidSucceed(); | 68 DidSucceed(); |
69 else | 69 else |
70 DidFail(error_code); | 70 DidFail(error_code); |
71 } | 71 } |
72 | 72 |
73 void WebFileWriterBase::DidWrite(int64 bytes, bool complete) { | 73 void WebFileWriterBase::DidWrite(int64 bytes, bool complete) { |
74 DCHECK(kOperationWrite == operation_); | 74 DCHECK(kOperationWrite == operation_); |
75 switch (cancel_state_) { | 75 switch (cancel_state_) { |
76 case kCancelNotInProgress: | 76 case kCancelNotInProgress: |
77 if (complete) | 77 if (complete) |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 break; | 110 break; |
111 case kCancelReceivedWriteResponse: | 111 case kCancelReceivedWriteResponse: |
112 // This is the success of the cancel operation. | 112 // This is the success of the cancel operation. |
113 FinishCancel(); | 113 FinishCancel(); |
114 break; | 114 break; |
115 default: | 115 default: |
116 NOTREACHED(); | 116 NOTREACHED(); |
117 } | 117 } |
118 } | 118 } |
119 | 119 |
120 void WebFileWriterBase::DidFail(base::PlatformFileError error_code) { | 120 void WebFileWriterBase::DidFail(base::File::Error error_code) { |
121 DCHECK(kOperationNone != operation_); | 121 DCHECK(kOperationNone != operation_); |
122 switch (cancel_state_) { | 122 switch (cancel_state_) { |
123 case kCancelNotInProgress: | 123 case kCancelNotInProgress: |
124 // A write or truncate failed. | 124 // A write or truncate failed. |
125 operation_ = kOperationNone; | 125 operation_ = kOperationNone; |
126 client_->didFail(PlatformFileErrorToWebFileError(error_code)); | 126 client_->didFail(FileErrorToWebFileError(error_code)); |
127 break; | 127 break; |
128 case kCancelSent: | 128 case kCancelSent: |
129 // This is the failure of a write or truncate; the next message should be | 129 // This is the failure of a write or truncate; the next message should be |
130 // the result of the cancel. We don't assume that it'll be a success, as | 130 // the result of the cancel. We don't assume that it'll be a success, as |
131 // the write/truncate could have failed for other reasons. | 131 // the write/truncate could have failed for other reasons. |
132 cancel_state_ = kCancelReceivedWriteResponse; | 132 cancel_state_ = kCancelReceivedWriteResponse; |
133 break; | 133 break; |
134 case kCancelReceivedWriteResponse: | 134 case kCancelReceivedWriteResponse: |
135 // The cancel reported failure, meaning that the write or truncate | 135 // The cancel reported failure, meaning that the write or truncate |
136 // finished before the cancel got there. But we suppressed the | 136 // finished before the cancel got there. But we suppressed the |
137 // write/truncate's response, and will now report that it was cancelled. | 137 // write/truncate's response, and will now report that it was cancelled. |
138 FinishCancel(); | 138 FinishCancel(); |
139 break; | 139 break; |
140 default: | 140 default: |
141 NOTREACHED(); | 141 NOTREACHED(); |
142 } | 142 } |
143 } | 143 } |
144 | 144 |
145 void WebFileWriterBase::FinishCancel() { | 145 void WebFileWriterBase::FinishCancel() { |
146 DCHECK(kCancelReceivedWriteResponse == cancel_state_); | 146 DCHECK(kCancelReceivedWriteResponse == cancel_state_); |
147 DCHECK(kOperationNone != operation_); | 147 DCHECK(kOperationNone != operation_); |
148 cancel_state_ = kCancelNotInProgress; | 148 cancel_state_ = kCancelNotInProgress; |
149 operation_ = kOperationNone; | 149 operation_ = kOperationNone; |
150 client_->didFail(blink::WebFileErrorAbort); | 150 client_->didFail(blink::WebFileErrorAbort); |
151 } | 151 } |
152 | 152 |
153 } // namespace content | 153 } // namespace content |
OLD | NEW |