blob: 9c372584d5a176fb966f344704ef5d547a547e88 [file] [log] [blame]
Darin Petkova4a8a8c2010-07-15 22:21:12 -07001// Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_OMAHA_REQUEST_PARAMS_H__
6#define CHROMEOS_PLATFORM_UPDATE_ENGINE_OMAHA_REQUEST_PARAMS_H__
7
8#include <string>
9
10#include "base/basictypes.h"
11
12// This gathers local system information and prepares info used by the
13// Omaha request action.
14
15namespace chromeos_update_engine {
16
17// This struct encapsulates the data Omaha gets for the request.
18// These strings in this struct should not be XML escaped.
19struct OmahaRequestParams {
20 OmahaRequestParams()
21 : os_platform(kOsPlatform), os_version(kOsVersion), app_id(kAppId) {}
Darin Petkov84c763c2010-07-29 16:27:58 -070022 OmahaRequestParams(const std::string& in_os_platform,
Darin Petkova4a8a8c2010-07-15 22:21:12 -070023 const std::string& in_os_version,
24 const std::string& in_os_sp,
25 const std::string& in_os_board,
26 const std::string& in_app_id,
27 const std::string& in_app_version,
28 const std::string& in_app_lang,
29 const std::string& in_app_track,
Andrew de los Reyes3f0303a2010-07-15 22:35:35 -070030 const bool in_delta_okay,
Darin Petkova4a8a8c2010-07-15 22:21:12 -070031 const std::string& in_update_url)
Darin Petkov84c763c2010-07-29 16:27:58 -070032 : os_platform(in_os_platform),
Darin Petkova4a8a8c2010-07-15 22:21:12 -070033 os_version(in_os_version),
34 os_sp(in_os_sp),
35 os_board(in_os_board),
36 app_id(in_app_id),
37 app_version(in_app_version),
38 app_lang(in_app_lang),
39 app_track(in_app_track),
Andrew de los Reyes3f0303a2010-07-15 22:35:35 -070040 delta_okay(in_delta_okay),
Darin Petkova4a8a8c2010-07-15 22:21:12 -070041 update_url(in_update_url) {}
42
Darin Petkova4a8a8c2010-07-15 22:21:12 -070043 std::string os_platform;
44 std::string os_version;
45 std::string os_sp;
46 std::string os_board;
47 std::string app_id;
48 std::string app_version;
49 std::string app_lang;
50 std::string app_track;
Andrew de los Reyes3f0303a2010-07-15 22:35:35 -070051 bool delta_okay; // If this client can accept a delta
Darin Petkova4a8a8c2010-07-15 22:21:12 -070052
53 std::string update_url;
54
55 // Suggested defaults
56 static const char* const kAppId;
57 static const char* const kOsPlatform;
58 static const char* const kOsVersion;
59 static const char* const kUpdateUrl;
60};
61
62class OmahaRequestDeviceParams : public OmahaRequestParams {
63 public:
Darin Petkov5a7f5652010-07-22 21:40:09 -070064 OmahaRequestDeviceParams() {}
Darin Petkova4a8a8c2010-07-15 22:21:12 -070065
Darin Petkov5a7f5652010-07-22 21:40:09 -070066 // Initializes all the data in the object. Non-empty
67 // |in_app_version| or |in_update_url| prevents automatic detection
68 // of the parameter. Returns true on success, false otherwise.
69 bool Init(const std::string& in_app_version,
70 const std::string& in_update_url);
Darin Petkova4a8a8c2010-07-15 22:21:12 -070071
72 // For unit-tests.
73 void set_root(const std::string& root) { root_ = root; }
74
75 private:
Darin Petkova4a8a8c2010-07-15 22:21:12 -070076 // Fetches the value for a given key from
77 // /mnt/stateful_partition/etc/lsb-release if possible. Failing that,
78 // it looks for the key in /etc/lsb-release.
79 std::string GetLsbValue(const std::string& key,
80 const std::string& default_value) const;
81
82 // Gets the machine type (e.g. "i686").
83 std::string GetMachineType() const;
84
85 // When reading files, prepend root_ to the paths. Useful for testing.
86 std::string root_;
87
88 DISALLOW_COPY_AND_ASSIGN(OmahaRequestDeviceParams);
89};
90
91} // namespace chromeos_update_engine
92
93#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_OMAHA_REQUEST_PARAMS_H__