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" |
11 #include "content/common/content_export.h" | 11 #include "content/common/content_export.h" |
12 #include "content/common/leveldb_wrapper.mojom.h" | 12 #include "content/common/leveldb_wrapper.mojom.h" |
13 #include "services/file/public/interfaces/file_system.mojom.h" | 13 #include "services/file/public/interfaces/file_system.mojom.h" |
14 #include "url/origin.h" | 14 #include "url/origin.h" |
15 | 15 |
16 namespace service_manager { | 16 namespace service_manager { |
17 class Connection; | |
18 class Connector; | 17 class Connector; |
19 } | 18 } |
20 | 19 |
21 namespace content { | 20 namespace content { |
22 | 21 |
23 class DOMStorageTaskRunner; | 22 class DOMStorageTaskRunner; |
24 class LevelDBWrapperImpl; | 23 class LevelDBWrapperImpl; |
25 struct LocalStorageUsageInfo; | 24 struct LocalStorageUsageInfo; |
26 | 25 |
27 // Used for mojo-based LocalStorage implementation (behind --mojo-local-storage | 26 // Used for mojo-based LocalStorage implementation (behind --mojo-local-storage |
(...skipping 26 matching lines...) Expand all Loading... |
54 private: | 53 private: |
55 friend class MojoDOMStorageBrowserTest; | 54 friend class MojoDOMStorageBrowserTest; |
56 | 55 |
57 class LevelDBWrapperHolder; | 56 class LevelDBWrapperHolder; |
58 | 57 |
59 // Runs |callback| immediately if already connected to a database, otherwise | 58 // Runs |callback| immediately if already connected to a database, otherwise |
60 // delays running |callback| untill after a connection has been established. | 59 // delays running |callback| untill after a connection has been established. |
61 // Initiates connecting to the database if no connection is in progres yet. | 60 // Initiates connecting to the database if no connection is in progres yet. |
62 void RunWhenConnected(base::OnceClosure callback); | 61 void RunWhenConnected(base::OnceClosure callback); |
63 | 62 |
64 void OnUserServiceConnectionComplete(); | |
65 void OnUserServiceConnectionError(); | |
66 | |
67 // Part of our asynchronous directory opening called from RunWhenConnected(). | 63 // Part of our asynchronous directory opening called from RunWhenConnected(). |
68 void InitiateConnection(bool in_memory_only = false); | 64 void InitiateConnection(bool in_memory_only = false); |
69 void OnDirectoryOpened(filesystem::mojom::FileError err); | 65 void OnDirectoryOpened(filesystem::mojom::FileError err); |
70 void OnDatabaseOpened(bool in_memory, leveldb::mojom::DatabaseError status); | 66 void OnDatabaseOpened(bool in_memory, leveldb::mojom::DatabaseError status); |
71 void OnGotDatabaseVersion(leveldb::mojom::DatabaseError status, | 67 void OnGotDatabaseVersion(leveldb::mojom::DatabaseError status, |
72 const std::vector<uint8_t>& value); | 68 const std::vector<uint8_t>& value); |
73 void OnConnectionFinished(); | 69 void OnConnectionFinished(); |
74 void DeleteAndRecreateDatabase(); | 70 void DeleteAndRecreateDatabase(); |
75 void OnDBDestroyed(bool recreate_in_memory, | 71 void OnDBDestroyed(bool recreate_in_memory, |
76 leveldb::mojom::DatabaseError status); | 72 leveldb::mojom::DatabaseError status); |
(...skipping 18 matching lines...) Expand all Loading... |
95 service_manager::Connector* const connector_; | 91 service_manager::Connector* const connector_; |
96 const base::FilePath subdirectory_; | 92 const base::FilePath subdirectory_; |
97 | 93 |
98 enum ConnectionState { | 94 enum ConnectionState { |
99 NO_CONNECTION, | 95 NO_CONNECTION, |
100 CONNECTION_IN_PROGRESS, | 96 CONNECTION_IN_PROGRESS, |
101 CONNECTION_FINISHED | 97 CONNECTION_FINISHED |
102 } connection_state_ = NO_CONNECTION; | 98 } connection_state_ = NO_CONNECTION; |
103 bool database_initialized_ = false; | 99 bool database_initialized_ = false; |
104 | 100 |
105 std::unique_ptr<service_manager::Connection> file_service_connection_; | |
106 | |
107 file::mojom::FileSystemPtr file_system_; | 101 file::mojom::FileSystemPtr file_system_; |
108 filesystem::mojom::DirectoryPtr directory_; | 102 filesystem::mojom::DirectoryPtr directory_; |
109 | 103 |
110 leveldb::mojom::LevelDBServicePtr leveldb_service_; | 104 leveldb::mojom::LevelDBServicePtr leveldb_service_; |
111 leveldb::mojom::LevelDBDatabaseAssociatedPtr database_; | 105 leveldb::mojom::LevelDBDatabaseAssociatedPtr database_; |
112 bool tried_to_recreate_ = false; | 106 bool tried_to_recreate_ = false; |
113 | 107 |
114 std::vector<base::OnceClosure> on_database_opened_callbacks_; | 108 std::vector<base::OnceClosure> on_database_opened_callbacks_; |
115 | 109 |
116 // Maps between an origin and its prefixed LevelDB view. | 110 // Maps between an origin and its prefixed LevelDB view. |
117 std::map<url::Origin, std::unique_ptr<LevelDBWrapperHolder>> | 111 std::map<url::Origin, std::unique_ptr<LevelDBWrapperHolder>> |
118 level_db_wrappers_; | 112 level_db_wrappers_; |
119 | 113 |
120 // Used to access old data for migration. | 114 // Used to access old data for migration. |
121 scoped_refptr<DOMStorageTaskRunner> task_runner_; | 115 scoped_refptr<DOMStorageTaskRunner> task_runner_; |
122 base::FilePath old_localstorage_path_; | 116 base::FilePath old_localstorage_path_; |
123 | 117 |
124 base::WeakPtrFactory<LocalStorageContextMojo> weak_ptr_factory_; | 118 base::WeakPtrFactory<LocalStorageContextMojo> weak_ptr_factory_; |
125 }; | 119 }; |
126 | 120 |
127 } // namespace content | 121 } // namespace content |
128 | 122 |
129 #endif // CONTENT_BROWSER_DOM_STORAGE_LOCAL_STORAGE_CONTEXT_MOJO_H_ | 123 #endif // CONTENT_BROWSER_DOM_STORAGE_LOCAL_STORAGE_CONTEXT_MOJO_H_ |
OLD | NEW |