File: database_helpers.h

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (92 lines) | stat: -rw-r--r-- 3,896 bytes parent folder | download | duplicates (8)
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
// Copyright 2017 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_BACKGROUND_FETCH_STORAGE_DATABASE_HELPERS_H_
#define CONTENT_BROWSER_BACKGROUND_FETCH_STORAGE_DATABASE_HELPERS_H_

#include <string>

#include "content/browser/background_fetch/background_fetch.pb.h"
#include "content/common/background_fetch/background_fetch_types.h"
#include "content/common/content_export.h"
#include "content/public/browser/background_fetch_delegate.h"
#include "third_party/blink/public/common/service_worker/service_worker_status_code.h"

namespace content {
namespace background_fetch {

// The database schema is content/browser/background_fetch/storage/README.md.
// When making any changes to these keys or the related functions, you must
// update the README.md file as well.

// Warning: registration |developer_id|s may contain kSeparator characters.
const char kSeparator[] = "_";

const char kActiveRegistrationUniqueIdKeyPrefix[] =
    "bgfetch_active_registration_unique_id_";
const char kRegistrationKeyPrefix[] = "bgfetch_registration_";
const char kUIOptionsKeyPrefix[] = "bgfetch_ui_options_";
const char kPendingRequestKeyPrefix[] = "bgfetch_pending_request_";
const char kActiveRequestKeyPrefix[] = "bgfetch_active_request_";
const char kCompletedRequestKeyPrefix[] = "bgfetch_completed_request_";
const char kStorageVersionKeyPrefix[] = "bgfetch_storage_version_";

// Database Keys.
CONTENT_EXPORT std::string ActiveRegistrationUniqueIdKey(
    const std::string& developer_id);

CONTENT_EXPORT std::string RegistrationKey(const std::string& unique_id);

std::string UIOptionsKey(const std::string& unique_id);

std::string PendingRequestKeyPrefix(const std::string& unique_id);

std::string PendingRequestKey(const std::string& unique_id, int request_index);

std::string ActiveRequestKeyPrefix(const std::string& unique_id);

std::string ActiveRequestKey(const std::string& unique_id, int request_index);

std::string CompletedRequestKeyPrefix(const std::string& unique_id);

std::string CompletedRequestKey(const std::string& unique_id,
                                int request_index);

CONTENT_EXPORT std::string StorageVersionKey(const std::string& unique_id);

// Database status.
enum class DatabaseStatus { kOk, kFailed, kNotFound };

DatabaseStatus ToDatabaseStatus(blink::ServiceWorkerStatusCode status);

// Converts the |metadata_proto| to a BackgroundFetchRegistration object.
bool ToBackgroundFetchRegistration(
    const proto::BackgroundFetchMetadata& metadata_proto,
    blink::mojom::BackgroundFetchRegistrationData* registration_data);

// Gets the storage key for a `BackgroundFetchMetadata`, falling back to
// `origin` if `storage_key` is not set.  If neither is set, this returns
// a key with an opaque origin.
CONTENT_EXPORT blink::StorageKey GetMetadataStorageKey(
    const content::proto::BackgroundFetchMetadata& metadata_proto);

bool MojoFailureReasonFromRegistrationProto(
    proto::BackgroundFetchRegistration_BackgroundFetchFailureReason
        proto_failure_reason,
    blink::mojom::BackgroundFetchFailureReason* failure_reason);

// Utility functions to make sure the request URLs are unique, since
// Cache Storage does not support duplicate URLs yet.
// Use `MakeCacheUrlUnique` before writing to the cache, and
// `RemoveUniqueParamFromCacheURL` when querying from the cache.
CONTENT_EXPORT GURL MakeCacheUrlUnique(const GURL& url,
                                       const std::string& unique_id,
                                       size_t request_index);
CONTENT_EXPORT GURL RemoveUniqueParamFromCacheURL(const GURL& url,
                                                  const std::string& unique_id);

}  // namespace background_fetch
}  // namespace content

#endif  // CONTENT_BROWSER_BACKGROUND_FETCH_STORAGE_DATABASE_HELPERS_H_