blob: 16def259192b276869c57153c5ffab5c3d82e494 [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) {}
22 OmahaRequestParams(const std::string& in_machine_id,
23 const std::string& in_user_id,
24 const std::string& in_os_platform,
25 const std::string& in_os_version,
26 const std::string& in_os_sp,
27 const std::string& in_os_board,
28 const std::string& in_app_id,
29 const std::string& in_app_version,
30 const std::string& in_app_lang,
31 const std::string& in_app_track,
Andrew de los Reyes3f0303a2010-07-15 22:35:35 -070032 const bool in_delta_okay,
Darin Petkova4a8a8c2010-07-15 22:21:12 -070033 const std::string& in_update_url)
34 : machine_id(in_machine_id),
35 user_id(in_user_id),
36 os_platform(in_os_platform),
37 os_version(in_os_version),
38 os_sp(in_os_sp),
39 os_board(in_os_board),
40 app_id(in_app_id),
41 app_version(in_app_version),
42 app_lang(in_app_lang),
43 app_track(in_app_track),
Andrew de los Reyes3f0303a2010-07-15 22:35:35 -070044 delta_okay(in_delta_okay),
Darin Petkova4a8a8c2010-07-15 22:21:12 -070045 update_url(in_update_url) {}
46
47 std::string machine_id;
48 std::string user_id;
49 std::string os_platform;
50 std::string os_version;
51 std::string os_sp;
52 std::string os_board;
53 std::string app_id;
54 std::string app_version;
55 std::string app_lang;
56 std::string app_track;
Andrew de los Reyes3f0303a2010-07-15 22:35:35 -070057 bool delta_okay; // If this client can accept a delta
Darin Petkova4a8a8c2010-07-15 22:21:12 -070058
59 std::string update_url;
60
61 // Suggested defaults
62 static const char* const kAppId;
63 static const char* const kOsPlatform;
64 static const char* const kOsVersion;
65 static const char* const kUpdateUrl;
66};
67
68class OmahaRequestDeviceParams : public OmahaRequestParams {
69 public:
Darin Petkov5a7f5652010-07-22 21:40:09 -070070 OmahaRequestDeviceParams() {}
Darin Petkova4a8a8c2010-07-15 22:21:12 -070071
Darin Petkov5a7f5652010-07-22 21:40:09 -070072 // Initializes all the data in the object. Non-empty
73 // |in_app_version| or |in_update_url| prevents automatic detection
74 // of the parameter. Returns true on success, false otherwise.
75 bool Init(const std::string& in_app_version,
76 const std::string& in_update_url);
Darin Petkova4a8a8c2010-07-15 22:21:12 -070077
78 // For unit-tests.
79 void set_root(const std::string& root) { root_ = root; }
80
81 private:
82 // Gets a machine-local ID (for now, first MAC address we find).
83 bool GetMachineId(std::string* out_id) const;
84
85 // Fetches the value for a given key from
86 // /mnt/stateful_partition/etc/lsb-release if possible. Failing that,
87 // it looks for the key in /etc/lsb-release.
88 std::string GetLsbValue(const std::string& key,
89 const std::string& default_value) const;
90
91 // Gets the machine type (e.g. "i686").
92 std::string GetMachineType() const;
93
94 // When reading files, prepend root_ to the paths. Useful for testing.
95 std::string root_;
96
97 DISALLOW_COPY_AND_ASSIGN(OmahaRequestDeviceParams);
98};
99
100} // namespace chromeos_update_engine
101
102#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_OMAHA_REQUEST_PARAMS_H__