Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/indexed_db/indexed_db_dispatcher_host.h" | 5 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/guid.h" | 9 #include "base/guid.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 return; | 88 return; |
| 89 } | 89 } |
| 90 | 90 |
| 91 DCHECK_GE(iter->second.second, 1); | 91 DCHECK_GE(iter->second.second, 1); |
| 92 if (iter->second.second == 1) | 92 if (iter->second.second == 1) |
| 93 blob_data_handle_map_.erase(iter); | 93 blob_data_handle_map_.erase(iter); |
| 94 else | 94 else |
| 95 --iter->second.second; | 95 --iter->second.second; |
| 96 } | 96 } |
| 97 | 97 |
| 98 void IndexedDBDispatcherHost::Configure( | |
| 99 const IndexedDBDataFormatVersion& client_data_format_version) { | |
| 100 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 101 | |
| 102 // TODO(jbroman): We could take mojo::GetBadMessageCallback here to tell the | |
|
jsbell
2017/04/04 19:24:33
If this is happening w/in dispatch, we should be a
| |
| 103 // IPC system that this is a bad message, if this ever changes. Should we? | |
| 104 indexed_db_context_->TaskRunner()->PostTask( | |
| 105 FROM_HERE, base::Bind(&IndexedDBDispatcherHost::ConfigureOnIDBThread, | |
| 106 this, client_data_format_version)); | |
| 107 } | |
| 108 | |
| 98 void IndexedDBDispatcherHost::GetDatabaseNames( | 109 void IndexedDBDispatcherHost::GetDatabaseNames( |
| 99 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info, | 110 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info, |
| 100 const url::Origin& origin) { | 111 const url::Origin& origin) { |
| 101 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 112 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 102 | 113 |
| 103 if (!IsValidOrigin(origin)) { | 114 if (!IsValidOrigin(origin)) { |
| 104 mojo::ReportBadMessage(kInvalidOrigin); | 115 mojo::ReportBadMessage(kInvalidOrigin); |
| 105 return; | 116 return; |
| 106 } | 117 } |
| 107 | 118 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 152 } | 163 } |
| 153 | 164 |
| 154 scoped_refptr<IndexedDBCallbacks> callbacks( | 165 scoped_refptr<IndexedDBCallbacks> callbacks( |
| 155 new IndexedDBCallbacks(this, origin, std::move(callbacks_info))); | 166 new IndexedDBCallbacks(this, origin, std::move(callbacks_info))); |
| 156 indexed_db_context_->TaskRunner()->PostTask( | 167 indexed_db_context_->TaskRunner()->PostTask( |
| 157 FROM_HERE, base::Bind(&IndexedDBDispatcherHost::DeleteDatabaseOnIDBThread, | 168 FROM_HERE, base::Bind(&IndexedDBDispatcherHost::DeleteDatabaseOnIDBThread, |
| 158 this, base::Passed(&callbacks), origin, name, | 169 this, base::Passed(&callbacks), origin, name, |
| 159 force_close)); | 170 force_close)); |
| 160 } | 171 } |
| 161 | 172 |
| 173 void IndexedDBDispatcherHost::ConfigureOnIDBThread( | |
| 174 const IndexedDBDataFormatVersion& client_data_format_version) { | |
| 175 if (!client_data_format_version_) | |
|
dcheng
2017/04/04 19:59:21
Since this is coming from the renderer, we do need
| |
| 176 client_data_format_version_ = client_data_format_version; | |
| 177 if (client_data_format_version_ != client_data_format_version) | |
| 178 LOG(ERROR) << "IndexedDB client's supported data format version changed!"; | |
|
dcheng
2017/04/04 19:59:21
Nit: DLOG instead of LOG? I don't think this will
| |
| 179 } | |
| 180 | |
| 162 void IndexedDBDispatcherHost::GetDatabaseNamesOnIDBThread( | 181 void IndexedDBDispatcherHost::GetDatabaseNamesOnIDBThread( |
| 163 scoped_refptr<IndexedDBCallbacks> callbacks, | 182 scoped_refptr<IndexedDBCallbacks> callbacks, |
| 164 const url::Origin& origin) { | 183 const url::Origin& origin) { |
| 165 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 184 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 166 | 185 |
| 186 // TODO(jbroman): How fail here? | |
| 187 if (!client_data_format_version_) | |
| 188 LOG(ERROR) << "IndexedDB client failed to call Configure!"; | |
| 189 | |
| 167 base::FilePath indexed_db_path = indexed_db_context_->data_path(); | 190 base::FilePath indexed_db_path = indexed_db_context_->data_path(); |
| 168 context()->GetIDBFactory()->GetDatabaseNames( | 191 context()->GetIDBFactory()->GetDatabaseNames( |
| 169 callbacks, origin, indexed_db_path, request_context_getter_); | 192 callbacks, origin, indexed_db_path, |
| 193 client_data_format_version_.value_or(IndexedDBDataFormatVersion()), | |
| 194 request_context_getter_); | |
| 170 } | 195 } |
| 171 | 196 |
| 172 void IndexedDBDispatcherHost::OpenOnIDBThread( | 197 void IndexedDBDispatcherHost::OpenOnIDBThread( |
| 173 scoped_refptr<IndexedDBCallbacks> callbacks, | 198 scoped_refptr<IndexedDBCallbacks> callbacks, |
| 174 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks, | 199 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks, |
| 175 const url::Origin& origin, | 200 const url::Origin& origin, |
| 176 const base::string16& name, | 201 const base::string16& name, |
| 177 int64_t version, | 202 int64_t version, |
| 178 int64_t transaction_id) { | 203 int64_t transaction_id) { |
| 179 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 204 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 180 | 205 |
| 181 base::TimeTicks begin_time = base::TimeTicks::Now(); | 206 base::TimeTicks begin_time = base::TimeTicks::Now(); |
| 182 base::FilePath indexed_db_path = indexed_db_context_->data_path(); | 207 base::FilePath indexed_db_path = indexed_db_context_->data_path(); |
| 183 | 208 |
| 209 // TODO(jbroman): How fail here? | |
| 210 if (!client_data_format_version_) | |
| 211 LOG(ERROR) << "IndexedDB client failed to call Configure!"; | |
| 212 | |
| 184 // TODO(dgrogan): Don't let a non-existing database be opened (and therefore | 213 // TODO(dgrogan): Don't let a non-existing database be opened (and therefore |
| 185 // created) if this origin is already over quota. | 214 // created) if this origin is already over quota. |
| 186 callbacks->SetConnectionOpenStartTime(begin_time); | 215 callbacks->SetConnectionOpenStartTime(begin_time); |
| 187 std::unique_ptr<IndexedDBPendingConnection> connection = | 216 std::unique_ptr<IndexedDBPendingConnection> connection = |
| 188 base::MakeUnique<IndexedDBPendingConnection>( | 217 base::MakeUnique<IndexedDBPendingConnection>( |
| 189 callbacks, database_callbacks, ipc_process_id_, transaction_id, | 218 callbacks, database_callbacks, ipc_process_id_, transaction_id, |
| 190 version); | 219 version); |
| 191 DCHECK(request_context_getter_); | 220 DCHECK(request_context_getter_); |
| 192 context()->GetIDBFactory()->Open(name, std::move(connection), | 221 context()->GetIDBFactory()->Open( |
| 193 request_context_getter_, origin, | 222 name, std::move(connection), request_context_getter_, origin, |
| 194 indexed_db_path); | 223 indexed_db_path, |
| 224 client_data_format_version_.value_or(IndexedDBDataFormatVersion())); | |
| 195 } | 225 } |
| 196 | 226 |
| 197 void IndexedDBDispatcherHost::DeleteDatabaseOnIDBThread( | 227 void IndexedDBDispatcherHost::DeleteDatabaseOnIDBThread( |
| 198 scoped_refptr<IndexedDBCallbacks> callbacks, | 228 scoped_refptr<IndexedDBCallbacks> callbacks, |
| 199 const url::Origin& origin, | 229 const url::Origin& origin, |
| 200 const base::string16& name, | 230 const base::string16& name, |
| 201 bool force_close) { | 231 bool force_close) { |
| 202 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 232 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 203 | 233 |
| 204 base::FilePath indexed_db_path = indexed_db_context_->data_path(); | 234 base::FilePath indexed_db_path = indexed_db_context_->data_path(); |
| 235 | |
| 236 // TODO(jbroman): How fail here? | |
| 237 if (!client_data_format_version_) | |
| 238 LOG(ERROR) << "IndexedDB client failed to call Configure!"; | |
| 239 | |
| 205 DCHECK(request_context_getter_); | 240 DCHECK(request_context_getter_); |
| 206 context()->GetIDBFactory()->DeleteDatabase( | 241 context()->GetIDBFactory()->DeleteDatabase( |
| 207 name, request_context_getter_, callbacks, origin, indexed_db_path, | 242 name, request_context_getter_, callbacks, origin, indexed_db_path, |
| 243 client_data_format_version_.value_or(IndexedDBDataFormatVersion()), | |
| 208 force_close); | 244 force_close); |
| 209 } | 245 } |
| 210 | 246 |
| 211 } // namespace content | 247 } // namespace content |
| OLD | NEW |