| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2011 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. |
| 4 |
| 5 #ifndef WEBKIT_FILEAPI_PATH_OBFUSCATOR_H |
| 6 #define WEBKIT_FILEAPI_PATH_OBFUSCATOR_H |
| 7 |
| 8 #include "base/file_path.h" |
| 9 #include "base/platform_file.h" |
| 10 #include "webkit/fileapi/obfuscated_name_map.h" |
| 11 |
| 12 using base::PlatformFileError; |
| 13 |
| 14 namespace fileapi { |
| 15 |
| 16 // This class is for use on the file thread only. TODO(ericu): Add CHECKs for |
| 17 // this. |
| 18 // The lifetime of the PathObfuscator must be limited such that any operation |
| 19 // that could move the directory to which it refers happens outside that |
| 20 // lifetime--otherwise you might be looking up keys in the wrong dictionary. |
| 21 // Also, you shouldn't have more than one of these for the same directory at the |
| 22 // same time, or they could get out of sync. |
| 23 // You can reuse one of these for multiple operations as long as you manage it |
| 24 // carefully: Rollback or Commit between each operation, and don't let it get |
| 25 // out of sync. |
| 26 class PathObfuscator { |
| 27 public: |
| 28 PathObfuscator(const FilePath& root_path); |
| 29 ~PathObfuscator() { |
| 30 Rollback(); |
| 31 } |
| 32 |
| 33 // As long as there's no salting on the hash, this can be static. |
| 34 FilePath ObfuscatedPathFromClearPath(const FilePath& virtual_path); |
| 35 |
| 36 PlatformFileError ClearPathFromObfuscatedPath( |
| 37 const FilePath& obfuscated_path, |
| 38 FilePath* clear_path); |
| 39 |
| 40 PlatformFileError PrepareAdd( |
| 41 const FilePath& clear_path, |
| 42 const FilePath& obfuscated_path); |
| 43 |
| 44 PlatformFileError PrepareDelete( |
| 45 const FilePath& clear_path, |
| 46 const FilePath& obfuscated_path); |
| 47 |
| 48 PlatformFileError PrepareMove( |
| 49 const FilePath& old_clear_path, |
| 50 const FilePath& old_obfuscated_path, |
| 51 const FilePath& new_clear_path, |
| 52 const FilePath& new_obfuscated_path); |
| 53 |
| 54 PlatformFileError Commit(); |
| 55 |
| 56 // Harmless if there no operation in progress. |
| 57 void Rollback(); |
| 58 |
| 59 private: |
| 60 ObfuscatedNameMap from_map_; |
| 61 ObfuscatedNameMap to_map_; |
| 62 bool from_map_valid_, to_map_valid_; |
| 63 FilePath root_path_; |
| 64 }; |
| 65 |
| 66 } // namespace fileapi |
| 67 |
| 68 #endif // WEBKIT_FILEAPI_PATH_OBFUSCATOR_H |
| OLD | NEW |