PPAPI: Add C++ wrapper for MessageHandler stuff.
[chromium-blink-merge.git] / storage / browser / fileapi / sandbox_origin_database.h
blob21779d587e1457b6e40441dee566ada460eb57d3
1 // Copyright (c) 2012 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.
5 #ifndef STORAGE_BROWSER_FILEAPI_SANDBOX_ORIGIN_DATABASE_H_
6 #define STORAGE_BROWSER_FILEAPI_SANDBOX_ORIGIN_DATABASE_H_
8 #include <string>
9 #include <vector>
11 #include "base/memory/scoped_ptr.h"
12 #include "base/time/time.h"
13 #include "storage/browser/fileapi/sandbox_origin_database_interface.h"
15 namespace leveldb {
16 class DB;
17 class Env;
18 class Status;
21 namespace tracked_objects {
22 class Location;
25 namespace storage {
27 // All methods of this class other than the constructor may be used only from
28 // the browser's FILE thread. The constructor may be used on any thread.
29 class STORAGE_EXPORT_PRIVATE SandboxOriginDatabase
30 : public SandboxOriginDatabaseInterface {
31 public:
32 // Only one instance of SandboxOriginDatabase should exist for a given path
33 // at a given time.
34 SandboxOriginDatabase(const base::FilePath& file_system_directory,
35 leveldb::Env* env_override);
36 virtual ~SandboxOriginDatabase();
38 // SandboxOriginDatabaseInterface overrides.
39 virtual bool HasOriginPath(const std::string& origin) OVERRIDE;
40 virtual bool GetPathForOrigin(const std::string& origin,
41 base::FilePath* directory) OVERRIDE;
42 virtual bool RemovePathForOrigin(const std::string& origin) OVERRIDE;
43 virtual bool ListAllOrigins(std::vector<OriginRecord>* origins) OVERRIDE;
44 virtual void DropDatabase() OVERRIDE;
46 base::FilePath GetDatabasePath() const;
47 void RemoveDatabase();
49 private:
50 enum RecoveryOption {
51 REPAIR_ON_CORRUPTION,
52 DELETE_ON_CORRUPTION,
53 FAIL_ON_CORRUPTION,
56 enum InitOption {
57 CREATE_IF_NONEXISTENT,
58 FAIL_IF_NONEXISTENT,
61 bool Init(InitOption init_option, RecoveryOption recovery_option);
62 bool RepairDatabase(const std::string& db_path);
63 void HandleError(const tracked_objects::Location& from_here,
64 const leveldb::Status& status);
65 void ReportInitStatus(const leveldb::Status& status);
66 bool GetLastPathNumber(int* number);
68 base::FilePath file_system_directory_;
69 leveldb::Env* env_override_;
70 scoped_ptr<leveldb::DB> db_;
71 base::Time last_reported_time_;
72 DISALLOW_COPY_AND_ASSIGN(SandboxOriginDatabase);
75 } // namespace storage
77 #endif // STORAGE_BROWSER_FILEAPI_SANDBOX_ORIGIN_DATABASE_H_