| 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_OBFUSCATED_NAME_MAP_H_ |
| 6 #define WEBKIT_FILEAPI_OBFUSCATED_NAME_MAP_H_ |
| 7 |
| 8 #include "base/file_path.h" |
| 9 #include "base/hash_tables.h" |
| 10 #include "base/platform_file.h" |
| 11 |
| 12 namespace fileapi { |
| 13 |
| 14 using base::PlatformFile; |
| 15 using base::PlatformFileError; |
| 16 |
| 17 typedef FilePath::StringType StringType; |
| 18 |
| 19 // Instances can be reused, but call Init between uses if you want to switch |
| 20 // directory. |
| 21 class ObfuscatedNameMap { |
| 22 public: |
| 23 ObfuscatedNameMap(); |
| 24 ~ObfuscatedNameMap() { |
| 25 Rollback(); |
| 26 } |
| 27 |
| 28 void Init(const FilePath& directory); |
| 29 |
| 30 PlatformFileError ClearNameFromObfuscatedName( |
| 31 StringType obfuscated_name, |
| 32 StringType* clear_name); |
| 33 |
| 34 static StringType ObfuscatedNameFromClearName(StringType clear_name); |
| 35 |
| 36 PlatformFileError PrepareAdd( |
| 37 const StringType& clear_name, const StringType& obfuscated_name); |
| 38 |
| 39 PlatformFileError PrepareDelete( |
| 40 const StringType& clear_name, const StringType& obfuscated_name); |
| 41 |
| 42 PlatformFileError PrepareMove( |
| 43 const StringType& old_clear_name, |
| 44 const StringType& old_obfuscated_name, |
| 45 const StringType& new_clear_name, |
| 46 const StringType& new_obfuscated_name); |
| 47 |
| 48 // You must either Commit or Rollback each change individually. |
| 49 // If Commit returns an error, you must either Init or Rollback in order for |
| 50 // this object to be safe to reuse. |
| 51 PlatformFileError Commit(); |
| 52 |
| 53 // Harmless if there no operation in progress. |
| 54 void Rollback(); |
| 55 |
| 56 private: |
| 57 typedef base::hash_map<StringType, StringType> MapType; |
| 58 |
| 59 static size_t hash(const FilePath& f); |
| 60 FilePath GetDictionaryLocation(); |
| 61 FilePath GetDictionaryNextLocation(); |
| 62 PlatformFileError LoadFromFileIfNeeded(); |
| 63 void LoadMapFromString(MapType* map, const StringType& serialized); |
| 64 StringType ConvertMapToString(const MapType& map); |
| 65 PlatformFileError InitMapNext(); |
| 66 PlatformFileError RecoverIfNeeded(); |
| 67 PlatformFileError WriteToNextFile(); |
| 68 |
| 69 static const StringType::value_type DICTIONARY_NAME[]; |
| 70 static const StringType::value_type DICTIONARY_NEXT_NAME[]; |
| 71 static const StringType::value_type SEPARATOR[]; |
| 72 static const size_t SEPARATOR_LENGTH; |
| 73 static const StringType::value_type TERMINATOR[]; |
| 74 static const size_t TERMINATOR_LENGTH; |
| 75 |
| 76 MapType map_; |
| 77 MapType map_next_; |
| 78 bool map_valid_; |
| 79 bool map_next_valid_; // == operation in progress |
| 80 FilePath directory_; |
| 81 }; |
| 82 |
| 83 } // namespace fileapi |
| 84 |
| 85 #endif // WEBKIT_FILEAPI_OBFUSCATED_NAME_MAP_H_ |
| OLD | NEW |