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_
11 #include "base/files/file_path.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "storage/browser/fileapi/sandbox_origin_database_interface.h"
21 class ObfuscatedFileUtil
;
22 class SandboxIsolatedOriginDatabase
;
23 class SandboxOriginDatabase
;
25 class STORAGE_EXPORT_PRIVATE SandboxPrioritizedOriginDatabase
26 : public SandboxOriginDatabaseInterface
{
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_
;
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
);
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_