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

Side by Side Diff: content/browser/indexed_db/indexed_db_cursor.cc

Issue 2941353002: Indexed DB: Use BindOnce / OnceCallback / OnceClosure where applicable (Closed)
Patch Set: Created 3 years, 6 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 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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_cursor.h" 5 #include "content/browser/indexed_db/indexed_db_cursor.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 16 matching lines...) Expand all
27 // so this would be ignored. 27 // so this would be ignored.
28 IndexedDBDatabaseError CreateCursorClosedError() { 28 IndexedDBDatabaseError CreateCursorClosedError() {
29 return IndexedDBDatabaseError(blink::kWebIDBDatabaseExceptionUnknownError, 29 return IndexedDBDatabaseError(blink::kWebIDBDatabaseExceptionUnknownError,
30 "The cursor has been closed."); 30 "The cursor has been closed.");
31 } 31 }
32 32
33 leveldb::Status InvokeOrSucceed(base::WeakPtr<IndexedDBCursor> weak_cursor, 33 leveldb::Status InvokeOrSucceed(base::WeakPtr<IndexedDBCursor> weak_cursor,
34 IndexedDBTransaction::Operation operation, 34 IndexedDBTransaction::Operation operation,
35 IndexedDBTransaction* transaction) { 35 IndexedDBTransaction* transaction) {
36 if (weak_cursor) 36 if (weak_cursor)
37 return operation.Run(transaction); 37 return std::move(operation).Run(transaction);
38 return leveldb::Status::OK(); 38 return leveldb::Status::OK();
39 } 39 }
40 40
41 // This allows us to bind a function with a return value to a weak ptr, and if 41 // This allows us to bind a function with a return value to a weak ptr, and if
42 // the weak pointer is invalidated then we just return a default (success). 42 // the weak pointer is invalidated then we just return a default (success).
43 template <typename Functor, typename... Args> 43 template <typename Functor, typename... Args>
44 IndexedDBTransaction::Operation BindWeakOperation( 44 IndexedDBTransaction::Operation BindWeakOperation(
45 Functor&& functor, 45 Functor&& functor,
46 base::WeakPtr<IndexedDBCursor> weak_cursor, 46 base::WeakPtr<IndexedDBCursor> weak_cursor,
47 Args&&... args) { 47 Args&&... args) {
48 DCHECK(weak_cursor); 48 DCHECK(weak_cursor);
49 IndexedDBCursor* cursor_ptr = weak_cursor.get(); 49 IndexedDBCursor* cursor_ptr = weak_cursor.get();
50 return base::Bind( 50 return base::BindOnce(&InvokeOrSucceed, std::move(weak_cursor),
51 &InvokeOrSucceed, std::move(weak_cursor), 51 base::BindOnce(std::forward<Functor>(functor),
52 base::Bind(std::forward<Functor>(functor), base::Unretained(cursor_ptr), 52 base::Unretained(cursor_ptr),
53 std::forward<Args>(args)...)); 53 std::forward<Args>(args)...));
54 } 54 }
55 55
56 } // namespace 56 } // namespace
57 57
58 IndexedDBCursor::IndexedDBCursor( 58 IndexedDBCursor::IndexedDBCursor(
59 std::unique_ptr<IndexedDBBackingStore::Cursor> cursor, 59 std::unique_ptr<IndexedDBBackingStore::Cursor> cursor,
60 indexed_db::CursorType cursor_type, 60 indexed_db::CursorType cursor_type,
61 blink::WebIDBTaskType task_type, 61 blink::WebIDBTaskType task_type,
62 IndexedDBTransaction* transaction) 62 IndexedDBTransaction* transaction)
63 : task_type_(task_type), 63 : task_type_(task_type),
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 return; 274 return;
275 IDB_ASYNC_TRACE_END("IndexedDBCursor::open", this); 275 IDB_ASYNC_TRACE_END("IndexedDBCursor::open", this);
276 IDB_TRACE("IndexedDBCursor::Close"); 276 IDB_TRACE("IndexedDBCursor::Close");
277 closed_ = true; 277 closed_ = true;
278 cursor_.reset(); 278 cursor_.reset();
279 saved_cursor_.reset(); 279 saved_cursor_.reset();
280 transaction_ = nullptr; 280 transaction_ = nullptr;
281 } 281 }
282 282
283 } // namespace content 283 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/indexed_db/indexed_db_context_impl.cc ('k') | content/browser/indexed_db/indexed_db_database.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698