Movatterモバイル変換


[0]ホーム

URL:


Google Git
Sign in
chromium /chromium /src /refs/heads/main /. /sql /streaming_blob_handle.h
blob: 8b6d3a25002a28ac0220902ae40a623acb823582 [file] [log] [blame]
Evan Stade416f46f12025-06-18 15:42:39[diff] [blame]1// Copyright 2025 The Chromium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef SQL_STREAMING_BLOB_HANDLE_H_
6#define SQL_STREAMING_BLOB_HANDLE_H_
7
8#include"base/component_export.h"
9#include"base/containers/span.h"
10#include"base/functional/callback.h"
11#include"base/memory/raw_ptr.h"
12#include"base/types/pass_key.h"
13#include"sql/sqlite_result_code.h"
14
15struct sqlite3_blob;
16
17namespace sql{
18
19classDatabase;
20
21// Wraps a blob handle opened for streaming.
22// See https://www.sqlite.org/c3ref/blob_open.html
23// The handle will be closed when the instance is destroyed, or when an error
24// occurs.
25//
26// Use `sql::Database::GetStreamingBlob()` to get an instance of this class.
27// Callers are responsible for deleting this instance before attempting to
28// close, poison, or raze the database. Note that even deleting an instance may
29// run into an error which would cause the database's error callback to run.
30class COMPONENT_EXPORT(SQL)StreamingBlobHandle{
31public:
32StreamingBlobHandle(
33base::PassKey<sql::Database>,
34 sqlite3_blob* blob,
35base::OnceCallback<void(SqliteResultCode,constchar*)> done_callback);
36~StreamingBlobHandle();
37
38// Move ctor is allowed to facilitate use with optional.
39StreamingBlobHandle(StreamingBlobHandle&&);
40
41StreamingBlobHandle&operator=(StreamingBlobHandle&&)=delete;
42StreamingBlobHandle(constStreamingBlobHandle&)=delete;
43StreamingBlobHandle&operator=(constStreamingBlobHandle&)=delete;
44
45// These return true for success. If they fail once, calling them again
46// will CHECK.
47[[nodiscard]]boolRead(int offset,base::span<uint8_t>into);
48[[nodiscard]]boolWrite(int offset,base::span<constuint8_t>from);
49
50private:
51// This handle is owned.
52 raw_ptr<sqlite3_blob> blob_handle_;
53
54// This callback is invoked when the blob is closed, either due to an error or
55// when `this` is destroyed normally. See `sql::Database::OnSqliteError()` for
56// documentation of the parameters.
57base::OnceCallback<void(SqliteResultCode,constchar*)> done_callback_;
58};
59
60}// namespace sql
61
62#endif// SQL_STREAMING_BLOB_HANDLE_H_

[8]ページ先頭

©2009-2025 Movatter.jp