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

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

Issue 2004313003: DevTools: migrate from OwnPtr to std::unique_ptr for inspector protocol classes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebaselined Created 4 years, 7 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 namespace blink { 55 namespace blink {
56 56
57 namespace DatabaseAgentState { 57 namespace DatabaseAgentState {
58 static const char databaseAgentEnabled[] = "databaseAgentEnabled"; 58 static const char databaseAgentEnabled[] = "databaseAgentEnabled";
59 }; 59 };
60 60
61 namespace { 61 namespace {
62 62
63 class ExecuteSQLCallbackWrapper : public RefCounted<ExecuteSQLCallbackWrapper> { 63 class ExecuteSQLCallbackWrapper : public RefCounted<ExecuteSQLCallbackWrapper> {
64 public: 64 public:
65 static PassRefPtr<ExecuteSQLCallbackWrapper> create(PassOwnPtr<ExecuteSQLCal lback> callback) { return adoptRef(new ExecuteSQLCallbackWrapper(std::move(callb ack))); } 65 static PassRefPtr<ExecuteSQLCallbackWrapper> create(std::unique_ptr<ExecuteS QLCallback> callback) { return adoptRef(new ExecuteSQLCallbackWrapper(std::move( callback))); }
66 ~ExecuteSQLCallbackWrapper() { } 66 ~ExecuteSQLCallbackWrapper() { }
67 ExecuteSQLCallback* get() { return m_callback.get(); } 67 ExecuteSQLCallback* get() { return m_callback.get(); }
68 68
69 void reportTransactionFailed(SQLError* error) 69 void reportTransactionFailed(SQLError* error)
70 { 70 {
71 OwnPtr<protocol::Database::Error> errorObject = protocol::Database::Erro r::create() 71 std::unique_ptr<protocol::Database::Error> errorObject = protocol::Datab ase::Error::create()
72 .setMessage(error->message()) 72 .setMessage(error->message())
73 .setCode(error->code()).build(); 73 .setCode(error->code()).build();
74 m_callback->sendSuccess(Maybe<protocol::Array<String>>(), Maybe<protocol ::Array<protocol::Value>>(), std::move(errorObject)); 74 m_callback->sendSuccess(Maybe<protocol::Array<String>>(), Maybe<protocol ::Array<protocol::Value>>(), std::move(errorObject));
75 } 75 }
76 76
77 private: 77 private:
78 explicit ExecuteSQLCallbackWrapper(PassOwnPtr<ExecuteSQLCallback> callback) : m_callback(std::move(callback)) { } 78 explicit ExecuteSQLCallbackWrapper(std::unique_ptr<ExecuteSQLCallback> callb ack) : m_callback(std::move(callback)) { }
79 OwnPtr<ExecuteSQLCallback> m_callback; 79 std::unique_ptr<ExecuteSQLCallback> m_callback;
80 }; 80 };
81 81
82 class StatementCallback final : public SQLStatementCallback { 82 class StatementCallback final : public SQLStatementCallback {
83 public: 83 public:
84 static StatementCallback* create(PassRefPtr<ExecuteSQLCallbackWrapper> reque stCallback) 84 static StatementCallback* create(PassRefPtr<ExecuteSQLCallbackWrapper> reque stCallback)
85 { 85 {
86 return new StatementCallback(requestCallback); 86 return new StatementCallback(requestCallback);
87 } 87 }
88 88
89 ~StatementCallback() override { } 89 ~StatementCallback() override { }
90 90
91 DEFINE_INLINE_VIRTUAL_TRACE() 91 DEFINE_INLINE_VIRTUAL_TRACE()
92 { 92 {
93 SQLStatementCallback::trace(visitor); 93 SQLStatementCallback::trace(visitor);
94 } 94 }
95 95
96 bool handleEvent(SQLTransaction*, SQLResultSet* resultSet) override 96 bool handleEvent(SQLTransaction*, SQLResultSet* resultSet) override
97 { 97 {
98 SQLResultSetRowList* rowList = resultSet->rows(); 98 SQLResultSetRowList* rowList = resultSet->rows();
99 99
100 OwnPtr<protocol::Array<String>> columnNames = protocol::Array<String>::c reate(); 100 std::unique_ptr<protocol::Array<String>> columnNames = protocol::Array<S tring>::create();
101 const Vector<String>& columns = rowList->columnNames(); 101 const Vector<String>& columns = rowList->columnNames();
102 for (size_t i = 0; i < columns.size(); ++i) 102 for (size_t i = 0; i < columns.size(); ++i)
103 columnNames->addItem(columns[i]); 103 columnNames->addItem(columns[i]);
104 104
105 OwnPtr<protocol::Array<protocol::Value>> values = protocol::Array<protoc ol::Value>::create(); 105 std::unique_ptr<protocol::Array<protocol::Value>> values = protocol::Arr ay<protocol::Value>::create();
106 const Vector<SQLValue>& data = rowList->values(); 106 const Vector<SQLValue>& data = rowList->values();
107 for (size_t i = 0; i < data.size(); ++i) { 107 for (size_t i = 0; i < data.size(); ++i) {
108 const SQLValue& value = rowList->values()[i]; 108 const SQLValue& value = rowList->values()[i];
109 switch (value.getType()) { 109 switch (value.getType()) {
110 case SQLValue::StringValue: values->addItem(protocol::StringValue::c reate(value.string())); break; 110 case SQLValue::StringValue: values->addItem(protocol::StringValue::c reate(value.string())); break;
111 case SQLValue::NumberValue: values->addItem(protocol::FundamentalVal ue::create(value.number())); break; 111 case SQLValue::NumberValue: values->addItem(protocol::FundamentalVal ue::create(value.number())); break;
112 case SQLValue::NullValue: values->addItem(protocol::Value::null()); break; 112 case SQLValue::NullValue: values->addItem(protocol::Value::null()); break;
113 } 113 }
114 } 114 }
115 m_requestCallback->get()->sendSuccess(std::move(columnNames), std::move( values), Maybe<protocol::Database::Error>()); 115 m_requestCallback->get()->sendSuccess(std::move(columnNames), std::move( values), Maybe<protocol::Database::Error>());
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 } 280 }
281 281
282 void InspectorDatabaseAgent::restore() 282 void InspectorDatabaseAgent::restore()
283 { 283 {
284 if (m_state->booleanProperty(DatabaseAgentState::databaseAgentEnabled, false )) { 284 if (m_state->booleanProperty(DatabaseAgentState::databaseAgentEnabled, false )) {
285 ErrorString error; 285 ErrorString error;
286 enable(&error); 286 enable(&error);
287 } 287 }
288 } 288 }
289 289
290 void InspectorDatabaseAgent::getDatabaseTableNames(ErrorString* error, const Str ing& databaseId, OwnPtr<protocol::Array<String>>* names) 290 void InspectorDatabaseAgent::getDatabaseTableNames(ErrorString* error, const Str ing& databaseId, std::unique_ptr<protocol::Array<String>>* names)
291 { 291 {
292 if (!m_enabled) { 292 if (!m_enabled) {
293 *error = "Database agent is not enabled"; 293 *error = "Database agent is not enabled";
294 return; 294 return;
295 } 295 }
296 296
297 *names = protocol::Array<String>::create(); 297 *names = protocol::Array<String>::create();
298 298
299 blink::Database* database = databaseForId(databaseId); 299 blink::Database* database = databaseForId(databaseId);
300 if (database) { 300 if (database) {
301 Vector<String> tableNames = database->tableNames(); 301 Vector<String> tableNames = database->tableNames();
302 unsigned length = tableNames.size(); 302 unsigned length = tableNames.size();
303 for (unsigned i = 0; i < length; ++i) 303 for (unsigned i = 0; i < length; ++i)
304 (*names)->addItem(tableNames[i]); 304 (*names)->addItem(tableNames[i]);
305 } 305 }
306 } 306 }
307 307
308 void InspectorDatabaseAgent::executeSQL(ErrorString*, const String& databaseId, const String& query, PassOwnPtr<ExecuteSQLCallback> prpRequestCallback) 308 void InspectorDatabaseAgent::executeSQL(ErrorString*, const String& databaseId, const String& query, std::unique_ptr<ExecuteSQLCallback> prpRequestCallback)
309 { 309 {
310 OwnPtr<ExecuteSQLCallback> requestCallback = std::move(prpRequestCallback); 310 std::unique_ptr<ExecuteSQLCallback> requestCallback = std::move(prpRequestCa llback);
311 311
312 if (!m_enabled) { 312 if (!m_enabled) {
313 requestCallback->sendFailure("Database agent is not enabled"); 313 requestCallback->sendFailure("Database agent is not enabled");
314 return; 314 return;
315 } 315 }
316 316
317 blink::Database* database = databaseForId(databaseId); 317 blink::Database* database = databaseForId(databaseId);
318 if (!database) { 318 if (!database) {
319 requestCallback->sendFailure("Database not found"); 319 requestCallback->sendFailure("Database not found");
320 return; 320 return;
(...skipping 24 matching lines...) Expand all
345 } 345 }
346 346
347 DEFINE_TRACE(InspectorDatabaseAgent) 347 DEFINE_TRACE(InspectorDatabaseAgent)
348 { 348 {
349 visitor->trace(m_page); 349 visitor->trace(m_page);
350 visitor->trace(m_resources); 350 visitor->trace(m_resources);
351 InspectorBaseAgent::trace(visitor); 351 InspectorBaseAgent::trace(visitor);
352 } 352 }
353 353
354 } // namespace blink 354 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698