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" |
13 #include "content/common/content_export.h" | 17 #include "content/common/content_export.h" |
14 #include "content/common/storage_partition_service.mojom.h" | 18 #include "content/common/storage_partition_service.mojom.h" |
15 #include "content/public/browser/dom_storage_context.h" | 19 #include "content/public/browser/dom_storage_context.h" |
16 | 20 |
17 namespace base { | 21 namespace base { |
18 class FilePath; | 22 class FilePath; |
19 } | 23 } |
20 | 24 |
21 namespace storage { | 25 namespace storage { |
22 class SpecialStoragePolicy; | 26 class SpecialStoragePolicy; |
23 } | 27 } |
24 | 28 |
25 namespace content { | 29 namespace content { |
26 | 30 |
27 class DOMStorageContextImpl; | 31 class DOMStorageContextImpl; |
28 class LevelDBWrapperImpl; | 32 class LevelDBWrapperImpl; |
| 33 class MojoAppConnection; |
29 | 34 |
30 // This is owned by Storage Partition and encapsulates all its dom storage | 35 // This is owned by Storage Partition and encapsulates all its dom storage |
31 // state. | 36 // state. |
32 class CONTENT_EXPORT DOMStorageContextWrapper : | 37 class CONTENT_EXPORT DOMStorageContextWrapper : |
33 NON_EXPORTED_BASE(public DOMStorageContext), | 38 NON_EXPORTED_BASE(public DOMStorageContext), |
34 public base::RefCountedThreadSafe<DOMStorageContextWrapper> { | 39 public base::RefCountedThreadSafe<DOMStorageContextWrapper> { |
35 public: | 40 public: |
36 // If |data_path| is empty, nothing will be saved to disk. | 41 // If |data_path| is empty, nothing will be saved to disk. |
37 DOMStorageContextWrapper( | 42 DOMStorageContextWrapper( |
38 const base::FilePath& data_path, | 43 const base::FilePath& data_path, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 private: | 75 private: |
71 friend class DOMStorageMessageFilter; // for access to context() | 76 friend class DOMStorageMessageFilter; // for access to context() |
72 friend class SessionStorageNamespaceImpl; // ditto | 77 friend class SessionStorageNamespaceImpl; // ditto |
73 friend class base::RefCountedThreadSafe<DOMStorageContextWrapper>; | 78 friend class base::RefCountedThreadSafe<DOMStorageContextWrapper>; |
74 | 79 |
75 ~DOMStorageContextWrapper() override; | 80 ~DOMStorageContextWrapper() override; |
76 DOMStorageContextImpl* context() const { return context_.get(); } | 81 DOMStorageContextImpl* context() const { return context_.get(); } |
77 | 82 |
78 void LevelDBWrapperImplHasNoBindings(const std::string& origin); | 83 void LevelDBWrapperImplHasNoBindings(const std::string& origin); |
79 | 84 |
| 85 // Part of our asynchronous directory opening called from OpenLocalStorage(). |
| 86 void OnDirectoryOpened(filesystem::FileError err); |
| 87 void OnDatabaseOpened(leveldb::DatabaseError status); |
| 88 |
| 89 // The (possibly delayed) implementation of OpenLocalStorage(). Can be called |
| 90 // directly from that function, or through |on_database_open_callbacks_|. |
| 91 void BindLocalStorage( |
| 92 const mojo::String& origin, |
| 93 LevelDBObserverPtr observer, |
| 94 mojo::InterfaceRequest<LevelDBWrapper> request); |
| 95 |
80 // Used for mojo-based LocalStorage implementation (behind | 96 // Used for mojo-based LocalStorage implementation (behind |
81 // --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 |
82 // LevelDB view. | 98 // LevelDB view. |
83 std::map<std::string, scoped_ptr<LevelDBWrapperImpl>> level_db_wrappers_; | 99 std::map<std::string, scoped_ptr<LevelDBWrapperImpl>> level_db_wrappers_; |
84 | 100 |
85 scoped_refptr<DOMStorageContextImpl> context_; | 101 scoped_refptr<DOMStorageContextImpl> context_; |
86 | 102 |
| 103 enum ConnectionState { |
| 104 NO_CONNECTION, |
| 105 CONNECITON_IN_PROGRESS, |
| 106 CONNECTED |
| 107 } connection_state_; |
| 108 |
| 109 scoped_ptr<MojoAppConnection> file_system_connection_; |
| 110 filesystem::FileSystemPtr file_system_; |
| 111 filesystem::DirectoryPtr directory_; |
| 112 |
| 113 scoped_ptr<MojoAppConnection> leveldb_connection_; |
| 114 leveldb::LevelDBServicePtr leveldb_; |
| 115 leveldb::LevelDBDatabasePtr database_; |
| 116 |
| 117 std::vector<base::Closure> on_database_opened_callbacks_; |
| 118 |
| 119 base::WeakPtrFactory<DOMStorageContextWrapper> weak_ptr_factory_; |
| 120 |
87 DISALLOW_IMPLICIT_CONSTRUCTORS(DOMStorageContextWrapper); | 121 DISALLOW_IMPLICIT_CONSTRUCTORS(DOMStorageContextWrapper); |
88 }; | 122 }; |
89 | 123 |
90 } // namespace content | 124 } // namespace content |
91 | 125 |
92 #endif // CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_CONTEXT_WRAPPER_H_ | 126 #endif // CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_CONTEXT_WRAPPER_H_ |
OLD | NEW |