Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(256)

Side by Side Diff: base/sys_info_chromeos.cc

Issue 2585633004: ozone: Allow ozone evdev/kvm features to be enabled without running on ChromeOS. (Closed)
Patch Set: fix bad rebase Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/sys_info.h" 5 #include "base/sys_info.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/base_switches.h"
11 #include "base/command_line.h"
10 #include "base/environment.h" 12 #include "base/environment.h"
11 #include "base/files/file.h" 13 #include "base/files/file.h"
12 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
13 #include "base/files/file_util.h" 15 #include "base/files/file_util.h"
14 #include "base/lazy_instance.h" 16 #include "base/lazy_instance.h"
15 #include "base/macros.h" 17 #include "base/macros.h"
16 #include "base/strings/string_number_conversions.h" 18 #include "base/strings/string_number_conversions.h"
17 #include "base/strings/string_piece.h" 19 #include "base/strings/string_piece.h"
18 #include "base/strings/string_split.h" 20 #include "base/strings/string_split.h"
19 #include "base/strings/string_tokenizer.h" 21 #include "base/strings/string_tokenizer.h"
(...skipping 23 matching lines...) Expand all
43 const char kLsbReleaseTimeKey[] = "LSB_RELEASE_TIME"; // Seconds since epoch 45 const char kLsbReleaseTimeKey[] = "LSB_RELEASE_TIME"; // Seconds since epoch
44 46
45 const char kLsbReleaseSourceKey[] = "lsb-release"; 47 const char kLsbReleaseSourceKey[] = "lsb-release";
46 const char kLsbReleaseSourceEnv[] = "env"; 48 const char kLsbReleaseSourceEnv[] = "env";
47 const char kLsbReleaseSourceFile[] = "file"; 49 const char kLsbReleaseSourceFile[] = "file";
48 50
49 class ChromeOSVersionInfo { 51 class ChromeOSVersionInfo {
50 public: 52 public:
51 ChromeOSVersionInfo() { 53 ChromeOSVersionInfo() {
52 Parse(); 54 Parse();
55
56 // Running as system compositor by default when running on ChromeOS.
57 is_running_as_system_compositor_ = is_running_on_chromeos_;
58
59 CommandLine* command_line = CommandLine::ForCurrentProcess();
60 if (command_line->HasSwitch(switches::kEnableSystemCompositorMode))
61 is_running_as_system_compositor_ = true;
62 if (command_line->HasSwitch(switches::kDisableSystemCompositorMode))
63 is_running_as_system_compositor_ = false;
53 } 64 }
54 65
55 void Parse() { 66 void Parse() {
56 lsb_release_map_.clear(); 67 lsb_release_map_.clear();
57 major_version_ = 0; 68 major_version_ = 0;
58 minor_version_ = 0; 69 minor_version_ = 0;
59 bugfix_version_ = 0; 70 bugfix_version_ = 0;
60 is_running_on_chromeos_ = false; 71 is_running_on_chromeos_ = false;
61 72
62 std::string lsb_release, lsb_release_time_str; 73 std::string lsb_release, lsb_release_time_str;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 *major_version = major_version_; 110 *major_version = major_version_;
100 *minor_version = minor_version_; 111 *minor_version = minor_version_;
101 *bugfix_version = bugfix_version_; 112 *bugfix_version = bugfix_version_;
102 } 113 }
103 114
104 const Time& lsb_release_time() const { return lsb_release_time_; } 115 const Time& lsb_release_time() const { return lsb_release_time_; }
105 const SysInfo::LsbReleaseMap& lsb_release_map() const { 116 const SysInfo::LsbReleaseMap& lsb_release_map() const {
106 return lsb_release_map_; 117 return lsb_release_map_;
107 } 118 }
108 bool is_running_on_chromeos() const { return is_running_on_chromeos_; } 119 bool is_running_on_chromeos() const { return is_running_on_chromeos_; }
120 bool is_running_as_system_compositor() const {
121 return is_running_as_system_compositor_;
122 }
109 123
110 private: 124 private:
111 void ParseLsbRelease(const std::string& lsb_release) { 125 void ParseLsbRelease(const std::string& lsb_release) {
112 // Parse and cache lsb_release key pairs. There should only be a handful 126 // Parse and cache lsb_release key pairs. There should only be a handful
113 // of entries so the overhead for this will be small, and it can be 127 // of entries so the overhead for this will be small, and it can be
114 // useful for debugging. 128 // useful for debugging.
115 base::StringPairs pairs; 129 base::StringPairs pairs;
116 SplitStringIntoKeyValuePairs(lsb_release, '=', '\n', &pairs); 130 SplitStringIntoKeyValuePairs(lsb_release, '=', '\n', &pairs);
117 for (size_t i = 0; i < pairs.size(); ++i) { 131 for (size_t i = 0; i < pairs.size(); ++i) {
118 std::string key, value; 132 std::string key, value;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 } 168 }
155 } 169 }
156 } 170 }
157 171
158 Time lsb_release_time_; 172 Time lsb_release_time_;
159 SysInfo::LsbReleaseMap lsb_release_map_; 173 SysInfo::LsbReleaseMap lsb_release_map_;
160 int32_t major_version_; 174 int32_t major_version_;
161 int32_t minor_version_; 175 int32_t minor_version_;
162 int32_t bugfix_version_; 176 int32_t bugfix_version_;
163 bool is_running_on_chromeos_; 177 bool is_running_on_chromeos_;
178 bool is_running_as_system_compositor_;
164 }; 179 };
165 180
166 static LazyInstance<ChromeOSVersionInfo>::Leaky 181 static LazyInstance<ChromeOSVersionInfo>::Leaky
167 g_chrome_os_version_info = LAZY_INSTANCE_INITIALIZER; 182 g_chrome_os_version_info = LAZY_INSTANCE_INITIALIZER;
168 183
169 ChromeOSVersionInfo& GetChromeOSVersionInfo() { 184 ChromeOSVersionInfo& GetChromeOSVersionInfo() {
170 return g_chrome_os_version_info.Get(); 185 return g_chrome_os_version_info.Get();
171 } 186 }
172 187
173 } // namespace 188 } // namespace
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 // static 237 // static
223 void SysInfo::SetChromeOSVersionInfoForTest(const std::string& lsb_release, 238 void SysInfo::SetChromeOSVersionInfoForTest(const std::string& lsb_release,
224 const Time& lsb_release_time) { 239 const Time& lsb_release_time) {
225 std::unique_ptr<Environment> env(Environment::Create()); 240 std::unique_ptr<Environment> env(Environment::Create());
226 env->SetVar(kLsbReleaseKey, lsb_release); 241 env->SetVar(kLsbReleaseKey, lsb_release);
227 env->SetVar(kLsbReleaseTimeKey, 242 env->SetVar(kLsbReleaseTimeKey,
228 DoubleToString(lsb_release_time.ToDoubleT())); 243 DoubleToString(lsb_release_time.ToDoubleT()));
229 g_chrome_os_version_info.Get().Parse(); 244 g_chrome_os_version_info.Get().Parse();
230 } 245 }
231 246
247 // static
248 bool SysInfo::IsRunningAsSystemCompositor() {
249 return GetChromeOSVersionInfo().is_running_as_system_compositor();
250 }
251
232 } // namespace base 252 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698