Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(204)

Side by Side Diff: third_party/WebKit/Source/modules/webdatabase/InspectorDatabaseAgent.cpp

Issue 1810843002: DevTools: split protocol Dispatcher into Backend interface and the dispatcher itself. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 30 matching lines...) Expand all
41 #include "modules/webdatabase/SQLResultSetRowList.h" 41 #include "modules/webdatabase/SQLResultSetRowList.h"
42 #include "modules/webdatabase/SQLStatementCallback.h" 42 #include "modules/webdatabase/SQLStatementCallback.h"
43 #include "modules/webdatabase/SQLStatementErrorCallback.h" 43 #include "modules/webdatabase/SQLStatementErrorCallback.h"
44 #include "modules/webdatabase/SQLTransaction.h" 44 #include "modules/webdatabase/SQLTransaction.h"
45 #include "modules/webdatabase/SQLTransactionCallback.h" 45 #include "modules/webdatabase/SQLTransactionCallback.h"
46 #include "modules/webdatabase/SQLTransactionErrorCallback.h" 46 #include "modules/webdatabase/SQLTransactionErrorCallback.h"
47 #include "modules/webdatabase/sqlite/SQLValue.h" 47 #include "modules/webdatabase/sqlite/SQLValue.h"
48 #include "platform/inspector_protocol/Values.h" 48 #include "platform/inspector_protocol/Values.h"
49 #include "wtf/Vector.h" 49 #include "wtf/Vector.h"
50 50
51 typedef blink::protocol::Dispatcher::DatabaseCommandHandler::ExecuteSQLCallback ExecuteSQLCallback; 51 typedef blink::protocol::Backend::Database::ExecuteSQLCallback ExecuteSQLCallbac k;
52 52
53 namespace blink { 53 namespace blink {
54 54
55 namespace DatabaseAgentState { 55 namespace DatabaseAgentState {
56 static const char databaseAgentEnabled[] = "databaseAgentEnabled"; 56 static const char databaseAgentEnabled[] = "databaseAgentEnabled";
57 }; 57 };
58 58
59 namespace { 59 namespace {
60 60
61 class ExecuteSQLCallbackWrapper : public RefCounted<ExecuteSQLCallbackWrapper> { 61 class ExecuteSQLCallbackWrapper : public RefCounted<ExecuteSQLCallbackWrapper> {
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 ~TransactionSuccessCallback() override { } 209 ~TransactionSuccessCallback() override { }
210 210
211 void handleEvent() override { } 211 void handleEvent() override { }
212 212
213 private: 213 private:
214 TransactionSuccessCallback() { } 214 TransactionSuccessCallback() { }
215 }; 215 };
216 216
217 } // namespace 217 } // namespace
218 218
219 void InspectorDatabaseAgent::didOpenDatabase(Database* database, const String& d omain, const String& name, const String& version) 219 void InspectorDatabaseAgent::didOpenDatabase(blink::Database* database, const St ring& domain, const String& name, const String& version)
220 { 220 {
221 if (InspectorDatabaseResource* resource = findByFileName(database->fileName( ))) { 221 if (InspectorDatabaseResource* resource = findByFileName(database->fileName( ))) {
222 resource->setDatabase(database); 222 resource->setDatabase(database);
223 return; 223 return;
224 } 224 }
225 225
226 InspectorDatabaseResource* resource = InspectorDatabaseResource::create(data base, domain, name, version); 226 InspectorDatabaseResource* resource = InspectorDatabaseResource::create(data base, domain, name, version);
227 m_resources.set(resource->id(), resource); 227 m_resources.set(resource->id(), resource);
228 // Resources are only bound while visible. 228 // Resources are only bound while visible.
229 if (frontend() && m_enabled) 229 if (frontend() && m_enabled)
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 278
279 void InspectorDatabaseAgent::getDatabaseTableNames(ErrorString* error, const Str ing& databaseId, OwnPtr<protocol::Array<String>>* names) 279 void InspectorDatabaseAgent::getDatabaseTableNames(ErrorString* error, const Str ing& databaseId, OwnPtr<protocol::Array<String>>* names)
280 { 280 {
281 if (!m_enabled) { 281 if (!m_enabled) {
282 *error = "Database agent is not enabled"; 282 *error = "Database agent is not enabled";
283 return; 283 return;
284 } 284 }
285 285
286 *names = protocol::Array<String>::create(); 286 *names = protocol::Array<String>::create();
287 287
288 Database* database = databaseForId(databaseId); 288 blink::Database* database = databaseForId(databaseId);
289 if (database) { 289 if (database) {
290 Vector<String> tableNames = database->tableNames(); 290 Vector<String> tableNames = database->tableNames();
291 unsigned length = tableNames.size(); 291 unsigned length = tableNames.size();
292 for (unsigned i = 0; i < length; ++i) 292 for (unsigned i = 0; i < length; ++i)
293 (*names)->addItem(tableNames[i]); 293 (*names)->addItem(tableNames[i]);
294 } 294 }
295 } 295 }
296 296
297 void InspectorDatabaseAgent::executeSQL(ErrorString*, const String& databaseId, const String& query, PassOwnPtr<ExecuteSQLCallback> prpRequestCallback) 297 void InspectorDatabaseAgent::executeSQL(ErrorString*, const String& databaseId, const String& query, PassOwnPtr<ExecuteSQLCallback> prpRequestCallback)
298 { 298 {
299 OwnPtr<ExecuteSQLCallback> requestCallback = prpRequestCallback; 299 OwnPtr<ExecuteSQLCallback> requestCallback = prpRequestCallback;
300 300
301 if (!m_enabled) { 301 if (!m_enabled) {
302 requestCallback->sendFailure("Database agent is not enabled"); 302 requestCallback->sendFailure("Database agent is not enabled");
303 return; 303 return;
304 } 304 }
305 305
306 Database* database = databaseForId(databaseId); 306 blink::Database* database = databaseForId(databaseId);
307 if (!database) { 307 if (!database) {
308 requestCallback->sendFailure("Database not found"); 308 requestCallback->sendFailure("Database not found");
309 return; 309 return;
310 } 310 }
311 311
312 RefPtr<ExecuteSQLCallbackWrapper> wrapper = ExecuteSQLCallbackWrapper::creat e(requestCallback.release()); 312 RefPtr<ExecuteSQLCallbackWrapper> wrapper = ExecuteSQLCallbackWrapper::creat e(requestCallback.release());
313 SQLTransactionCallback* callback = TransactionCallback::create(query, wrappe r); 313 SQLTransactionCallback* callback = TransactionCallback::create(query, wrappe r);
314 SQLTransactionErrorCallback* errorCallback = TransactionErrorCallback::creat e(wrapper); 314 SQLTransactionErrorCallback* errorCallback = TransactionErrorCallback::creat e(wrapper);
315 VoidCallback* successCallback = TransactionSuccessCallback::create(); 315 VoidCallback* successCallback = TransactionSuccessCallback::create();
316 database->transaction(callback, errorCallback, successCallback); 316 database->transaction(callback, errorCallback, successCallback);
317 } 317 }
318 318
319 InspectorDatabaseResource* InspectorDatabaseAgent::findByFileName(const String& fileName) 319 InspectorDatabaseResource* InspectorDatabaseAgent::findByFileName(const String& fileName)
320 { 320 {
321 for (DatabaseResourcesHeapMap::iterator it = m_resources.begin(); it != m_re sources.end(); ++it) { 321 for (DatabaseResourcesHeapMap::iterator it = m_resources.begin(); it != m_re sources.end(); ++it) {
322 if (it->value->database()->fileName() == fileName) 322 if (it->value->database()->fileName() == fileName)
323 return it->value.get(); 323 return it->value.get();
324 } 324 }
325 return 0; 325 return 0;
326 } 326 }
327 327
328 Database* InspectorDatabaseAgent::databaseForId(const String& databaseId) 328 blink::Database* InspectorDatabaseAgent::databaseForId(const String& databaseId)
329 { 329 {
330 DatabaseResourcesHeapMap::iterator it = m_resources.find(databaseId); 330 DatabaseResourcesHeapMap::iterator it = m_resources.find(databaseId);
331 if (it == m_resources.end()) 331 if (it == m_resources.end())
332 return 0; 332 return 0;
333 return it->value->database(); 333 return it->value->database();
334 } 334 }
335 335
336 DEFINE_TRACE(InspectorDatabaseAgent) 336 DEFINE_TRACE(InspectorDatabaseAgent)
337 { 337 {
338 visitor->trace(m_page); 338 visitor->trace(m_page);
339 visitor->trace(m_resources); 339 visitor->trace(m_resources);
340 InspectorBaseAgent::trace(visitor); 340 InspectorBaseAgent::trace(visitor);
341 } 341 }
342 342
343 } // namespace blink 343 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698