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_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" | 9 #include "base/guid.h" |
| 10 #include "base/metrics/histogram.h" | |
| 10 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 11 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 12 #include "content/browser/child_process_security_policy_impl.h" | 13 #include "content/browser/child_process_security_policy_impl.h" |
| 13 #include "content/browser/fileapi/fileapi_message_filter.h" | 14 #include "content/browser/fileapi/fileapi_message_filter.h" |
| 14 #include "content/browser/indexed_db/indexed_db_blob_info.h" | 15 #include "content/browser/indexed_db/indexed_db_blob_info.h" |
| 15 #include "content/browser/indexed_db/indexed_db_connection.h" | 16 #include "content/browser/indexed_db/indexed_db_connection.h" |
| 16 #include "content/browser/indexed_db/indexed_db_context_impl.h" | 17 #include "content/browser/indexed_db/indexed_db_context_impl.h" |
| 17 #include "content/browser/indexed_db/indexed_db_cursor.h" | 18 #include "content/browser/indexed_db/indexed_db_cursor.h" |
| 18 #include "content/browser/indexed_db/indexed_db_database_callbacks.h" | 19 #include "content/browser/indexed_db/indexed_db_database_callbacks.h" |
| 19 #include "content/browser/indexed_db/indexed_db_database_error.h" | 20 #include "content/browser/indexed_db/indexed_db_database_error.h" |
| 20 #include "content/browser/indexed_db/indexed_db_metadata.h" | 21 #include "content/browser/indexed_db/indexed_db_metadata.h" |
| 21 #include "content/browser/indexed_db/indexed_db_value.h" | 22 #include "content/browser/indexed_db/indexed_db_value.h" |
| 22 #include "content/common/indexed_db/indexed_db_constants.h" | 23 #include "content/common/indexed_db/indexed_db_constants.h" |
| 23 #include "content/common/indexed_db/indexed_db_messages.h" | 24 #include "content/common/indexed_db/indexed_db_messages.h" |
| 24 #include "webkit/browser/blob/blob_storage_context.h" | 25 #include "webkit/browser/blob/blob_storage_context.h" |
| 25 #include "webkit/browser/quota/quota_manager.h" | 26 #include "webkit/browser/quota/quota_manager.h" |
| 26 #include "webkit/common/blob/blob_data.h" | 27 #include "webkit/common/blob/blob_data.h" |
| 27 #include "webkit/common/blob/shareable_file_reference.h" | 28 #include "webkit/common/blob/shareable_file_reference.h" |
| 28 | 29 |
| 29 using webkit_blob::ShareableFileReference; | 30 using webkit_blob::ShareableFileReference; |
| 30 | 31 |
| 31 namespace content { | 32 namespace content { |
| 32 | 33 |
| 33 namespace { | 34 namespace { |
| 34 const int32 kNoCursor = -1; | 35 const int32 kNoCursor = -1; |
| 35 const int32 kNoDatabaseCallbacks = -1; | 36 const int32 kNoDatabaseCallbacks = -1; |
| 36 const int64 kNoTransaction = -1; | 37 const int64 kNoTransaction = -1; |
| 37 } | 38 } |
| 38 | 39 |
| 40 static const char* const kDatabaseOpenTime = "WebCore.IndexedDB.OpenTime"; | |
|
Ilya Sherman
2014/08/14 22:37:49
nit: I'd include "histogram", and probably also "n
Ilya Sherman
2014/08/14 22:37:49
nit: "const char kDatabaseOpenTime[]" is slightly
| |
| 41 | |
| 39 IndexedDBCallbacks::IndexedDBCallbacks(IndexedDBDispatcherHost* dispatcher_host, | 42 IndexedDBCallbacks::IndexedDBCallbacks(IndexedDBDispatcherHost* dispatcher_host, |
| 40 int32 ipc_thread_id, | 43 int32 ipc_thread_id, |
| 41 int32 ipc_callbacks_id) | 44 int32 ipc_callbacks_id) |
| 42 : dispatcher_host_(dispatcher_host), | 45 : dispatcher_host_(dispatcher_host), |
| 43 ipc_callbacks_id_(ipc_callbacks_id), | 46 ipc_callbacks_id_(ipc_callbacks_id), |
| 44 ipc_thread_id_(ipc_thread_id), | 47 ipc_thread_id_(ipc_thread_id), |
| 45 ipc_cursor_id_(kNoCursor), | 48 ipc_cursor_id_(kNoCursor), |
| 46 host_transaction_id_(kNoTransaction), | 49 host_transaction_id_(kNoTransaction), |
| 47 ipc_database_id_(kNoDatabase), | 50 ipc_database_id_(kNoDatabase), |
| 48 ipc_database_callbacks_id_(kNoDatabaseCallbacks), | 51 ipc_database_callbacks_id_(kNoDatabaseCallbacks), |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 } | 87 } |
| 85 | 88 |
| 86 IndexedDBCallbacks::~IndexedDBCallbacks() {} | 89 IndexedDBCallbacks::~IndexedDBCallbacks() {} |
| 87 | 90 |
| 88 void IndexedDBCallbacks::OnError(const IndexedDBDatabaseError& error) { | 91 void IndexedDBCallbacks::OnError(const IndexedDBDatabaseError& error) { |
| 89 DCHECK(dispatcher_host_.get()); | 92 DCHECK(dispatcher_host_.get()); |
| 90 | 93 |
| 91 dispatcher_host_->Send(new IndexedDBMsg_CallbacksError( | 94 dispatcher_host_->Send(new IndexedDBMsg_CallbacksError( |
| 92 ipc_thread_id_, ipc_callbacks_id_, error.code(), error.message())); | 95 ipc_thread_id_, ipc_callbacks_id_, error.code(), error.message())); |
| 93 dispatcher_host_ = NULL; | 96 dispatcher_host_ = NULL; |
| 97 | |
| 98 if (!db_open_start_time_.is_null()) { | |
| 99 UMA_HISTOGRAM_MEDIUM_TIMES(kDatabaseOpenTime, | |
| 100 base::TimeTicks::Now() - db_open_start_time_); | |
| 101 db_open_start_time_ = base::TimeTicks(); | |
| 102 } | |
| 94 } | 103 } |
| 95 | 104 |
| 96 void IndexedDBCallbacks::OnSuccess(const std::vector<base::string16>& value) { | 105 void IndexedDBCallbacks::OnSuccess(const std::vector<base::string16>& value) { |
| 97 DCHECK(dispatcher_host_.get()); | 106 DCHECK(dispatcher_host_.get()); |
| 98 | 107 |
| 99 DCHECK_EQ(kNoCursor, ipc_cursor_id_); | 108 DCHECK_EQ(kNoCursor, ipc_cursor_id_); |
| 100 DCHECK_EQ(kNoTransaction, host_transaction_id_); | 109 DCHECK_EQ(kNoTransaction, host_transaction_id_); |
| 101 DCHECK_EQ(kNoDatabase, ipc_database_id_); | 110 DCHECK_EQ(kNoDatabase, ipc_database_id_); |
| 102 DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_); | 111 DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_); |
| 103 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); | 112 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 119 DCHECK_EQ(kNoTransaction == host_transaction_id_, | 128 DCHECK_EQ(kNoTransaction == host_transaction_id_, |
| 120 kNoDatabaseCallbacks == ipc_database_callbacks_id_); | 129 kNoDatabaseCallbacks == ipc_database_callbacks_id_); |
| 121 DCHECK_EQ(kNoDatabase, ipc_database_id_); | 130 DCHECK_EQ(kNoDatabase, ipc_database_id_); |
| 122 | 131 |
| 123 if (sent_blocked_) | 132 if (sent_blocked_) |
| 124 return; | 133 return; |
| 125 | 134 |
| 126 sent_blocked_ = true; | 135 sent_blocked_ = true; |
| 127 dispatcher_host_->Send(new IndexedDBMsg_CallbacksIntBlocked( | 136 dispatcher_host_->Send(new IndexedDBMsg_CallbacksIntBlocked( |
| 128 ipc_thread_id_, ipc_callbacks_id_, existing_version)); | 137 ipc_thread_id_, ipc_callbacks_id_, existing_version)); |
| 138 | |
| 139 if (!db_open_start_time_.is_null()) { | |
| 140 UMA_HISTOGRAM_MEDIUM_TIMES(kDatabaseOpenTime, | |
| 141 base::TimeTicks::Now() - db_open_start_time_); | |
| 142 db_open_start_time_ = base::TimeTicks(); | |
| 143 } | |
| 129 } | 144 } |
| 130 | 145 |
| 131 void IndexedDBCallbacks::OnDataLoss(blink::WebIDBDataLoss data_loss, | 146 void IndexedDBCallbacks::OnDataLoss(blink::WebIDBDataLoss data_loss, |
| 132 std::string data_loss_message) { | 147 std::string data_loss_message) { |
| 133 DCHECK_NE(blink::WebIDBDataLossNone, data_loss); | 148 DCHECK_NE(blink::WebIDBDataLossNone, data_loss); |
| 134 data_loss_ = data_loss; | 149 data_loss_ = data_loss; |
| 135 data_loss_message_ = data_loss_message; | 150 data_loss_message_ = data_loss_message; |
| 136 } | 151 } |
| 137 | 152 |
| 138 void IndexedDBCallbacks::OnUpgradeNeeded( | 153 void IndexedDBCallbacks::OnUpgradeNeeded( |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 155 IndexedDBMsg_CallbacksUpgradeNeeded_Params params; | 170 IndexedDBMsg_CallbacksUpgradeNeeded_Params params; |
| 156 params.ipc_thread_id = ipc_thread_id_; | 171 params.ipc_thread_id = ipc_thread_id_; |
| 157 params.ipc_callbacks_id = ipc_callbacks_id_; | 172 params.ipc_callbacks_id = ipc_callbacks_id_; |
| 158 params.ipc_database_id = ipc_database_id; | 173 params.ipc_database_id = ipc_database_id; |
| 159 params.ipc_database_callbacks_id = ipc_database_callbacks_id_; | 174 params.ipc_database_callbacks_id = ipc_database_callbacks_id_; |
| 160 params.old_version = old_version; | 175 params.old_version = old_version; |
| 161 params.idb_metadata = IndexedDBDispatcherHost::ConvertMetadata(metadata); | 176 params.idb_metadata = IndexedDBDispatcherHost::ConvertMetadata(metadata); |
| 162 params.data_loss = data_loss_; | 177 params.data_loss = data_loss_; |
| 163 params.data_loss_message = data_loss_message_; | 178 params.data_loss_message = data_loss_message_; |
| 164 dispatcher_host_->Send(new IndexedDBMsg_CallbacksUpgradeNeeded(params)); | 179 dispatcher_host_->Send(new IndexedDBMsg_CallbacksUpgradeNeeded(params)); |
| 180 | |
| 181 if (!db_open_start_time_.is_null()) { | |
| 182 UMA_HISTOGRAM_MEDIUM_TIMES(kDatabaseOpenTime, | |
| 183 base::TimeTicks::Now() - db_open_start_time_); | |
| 184 db_open_start_time_ = base::TimeTicks(); | |
| 185 } | |
| 165 } | 186 } |
| 166 | 187 |
| 167 void IndexedDBCallbacks::OnSuccess(scoped_ptr<IndexedDBConnection> connection, | 188 void IndexedDBCallbacks::OnSuccess(scoped_ptr<IndexedDBConnection> connection, |
| 168 const IndexedDBDatabaseMetadata& metadata) { | 189 const IndexedDBDatabaseMetadata& metadata) { |
| 169 DCHECK(dispatcher_host_.get()); | 190 DCHECK(dispatcher_host_.get()); |
| 170 | 191 |
| 171 DCHECK_EQ(kNoCursor, ipc_cursor_id_); | 192 DCHECK_EQ(kNoCursor, ipc_cursor_id_); |
| 172 DCHECK_NE(kNoTransaction, host_transaction_id_); | 193 DCHECK_NE(kNoTransaction, host_transaction_id_); |
| 173 DCHECK_NE(ipc_database_id_ == kNoDatabase, !connection); | 194 DCHECK_NE(ipc_database_id_ == kNoDatabase, !connection); |
| 174 DCHECK_NE(kNoDatabaseCallbacks, ipc_database_callbacks_id_); | 195 DCHECK_NE(kNoDatabaseCallbacks, ipc_database_callbacks_id_); |
| 175 | 196 |
| 176 scoped_refptr<IndexedDBCallbacks> self(this); | 197 scoped_refptr<IndexedDBCallbacks> self(this); |
| 177 | 198 |
| 178 int32 ipc_object_id = kNoDatabase; | 199 int32 ipc_object_id = kNoDatabase; |
| 179 // Only register if the connection was not previously sent in OnUpgradeNeeded. | 200 // Only register if the connection was not previously sent in OnUpgradeNeeded. |
| 180 if (ipc_database_id_ == kNoDatabase) { | 201 if (ipc_database_id_ == kNoDatabase) { |
| 181 ipc_object_id = dispatcher_host_->Add( | 202 ipc_object_id = dispatcher_host_->Add( |
| 182 connection.release(), ipc_thread_id_, origin_url_); | 203 connection.release(), ipc_thread_id_, origin_url_); |
| 183 } | 204 } |
| 184 | 205 |
| 185 dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessIDBDatabase( | 206 dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessIDBDatabase( |
| 186 ipc_thread_id_, | 207 ipc_thread_id_, |
| 187 ipc_callbacks_id_, | 208 ipc_callbacks_id_, |
| 188 ipc_database_callbacks_id_, | 209 ipc_database_callbacks_id_, |
| 189 ipc_object_id, | 210 ipc_object_id, |
| 190 IndexedDBDispatcherHost::ConvertMetadata(metadata))); | 211 IndexedDBDispatcherHost::ConvertMetadata(metadata))); |
| 191 dispatcher_host_ = NULL; | 212 dispatcher_host_ = NULL; |
| 213 | |
| 214 if (!db_open_start_time_.is_null()) { | |
| 215 UMA_HISTOGRAM_MEDIUM_TIMES(kDatabaseOpenTime, | |
| 216 base::TimeTicks::Now() - db_open_start_time_); | |
| 217 db_open_start_time_ = base::TimeTicks(); | |
| 218 } | |
| 192 } | 219 } |
| 193 | 220 |
| 194 static std::string CreateBlobData( | 221 static std::string CreateBlobData( |
| 195 const IndexedDBBlobInfo& blob_info, | 222 const IndexedDBBlobInfo& blob_info, |
| 196 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host, | 223 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host, |
| 197 webkit_blob::BlobStorageContext* blob_storage_context, | 224 webkit_blob::BlobStorageContext* blob_storage_context, |
| 198 base::TaskRunner* task_runner) { | 225 base::TaskRunner* task_runner) { |
| 199 std::string uuid = blob_info.uuid(); | 226 std::string uuid = blob_info.uuid(); |
| 200 if (!uuid.empty()) { | 227 if (!uuid.empty()) { |
| 201 // We're sending back a live blob, not a reference into our backing store. | 228 // We're sending back a live blob, not a reference into our backing store. |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 572 DCHECK_EQ(kNoTransaction, host_transaction_id_); | 599 DCHECK_EQ(kNoTransaction, host_transaction_id_); |
| 573 DCHECK_EQ(kNoDatabase, ipc_database_id_); | 600 DCHECK_EQ(kNoDatabase, ipc_database_id_); |
| 574 DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_); | 601 DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_); |
| 575 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); | 602 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); |
| 576 | 603 |
| 577 dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessUndefined( | 604 dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessUndefined( |
| 578 ipc_thread_id_, ipc_callbacks_id_)); | 605 ipc_thread_id_, ipc_callbacks_id_)); |
| 579 dispatcher_host_ = NULL; | 606 dispatcher_host_ = NULL; |
| 580 } | 607 } |
| 581 | 608 |
| 609 void IndexedDBCallbacks::SetDatbaseOpenStartTime( | |
|
jsbell
2014/08/14 22:58:05
Typo (but at least it compiles!)
| |
| 610 const base::TimeTicks& start_time) { | |
| 611 db_open_start_time_ = start_time; | |
| 612 } | |
| 613 | |
| 582 } // namespace content | 614 } // namespace content |
| OLD | NEW |