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

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

Issue 2861473002: Clear up session only storage on localstorage shutdown (Closed)
Patch Set: address comments Created 3 years, 7 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 "content/public/browser/browser_thread.h"
13 #include "services/file/public/interfaces/file_system.mojom.h" 14 #include "services/file/public/interfaces/file_system.mojom.h"
14 #include "url/origin.h" 15 #include "url/origin.h"
15 16
16 namespace service_manager { 17 namespace service_manager {
17 class Connector; 18 class Connector;
18 } 19 }
19 20
21 namespace storage {
22 class SpecialStoragePolicy;
23 }
24
20 namespace content { 25 namespace content {
21 26
22 class DOMStorageTaskRunner; 27 class DOMStorageTaskRunner;
23 class LevelDBWrapperImpl; 28 class LevelDBWrapperImpl;
24 struct LocalStorageUsageInfo; 29 struct LocalStorageUsageInfo;
25 30
26 // Used for mojo-based LocalStorage implementation (behind --mojo-local-storage 31 // Used for mojo-based LocalStorage implementation (behind --mojo-local-storage
27 // for now). 32 // for now).
33 // Created on the UI thread, but all further methods are called on the IO
34 // thread. Furthermore since destruction of this class can involve asynchronous
35 // steps, it can only be deleted by calling ShutdownAndDelete (on the IO
36 // thread),
28 class CONTENT_EXPORT LocalStorageContextMojo { 37 class CONTENT_EXPORT LocalStorageContextMojo {
29 public: 38 public:
30 using GetStorageUsageCallback = 39 using GetStorageUsageCallback =
31 base::OnceCallback<void(std::vector<LocalStorageUsageInfo>)>; 40 base::OnceCallback<void(std::vector<LocalStorageUsageInfo>)>;
32 41
33 LocalStorageContextMojo(service_manager::Connector* connector, 42 LocalStorageContextMojo(
34 scoped_refptr<DOMStorageTaskRunner> task_runner, 43 service_manager::Connector* connector,
35 const base::FilePath& old_localstorage_path, 44 scoped_refptr<DOMStorageTaskRunner> task_runner,
36 const base::FilePath& subdirectory); 45 const base::FilePath& old_localstorage_path,
37 ~LocalStorageContextMojo(); 46 const base::FilePath& subdirectory,
47 scoped_refptr<storage::SpecialStoragePolicy> special_storage_policy);
38 48
39 void OpenLocalStorage(const url::Origin& origin, 49 void OpenLocalStorage(const url::Origin& origin,
40 mojom::LevelDBWrapperRequest request); 50 mojom::LevelDBWrapperRequest request);
41 void GetStorageUsage(GetStorageUsageCallback callback); 51 void GetStorageUsage(GetStorageUsageCallback callback);
42 void DeleteStorage(const url::Origin& origin); 52 void DeleteStorage(const url::Origin& origin);
43 // Like DeleteStorage(), but also deletes storage for all sub-origins. 53 // Like DeleteStorage(), but also deletes storage for all sub-origins.
44 void DeleteStorageForPhysicalOrigin(const url::Origin& origin); 54 void DeleteStorageForPhysicalOrigin(const url::Origin& origin);
45 void Flush(); 55 void Flush();
46 56
57 // Used by content settings to alter the behavior around
58 // what data to keep and what data to discard at shutdown.
59 // The policy is not so straight forward to describe, see
60 // the implementation for details.
61 void SetForceKeepSessionState() { force_keep_session_state_ = true; }
62
63 // Called when the owning BrowserContext is ending.
64 // Schedules the commit of any unsaved changes and will delete
65 // and keep data on disk per the content settings and special storage
66 // policies.
67 void ShutdownAndDelete();
68
47 // Clears any caches, to free up as much memory as possible. Next access to 69 // Clears any caches, to free up as much memory as possible. Next access to
48 // storage for a particular origin will reload the data from the database. 70 // storage for a particular origin will reload the data from the database.
49 void PurgeMemory(); 71 void PurgeMemory();
50 72
51 leveldb::mojom::LevelDBDatabaseAssociatedRequest DatabaseRequestForTesting(); 73 leveldb::mojom::LevelDBDatabaseAssociatedRequest DatabaseRequestForTesting();
52 74
53 // Converts a string from the old storage format to the new storage format. 75 // Converts a string from the old storage format to the new storage format.
54 static std::vector<uint8_t> MigrateString(const base::string16& input); 76 static std::vector<uint8_t> MigrateString(const base::string16& input);
55 77
56 private: 78 private:
57 friend class MojoDOMStorageBrowserTest; 79 friend class MojoDOMStorageBrowserTest;
58 80
59 class LevelDBWrapperHolder; 81 class LevelDBWrapperHolder;
60 82
83 ~LocalStorageContextMojo();
84
61 // Runs |callback| immediately if already connected to a database, otherwise 85 // Runs |callback| immediately if already connected to a database, otherwise
62 // delays running |callback| untill after a connection has been established. 86 // delays running |callback| untill after a connection has been established.
63 // Initiates connecting to the database if no connection is in progres yet. 87 // Initiates connecting to the database if no connection is in progres yet.
64 void RunWhenConnected(base::OnceClosure callback); 88 void RunWhenConnected(base::OnceClosure callback);
65 89
66 // Part of our asynchronous directory opening called from RunWhenConnected(). 90 // Part of our asynchronous directory opening called from RunWhenConnected().
67 void InitiateConnection(bool in_memory_only = false); 91 void InitiateConnection(bool in_memory_only = false);
68 void OnDirectoryOpened(filesystem::mojom::FileError err); 92 void OnDirectoryOpened(filesystem::mojom::FileError err);
69 void OnDatabaseOpened(bool in_memory, leveldb::mojom::DatabaseError status); 93 void OnDatabaseOpened(bool in_memory, leveldb::mojom::DatabaseError status);
70 void OnGotDatabaseVersion(leveldb::mojom::DatabaseError status, 94 void OnGotDatabaseVersion(leveldb::mojom::DatabaseError status,
(...skipping 13 matching lines...) Expand all
84 // directly from that function, or through |on_database_open_callbacks_|. 108 // directly from that function, or through |on_database_open_callbacks_|.
85 void RetrieveStorageUsage(GetStorageUsageCallback callback); 109 void RetrieveStorageUsage(GetStorageUsageCallback callback);
86 void OnGotMetaData(GetStorageUsageCallback callback, 110 void OnGotMetaData(GetStorageUsageCallback callback,
87 leveldb::mojom::DatabaseError status, 111 leveldb::mojom::DatabaseError status,
88 std::vector<leveldb::mojom::KeyValuePtr> data); 112 std::vector<leveldb::mojom::KeyValuePtr> data);
89 113
90 void OnGotStorageUsageForDeletePhysicalOrigin( 114 void OnGotStorageUsageForDeletePhysicalOrigin(
91 const url::Origin& origin, 115 const url::Origin& origin,
92 std::vector<LocalStorageUsageInfo> usage); 116 std::vector<LocalStorageUsageInfo> usage);
93 117
94 service_manager::Connector* const connector_; 118 void OnGotStorageUsageForShutdown(std::vector<LocalStorageUsageInfo> usage);
119 void OnShutdownComplete(leveldb::mojom::DatabaseError error);
120
121 std::unique_ptr<service_manager::Connector> connector_;
95 const base::FilePath subdirectory_; 122 const base::FilePath subdirectory_;
96 123
97 enum ConnectionState { 124 enum ConnectionState {
98 NO_CONNECTION, 125 NO_CONNECTION,
99 CONNECTION_IN_PROGRESS, 126 CONNECTION_IN_PROGRESS,
100 CONNECTION_FINISHED 127 CONNECTION_FINISHED,
128 CONNECTION_SHUTDOWN
101 } connection_state_ = NO_CONNECTION; 129 } connection_state_ = NO_CONNECTION;
102 bool database_initialized_ = false; 130 bool database_initialized_ = false;
103 131
132 bool force_keep_session_state_ = false;
133 scoped_refptr<storage::SpecialStoragePolicy> special_storage_policy_;
134
104 file::mojom::FileSystemPtr file_system_; 135 file::mojom::FileSystemPtr file_system_;
105 filesystem::mojom::DirectoryPtr directory_; 136 filesystem::mojom::DirectoryPtr directory_;
106 137
107 leveldb::mojom::LevelDBServicePtr leveldb_service_; 138 leveldb::mojom::LevelDBServicePtr leveldb_service_;
108 leveldb::mojom::LevelDBDatabaseAssociatedPtr database_; 139 leveldb::mojom::LevelDBDatabaseAssociatedPtr database_;
109 bool tried_to_recreate_ = false; 140 bool tried_to_recreate_ = false;
110 141
111 std::vector<base::OnceClosure> on_database_opened_callbacks_; 142 std::vector<base::OnceClosure> on_database_opened_callbacks_;
112 143
113 // Maps between an origin and its prefixed LevelDB view. 144 // Maps between an origin and its prefixed LevelDB view.
114 std::map<url::Origin, std::unique_ptr<LevelDBWrapperHolder>> 145 std::map<url::Origin, std::unique_ptr<LevelDBWrapperHolder>>
115 level_db_wrappers_; 146 level_db_wrappers_;
116 147
117 // Used to access old data for migration. 148 // Used to access old data for migration.
118 scoped_refptr<DOMStorageTaskRunner> task_runner_; 149 scoped_refptr<DOMStorageTaskRunner> task_runner_;
119 base::FilePath old_localstorage_path_; 150 base::FilePath old_localstorage_path_;
120 151
121 base::WeakPtrFactory<LocalStorageContextMojo> weak_ptr_factory_; 152 base::WeakPtrFactory<LocalStorageContextMojo> weak_ptr_factory_;
122 }; 153 };
123 154
124 } // namespace content 155 } // namespace content
125 156
126 #endif // CONTENT_BROWSER_DOM_STORAGE_LOCAL_STORAGE_CONTEXT_MOJO_H_ 157 #endif // CONTENT_BROWSER_DOM_STORAGE_LOCAL_STORAGE_CONTEXT_MOJO_H_
OLDNEW
« no previous file with comments | « content/browser/dom_storage/dom_storage_context_wrapper.cc ('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