Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Unified Diff: webkit/fileapi/obfuscated_name_map.h

Issue 6286038: Add initial code to do filename munging in the FileSystem.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webkit/fileapi/obfuscated_name_map.h
===================================================================
--- webkit/fileapi/obfuscated_name_map.h (revision 0)
+++ webkit/fileapi/obfuscated_name_map.h (revision 0)
@@ -0,0 +1,85 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef WEBKIT_FILEAPI_OBFUSCATED_NAME_MAP_H_
+#define WEBKIT_FILEAPI_OBFUSCATED_NAME_MAP_H_
+
+#include "base/file_path.h"
+#include "base/hash_tables.h"
+#include "base/platform_file.h"
+
+namespace fileapi {
+
+using base::PlatformFile;
+using base::PlatformFileError;
+
+typedef FilePath::StringType StringType;
+
+// Instances can be reused, but call Init between uses if you want to switch
+// directory.
+class ObfuscatedNameMap {
+ public:
+ ObfuscatedNameMap();
+ ~ObfuscatedNameMap() {
+ Rollback();
+ }
+
+ void Init(const FilePath& directory);
+
+ PlatformFileError ClearNameFromObfuscatedName(
+ StringType obfuscated_name,
+ StringType* clear_name);
+
+ static StringType ObfuscatedNameFromClearName(StringType clear_name);
+
+ PlatformFileError PrepareAdd(
+ const StringType& clear_name, const StringType& obfuscated_name);
+
+ PlatformFileError PrepareDelete(
+ const StringType& clear_name, const StringType& obfuscated_name);
+
+ PlatformFileError PrepareMove(
+ const StringType& old_clear_name,
+ const StringType& old_obfuscated_name,
+ const StringType& new_clear_name,
+ const StringType& new_obfuscated_name);
+
+ // You must either Commit or Rollback each change individually.
+ // If Commit returns an error, you must either Init or Rollback in order for
+ // this object to be safe to reuse.
+ PlatformFileError Commit();
+
+ // Harmless if there no operation in progress.
+ void Rollback();
+
+ private:
+ typedef base::hash_map<StringType, StringType> MapType;
+
+ static size_t hash(const FilePath& f);
+ FilePath GetDictionaryLocation();
+ FilePath GetDictionaryNextLocation();
+ PlatformFileError LoadFromFileIfNeeded();
+ void LoadMapFromString(MapType* map, const StringType& serialized);
+ StringType ConvertMapToString(const MapType& map);
+ PlatformFileError InitMapNext();
+ PlatformFileError RecoverIfNeeded();
+ PlatformFileError WriteToNextFile();
+
+ static const StringType::value_type DICTIONARY_NAME[];
+ static const StringType::value_type DICTIONARY_NEXT_NAME[];
+ static const StringType::value_type SEPARATOR[];
+ static const size_t SEPARATOR_LENGTH;
+ static const StringType::value_type TERMINATOR[];
+ static const size_t TERMINATOR_LENGTH;
+
+ MapType map_;
+ MapType map_next_;
+ bool map_valid_;
+ bool map_next_valid_; // == operation in progress
+ FilePath directory_;
Dai Mikurube (google.com) 2011/02/22 02:57:35 Move this declaration before "bool map_valid_;"
+};
+
+} // namespace fileapi
+
+#endif // WEBKIT_FILEAPI_OBFUSCATED_NAME_MAP_H_
Property changes on: webkit\fileapi\obfuscated_name_map.h
___________________________________________________________________
Added: svn:eol-style
+ LF

Powered by Google App Engine
This is Rietveld 408576698