Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(489)

Side by Side Diff: webkit/fileapi/webfilewriter_base.cc

Issue 14796018: Cleanup: Deprecate FileSystemCallbackDispatcher (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 "webkit/fileapi/webfilewriter_base.h" 5 #include "webkit/fileapi/webfilewriter_base.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "third_party/WebKit/Source/Platform/chromium/public/WebURL.h" 8 #include "third_party/WebKit/Source/Platform/chromium/public/WebURL.h"
9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileError.h" 9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileError.h"
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileWriterClient.h " 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileWriterClient.h "
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
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) {
67 if (error_code == base::PLATFORM_FILE_OK)
68 DidSucceed();
69 else
70 DidFail(error_code);
71 }
72
73 void WebFileWriterBase::DidWrite(int64 bytes, bool complete) {
74 DCHECK(kOperationWrite == operation_);
75 switch (cancel_state_) {
76 case kCancelNotInProgress:
77 if (complete)
78 operation_ = kOperationNone;
79 client_->didWrite(bytes, complete);
80 break;
81 case kCancelSent:
82 // This is the success call of the write, which we'll eat, even though
83 // it succeeded before the cancel got there. We accepted the cancel call,
84 // so the write will eventually return an error.
85 if (complete)
86 cancel_state_ = kCancelReceivedWriteResponse;
87 break;
88 case kCancelReceivedWriteResponse:
89 default:
90 NOTREACHED();
91 }
92 }
93
66 void WebFileWriterBase::DidSucceed() { 94 void WebFileWriterBase::DidSucceed() {
67 // Write never gets a DidSucceed call, so this is either a cancel or truncate 95 // Write never gets a DidSucceed call, so this is either a cancel or truncate
68 // response. 96 // response.
69 switch (cancel_state_) { 97 switch (cancel_state_) {
70 case kCancelNotInProgress: 98 case kCancelNotInProgress:
71 // A truncate succeeded, with no complications. 99 // A truncate succeeded, with no complications.
72 DCHECK(kOperationTruncate == operation_); 100 DCHECK(kOperationTruncate == operation_);
73 operation_ = kOperationNone; 101 operation_ = kOperationNone;
74 client_->didTruncate(); 102 client_->didTruncate();
75 break; 103 break;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 // The cancel reported failure, meaning that the write or truncate 136 // The cancel reported failure, meaning that the write or truncate
109 // finished before the cancel got there. But we suppressed the 137 // finished before the cancel got there. But we suppressed the
110 // write/truncate's response, and will now report that it was cancelled. 138 // write/truncate's response, and will now report that it was cancelled.
111 FinishCancel(); 139 FinishCancel();
112 break; 140 break;
113 default: 141 default:
114 NOTREACHED(); 142 NOTREACHED();
115 } 143 }
116 } 144 }
117 145
118 void WebFileWriterBase::DidWrite(int64 bytes, bool complete) {
119 DCHECK(kOperationWrite == operation_);
120 switch (cancel_state_) {
121 case kCancelNotInProgress:
122 if (complete)
123 operation_ = kOperationNone;
124 client_->didWrite(bytes, complete);
125 break;
126 case kCancelSent:
127 // This is the success call of the write, which we'll eat, even though
128 // it succeeded before the cancel got there. We accepted the cancel call,
129 // so the write will eventually return an error.
130 if (complete)
131 cancel_state_ = kCancelReceivedWriteResponse;
132 break;
133 case kCancelReceivedWriteResponse:
134 default:
135 NOTREACHED();
136 }
137 }
138
139 void WebFileWriterBase::FinishCancel() { 146 void WebFileWriterBase::FinishCancel() {
140 DCHECK(kCancelReceivedWriteResponse == cancel_state_); 147 DCHECK(kCancelReceivedWriteResponse == cancel_state_);
141 DCHECK(kOperationNone != operation_); 148 DCHECK(kOperationNone != operation_);
142 cancel_state_ = kCancelNotInProgress; 149 cancel_state_ = kCancelNotInProgress;
143 operation_ = kOperationNone; 150 operation_ = kOperationNone;
144 client_->didFail(WebKit::WebFileErrorAbort); 151 client_->didFail(WebKit::WebFileErrorAbort);
145 } 152 }
146 153
147 } // namespace fileapi 154 } // namespace fileapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698