Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / storage / browser / fileapi / sandbox_prioritized_origin_database.h
blobc1b6a80c5ca92db8b6707a071ae10db60712e42c
1 // Copyright 2013 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_PRIORITIZED_ORIGIN_DATABASE_H_
6 #define STORAGE_BROWSER_FILEAPI_SANDBOX_PRIORITIZED_ORIGIN_DATABASE_H_
8 #include <string>
9 #include <vector>
11 #include "base/files/file_path.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "storage/browser/fileapi/sandbox_origin_database_interface.h"
15 namespace leveldb {
16 class Env;
19 namespace storage {
21 class ObfuscatedFileUtil;
22 class SandboxIsolatedOriginDatabase;
23 class SandboxOriginDatabase;
25 class STORAGE_EXPORT_PRIVATE SandboxPrioritizedOriginDatabase
26 : public SandboxOriginDatabaseInterface {
27 public:
28 static const base::FilePath::CharType* kPrimaryDirectory;
29 static const base::FilePath::CharType* kPrimaryOriginFile;
31 SandboxPrioritizedOriginDatabase(const base::FilePath& file_system_directory,
32 leveldb::Env* env_override);
33 ~SandboxPrioritizedOriginDatabase() override;
35 // Sets |origin| as primary origin in this database (e.g. may
36 // allow faster access).
37 // Returns false if this database already has a primary origin
38 // which is different from |origin|.
39 bool InitializePrimaryOrigin(const std::string& origin);
40 std::string GetPrimaryOrigin();
42 // SandboxOriginDatabaseInterface overrides.
43 bool HasOriginPath(const std::string& origin) override;
44 bool GetPathForOrigin(const std::string& origin,
45 base::FilePath* directory) override;
46 bool RemovePathForOrigin(const std::string& origin) override;
47 bool ListAllOrigins(std::vector<OriginRecord>* origins) override;
48 void DropDatabase() override;
50 const base::FilePath& primary_origin_file() const {
51 return primary_origin_file_;
54 private:
55 bool MaybeLoadPrimaryOrigin();
56 bool ResetPrimaryOrigin(const std::string& origin);
57 void MaybeMigrateDatabase(const std::string& origin);
58 void MaybeInitializeDatabases(bool create);
59 void MaybeInitializeNonPrimaryDatabase(bool create);
61 // For migration.
62 friend class ObfuscatedFileUtil;
63 SandboxOriginDatabase* GetSandboxOriginDatabase();
65 const base::FilePath file_system_directory_;
66 leveldb::Env* env_override_;
67 const base::FilePath primary_origin_file_;
68 scoped_ptr<SandboxOriginDatabase> origin_database_;
69 scoped_ptr<SandboxIsolatedOriginDatabase> primary_origin_database_;
71 DISALLOW_COPY_AND_ASSIGN(SandboxPrioritizedOriginDatabase);
74 } // namespace storage
76 #endif // STORAGE_BROWSER_FILEAPI_SANDBOX_PRIORITIZED_ORIGIN_DATABASE_H_