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" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 } | 85 } |
85 | 86 |
86 IndexedDBCallbacks::~IndexedDBCallbacks() {} | 87 IndexedDBCallbacks::~IndexedDBCallbacks() {} |
87 | 88 |
88 void IndexedDBCallbacks::OnError(const IndexedDBDatabaseError& error) { | 89 void IndexedDBCallbacks::OnError(const IndexedDBDatabaseError& error) { |
89 DCHECK(dispatcher_host_.get()); | 90 DCHECK(dispatcher_host_.get()); |
90 | 91 |
91 dispatcher_host_->Send(new IndexedDBMsg_CallbacksError( | 92 dispatcher_host_->Send(new IndexedDBMsg_CallbacksError( |
92 ipc_thread_id_, ipc_callbacks_id_, error.code(), error.message())); | 93 ipc_thread_id_, ipc_callbacks_id_, error.code(), error.message())); |
93 dispatcher_host_ = NULL; | 94 dispatcher_host_ = NULL; |
| 95 |
| 96 if (!connection_open_start_time_.is_null()) { |
| 97 UMA_HISTOGRAM_MEDIUM_TIMES( |
| 98 "WebCore.IndexedDB.OpenTime.Error", |
| 99 base::TimeTicks::Now() - connection_open_start_time_); |
| 100 connection_open_start_time_ = base::TimeTicks(); |
| 101 } |
94 } | 102 } |
95 | 103 |
96 void IndexedDBCallbacks::OnSuccess(const std::vector<base::string16>& value) { | 104 void IndexedDBCallbacks::OnSuccess(const std::vector<base::string16>& value) { |
97 DCHECK(dispatcher_host_.get()); | 105 DCHECK(dispatcher_host_.get()); |
98 | 106 |
99 DCHECK_EQ(kNoCursor, ipc_cursor_id_); | 107 DCHECK_EQ(kNoCursor, ipc_cursor_id_); |
100 DCHECK_EQ(kNoTransaction, host_transaction_id_); | 108 DCHECK_EQ(kNoTransaction, host_transaction_id_); |
101 DCHECK_EQ(kNoDatabase, ipc_database_id_); | 109 DCHECK_EQ(kNoDatabase, ipc_database_id_); |
102 DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_); | 110 DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_); |
103 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); | 111 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); |
(...skipping 15 matching lines...) Expand all Loading... |
119 DCHECK_EQ(kNoTransaction == host_transaction_id_, | 127 DCHECK_EQ(kNoTransaction == host_transaction_id_, |
120 kNoDatabaseCallbacks == ipc_database_callbacks_id_); | 128 kNoDatabaseCallbacks == ipc_database_callbacks_id_); |
121 DCHECK_EQ(kNoDatabase, ipc_database_id_); | 129 DCHECK_EQ(kNoDatabase, ipc_database_id_); |
122 | 130 |
123 if (sent_blocked_) | 131 if (sent_blocked_) |
124 return; | 132 return; |
125 | 133 |
126 sent_blocked_ = true; | 134 sent_blocked_ = true; |
127 dispatcher_host_->Send(new IndexedDBMsg_CallbacksIntBlocked( | 135 dispatcher_host_->Send(new IndexedDBMsg_CallbacksIntBlocked( |
128 ipc_thread_id_, ipc_callbacks_id_, existing_version)); | 136 ipc_thread_id_, ipc_callbacks_id_, existing_version)); |
| 137 |
| 138 if (!connection_open_start_time_.is_null()) { |
| 139 UMA_HISTOGRAM_MEDIUM_TIMES( |
| 140 "WebCore.IndexedDB.OpenTime.Blocked", |
| 141 base::TimeTicks::Now() - connection_open_start_time_); |
| 142 connection_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 (!connection_open_start_time_.is_null()) { |
| 182 UMA_HISTOGRAM_MEDIUM_TIMES( |
| 183 "WebCore.IndexedDB.OpenTime.UpgradeNeeded", |
| 184 base::TimeTicks::Now() - connection_open_start_time_); |
| 185 connection_open_start_time_ = base::TimeTicks(); |
| 186 } |
165 } | 187 } |
166 | 188 |
167 void IndexedDBCallbacks::OnSuccess(scoped_ptr<IndexedDBConnection> connection, | 189 void IndexedDBCallbacks::OnSuccess(scoped_ptr<IndexedDBConnection> connection, |
168 const IndexedDBDatabaseMetadata& metadata) { | 190 const IndexedDBDatabaseMetadata& metadata) { |
169 DCHECK(dispatcher_host_.get()); | 191 DCHECK(dispatcher_host_.get()); |
170 | 192 |
171 DCHECK_EQ(kNoCursor, ipc_cursor_id_); | 193 DCHECK_EQ(kNoCursor, ipc_cursor_id_); |
172 DCHECK_NE(kNoTransaction, host_transaction_id_); | 194 DCHECK_NE(kNoTransaction, host_transaction_id_); |
173 DCHECK_NE(ipc_database_id_ == kNoDatabase, !connection); | 195 DCHECK_NE(ipc_database_id_ == kNoDatabase, !connection); |
174 DCHECK_NE(kNoDatabaseCallbacks, ipc_database_callbacks_id_); | 196 DCHECK_NE(kNoDatabaseCallbacks, ipc_database_callbacks_id_); |
175 | 197 |
176 scoped_refptr<IndexedDBCallbacks> self(this); | 198 scoped_refptr<IndexedDBCallbacks> self(this); |
177 | 199 |
178 int32 ipc_object_id = kNoDatabase; | 200 int32 ipc_object_id = kNoDatabase; |
179 // Only register if the connection was not previously sent in OnUpgradeNeeded. | 201 // Only register if the connection was not previously sent in OnUpgradeNeeded. |
180 if (ipc_database_id_ == kNoDatabase) { | 202 if (ipc_database_id_ == kNoDatabase) { |
181 ipc_object_id = dispatcher_host_->Add( | 203 ipc_object_id = dispatcher_host_->Add( |
182 connection.release(), ipc_thread_id_, origin_url_); | 204 connection.release(), ipc_thread_id_, origin_url_); |
183 } | 205 } |
184 | 206 |
185 dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessIDBDatabase( | 207 dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessIDBDatabase( |
186 ipc_thread_id_, | 208 ipc_thread_id_, |
187 ipc_callbacks_id_, | 209 ipc_callbacks_id_, |
188 ipc_database_callbacks_id_, | 210 ipc_database_callbacks_id_, |
189 ipc_object_id, | 211 ipc_object_id, |
190 IndexedDBDispatcherHost::ConvertMetadata(metadata))); | 212 IndexedDBDispatcherHost::ConvertMetadata(metadata))); |
191 dispatcher_host_ = NULL; | 213 dispatcher_host_ = NULL; |
| 214 |
| 215 if (!connection_open_start_time_.is_null()) { |
| 216 UMA_HISTOGRAM_MEDIUM_TIMES( |
| 217 "WebCore.IndexedDB.OpenTime.Success", |
| 218 base::TimeTicks::Now() - connection_open_start_time_); |
| 219 connection_open_start_time_ = base::TimeTicks(); |
| 220 } |
192 } | 221 } |
193 | 222 |
194 static std::string CreateBlobData( | 223 static std::string CreateBlobData( |
195 const IndexedDBBlobInfo& blob_info, | 224 const IndexedDBBlobInfo& blob_info, |
196 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host, | 225 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host, |
197 webkit_blob::BlobStorageContext* blob_storage_context, | 226 webkit_blob::BlobStorageContext* blob_storage_context, |
198 base::TaskRunner* task_runner) { | 227 base::TaskRunner* task_runner) { |
199 std::string uuid = blob_info.uuid(); | 228 std::string uuid = blob_info.uuid(); |
200 if (!uuid.empty()) { | 229 if (!uuid.empty()) { |
201 // We're sending back a live blob, not a reference into our backing store. | 230 // 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_); | 601 DCHECK_EQ(kNoTransaction, host_transaction_id_); |
573 DCHECK_EQ(kNoDatabase, ipc_database_id_); | 602 DCHECK_EQ(kNoDatabase, ipc_database_id_); |
574 DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_); | 603 DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_); |
575 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); | 604 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); |
576 | 605 |
577 dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessUndefined( | 606 dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessUndefined( |
578 ipc_thread_id_, ipc_callbacks_id_)); | 607 ipc_thread_id_, ipc_callbacks_id_)); |
579 dispatcher_host_ = NULL; | 608 dispatcher_host_ = NULL; |
580 } | 609 } |
581 | 610 |
| 611 void IndexedDBCallbacks::SetConnectionOpenStartTime( |
| 612 const base::TimeTicks& start_time) { |
| 613 connection_open_start_time_ = start_time; |
| 614 } |
| 615 |
582 } // namespace content | 616 } // namespace content |
OLD | NEW |