Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(649)

Side by Side Diff: content/browser/dom_storage/local_storage_context_mojo.h

Issue 2604963002: Store per-origin metadata for localstorage. (Closed)
Patch Set: remove duplicate include line Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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; 17 class Connection;
18 class Connector; 18 class Connector;
19 } 19 }
20 20
21 namespace content { 21 namespace content {
22 22
23 class LevelDBWrapperImpl; 23 class LevelDBWrapperImpl;
24 struct LocalStorageUsageInfo;
24 25
25 // Used for mojo-based LocalStorage implementation (behind --mojo-local-storage 26 // Used for mojo-based LocalStorage implementation (behind --mojo-local-storage
26 // for now). 27 // for now).
27 class CONTENT_EXPORT LocalStorageContextMojo { 28 class CONTENT_EXPORT LocalStorageContextMojo {
28 public: 29 public:
30 using GetStorageUsageCallback =
31 base::OnceCallback<void(std::vector<LocalStorageUsageInfo>)>;
32
29 LocalStorageContextMojo(service_manager::Connector* connector, 33 LocalStorageContextMojo(service_manager::Connector* connector,
30 const base::FilePath& subdirectory); 34 const base::FilePath& subdirectory);
31 ~LocalStorageContextMojo(); 35 ~LocalStorageContextMojo();
32 36
33 void OpenLocalStorage(const url::Origin& origin, 37 void OpenLocalStorage(const url::Origin& origin,
34 mojom::LevelDBWrapperRequest request); 38 mojom::LevelDBWrapperRequest request);
39 void GetStorageUsage(GetStorageUsageCallback callback);
35 40
36 void SetDatabaseForTesting(leveldb::mojom::LevelDBDatabasePtr database); 41 void SetDatabaseForTesting(leveldb::mojom::LevelDBDatabasePtr database);
37 42
38 private: 43 private:
44 // Runs |callback| immediately if already connected to a database, otherwise
45 // delays running |callback| untill after a connection has been established.
46 // Initiates connecting to the database if no connection is in progres yet.
47 void RunWhenConnected(base::OnceClosure callback);
48
39 void OnLevelDBWrapperHasNoBindings(const url::Origin& origin); 49 void OnLevelDBWrapperHasNoBindings(const url::Origin& origin);
40 std::vector<leveldb::mojom::BatchedOperationPtr> 50 std::vector<leveldb::mojom::BatchedOperationPtr>
41 OnLevelDBWrapperPrepareToCommit(); 51 OnLevelDBWrapperPrepareToCommit(const url::Origin& origin,
52 const LevelDBWrapperImpl& wrapper);
42 void OnUserServiceConnectionComplete(); 53 void OnUserServiceConnectionComplete();
43 void OnUserServiceConnectionError(); 54 void OnUserServiceConnectionError();
44 55
45 // Part of our asynchronous directory opening called from OpenLocalStorage(). 56 // Part of our asynchronous directory opening called from OpenLocalStorage().
46 void OnDirectoryOpened(filesystem::mojom::FileError err); 57 void OnDirectoryOpened(filesystem::mojom::FileError err);
47 void OnDatabaseOpened(leveldb::mojom::DatabaseError status); 58 void OnDatabaseOpened(leveldb::mojom::DatabaseError status);
48 void OnGotDatabaseVersion(leveldb::mojom::DatabaseError status, 59 void OnGotDatabaseVersion(leveldb::mojom::DatabaseError status,
49 const std::vector<uint8_t>& value); 60 const std::vector<uint8_t>& value);
50 61
51 // The (possibly delayed) implementation of OpenLocalStorage(). Can be called 62 // The (possibly delayed) implementation of OpenLocalStorage(). Can be called
52 // directly from that function, or through |on_database_open_callbacks_|. 63 // directly from that function, or through |on_database_open_callbacks_|.
53 void BindLocalStorage(const url::Origin& origin, 64 void BindLocalStorage(const url::Origin& origin,
54 mojom::LevelDBWrapperRequest request); 65 mojom::LevelDBWrapperRequest request);
55 66
67 // The (possibly delayed) implementation of GetStorageUsage(). Can be called
68 // directly from that function, or through |on_database_open_callbacks_|.
69 void RetrieveStorageUsage(GetStorageUsageCallback callback);
70 void OnGotMetaData(GetStorageUsageCallback callback,
71 leveldb::mojom::DatabaseError status,
72 std::vector<leveldb::mojom::KeyValuePtr> data);
73
56 service_manager::Connector* const connector_; 74 service_manager::Connector* const connector_;
57 const base::FilePath subdirectory_; 75 const base::FilePath subdirectory_;
58 76
59 enum ConnectionState { 77 enum ConnectionState {
60 NO_CONNECTION, 78 NO_CONNECTION,
61 CONNECTION_IN_PROGRESS, 79 CONNECTION_IN_PROGRESS,
62 CONNECTION_FINISHED 80 CONNECTION_FINISHED
63 } connection_state_ = NO_CONNECTION; 81 } connection_state_ = NO_CONNECTION;
64 bool database_initialized_ = false; 82 bool database_initialized_ = false;
65 83
66 std::unique_ptr<service_manager::Connection> file_service_connection_; 84 std::unique_ptr<service_manager::Connection> file_service_connection_;
67 85
68 file::mojom::FileSystemPtr file_system_; 86 file::mojom::FileSystemPtr file_system_;
69 filesystem::mojom::DirectoryPtr directory_; 87 filesystem::mojom::DirectoryPtr directory_;
70 88
71 leveldb::mojom::LevelDBServicePtr leveldb_service_; 89 leveldb::mojom::LevelDBServicePtr leveldb_service_;
72 leveldb::mojom::LevelDBDatabasePtr database_; 90 leveldb::mojom::LevelDBDatabasePtr database_;
73 91
74 std::vector<base::OnceClosure> on_database_opened_callbacks_; 92 std::vector<base::OnceClosure> on_database_opened_callbacks_;
75 93
76 // Maps between an origin and its prefixed LevelDB view. 94 // Maps between an origin and its prefixed LevelDB view.
77 std::map<url::Origin, std::unique_ptr<LevelDBWrapperImpl>> level_db_wrappers_; 95 std::map<url::Origin, std::unique_ptr<LevelDBWrapperImpl>> level_db_wrappers_;
78 96
79 base::WeakPtrFactory<LocalStorageContextMojo> weak_ptr_factory_; 97 base::WeakPtrFactory<LocalStorageContextMojo> weak_ptr_factory_;
80 }; 98 };
81 99
82 } // namespace content 100 } // namespace content
83 101
84 #endif // CONTENT_BROWSER_DOM_STORAGE_LOCAL_STORAGE_CONTEXT_MOJO_H_ 102 #endif // CONTENT_BROWSER_DOM_STORAGE_LOCAL_STORAGE_CONTEXT_MOJO_H_
OLDNEW
« no previous file with comments | « content/browser/dom_storage/BUILD.gn ('k') | content/browser/dom_storage/local_storage_context_mojo.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698