File: blob_storage_constants.cc

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (102 lines) | stat: -rw-r--r-- 4,014 bytes parent folder | download | duplicates (9)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "storage/browser/blob/blob_storage_constants.h"

#include <ostream>

#include "base/check.h"
#include "base/command_line.h"
#include "base/strings/string_number_conversions.h"

namespace storage {
namespace {
// Specifies the minimum file size.
constexpr const char kBlobFileTransportMinFileSizeSwitch[] =
    "blob-transport-file-min-size";
// Specifies the maximum file size.
constexpr const char kBlobFileTransportMaxFileSizeSwitch[] =
    "blob-transport-file-max-size";
// Specifies a custom maximum size of the shared memory segments used to
// transport blob.
const char kBlobSharedMemoryTransportMaxSizeSwitch[] =
    "blob-transport-shared-memory-max-size";
}  // namespace

static_assert(kDefaultIPCMemorySize < kDefaultSharedMemorySize,
              "IPC transport size must be smaller than shared memory size.");
static_assert(kDefaultMinPageFileSize < kDefaultMaxPageFileSize,
              "Min page file size must be less than max.");
static_assert(kDefaultMinPageFileSize < kDefaultMaxBlobInMemorySpace,
              "Page file size must be less than in-memory space.");

BlobStorageLimits::BlobStorageLimits() {
  base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
  if (command_line->HasSwitch(kBlobFileTransportByFileTriggerSwitch))
      [[unlikely]] {
    CHECK(base::StringToUint64(command_line->GetSwitchValueASCII(
                                   kBlobFileTransportByFileTriggerSwitch),
                               &override_file_transport_min_size))
        << "Unable to parse "
        << command_line->GetSwitchValueASCII(
               kBlobFileTransportByFileTriggerSwitch);
  }
  if (command_line->HasSwitch(kBlobSharedMemoryTransportMaxSizeSwitch))
      [[unlikely]] {
    CHECK(base::StringToSizeT(command_line->GetSwitchValueASCII(
                                  kBlobSharedMemoryTransportMaxSizeSwitch),
                              &max_shared_memory_size))
        << "Unable to parse "
        << command_line->GetSwitchValueASCII(
               kBlobSharedMemoryTransportMaxSizeSwitch);
  }
  if (command_line->HasSwitch(kBlobFileTransportMinFileSizeSwitch))
      [[unlikely]] {
    CHECK(base::StringToUint64(
        command_line->GetSwitchValueASCII(kBlobFileTransportMinFileSizeSwitch),
        &min_page_file_size))
        << "Unable to parse "
        << command_line->GetSwitchValueASCII(
               kBlobSharedMemoryTransportMaxSizeSwitch);
  }
  if (command_line->HasSwitch(kBlobFileTransportMaxFileSizeSwitch))
      [[unlikely]] {
    CHECK(base::StringToUint64(
        command_line->GetSwitchValueASCII(kBlobFileTransportMaxFileSizeSwitch),
        &max_file_size))
        << "Unable to parse "
        << command_line->GetSwitchValueASCII(
               kBlobSharedMemoryTransportMaxSizeSwitch);
  }
  CHECK(IsValid());
}
BlobStorageLimits::~BlobStorageLimits() {}

BlobStorageLimits::BlobStorageLimits(const BlobStorageLimits&) = default;
BlobStorageLimits& BlobStorageLimits::operator=(const BlobStorageLimits&) =
    default;

bool BlobStorageLimits::IsValid() const {
  return max_ipc_memory_size <= max_bytes_data_item_size &&
         max_shared_memory_size <= max_bytes_data_item_size &&
         min_page_file_size <= max_file_size &&
         min_page_file_size <= max_blob_in_memory_space &&
         effective_max_disk_space <= desired_max_disk_space;
}

bool BlobStatusIsError(BlobStatus status) {
  return static_cast<int>(status) <= static_cast<int>(BlobStatus::LAST_ERROR);
}

bool BlobStatusIsPending(BlobStatus status) {
  int status_int = static_cast<int>(status);
  return status_int >= static_cast<int>(BlobStatus::PENDING_QUOTA) &&
         status_int <= static_cast<int>(BlobStatus::LAST_PENDING);
}

bool BlobStatusIsBadIPC(BlobStatus status) {
  return status == BlobStatus::ERR_INVALID_CONSTRUCTION_ARGUMENTS;
}

}  // namespace storage