Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / native_client_sdk / src / libraries / nacl_io / html5fs / html5_fs.h
blobc075aa64d2f93d09cbde13ab26d059d2585df127
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 LIBRARIES_NACL_IO_HTML5FS_HTML5_FS_H_
6 #define LIBRARIES_NACL_IO_HTML5FS_HTML5_FS_H_
8 #include <pthread.h>
10 #include "nacl_io/filesystem.h"
11 #include "nacl_io/pepper_interface.h"
12 #include "nacl_io/typed_fs_factory.h"
13 #include "sdk_util/simple_lock.h"
15 namespace nacl_io {
17 class Node;
19 class Html5Fs : public Filesystem {
20 public:
21 virtual Error OpenWithMode(const Path& path, int open_flags, mode_t mode,
22 ScopedNode* out_node);
23 virtual Error Unlink(const Path& path);
24 virtual Error Mkdir(const Path& path, int permissions);
25 virtual Error Rmdir(const Path& path);
26 virtual Error Remove(const Path& path);
27 virtual Error Rename(const Path& path, const Path& newpath);
29 PP_Resource filesystem_resource() { return filesystem_resource_; }
31 virtual void OnNodeCreated(Node* node);
32 virtual void OnNodeDestroyed(Node* node);
34 static ino_t HashPathSegment(ino_t hash, const char *str, size_t len);
35 static ino_t HashPath(const Path& path);
37 protected:
38 static const int REMOVE_DIR = 1;
39 static const int REMOVE_FILE = 2;
40 static const int REMOVE_ALL = REMOVE_DIR | REMOVE_FILE;
42 Html5Fs();
44 virtual Error Init(const FsInitArgs& args);
45 virtual void Destroy();
47 virtual Error RemoveInternal(const Path& path, int remove_type);
48 Error BlockUntilFilesystemOpen();
50 private:
51 static void FilesystemOpenCallbackThunk(void* user_data, int32_t result);
52 void FilesystemOpenCallback(int32_t result);
53 Path GetFullPath(const Path& path);
55 CoreInterface* core_iface_;
56 FileSystemInterface* filesystem_iface_;
57 FileRefInterface* file_ref_iface_;
58 FileIoInterface* file_io_iface_;
60 PP_Resource filesystem_resource_;
61 bool filesystem_open_has_result_; // protected by lock_.
62 Error filesystem_open_error_; // protected by lock_.
64 pthread_cond_t filesystem_open_cond_;
65 sdk_util::SimpleLock filesysem_open_lock_;
66 std::string prefix_;
68 friend class TypedFsFactory<Html5Fs>;
71 } // namespace nacl_io
73 #endif // LIBRARIES_NACL_IO_HTML5FS_HTML5_FS_H_