blob: bfd6f046a0729d45d6755eddf8a7c921a3d0fe55 [file] [log] [blame]
Jae Hoon Kim38de3b12020-04-29 19:41:23 -07001//
2// Copyright (C) 2020 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
16
17#include "update_engine/excluder_chromeos.h"
18
19#include <memory>
20#include <vector>
21
22#include <base/logging.h>
23#include <base/strings/string_piece.h>
24#include <base/strings/string_number_conversions.h>
25#include <base/strings/string_split.h>
26
27#include "update_engine/common/constants.h"
28#include "update_engine/common/prefs.h"
29#include "update_engine/system_state.h"
30
31using std::string;
32using std::vector;
33
34namespace chromeos_update_engine {
35
36std::unique_ptr<ExcluderInterface> CreateExcluder(PrefsInterface* prefs) {
37 return std::make_unique<ExcluderChromeOS>(prefs);
38}
39
40ExcluderChromeOS::ExcluderChromeOS(PrefsInterface* prefs) : prefs_(prefs) {}
41
42bool ExcluderChromeOS::Exclude(const string& name) {
43 auto key = prefs_->CreateSubKey({kExclusionPrefsSubDir, name});
44 return prefs_->SetString(key, "");
45}
46
47bool ExcluderChromeOS::IsExcluded(const string& name) {
48 auto key = prefs_->CreateSubKey({kExclusionPrefsSubDir, name});
49 return prefs_->Exists(key);
50}
51
52bool ExcluderChromeOS::Reset() {
53 bool ret = true;
54 vector<string> keys;
55 if (!prefs_->GetSubKeys(kExclusionPrefsSubDir, &keys))
56 return false;
57 for (const auto& key : keys)
58 if (!(ret &= prefs_->Delete(key)))
59 LOG(ERROR) << "Failed to delete exclusion pref for " << key;
60 return ret;
61}
62
63} // namespace chromeos_update_engine