| OLD | NEW |
| 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 #ifndef WEBKIT_FILEAPI_ISOLATED_CONTEXT_H_ | 5 #ifndef WEBKIT_FILEAPI_ISOLATED_CONTEXT_H_ |
| 6 #define WEBKIT_FILEAPI_ISOLATED_CONTEXT_H_ | 6 #define WEBKIT_FILEAPI_ISOLATED_CONTEXT_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 14 #include "base/file_path.h" | 14 #include "base/file_path.h" |
| 15 #include "base/lazy_instance.h" |
| 15 #include "base/memory/singleton.h" | 16 #include "base/memory/singleton.h" |
| 16 #include "base/synchronization/lock.h" | 17 #include "base/synchronization/lock.h" |
| 17 #include "base/lazy_instance.h" | |
| 18 #include "webkit/fileapi/file_system_types.h" | 18 #include "webkit/fileapi/file_system_types.h" |
| 19 #include "webkit/fileapi/fileapi_export.h" | 19 #include "webkit/storage/webkit_storage_export.h" |
| 20 | 20 |
| 21 namespace fileapi { | 21 namespace fileapi { |
| 22 | 22 |
| 23 // Manages isolated filesystem namespaces. | 23 // Manages isolated filesystem namespaces. |
| 24 // This context class is a singleton and access to the context is | 24 // This context class is a singleton and access to the context is |
| 25 // thread-safe (protected with a lock). | 25 // thread-safe (protected with a lock). |
| 26 // | 26 // |
| 27 // There are two types of filesystems managed by this context: | 27 // There are two types of filesystems managed by this context: |
| 28 // isolated and external. | 28 // isolated and external. |
| 29 // The former is transient while the latter is persistent. | 29 // The former is transient while the latter is persistent. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 45 // | 45 // |
| 46 // A filesystem instance is represented by IsolatedContext::Instance, and | 46 // A filesystem instance is represented by IsolatedContext::Instance, and |
| 47 // managed as a map instance_map_ which maps from filesystem ID (or name) | 47 // managed as a map instance_map_ which maps from filesystem ID (or name) |
| 48 // to the instance. | 48 // to the instance. |
| 49 // | 49 // |
| 50 // Some methods of this class are virtual just for mocking. | 50 // Some methods of this class are virtual just for mocking. |
| 51 // | 51 // |
| 52 // TODO(kinuko): This should have a better name since this handles both | 52 // TODO(kinuko): This should have a better name since this handles both |
| 53 // isolated and external file systems. | 53 // isolated and external file systems. |
| 54 // | 54 // |
| 55 class FILEAPI_EXPORT IsolatedContext { | 55 class WEBKIT_STORAGE_EXPORT IsolatedContext { |
| 56 public: | 56 public: |
| 57 struct FILEAPI_EXPORT FileInfo { | 57 struct WEBKIT_STORAGE_EXPORT FileInfo { |
| 58 FileInfo(); | 58 FileInfo(); |
| 59 FileInfo(const std::string& name, const FilePath& path); | 59 FileInfo(const std::string& name, const FilePath& path); |
| 60 | 60 |
| 61 // The name to be used to register the file. The registered file can | 61 // The name to be used to register the file. The registered file can |
| 62 // be referred by a virtual path /<filesystem_id>/<name>. | 62 // be referred by a virtual path /<filesystem_id>/<name>. |
| 63 // The name should NOT contain a path separator '/'. | 63 // The name should NOT contain a path separator '/'. |
| 64 std::string name; | 64 std::string name; |
| 65 | 65 |
| 66 // The path of the file. | 66 // The path of the file. |
| 67 FilePath path; | 67 FilePath path; |
| 68 | 68 |
| 69 // For STL operation. | 69 // For STL operation. |
| 70 bool operator<(const FileInfo& that) const { return name < that.name; } | 70 bool operator<(const FileInfo& that) const { return name < that.name; } |
| 71 }; | 71 }; |
| 72 | 72 |
| 73 class FILEAPI_EXPORT FileInfoSet { | 73 class WEBKIT_STORAGE_EXPORT FileInfoSet { |
| 74 public: | 74 public: |
| 75 FileInfoSet(); | 75 FileInfoSet(); |
| 76 ~FileInfoSet(); | 76 ~FileInfoSet(); |
| 77 | 77 |
| 78 // Add the given |path| to the set and populates |registered_name| with | 78 // Add the given |path| to the set and populates |registered_name| with |
| 79 // the registered name assigned for the path. |path| needs to be | 79 // the registered name assigned for the path. |path| needs to be |
| 80 // absolute and should not contain parent references. | 80 // absolute and should not contain parent references. |
| 81 // Return false if the |path| is not valid and could not be added. | 81 // Return false if the |path| is not valid and could not be added. |
| 82 bool AddPath(const FilePath& path, std::string* registered_name); | 82 bool AddPath(const FilePath& path, std::string* registered_name); |
| 83 | 83 |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 // This lock needs to be obtained when accessing the instance_map_. | 237 // This lock needs to be obtained when accessing the instance_map_. |
| 238 mutable base::Lock lock_; | 238 mutable base::Lock lock_; |
| 239 | 239 |
| 240 IDToInstance instance_map_; | 240 IDToInstance instance_map_; |
| 241 PathToID path_to_id_map_; | 241 PathToID path_to_id_map_; |
| 242 | 242 |
| 243 DISALLOW_COPY_AND_ASSIGN(IsolatedContext); | 243 DISALLOW_COPY_AND_ASSIGN(IsolatedContext); |
| 244 }; | 244 }; |
| 245 | 245 |
| 246 // Registers a scoped external filesystem which gets revoked when it scopes out. | 246 // Registers a scoped external filesystem which gets revoked when it scopes out. |
| 247 class FILEAPI_EXPORT ScopedExternalFileSystem { | 247 class WEBKIT_STORAGE_EXPORT ScopedExternalFileSystem { |
| 248 public: | 248 public: |
| 249 ScopedExternalFileSystem(const std::string& mount_name, | 249 ScopedExternalFileSystem(const std::string& mount_name, |
| 250 FileSystemType type, | 250 FileSystemType type, |
| 251 const FilePath& path); | 251 const FilePath& path); |
| 252 ~ScopedExternalFileSystem(); | 252 ~ScopedExternalFileSystem(); |
| 253 | 253 |
| 254 FilePath GetVirtualRootPath() const; | 254 FilePath GetVirtualRootPath() const; |
| 255 | 255 |
| 256 private: | 256 private: |
| 257 const std::string mount_name_; | 257 const std::string mount_name_; |
| 258 }; | 258 }; |
| 259 | 259 |
| 260 } // namespace fileapi | 260 } // namespace fileapi |
| 261 | 261 |
| 262 #endif // WEBKIT_FILEAPI_ISOLATED_CONTEXT_H_ | 262 #endif // WEBKIT_FILEAPI_ISOLATED_CONTEXT_H_ |
| OLD | NEW |