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

Side by Side Diff: webkit/fileapi/file_system_origin_database.h

Issue 9663021: Add database recovery for FileSystemOriginDatabase (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: bool -> enum Created 8 years, 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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_FILE_SYSTEM_ORIGIN_DATABASE_H_ 5 #ifndef WEBKIT_FILEAPI_FILE_SYSTEM_ORIGIN_DATABASE_H_
6 #define WEBKIT_FILEAPI_FILE_SYSTEM_ORIGIN_DATABASE_H_ 6 #define WEBKIT_FILEAPI_FILE_SYSTEM_ORIGIN_DATABASE_H_
7 7
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/file_path.h" 12 #include "base/file_path.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "third_party/leveldatabase/src/include/leveldb/db.h" 14 #include "third_party/leveldatabase/src/include/leveldb/db.h"
15 15
16 namespace tracked_objects { 16 namespace tracked_objects {
17 class Location; 17 class Location;
18 } 18 }
19 19
20 namespace fileapi { 20 namespace fileapi {
21 21
22 // All methods of this class other than the constructor may be used only from 22 // All methods of this class other than the constructor may be used only from
23 // the browser's FILE thread. The constructor may be used on any thread. 23 // the browser's FILE thread. The constructor may be used on any thread.
24 class FileSystemOriginDatabase { 24 class FileSystemOriginDatabase {
25 public: 25 public:
26 enum RecoveringOption {
27 REBUILD_ON_CORRUPTION,
28 LEAVE_ON_CORRUPTION,
29 };
30
26 struct OriginRecord { 31 struct OriginRecord {
27 std::string origin; 32 std::string origin;
28 FilePath path; 33 FilePath path;
29 34
30 OriginRecord(); 35 OriginRecord();
31 OriginRecord(const std::string& origin, const FilePath& path); 36 OriginRecord(const std::string& origin, const FilePath& path);
32 ~OriginRecord(); 37 ~OriginRecord();
33 }; 38 };
34 39
35 // Only one instance of FileSystemOriginDatabase should exist for a given path 40 // Only one instance of FileSystemOriginDatabase should exist for a given path
36 // at a given time. 41 // at a given time.
37 explicit FileSystemOriginDatabase(const FilePath& path); 42 explicit FileSystemOriginDatabase(const FilePath& path);
38 ~FileSystemOriginDatabase(); 43 ~FileSystemOriginDatabase();
39 44
40 bool HasOriginPath(const std::string& origin); 45 bool HasOriginPath(const std::string& origin);
41 46
42 // This will produce a unique path and add it to its database, if it's not 47 // This will produce a unique path and add it to its database, if it's not
43 // already present. 48 // already present.
44 bool GetPathForOrigin(const std::string& origin, FilePath* directory); 49 bool GetPathForOrigin(const std::string& origin, FilePath* directory);
45 50
46 // Also returns success if the origin is not found. 51 // Also returns success if the origin is not found.
47 bool RemovePathForOrigin(const std::string& origin); 52 bool RemovePathForOrigin(const std::string& origin);
48 53
49 bool ListAllOrigins(std::vector<OriginRecord>* origins); 54 bool ListAllOrigins(std::vector<OriginRecord>* origins);
50 55
51 // This will release all database resources in use; call it to save memory. 56 // This will release all database resources in use; call it to save memory.
52 void DropDatabase(); 57 void DropDatabase();
53 58
54 private: 59 private:
55 bool Init(); 60 bool Init(RecoveringOption recovering_option);
56 void HandleError(const tracked_objects::Location& from_here, 61 void HandleError(const tracked_objects::Location& from_here,
57 leveldb::Status status); 62 leveldb::Status status);
58 bool GetLastPathNumber(int* number); 63 bool GetLastPathNumber(int* number);
59 64
60 std::string path_; 65 std::string path_;
61 scoped_ptr<leveldb::DB> db_; 66 scoped_ptr<leveldb::DB> db_;
62 DISALLOW_COPY_AND_ASSIGN(FileSystemOriginDatabase); 67 DISALLOW_COPY_AND_ASSIGN(FileSystemOriginDatabase);
63 }; 68 };
64 69
65 } // namespace fileapi 70 } // namespace fileapi
66 71
67 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_ORIGIN_DATABASE_H_ 72 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_ORIGIN_DATABASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698