| 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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 void OnUserServiceConnectionComplete() { | 101 void OnUserServiceConnectionComplete() { |
| 102 CHECK_EQ(shell::mojom::ConnectResult::SUCCEEDED, | 102 CHECK_EQ(shell::mojom::ConnectResult::SUCCEEDED, |
| 103 user_service_connection_->GetResult()); | 103 user_service_connection_->GetResult()); |
| 104 } | 104 } |
| 105 | 105 |
| 106 void OnUserServiceConnectionError() { | 106 void OnUserServiceConnectionError() { |
| 107 CHECK(false); | 107 CHECK(false); |
| 108 } | 108 } |
| 109 | 109 |
| 110 // Part of our asynchronous directory opening called from OpenLocalStorage(). | 110 // Part of our asynchronous directory opening called from OpenLocalStorage(). |
| 111 void OnDirectoryOpened(filesystem::FileError err); | 111 void OnDirectoryOpened(filesystem::mojom::FileError err); |
| 112 void OnDatabaseOpened(leveldb::DatabaseError status); | 112 void OnDatabaseOpened(leveldb::DatabaseError status); |
| 113 | 113 |
| 114 // The (possibly delayed) implementation of OpenLocalStorage(). Can be called | 114 // The (possibly delayed) implementation of OpenLocalStorage(). Can be called |
| 115 // directly from that function, or through |on_database_open_callbacks_|. | 115 // directly from that function, or through |on_database_open_callbacks_|. |
| 116 void BindLocalStorage(const url::Origin& origin, | 116 void BindLocalStorage(const url::Origin& origin, |
| 117 mojom::LevelDBObserverPtr observer, | 117 mojom::LevelDBObserverPtr observer, |
| 118 mojom::LevelDBWrapperRequest request); | 118 mojom::LevelDBWrapperRequest request); |
| 119 | 119 |
| 120 // Maps between an origin and its prefixed LevelDB view. | 120 // Maps between an origin and its prefixed LevelDB view. |
| 121 std::map<url::Origin, std::unique_ptr<LevelDBWrapperImpl>> level_db_wrappers_; | 121 std::map<url::Origin, std::unique_ptr<LevelDBWrapperImpl>> level_db_wrappers_; |
| 122 | 122 |
| 123 shell::Connector* const connector_; | 123 shell::Connector* const connector_; |
| 124 const base::FilePath subdirectory_; | 124 const base::FilePath subdirectory_; |
| 125 | 125 |
| 126 enum ConnectionState { | 126 enum ConnectionState { |
| 127 NO_CONNECTION, | 127 NO_CONNECTION, |
| 128 CONNECTION_IN_PROGRESS, | 128 CONNECTION_IN_PROGRESS, |
| 129 CONNECTION_FINISHED | 129 CONNECTION_FINISHED |
| 130 } connection_state_; | 130 } connection_state_; |
| 131 | 131 |
| 132 std::unique_ptr<shell::Connection> user_service_connection_; | 132 std::unique_ptr<shell::Connection> user_service_connection_; |
| 133 | 133 |
| 134 user_service::mojom::UserServicePtr user_service_; | 134 user_service::mojom::UserServicePtr user_service_; |
| 135 filesystem::DirectoryPtr directory_; | 135 filesystem::mojom::DirectoryPtr directory_; |
| 136 | 136 |
| 137 leveldb::LevelDBServicePtr leveldb_service_; | 137 leveldb::LevelDBServicePtr leveldb_service_; |
| 138 leveldb::LevelDBDatabasePtr database_; | 138 leveldb::LevelDBDatabasePtr database_; |
| 139 | 139 |
| 140 std::vector<base::Closure> on_database_opened_callbacks_; | 140 std::vector<base::Closure> on_database_opened_callbacks_; |
| 141 | 141 |
| 142 base::WeakPtrFactory<MojoState> weak_ptr_factory_; | 142 base::WeakPtrFactory<MojoState> weak_ptr_factory_; |
| 143 }; | 143 }; |
| 144 | 144 |
| 145 void DOMStorageContextWrapper::MojoState::OpenLocalStorage( | 145 void DOMStorageContextWrapper::MojoState::OpenLocalStorage( |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 on_database_opened_callbacks_.push_back( | 183 on_database_opened_callbacks_.push_back( |
| 184 base::Bind(&MojoState::BindLocalStorage, weak_ptr_factory_.GetWeakPtr(), | 184 base::Bind(&MojoState::BindLocalStorage, weak_ptr_factory_.GetWeakPtr(), |
| 185 origin, base::Passed(&observer), base::Passed(&request))); | 185 origin, base::Passed(&observer), base::Passed(&request))); |
| 186 return; | 186 return; |
| 187 } | 187 } |
| 188 | 188 |
| 189 BindLocalStorage(origin, std::move(observer), std::move(request)); | 189 BindLocalStorage(origin, std::move(observer), std::move(request)); |
| 190 } | 190 } |
| 191 | 191 |
| 192 void DOMStorageContextWrapper::MojoState::OnDirectoryOpened( | 192 void DOMStorageContextWrapper::MojoState::OnDirectoryOpened( |
| 193 filesystem::FileError err) { | 193 filesystem::mojom::FileError err) { |
| 194 if (err != filesystem::FileError::OK) { | 194 if (err != filesystem::mojom::FileError::OK) { |
| 195 // We failed to open the directory; continue with startup so that we create | 195 // We failed to open the directory; continue with startup so that we create |
| 196 // the |level_db_wrappers_|. | 196 // the |level_db_wrappers_|. |
| 197 OnDatabaseOpened(leveldb::DatabaseError::IO_ERROR); | 197 OnDatabaseOpened(leveldb::DatabaseError::IO_ERROR); |
| 198 return; | 198 return; |
| 199 } | 199 } |
| 200 | 200 |
| 201 // Now that we have a directory, connect to the LevelDB service and get our | 201 // Now that we have a directory, connect to the LevelDB service and get our |
| 202 // database. | 202 // database. |
| 203 user_service_connection_->GetInterface(&leveldb_service_); | 203 user_service_connection_->GetInterface(&leveldb_service_); |
| 204 | 204 |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 | 374 |
| 375 void DOMStorageContextWrapper::OpenLocalStorage( | 375 void DOMStorageContextWrapper::OpenLocalStorage( |
| 376 const url::Origin& origin, | 376 const url::Origin& origin, |
| 377 mojom::LevelDBObserverPtr observer, | 377 mojom::LevelDBObserverPtr observer, |
| 378 mojom::LevelDBWrapperRequest request) { | 378 mojom::LevelDBWrapperRequest request) { |
| 379 mojo_state_->OpenLocalStorage( | 379 mojo_state_->OpenLocalStorage( |
| 380 origin, std::move(observer), std::move(request)); | 380 origin, std::move(observer), std::move(request)); |
| 381 } | 381 } |
| 382 | 382 |
| 383 } // namespace content | 383 } // namespace content |
| OLD | NEW |