Chromium Code Reviews
|
| 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 obfuscated_file_util { | |
| 13 | |
| 14 using base::PlatformFile; | |
| 15 using base::PlatformFileError; | |
| 16 | |
| 17 typedef FilePath::StringType StringType; | |
| 18 | |
| 19 // This can be reused, but call Init between uses if you want to switch | |
| 20 // directory. You must either RollBack or Commit each change individually. If | |
| 21 // you get an error, call either Init or RollBack before trying to reuse the | |
| 22 // object. | |
|
michaeln
2011/02/11 00:03:34
class comments about what this class does might be
ericu
2011/02/11 01:57:47
Hmm...I thought it best to put "how to reuse this
| |
| 23 class ObfuscatedNameMap { | |
| 24 public: | |
| 25 ObfuscatedNameMap(); | |
| 26 ~ObfuscatedNameMap() { | |
| 27 RollBack(); | |
| 28 } | |
| 29 | |
| 30 void Init(const FilePath& directory); | |
| 31 | |
| 32 PlatformFileError ClearNameFromObfuscatedName( | |
| 33 StringType obfuscated_name, | |
| 34 StringType* clear_name); | |
| 35 | |
| 36 static StringType ObfuscatedNameFromClearName(StringType clear_name); | |
| 37 | |
| 38 PlatformFileError PrepareAdd( | |
| 39 const StringType& clear_name, const StringType& obfuscated_name); | |
| 40 | |
| 41 PlatformFileError PrepareDelete( | |
| 42 const StringType& clear_name, const StringType& obfuscated_name); | |
| 43 | |
| 44 PlatformFileError PrepareMove( | |
| 45 const StringType& old_clear_name, | |
| 46 const StringType& old_obfuscated_name, | |
| 47 const StringType& new_clear_name, | |
| 48 const StringType& new_obfuscated_name); | |
| 49 | |
| 50 PlatformFileError Commit(); | |
| 51 | |
| 52 // Harmless if there no operation in progress. | |
| 53 void RollBack(); | |
|
michaeln
2011/02/11 00:03:34
There's precedence in the project for 'Rollback' w
ericu
2011/02/11 01:57:47
OK, will change.
| |
| 54 | |
| 55 private: | |
| 56 typedef base::hash_map<StringType, StringType> MapType; | |
| 57 | |
| 58 static size_t hash(const FilePath& f); | |
| 59 FilePath GetDictionaryLocation(); | |
| 60 FilePath GetDictionaryNextLocation(); | |
| 61 PlatformFileError LoadFromFile(); | |
| 62 void LoadMapFromString(MapType* map, const StringType& serialized); | |
| 63 StringType ConvertMapToString(const MapType& map); | |
| 64 PlatformFileError InitDictNext(); | |
| 65 PlatformFileError RecoverIfNeeded(); | |
| 66 PlatformFileError WriteToNextFile(); | |
| 67 | |
| 68 static const StringType DICTIONARY_NAME; | |
| 69 static const StringType DICTIONARY_NEXT_NAME; | |
| 70 static const StringType SEPARATOR; | |
| 71 static const StringType TERMINATOR; | |
| 72 | |
| 73 MapType map_; | |
| 74 MapType map_next_; | |
| 75 bool map_valid_; | |
| 76 bool map_next_valid_; // == operation in progress | |
| 77 FilePath directory_; | |
| 78 }; | |
| 79 | |
| 80 } // namespace obfuscated_file_util | |
| 81 | |
| 82 #endif // WEBKIT_FILEAPI_OBFUSCATED_NAME_MAP_H_ | |
| OLD | NEW |