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 #include "content/browser/dom_storage/dom_storage_context_wrapper.h" | 5 #include "content/browser/dom_storage/dom_storage_context_wrapper.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 FROM_HERE, base::Bind(&InvokeSessionStorageUsageCallbackHelper, callback, | 76 FROM_HERE, base::Bind(&InvokeSessionStorageUsageCallbackHelper, callback, |
77 base::Owned(infos))); | 77 base::Owned(infos))); |
78 } | 78 } |
79 | 79 |
80 } // namespace | 80 } // namespace |
81 | 81 |
82 // Used for mojo-based LocalStorage implementation (behind --mojo-local-storage | 82 // Used for mojo-based LocalStorage implementation (behind --mojo-local-storage |
83 // for now). | 83 // for now). |
84 class DOMStorageContextWrapper::MojoState { | 84 class DOMStorageContextWrapper::MojoState { |
85 public: | 85 public: |
86 MojoState(shell::Connector* connector, const base::FilePath& subdirectory) | 86 MojoState(service_manager::Connector* connector, |
| 87 const base::FilePath& subdirectory) |
87 : connector_(connector), | 88 : connector_(connector), |
88 // TODO(michaeln): Enable writing to disk when db is versioned, | 89 // TODO(michaeln): Enable writing to disk when db is versioned, |
89 // for now using an empty subdirectory to use an in-memory db. | 90 // for now using an empty subdirectory to use an in-memory db. |
90 // subdirectory_(subdirectory), | 91 // subdirectory_(subdirectory), |
91 connection_state_(NO_CONNECTION), | 92 connection_state_(NO_CONNECTION), |
92 weak_ptr_factory_(this) {} | 93 weak_ptr_factory_(this) {} |
93 | 94 |
94 void OpenLocalStorage(const url::Origin& origin, | 95 void OpenLocalStorage(const url::Origin& origin, |
95 mojom::LevelDBObserverPtr observer, | 96 mojom::LevelDBObserverPtr observer, |
96 mojom::LevelDBWrapperRequest request); | 97 mojom::LevelDBWrapperRequest request); |
97 | 98 |
98 private: | 99 private: |
99 void OnLevelDDWrapperHasNoBindings(const url::Origin& origin) { | 100 void OnLevelDDWrapperHasNoBindings(const url::Origin& origin) { |
100 DCHECK(level_db_wrappers_.find(origin) != level_db_wrappers_.end()); | 101 DCHECK(level_db_wrappers_.find(origin) != level_db_wrappers_.end()); |
101 level_db_wrappers_.erase(origin); | 102 level_db_wrappers_.erase(origin); |
102 } | 103 } |
103 | 104 |
104 void OnUserServiceConnectionComplete() { | 105 void OnUserServiceConnectionComplete() { |
105 CHECK_EQ(shell::mojom::ConnectResult::SUCCEEDED, | 106 CHECK_EQ(service_manager::mojom::ConnectResult::SUCCEEDED, |
106 file_service_connection_->GetResult()); | 107 file_service_connection_->GetResult()); |
107 } | 108 } |
108 | 109 |
109 void OnUserServiceConnectionError() { | 110 void OnUserServiceConnectionError() { |
110 CHECK(false); | 111 CHECK(false); |
111 } | 112 } |
112 | 113 |
113 // Part of our asynchronous directory opening called from OpenLocalStorage(). | 114 // Part of our asynchronous directory opening called from OpenLocalStorage(). |
114 void OnDirectoryOpened(filesystem::mojom::FileError err); | 115 void OnDirectoryOpened(filesystem::mojom::FileError err); |
115 void OnDatabaseOpened(leveldb::mojom::DatabaseError status); | 116 void OnDatabaseOpened(leveldb::mojom::DatabaseError status); |
116 | 117 |
117 // The (possibly delayed) implementation of OpenLocalStorage(). Can be called | 118 // The (possibly delayed) implementation of OpenLocalStorage(). Can be called |
118 // directly from that function, or through |on_database_open_callbacks_|. | 119 // directly from that function, or through |on_database_open_callbacks_|. |
119 void BindLocalStorage(const url::Origin& origin, | 120 void BindLocalStorage(const url::Origin& origin, |
120 mojom::LevelDBObserverPtr observer, | 121 mojom::LevelDBObserverPtr observer, |
121 mojom::LevelDBWrapperRequest request); | 122 mojom::LevelDBWrapperRequest request); |
122 | 123 |
123 // Maps between an origin and its prefixed LevelDB view. | 124 // Maps between an origin and its prefixed LevelDB view. |
124 std::map<url::Origin, std::unique_ptr<LevelDBWrapperImpl>> level_db_wrappers_; | 125 std::map<url::Origin, std::unique_ptr<LevelDBWrapperImpl>> level_db_wrappers_; |
125 | 126 |
126 shell::Connector* const connector_; | 127 service_manager::Connector* const connector_; |
127 const base::FilePath subdirectory_; | 128 const base::FilePath subdirectory_; |
128 | 129 |
129 enum ConnectionState { | 130 enum ConnectionState { |
130 NO_CONNECTION, | 131 NO_CONNECTION, |
131 CONNECTION_IN_PROGRESS, | 132 CONNECTION_IN_PROGRESS, |
132 CONNECTION_FINISHED | 133 CONNECTION_FINISHED |
133 } connection_state_; | 134 } connection_state_; |
134 | 135 |
135 std::unique_ptr<shell::Connection> file_service_connection_; | 136 std::unique_ptr<service_manager::Connection> file_service_connection_; |
136 | 137 |
137 file::mojom::FileSystemPtr file_system_; | 138 file::mojom::FileSystemPtr file_system_; |
138 filesystem::mojom::DirectoryPtr directory_; | 139 filesystem::mojom::DirectoryPtr directory_; |
139 | 140 |
140 leveldb::mojom::LevelDBServicePtr leveldb_service_; | 141 leveldb::mojom::LevelDBServicePtr leveldb_service_; |
141 leveldb::mojom::LevelDBDatabasePtr database_; | 142 leveldb::mojom::LevelDBDatabasePtr database_; |
142 | 143 |
143 std::vector<base::Closure> on_database_opened_callbacks_; | 144 std::vector<base::Closure> on_database_opened_callbacks_; |
144 | 145 |
145 base::WeakPtrFactory<MojoState> weak_ptr_factory_; | 146 base::WeakPtrFactory<MojoState> weak_ptr_factory_; |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 base::Bind(&MojoState::OnLevelDDWrapperHasNoBindings, | 256 base::Bind(&MojoState::OnLevelDDWrapperHasNoBindings, |
256 base::Unretained(this), origin)); | 257 base::Unretained(this), origin)); |
257 found = level_db_wrappers_.find(origin); | 258 found = level_db_wrappers_.find(origin); |
258 } | 259 } |
259 | 260 |
260 found->second->Bind(std::move(request)); | 261 found->second->Bind(std::move(request)); |
261 found->second->AddObserver(std::move(observer)); | 262 found->second->AddObserver(std::move(observer)); |
262 } | 263 } |
263 | 264 |
264 DOMStorageContextWrapper::DOMStorageContextWrapper( | 265 DOMStorageContextWrapper::DOMStorageContextWrapper( |
265 shell::Connector* connector, | 266 service_manager::Connector* connector, |
266 const base::FilePath& profile_path, | 267 const base::FilePath& profile_path, |
267 const base::FilePath& local_partition_path, | 268 const base::FilePath& local_partition_path, |
268 storage::SpecialStoragePolicy* special_storage_policy) { | 269 storage::SpecialStoragePolicy* special_storage_policy) { |
269 base::FilePath storage_dir; | 270 base::FilePath storage_dir; |
270 if (!profile_path.empty()) | 271 if (!profile_path.empty()) |
271 storage_dir = local_partition_path.AppendASCII(kLocalStorageDirectory); | 272 storage_dir = local_partition_path.AppendASCII(kLocalStorageDirectory); |
272 mojo_state_.reset(new MojoState(connector, storage_dir)); | 273 mojo_state_.reset(new MojoState(connector, storage_dir)); |
273 | 274 |
274 base::FilePath data_path; | 275 base::FilePath data_path; |
275 if (!profile_path.empty()) | 276 if (!profile_path.empty()) |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 } | 428 } |
428 | 429 |
429 void DOMStorageContextWrapper::PurgeMemory(DOMStorageContextImpl::PurgeOption | 430 void DOMStorageContextWrapper::PurgeMemory(DOMStorageContextImpl::PurgeOption |
430 purge_option) { | 431 purge_option) { |
431 context_->task_runner()->PostTask( | 432 context_->task_runner()->PostTask( |
432 FROM_HERE, | 433 FROM_HERE, |
433 base::Bind(&DOMStorageContextImpl::PurgeMemory, context_, purge_option)); | 434 base::Bind(&DOMStorageContextImpl::PurgeMemory, context_, purge_option)); |
434 } | 435 } |
435 | 436 |
436 } // namespace content | 437 } // namespace content |
OLD | NEW |