When enabling new profile management programmatically, make sure to set the
[chromium-blink-merge.git] / webkit / browser / fileapi / sandbox_prioritized_origin_database.h
blob6f390dc25143d25535c8781d5375bbbd4fae326e
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 WEBKIT_BROWSER_FILEAPI_SANDBOX_PRIORITIZED_ORIGIN_DATABASE_H_
6 #define WEBKIT_BROWSER_FILEAPI_SANDBOX_PRIORITIZED_ORIGIN_DATABASE_H_
8 #include <string>
9 #include <vector>
11 #include "base/memory/scoped_ptr.h"
12 #include "webkit/browser/fileapi/sandbox_origin_database_interface.h"
14 namespace leveldb {
15 class Env;
18 namespace fileapi {
20 class ObfuscatedFileUtil;
21 class SandboxIsolatedOriginDatabase;
22 class SandboxOriginDatabase;
24 class WEBKIT_STORAGE_BROWSER_EXPORT_PRIVATE SandboxPrioritizedOriginDatabase
25 : public SandboxOriginDatabaseInterface {
26 public:
27 SandboxPrioritizedOriginDatabase(const base::FilePath& file_system_directory,
28 leveldb::Env* env_override);
29 virtual ~SandboxPrioritizedOriginDatabase();
31 // Sets |origin| as primary origin in this database (e.g. may
32 // allow faster access).
33 // Returns false if this database already has a primary origin
34 // which is different from |origin|.
35 bool InitializePrimaryOrigin(const std::string& origin);
36 std::string GetPrimaryOrigin();
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 const base::FilePath& primary_origin_file() const {
47 return primary_origin_file_;
50 private:
51 bool MaybeLoadPrimaryOrigin();
52 bool ResetPrimaryOrigin(const std::string& origin);
53 void MaybeMigrateDatabase(const std::string& origin);
54 void MaybeInitializeDatabases(bool create);
55 void MaybeInitializeNonPrimaryDatabase(bool create);
57 // For migration.
58 friend class ObfuscatedFileUtil;
59 SandboxOriginDatabase* GetSandboxOriginDatabase();
61 const base::FilePath file_system_directory_;
62 leveldb::Env* env_override_;
63 const base::FilePath primary_origin_file_;
64 scoped_ptr<SandboxOriginDatabase> origin_database_;
65 scoped_ptr<SandboxIsolatedOriginDatabase> primary_origin_database_;
67 DISALLOW_COPY_AND_ASSIGN(SandboxPrioritizedOriginDatabase);
70 } // namespace fileapi
72 #endif // WEBKIT_BROWSER_FILEAPI_SANDBOX_PRIORITIZED_ORIGIN_DATABASE_H_