13551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
53551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#ifndef CONTENT_CHILD_FILEAPI_WEBFILEWRITER_BASE_H_
63551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#define CONTENT_CHILD_FILEAPI_WEBFILEWRITER_BASE_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/files/file.h"
93551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "content/common/content_export.h"
1058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "third_party/WebKit/public/platform/WebFileWriter.h"
11eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "url/gurl.h"
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
13f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)namespace blink {
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class WebFileWriterClient;
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class WebURL;
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
183551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)namespace content {
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
203551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)class CONTENT_EXPORT WebFileWriterBase
21f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    : public NON_EXPORTED_BASE(blink::WebFileWriter) {
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
23f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  WebFileWriterBase(const GURL& path, blink::WebFileWriterClient* client);
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~WebFileWriterBase();
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // WebFileWriter implementation
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void truncate(long long length);
28f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual void write(long long position, const blink::WebString& id);
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void cancel();
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected:
3290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // This calls DidSucceed() or DidFail() based on the value of |error_code|.
335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void DidFinish(base::File::Error error_code);
3490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
3590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  void DidWrite(int64 bytes, bool complete);
3690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  void DidSucceed();
375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void DidFail(base::File::Error error_code);
3890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Derived classes must provide these methods to asynchronously perform
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the requested operation, and they must call the appropiate DidSomething
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // method upon completion and as progress is made in the Write case.
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void DoTruncate(const GURL& path, int64 offset) = 0;
433551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  virtual void DoWrite(const GURL& path,
4458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)                       const std::string& blob_id,
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                       int64 offset) = 0;
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void DoCancel() = 0;
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  enum OperationType {
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    kOperationNone,
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    kOperationWrite,
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    kOperationTruncate
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  enum CancelState {
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    kCancelNotInProgress,
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    kCancelSent,
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    kCancelReceivedWriteResponse,
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void FinishCancel();
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GURL path_;
64f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  blink::WebFileWriterClient* client_;
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  OperationType operation_;
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CancelState cancel_state_;
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
693551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)}  // namespace content
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
713551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#endif  // CONTENT_CHILD_FILEAPI_WEBFILEWRITER_BASE_H_
72