blob: 551a3a3d774924f54b82430737f8d02e69be1b82 [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,
Darin Petkovfbb40092010-07-29 17:05:50 -070030 const std::string& in_hardware_class,
Andrew de los Reyes3f0303a2010-07-15 22:35:35 -070031 const bool in_delta_okay,
Darin Petkova4a8a8c2010-07-15 22:21:12 -070032 const std::string& in_update_url)
Darin Petkov84c763c2010-07-29 16:27:58 -070033 : os_platform(in_os_platform),
Darin Petkova4a8a8c2010-07-15 22:21:12 -070034 os_version(in_os_version),
35 os_sp(in_os_sp),
36 os_board(in_os_board),
37 app_id(in_app_id),
38 app_version(in_app_version),
39 app_lang(in_app_lang),
40 app_track(in_app_track),
Darin Petkovfbb40092010-07-29 17:05:50 -070041 hardware_class(in_hardware_class),
Andrew de los Reyes3f0303a2010-07-15 22:35:35 -070042 delta_okay(in_delta_okay),
Darin Petkova4a8a8c2010-07-15 22:21:12 -070043 update_url(in_update_url) {}
44
Darin Petkova4a8a8c2010-07-15 22:21:12 -070045 std::string os_platform;
46 std::string os_version;
47 std::string os_sp;
48 std::string os_board;
49 std::string app_id;
50 std::string app_version;
51 std::string app_lang;
52 std::string app_track;
Darin Petkovfbb40092010-07-29 17:05:50 -070053 std::string hardware_class; // Hardware Qualification ID of the client
Andrew de los Reyes3f0303a2010-07-15 22:35:35 -070054 bool delta_okay; // If this client can accept a delta
Darin Petkova4a8a8c2010-07-15 22:21:12 -070055
56 std::string update_url;
57
58 // Suggested defaults
59 static const char* const kAppId;
60 static const char* const kOsPlatform;
61 static const char* const kOsVersion;
62 static const char* const kUpdateUrl;
63};
64
65class OmahaRequestDeviceParams : public OmahaRequestParams {
66 public:
Darin Petkov5a7f5652010-07-22 21:40:09 -070067 OmahaRequestDeviceParams() {}
Darin Petkova4a8a8c2010-07-15 22:21:12 -070068
Darin Petkov5a7f5652010-07-22 21:40:09 -070069 // Initializes all the data in the object. Non-empty
70 // |in_app_version| or |in_update_url| prevents automatic detection
71 // of the parameter. Returns true on success, false otherwise.
72 bool Init(const std::string& in_app_version,
73 const std::string& in_update_url);
Darin Petkova4a8a8c2010-07-15 22:21:12 -070074
75 // For unit-tests.
76 void set_root(const std::string& root) { root_ = root; }
77
78 private:
Darin Petkova4a8a8c2010-07-15 22:21:12 -070079 // Fetches the value for a given key from
80 // /mnt/stateful_partition/etc/lsb-release if possible. Failing that,
81 // it looks for the key in /etc/lsb-release.
82 std::string GetLsbValue(const std::string& key,
83 const std::string& default_value) const;
84
85 // Gets the machine type (e.g. "i686").
86 std::string GetMachineType() const;
87
Darin Petkovfbb40092010-07-29 17:05:50 -070088 // Returns the hardware qualification ID of the system, or empty
89 // string if the HWID is unavailable.
90 std::string GetHardwareClass() const;
91
Darin Petkova4a8a8c2010-07-15 22:21:12 -070092 // When reading files, prepend root_ to the paths. Useful for testing.
93 std::string root_;
94
95 DISALLOW_COPY_AND_ASSIGN(OmahaRequestDeviceParams);
96};
97
98} // namespace chromeos_update_engine
99
100#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_OMAHA_REQUEST_PARAMS_H__