OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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_DOM_STORAGE_CONTEXT_WRAPPER_H_ | 5 #ifndef CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_CONTEXT_WRAPPER_H_ |
6 #define CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_CONTEXT_WRAPPER_H_ | 6 #define CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_CONTEXT_WRAPPER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/weak_ptr.h" |
| 14 #include "components/filesystem/public/interfaces/directory.mojom.h" |
| 15 #include "components/filesystem/public/interfaces/file_system.mojom.h" |
| 16 #include "components/leveldb/public/interfaces/leveldb.mojom.h" |
| 17 #include "components/profile_service/public/interfaces/profile.mojom.h" |
13 #include "content/common/content_export.h" | 18 #include "content/common/content_export.h" |
14 #include "content/common/storage_partition_service.mojom.h" | 19 #include "content/common/storage_partition_service.mojom.h" |
15 #include "content/public/browser/dom_storage_context.h" | 20 #include "content/public/browser/dom_storage_context.h" |
16 | 21 |
17 namespace base { | 22 namespace base { |
18 class FilePath; | 23 class FilePath; |
19 } | 24 } |
20 | 25 |
21 namespace storage { | 26 namespace storage { |
22 class SpecialStoragePolicy; | 27 class SpecialStoragePolicy; |
23 } | 28 } |
24 | 29 |
25 namespace content { | 30 namespace content { |
26 | 31 |
27 class DOMStorageContextImpl; | 32 class DOMStorageContextImpl; |
28 class LevelDBWrapperImpl; | 33 class LevelDBWrapperImpl; |
| 34 class MojoAppConnection; |
29 | 35 |
30 // This is owned by Storage Partition and encapsulates all its dom storage | 36 // This is owned by Storage Partition and encapsulates all its dom storage |
31 // state. | 37 // state. |
32 class CONTENT_EXPORT DOMStorageContextWrapper : | 38 class CONTENT_EXPORT DOMStorageContextWrapper : |
33 NON_EXPORTED_BASE(public DOMStorageContext), | 39 NON_EXPORTED_BASE(public DOMStorageContext), |
34 public base::RefCountedThreadSafe<DOMStorageContextWrapper> { | 40 public base::RefCountedThreadSafe<DOMStorageContextWrapper> { |
35 public: | 41 public: |
36 // If |data_path| is empty, nothing will be saved to disk. | 42 // If |data_path| is empty, nothing will be saved to disk. |
37 DOMStorageContextWrapper( | 43 DOMStorageContextWrapper(BrowserContext* context, |
38 const base::FilePath& data_path, | 44 const base::FilePath& data_path); |
39 storage::SpecialStoragePolicy* special_storage_policy); | |
40 | 45 |
41 // DOMStorageContext implementation. | 46 // DOMStorageContext implementation. |
42 void GetLocalStorageUsage( | 47 void GetLocalStorageUsage( |
43 const GetLocalStorageUsageCallback& callback) override; | 48 const GetLocalStorageUsageCallback& callback) override; |
44 void GetSessionStorageUsage( | 49 void GetSessionStorageUsage( |
45 const GetSessionStorageUsageCallback& callback) override; | 50 const GetSessionStorageUsageCallback& callback) override; |
46 void DeleteLocalStorage(const GURL& origin) override; | 51 void DeleteLocalStorage(const GURL& origin) override; |
47 void DeleteSessionStorage(const SessionStorageUsageInfo& usage_info) override; | 52 void DeleteSessionStorage(const SessionStorageUsageInfo& usage_info) override; |
48 void SetSaveSessionStorageOnDisk() override; | 53 void SetSaveSessionStorageOnDisk() override; |
49 scoped_refptr<SessionStorageNamespace> RecreateSessionStorage( | 54 scoped_refptr<SessionStorageNamespace> RecreateSessionStorage( |
(...skipping 19 matching lines...) Expand all Loading... |
69 private: | 74 private: |
70 friend class DOMStorageMessageFilter; // for access to context() | 75 friend class DOMStorageMessageFilter; // for access to context() |
71 friend class SessionStorageNamespaceImpl; // ditto | 76 friend class SessionStorageNamespaceImpl; // ditto |
72 friend class base::RefCountedThreadSafe<DOMStorageContextWrapper>; | 77 friend class base::RefCountedThreadSafe<DOMStorageContextWrapper>; |
73 | 78 |
74 ~DOMStorageContextWrapper() override; | 79 ~DOMStorageContextWrapper() override; |
75 DOMStorageContextImpl* context() const { return context_.get(); } | 80 DOMStorageContextImpl* context() const { return context_.get(); } |
76 | 81 |
77 void LevelDBWrapperImplHasNoBindings(const std::string& origin); | 82 void LevelDBWrapperImplHasNoBindings(const std::string& origin); |
78 | 83 |
| 84 // Part of our asynchronous directory opening called from OpenLocalStorage(). |
| 85 void OnDirectoryOpened(filesystem::FileError err); |
| 86 void OnDatabaseOpened(leveldb::DatabaseError status); |
| 87 |
| 88 void OnCrudWritten(leveldb::DatabaseError status); |
| 89 |
| 90 // The (possibly delayed) implementation of OpenLocalStorage(). Can be called |
| 91 // directly from that function, or through |on_database_open_callbacks_|. |
| 92 void BindLocalStorage( |
| 93 const mojo::String& origin, |
| 94 mojo::InterfaceRequest<LevelDBWrapper> request); |
| 95 |
79 // Used for mojo-based LocalStorage implementation (behind | 96 // Used for mojo-based LocalStorage implementation (behind |
80 // --mojo-local-storage for now). Maps between an origin and its prefixed | 97 // --mojo-local-storage for now). Maps between an origin and its prefixed |
81 // LevelDB view. | 98 // LevelDB view. |
82 std::map<std::string, scoped_ptr<LevelDBWrapperImpl>> level_db_wrappers_; | 99 std::map<std::string, scoped_ptr<LevelDBWrapperImpl>> level_db_wrappers_; |
83 | 100 |
| 101 BrowserContext* browser_context_; |
84 scoped_refptr<DOMStorageContextImpl> context_; | 102 scoped_refptr<DOMStorageContextImpl> context_; |
85 | 103 |
| 104 enum ConnectionState { |
| 105 NO_CONNECTION, |
| 106 CONNECITON_IN_PROGRESS, |
| 107 CONNECTED |
| 108 } connection_state_; |
| 109 |
| 110 scoped_ptr<MojoAppConnection> profile_connection_; |
| 111 profile::ProfileServicePtr profile_service_; |
| 112 filesystem::DirectoryPtr directory_; |
| 113 |
| 114 scoped_ptr<MojoAppConnection> leveldb_connection_; |
| 115 leveldb::LevelDBServicePtr leveldb_; |
| 116 leveldb::LevelDBDatabasePtr database_; |
| 117 |
| 118 std::vector<base::Closure> on_database_opened_callbacks_; |
| 119 |
| 120 base::WeakPtrFactory<DOMStorageContextWrapper> weak_ptr_factory_; |
| 121 |
86 DISALLOW_IMPLICIT_CONSTRUCTORS(DOMStorageContextWrapper); | 122 DISALLOW_IMPLICIT_CONSTRUCTORS(DOMStorageContextWrapper); |
87 }; | 123 }; |
88 | 124 |
89 } // namespace content | 125 } // namespace content |
90 | 126 |
91 #endif // CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_CONTEXT_WRAPPER_H_ | 127 #endif // CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_CONTEXT_WRAPPER_H_ |
OLD | NEW |