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_callbacks.h" | 5 #include "content/browser/indexed_db/indexed_db_callbacks.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/guid.h" | |
10 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
11 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
12 #include "base/time/time.h" | 11 #include "base/time/time.h" |
13 #include "content/browser/child_process_security_policy_impl.h" | 12 #include "content/browser/child_process_security_policy_impl.h" |
14 #include "content/browser/fileapi/fileapi_message_filter.h" | 13 #include "content/browser/fileapi/fileapi_message_filter.h" |
15 #include "content/browser/indexed_db/indexed_db_blob_info.h" | 14 #include "content/browser/indexed_db/indexed_db_blob_info.h" |
16 #include "content/browser/indexed_db/indexed_db_connection.h" | 15 #include "content/browser/indexed_db/indexed_db_connection.h" |
17 #include "content/browser/indexed_db/indexed_db_context_impl.h" | 16 #include "content/browser/indexed_db/indexed_db_context_impl.h" |
18 #include "content/browser/indexed_db/indexed_db_cursor.h" | 17 #include "content/browser/indexed_db/indexed_db_cursor.h" |
19 #include "content/browser/indexed_db/indexed_db_database_callbacks.h" | 18 #include "content/browser/indexed_db/indexed_db_database_callbacks.h" |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 UMA_HISTOGRAM_MEDIUM_TIMES( | 215 UMA_HISTOGRAM_MEDIUM_TIMES( |
217 "WebCore.IndexedDB.OpenTime.Success", | 216 "WebCore.IndexedDB.OpenTime.Success", |
218 base::TimeTicks::Now() - connection_open_start_time_); | 217 base::TimeTicks::Now() - connection_open_start_time_); |
219 connection_open_start_time_ = base::TimeTicks(); | 218 connection_open_start_time_ = base::TimeTicks(); |
220 } | 219 } |
221 } | 220 } |
222 | 221 |
223 static std::string CreateBlobData( | 222 static std::string CreateBlobData( |
224 const IndexedDBBlobInfo& blob_info, | 223 const IndexedDBBlobInfo& blob_info, |
225 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host, | 224 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host, |
226 storage::BlobStorageContext* blob_storage_context, | |
227 base::TaskRunner* task_runner) { | 225 base::TaskRunner* task_runner) { |
228 std::string uuid = blob_info.uuid(); | 226 if (!blob_info.uuid().empty()) { |
229 if (!uuid.empty()) { | |
230 // We're sending back a live blob, not a reference into our backing store. | 227 // We're sending back a live blob, not a reference into our backing store. |
231 scoped_ptr<storage::BlobDataHandle> blob_data_handle( | 228 return dispatcher_host->HoldBlobData(blob_info); |
232 blob_storage_context->GetBlobDataFromUUID(uuid)); | |
233 dispatcher_host->HoldBlobDataHandle(uuid, blob_data_handle.Pass()); | |
234 return uuid; | |
235 } | 229 } |
236 scoped_refptr<ShareableFileReference> shareable_file = | 230 scoped_refptr<ShareableFileReference> shareable_file = |
237 ShareableFileReference::Get(blob_info.file_path()); | 231 ShareableFileReference::Get(blob_info.file_path()); |
238 if (!shareable_file.get()) { | 232 if (!shareable_file.get()) { |
239 shareable_file = ShareableFileReference::GetOrCreate( | 233 shareable_file = ShareableFileReference::GetOrCreate( |
240 blob_info.file_path(), | 234 blob_info.file_path(), |
241 ShareableFileReference::DONT_DELETE_ON_FINAL_RELEASE, | 235 ShareableFileReference::DONT_DELETE_ON_FINAL_RELEASE, |
242 task_runner); | 236 task_runner); |
243 if (!blob_info.release_callback().is_null()) | 237 if (!blob_info.release_callback().is_null()) |
244 shareable_file->AddFinalReleaseCallback(blob_info.release_callback()); | 238 shareable_file->AddFinalReleaseCallback(blob_info.release_callback()); |
245 } | 239 } |
246 | 240 return dispatcher_host->HoldBlobData(blob_info); |
247 uuid = base::GenerateGUID(); | |
248 scoped_refptr<storage::BlobData> blob_data = new storage::BlobData(uuid); | |
249 blob_data->set_content_type(base::UTF16ToUTF8(blob_info.type())); | |
250 blob_data->AppendFile( | |
251 blob_info.file_path(), 0, blob_info.size(), blob_info.last_modified()); | |
252 scoped_ptr<storage::BlobDataHandle> blob_data_handle( | |
253 blob_storage_context->AddFinishedBlob(blob_data.get())); | |
254 dispatcher_host->HoldBlobDataHandle(uuid, blob_data_handle.Pass()); | |
255 | |
256 return uuid; | |
257 } | 241 } |
258 | 242 |
259 static bool CreateAllBlobs( | 243 static bool CreateAllBlobs( |
260 const std::vector<IndexedDBBlobInfo>& blob_info, | 244 const std::vector<IndexedDBBlobInfo>& blob_info, |
261 std::vector<IndexedDBMsg_BlobOrFileInfo>* blob_or_file_info, | 245 std::vector<IndexedDBMsg_BlobOrFileInfo>* blob_or_file_info, |
262 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host) { | 246 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host) { |
263 DCHECK_EQ(blob_info.size(), blob_or_file_info->size()); | 247 DCHECK_EQ(blob_info.size(), blob_or_file_info->size()); |
264 size_t i; | 248 size_t i; |
265 if (!dispatcher_host->blob_storage_context()) | 249 if (!dispatcher_host->blob_storage_context()) |
266 return false; | 250 return false; |
267 for (i = 0; i < blob_info.size(); ++i) { | 251 for (i = 0; i < blob_info.size(); ++i) { |
268 (*blob_or_file_info)[i].uuid = | 252 (*blob_or_file_info)[i].uuid = |
269 CreateBlobData(blob_info[i], | 253 CreateBlobData(blob_info[i], |
270 dispatcher_host, | 254 dispatcher_host, |
271 dispatcher_host->blob_storage_context(), | |
272 dispatcher_host->Context()->TaskRunner()); | 255 dispatcher_host->Context()->TaskRunner()); |
273 } | 256 } |
274 return true; | 257 return true; |
275 } | 258 } |
276 | 259 |
277 template <class ParamType, class MsgType> | 260 template <class ParamType, class MsgType> |
278 static void CreateBlobsAndSend( | 261 static void CreateBlobsAndSend( |
279 ParamType* params, | 262 ParamType* params, |
280 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host, | 263 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host, |
281 const std::vector<IndexedDBBlobInfo>& blob_info, | 264 const std::vector<IndexedDBBlobInfo>& blob_info, |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
601 ipc_thread_id_, ipc_callbacks_id_)); | 584 ipc_thread_id_, ipc_callbacks_id_)); |
602 dispatcher_host_ = NULL; | 585 dispatcher_host_ = NULL; |
603 } | 586 } |
604 | 587 |
605 void IndexedDBCallbacks::SetConnectionOpenStartTime( | 588 void IndexedDBCallbacks::SetConnectionOpenStartTime( |
606 const base::TimeTicks& start_time) { | 589 const base::TimeTicks& start_time) { |
607 connection_open_start_time_ = start_time; | 590 connection_open_start_time_ = start_time; |
608 } | 591 } |
609 | 592 |
610 } // namespace content | 593 } // namespace content |
OLD | NEW |