• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2023 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef ICING_SCHEMA_BACKUP_SCHEMA_PRODUCER_H_
16 #define ICING_SCHEMA_BACKUP_SCHEMA_PRODUCER_H_
17 
18 #include "icing/text_classifier/lib3/utils/base/statusor.h"
19 #include "icing/feature-flags.h"
20 #include "icing/proto/schema.pb.h"
21 #include "icing/schema/section-manager.h"
22 
23 namespace icing {
24 namespace lib {
25 
26 class BackupSchemaProducer {
27  public:
BackupSchemaProducer(const FeatureFlags * feature_flags)28   explicit BackupSchemaProducer(const FeatureFlags* feature_flags)
29       : feature_flags_(*feature_flags) {}
30 
31   // Creates a BackupSchemaResult based off of schema.
32   // If schema doesn't require a backup schema (because it is fully
33   // rollback-proof) then `BackupSchemaResult::backup_schema_produced` will be
34   // false. No guarantee is made about the state of
35   // `BackupSchemaResult::backup_schema` in this case.
36   // If schema *does* require a backup schema, then
37   //`BackupSchemaResult::backup_schema_produced` will be true and
38   // `BackupSchemaResult::backup_schema` will be populated accordingly.
39   // Returns:
40   //   - On success, a BackupSchemaResult
41   //   - INTERNAL_ERROR if the schema is inconsistent with the type_manager.
42   struct BackupSchemaResult {
BackupSchemaResultBackupSchemaResult43     BackupSchemaResult() : backup_schema(), backup_schema_produced(false) {}
BackupSchemaResultBackupSchemaResult44     explicit BackupSchemaResult(SchemaProto backup_schema_in)
45         : backup_schema(backup_schema_in), backup_schema_produced(true) {}
46 
47     SchemaProto backup_schema;
48     bool backup_schema_produced;
49   };
50   libtextclassifier3::StatusOr<BackupSchemaProducer::BackupSchemaResult>
51   Produce(const SchemaProto& schema, const SectionManager& type_manager);
52 
53  private:
54   const FeatureFlags& feature_flags_;
55 };
56 
57 }  // namespace lib
58 }  // namespace icing
59 
60 #endif  // ICING_SCHEMA_BACKUP_SCHEMA_PRODUCER_H_
61