1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
content / browser / indexed_db / status.h [blame]
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_BROWSER_INDEXED_DB_STATUS_H_
#define CONTENT_BROWSER_INDEXED_DB_STATUS_H_
#include <optional>
#include <string>
#include "base/strings/string_util.h"
#include "content/common/content_export.h"
#include "third_party/leveldatabase/src/include/leveldb/status.h"
namespace content::indexed_db {
// A backing store status code and message.
// This thin leveldb::Status wrapper aids SQLite backing store prototyping.
class CONTENT_EXPORT Status {
public:
Status() noexcept;
Status(const Status& rhs) noexcept;
explicit Status(const leveldb::Status& status) noexcept;
~Status();
Status& operator=(const Status& rhs);
Status& operator=(const leveldb::Status& rhs);
// Create a corresponding success or error status.
static Status OK();
static Status NotFound(const std::string& msg,
const std::string& msg2 = base::EmptyString());
static Status Corruption(const std::string& msg,
const std::string& msg2 = base::EmptyString());
static Status NotSupported(const std::string& msg,
const std::string& msg2 = base::EmptyString());
static Status InvalidArgument(const std::string& msg,
const std::string& msg2 = base::EmptyString());
static Status IOError(const std::string& msg,
const std::string& msg2 = base::EmptyString());
// Returns true iff the status indicates the corresponding success or error.
bool ok() const { return !status_ || status_->ok(); }
bool IsNotFound() const;
bool IsCorruption() const;
bool IsIOError() const;
bool IsNotSupportedError() const;
bool IsInvalidArgument() const;
// Return a string representation of this status suitable for printing.
// Returns the string "OK" for success.
std::string ToString() const;
leveldb::Status leveldb_status() const {
return status_.value_or(leveldb::Status::OK());
}
private:
std::optional<leveldb::Status> status_;
};
} // namespace content::indexed_db
#endif // CONTENT_BROWSER_INDEXED_DB_STATUS_H_