OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 CONTENT_BROWSER_DOM_STORAGE_LOCAL_STORAGE_CONTEXT_MOJO_H_ | 5 #ifndef CONTENT_BROWSER_DOM_STORAGE_LOCAL_STORAGE_CONTEXT_MOJO_H_ |
6 #define CONTENT_BROWSER_DOM_STORAGE_LOCAL_STORAGE_CONTEXT_MOJO_H_ | 6 #define CONTENT_BROWSER_DOM_STORAGE_LOCAL_STORAGE_CONTEXT_MOJO_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 using GetStorageUsageCallback = | 30 using GetStorageUsageCallback = |
31 base::OnceCallback<void(std::vector<LocalStorageUsageInfo>)>; | 31 base::OnceCallback<void(std::vector<LocalStorageUsageInfo>)>; |
32 | 32 |
33 LocalStorageContextMojo(service_manager::Connector* connector, | 33 LocalStorageContextMojo(service_manager::Connector* connector, |
34 const base::FilePath& subdirectory); | 34 const base::FilePath& subdirectory); |
35 ~LocalStorageContextMojo(); | 35 ~LocalStorageContextMojo(); |
36 | 36 |
37 void OpenLocalStorage(const url::Origin& origin, | 37 void OpenLocalStorage(const url::Origin& origin, |
38 mojom::LevelDBWrapperRequest request); | 38 mojom::LevelDBWrapperRequest request); |
39 void GetStorageUsage(GetStorageUsageCallback callback); | 39 void GetStorageUsage(GetStorageUsageCallback callback); |
| 40 void DeleteStorage(const url::Origin& origin); |
| 41 // Like DeleteStorage(), but also deletes storage for all sub-origins. |
| 42 void DeleteStorageForPhysicalOrigin(const url::Origin& origin); |
40 | 43 |
41 void SetDatabaseForTesting(leveldb::mojom::LevelDBDatabasePtr database); | 44 void SetDatabaseForTesting(leveldb::mojom::LevelDBDatabasePtr database); |
42 | 45 |
43 private: | 46 private: |
44 // Runs |callback| immediately if already connected to a database, otherwise | 47 // Runs |callback| immediately if already connected to a database, otherwise |
45 // delays running |callback| untill after a connection has been established. | 48 // delays running |callback| untill after a connection has been established. |
46 // Initiates connecting to the database if no connection is in progres yet. | 49 // Initiates connecting to the database if no connection is in progres yet. |
47 void RunWhenConnected(base::OnceClosure callback); | 50 void RunWhenConnected(base::OnceClosure callback); |
48 | 51 |
49 void OnLevelDBWrapperHasNoBindings(const url::Origin& origin); | 52 void OnLevelDBWrapperHasNoBindings(const url::Origin& origin); |
50 std::vector<leveldb::mojom::BatchedOperationPtr> | 53 std::vector<leveldb::mojom::BatchedOperationPtr> |
51 OnLevelDBWrapperPrepareToCommit(const url::Origin& origin, | 54 OnLevelDBWrapperPrepareToCommit(const url::Origin& origin, |
52 const LevelDBWrapperImpl& wrapper); | 55 const LevelDBWrapperImpl& wrapper); |
53 void OnUserServiceConnectionComplete(); | 56 void OnUserServiceConnectionComplete(); |
54 void OnUserServiceConnectionError(); | 57 void OnUserServiceConnectionError(); |
55 | 58 |
56 // Part of our asynchronous directory opening called from OpenLocalStorage(). | 59 // Part of our asynchronous directory opening called from OpenLocalStorage(). |
57 void OnDirectoryOpened(filesystem::mojom::FileError err); | 60 void OnDirectoryOpened(filesystem::mojom::FileError err); |
58 void OnDatabaseOpened(leveldb::mojom::DatabaseError status); | 61 void OnDatabaseOpened(leveldb::mojom::DatabaseError status); |
59 void OnGotDatabaseVersion(leveldb::mojom::DatabaseError status, | 62 void OnGotDatabaseVersion(leveldb::mojom::DatabaseError status, |
60 const std::vector<uint8_t>& value); | 63 const std::vector<uint8_t>& value); |
61 | 64 |
62 // The (possibly delayed) implementation of OpenLocalStorage(). Can be called | 65 // The (possibly delayed) implementation of OpenLocalStorage(). Can be called |
63 // directly from that function, or through |on_database_open_callbacks_|. | 66 // directly from that function, or through |on_database_open_callbacks_|. |
64 void BindLocalStorage(const url::Origin& origin, | 67 void BindLocalStorage(const url::Origin& origin, |
65 mojom::LevelDBWrapperRequest request); | 68 mojom::LevelDBWrapperRequest request); |
| 69 LevelDBWrapperImpl* GetOrCreateDBWrapper(const url::Origin& origin); |
66 | 70 |
67 // The (possibly delayed) implementation of GetStorageUsage(). Can be called | 71 // The (possibly delayed) implementation of GetStorageUsage(). Can be called |
68 // directly from that function, or through |on_database_open_callbacks_|. | 72 // directly from that function, or through |on_database_open_callbacks_|. |
69 void RetrieveStorageUsage(GetStorageUsageCallback callback); | 73 void RetrieveStorageUsage(GetStorageUsageCallback callback); |
70 void OnGotMetaData(GetStorageUsageCallback callback, | 74 void OnGotMetaData(GetStorageUsageCallback callback, |
71 leveldb::mojom::DatabaseError status, | 75 leveldb::mojom::DatabaseError status, |
72 std::vector<leveldb::mojom::KeyValuePtr> data); | 76 std::vector<leveldb::mojom::KeyValuePtr> data); |
73 | 77 |
| 78 void OnGotStorageUsageForDeletePhysicalOrigin( |
| 79 const url::Origin& origin, |
| 80 std::vector<LocalStorageUsageInfo> usage); |
| 81 |
74 service_manager::Connector* const connector_; | 82 service_manager::Connector* const connector_; |
75 const base::FilePath subdirectory_; | 83 const base::FilePath subdirectory_; |
76 | 84 |
77 enum ConnectionState { | 85 enum ConnectionState { |
78 NO_CONNECTION, | 86 NO_CONNECTION, |
79 CONNECTION_IN_PROGRESS, | 87 CONNECTION_IN_PROGRESS, |
80 CONNECTION_FINISHED | 88 CONNECTION_FINISHED |
81 } connection_state_ = NO_CONNECTION; | 89 } connection_state_ = NO_CONNECTION; |
82 bool database_initialized_ = false; | 90 bool database_initialized_ = false; |
83 | 91 |
84 std::unique_ptr<service_manager::Connection> file_service_connection_; | 92 std::unique_ptr<service_manager::Connection> file_service_connection_; |
85 | 93 |
86 file::mojom::FileSystemPtr file_system_; | 94 file::mojom::FileSystemPtr file_system_; |
87 filesystem::mojom::DirectoryPtr directory_; | 95 filesystem::mojom::DirectoryPtr directory_; |
88 | 96 |
89 leveldb::mojom::LevelDBServicePtr leveldb_service_; | 97 leveldb::mojom::LevelDBServicePtr leveldb_service_; |
90 leveldb::mojom::LevelDBDatabasePtr database_; | 98 leveldb::mojom::LevelDBDatabasePtr database_; |
91 | 99 |
92 std::vector<base::OnceClosure> on_database_opened_callbacks_; | 100 std::vector<base::OnceClosure> on_database_opened_callbacks_; |
93 | 101 |
94 // Maps between an origin and its prefixed LevelDB view. | 102 // Maps between an origin and its prefixed LevelDB view. |
95 std::map<url::Origin, std::unique_ptr<LevelDBWrapperImpl>> level_db_wrappers_; | 103 std::map<url::Origin, std::unique_ptr<LevelDBWrapperImpl>> level_db_wrappers_; |
96 | 104 |
97 base::WeakPtrFactory<LocalStorageContextMojo> weak_ptr_factory_; | 105 base::WeakPtrFactory<LocalStorageContextMojo> weak_ptr_factory_; |
98 }; | 106 }; |
99 | 107 |
100 } // namespace content | 108 } // namespace content |
101 | 109 |
102 #endif // CONTENT_BROWSER_DOM_STORAGE_LOCAL_STORAGE_CONTEXT_MOJO_H_ | 110 #endif // CONTENT_BROWSER_DOM_STORAGE_LOCAL_STORAGE_CONTEXT_MOJO_H_ |
OLD | NEW |