summaryrefslogtreecommitdiff
path: root/cros/dlcservice_chromeos.cc
blob: e510c1d1e14f292b80e10e1bfd4c8129a296e7e0 (plain)
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
//
// Copyright (C) 2018 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#include "update_engine/cros/dlcservice_chromeos.h"

#include <brillo/errors/error.h>
#include <dlcservice/proto_bindings/dlcservice.pb.h>
// NOLINTNEXTLINE(build/include_alpha) "dbus-proxies.h" needs "dlcservice.pb.h"
#include <dlcservice/dbus-proxies.h>

#include "update_engine/cros/dbus_connection.h"

using std::string;
using std::vector;

namespace chromeos_update_engine {

namespace {
org::chromium::DlcServiceInterfaceProxy GetDlcServiceProxy() {
  return {DBusConnection::Get()->GetDBus()};
}
}  // namespace

std::unique_ptr<DlcServiceInterface> CreateDlcService() {
  return std::make_unique<DlcServiceChromeOS>();
}

bool DlcServiceChromeOS::GetDlcsToUpdate(vector<string>* dlc_ids) {
  if (!dlc_ids)
    return false;
  dlc_ids->clear();

  brillo::ErrorPtr err;
  if (!GetDlcServiceProxy().GetDlcsToUpdate(dlc_ids, &err)) {
    LOG(ERROR) << "dlcservice failed to return DLCs that need to be updated. "
               << "ErrorCode=" << err->GetCode()
               << ", ErrMsg=" << err->GetMessage();
    dlc_ids->clear();
    return false;
  }
  return true;
}

bool DlcServiceChromeOS::InstallCompleted(const vector<string>& dlc_ids) {
  brillo::ErrorPtr err;
  if (!GetDlcServiceProxy().InstallCompleted(dlc_ids, &err)) {
    LOG(ERROR) << "dlcservice failed to complete install. ErrCode="
               << err->GetCode() << ", ErrMsg=" << err->GetMessage();
    return false;
  }
  return true;
}

bool DlcServiceChromeOS::UpdateCompleted(const vector<string>& dlc_ids) {
  brillo::ErrorPtr err;
  if (!GetDlcServiceProxy().UpdateCompleted(dlc_ids, &err)) {
    LOG(ERROR) << "dlcservice failed to complete updated. ErrCode="
               << err->GetCode() << ", ErrMsg=" << err->GetMessage();
    return false;
  }
  return true;
}

}  // namespace chromeos_update_engine