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

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

Issue 2468273002: [DevTools] migrate Database, IndexedDB and CacheStorage to new style (Closed)
Patch Set: addressed comments & rebased Created 4 years, 1 month 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 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 return; 258 return;
259 259
260 m_resources.clear(); 260 m_resources.clear();
261 } 261 }
262 262
263 InspectorDatabaseAgent::InspectorDatabaseAgent(Page* page) 263 InspectorDatabaseAgent::InspectorDatabaseAgent(Page* page)
264 : m_page(page), m_enabled(false) {} 264 : m_page(page), m_enabled(false) {}
265 265
266 InspectorDatabaseAgent::~InspectorDatabaseAgent() {} 266 InspectorDatabaseAgent::~InspectorDatabaseAgent() {}
267 267
268 void InspectorDatabaseAgent::enable(ErrorString*) { 268 Response InspectorDatabaseAgent::enable() {
269 if (m_enabled) 269 if (m_enabled)
270 return; 270 return Response::OK();
271 m_enabled = true; 271 m_enabled = true;
272 m_state->setBoolean(DatabaseAgentState::databaseAgentEnabled, m_enabled); 272 m_state->setBoolean(DatabaseAgentState::databaseAgentEnabled, m_enabled);
273 if (DatabaseClient* client = DatabaseClient::fromPage(m_page)) 273 if (DatabaseClient* client = DatabaseClient::fromPage(m_page))
274 client->setInspectorAgent(this); 274 client->setInspectorAgent(this);
275 DatabaseTracker::tracker().forEachOpenDatabaseInPage( 275 DatabaseTracker::tracker().forEachOpenDatabaseInPage(
276 m_page, WTF::bind(&InspectorDatabaseAgent::registerDatabaseOnCreation, 276 m_page, WTF::bind(&InspectorDatabaseAgent::registerDatabaseOnCreation,
277 wrapPersistent(this))); 277 wrapPersistent(this)));
278 return Response::OK();
278 } 279 }
279 280
280 void InspectorDatabaseAgent::disable(ErrorString*) { 281 Response InspectorDatabaseAgent::disable() {
281 if (!m_enabled) 282 if (!m_enabled)
282 return; 283 return Response::OK();
283 m_enabled = false; 284 m_enabled = false;
284 m_state->setBoolean(DatabaseAgentState::databaseAgentEnabled, m_enabled); 285 m_state->setBoolean(DatabaseAgentState::databaseAgentEnabled, m_enabled);
285 if (DatabaseClient* client = DatabaseClient::fromPage(m_page)) 286 if (DatabaseClient* client = DatabaseClient::fromPage(m_page))
286 client->setInspectorAgent(nullptr); 287 client->setInspectorAgent(nullptr);
287 m_resources.clear(); 288 m_resources.clear();
289 return Response::OK();
288 } 290 }
289 291
290 void InspectorDatabaseAgent::restore() { 292 void InspectorDatabaseAgent::restore() {
291 if (m_state->booleanProperty(DatabaseAgentState::databaseAgentEnabled, 293 if (m_state->booleanProperty(DatabaseAgentState::databaseAgentEnabled,
292 false)) { 294 false)) {
293 ErrorString error; 295 enable();
294 enable(&error);
295 } 296 }
296 } 297 }
297 298
298 void InspectorDatabaseAgent::getDatabaseTableNames( 299 Response InspectorDatabaseAgent::getDatabaseTableNames(
299 ErrorString* error,
300 const String& databaseId, 300 const String& databaseId,
301 std::unique_ptr<protocol::Array<String>>* names) { 301 std::unique_ptr<protocol::Array<String>>* names) {
302 if (!m_enabled) { 302 if (!m_enabled)
303 *error = "Database agent is not enabled"; 303 return Response::Error("Database agent is not enabled");
304 return;
305 }
306 304
307 *names = protocol::Array<String>::create(); 305 *names = protocol::Array<String>::create();
308 306
309 blink::Database* database = databaseForId(databaseId); 307 blink::Database* database = databaseForId(databaseId);
310 if (database) { 308 if (database) {
311 Vector<String> tableNames = database->tableNames(); 309 Vector<String> tableNames = database->tableNames();
312 unsigned length = tableNames.size(); 310 unsigned length = tableNames.size();
313 for (unsigned i = 0; i < length; ++i) 311 for (unsigned i = 0; i < length; ++i)
314 (*names)->addItem(tableNames[i]); 312 (*names)->addItem(tableNames[i]);
315 } 313 }
314 return Response::OK();
316 } 315 }
317 316
318 void InspectorDatabaseAgent::executeSQL( 317 void InspectorDatabaseAgent::executeSQL(
319 const String& databaseId, 318 const String& databaseId,
320 const String& query, 319 const String& query,
321 std::unique_ptr<ExecuteSQLCallback> prpRequestCallback) { 320 std::unique_ptr<ExecuteSQLCallback> prpRequestCallback) {
322 std::unique_ptr<ExecuteSQLCallback> requestCallback = 321 std::unique_ptr<ExecuteSQLCallback> requestCallback =
323 std::move(prpRequestCallback); 322 std::move(prpRequestCallback);
324 323
325 if (!m_enabled) { 324 if (!m_enabled) {
326 requestCallback->sendFailure("Database agent is not enabled"); 325 requestCallback->sendFailure(
326 Response::Error("Database agent is not enabled"));
327 return; 327 return;
328 } 328 }
329 329
330 blink::Database* database = databaseForId(databaseId); 330 blink::Database* database = databaseForId(databaseId);
331 if (!database) { 331 if (!database) {
332 requestCallback->sendFailure("Database not found"); 332 requestCallback->sendFailure(Response::Error("Database not found"));
333 return; 333 return;
334 } 334 }
335 335
336 RefPtr<ExecuteSQLCallbackWrapper> wrapper = 336 RefPtr<ExecuteSQLCallbackWrapper> wrapper =
337 ExecuteSQLCallbackWrapper::create(std::move(requestCallback)); 337 ExecuteSQLCallbackWrapper::create(std::move(requestCallback));
338 SQLTransactionCallback* callback = 338 SQLTransactionCallback* callback =
339 TransactionCallback::create(query, wrapper); 339 TransactionCallback::create(query, wrapper);
340 SQLTransactionErrorCallback* errorCallback = 340 SQLTransactionErrorCallback* errorCallback =
341 TransactionErrorCallback::create(wrapper); 341 TransactionErrorCallback::create(wrapper);
342 VoidCallback* successCallback = TransactionSuccessCallback::create(); 342 VoidCallback* successCallback = TransactionSuccessCallback::create();
(...skipping 18 matching lines...) Expand all
361 return it->value->database(); 361 return it->value->database();
362 } 362 }
363 363
364 DEFINE_TRACE(InspectorDatabaseAgent) { 364 DEFINE_TRACE(InspectorDatabaseAgent) {
365 visitor->trace(m_page); 365 visitor->trace(m_page);
366 visitor->trace(m_resources); 366 visitor->trace(m_resources);
367 InspectorBaseAgent::trace(visitor); 367 InspectorBaseAgent::trace(visitor);
368 } 368 }
369 369
370 } // namespace blink 370 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698