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

Side by Side Diff: ui/base/material_design/material_design_controller.cc

Issue 1844033002: Permit MaterialDesignController to make IO call (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: presubmit change Created 4 years, 7 months 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
« no previous file with comments | « PRESUBMIT.py ('k') | ui/events/devices/device_util_linux.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 <string> 5 #include <string>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/trace_event/trace_event.h" 9 #include "base/trace_event/trace_event.h"
10 #include "ui/base/material_design/material_design_controller.h" 10 #include "ui/base/material_design/material_design_controller.h"
11 #include "ui/base/ui_base_switches.h" 11 #include "ui/base/ui_base_switches.h"
12 12
13 #if defined(OS_CHROMEOS) 13 #if defined(OS_CHROMEOS)
14 #include "ui/base/touch/touch_device.h" 14 #include "ui/base/touch/touch_device.h"
15 #include "ui/events/devices/device_data_manager.h" 15 #include "ui/events/devices/device_data_manager.h"
16 16
17 #if defined(USE_OZONE) 17 #if defined(USE_OZONE)
18 #include <fcntl.h> 18 #include <fcntl.h>
19 19
20 #include "base/files/file_enumerator.h" 20 #include "base/files/file_enumerator.h"
21 #include "base/threading/thread_restrictions.h"
21 #include "ui/events/ozone/evdev/event_device_info.h" 22 #include "ui/events/ozone/evdev/event_device_info.h"
22 #endif // defined(USE_OZONE) 23 #endif // defined(USE_OZONE)
23 24
24 #endif // defined(OS_CHROMEOS) 25 #endif // defined(OS_CHROMEOS)
25 26
26 namespace ui { 27 namespace ui {
27 28
28 bool MaterialDesignController::is_mode_initialized_ = false; 29 bool MaterialDesignController::is_mode_initialized_ = false;
29 30
30 MaterialDesignController::Mode MaterialDesignController::mode_ = 31 MaterialDesignController::Mode MaterialDesignController::mode_ =
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 } 76 }
76 77
77 // static 78 // static
78 bool MaterialDesignController::IsSecondaryUiMaterial() { 79 bool MaterialDesignController::IsSecondaryUiMaterial() {
79 return IsModeMaterial() && include_secondary_ui_; 80 return IsModeMaterial() && include_secondary_ui_;
80 } 81 }
81 82
82 // static 83 // static
83 MaterialDesignController::Mode MaterialDesignController::DefaultMode() { 84 MaterialDesignController::Mode MaterialDesignController::DefaultMode() {
84 #if defined(OS_CHROMEOS) 85 #if defined(OS_CHROMEOS)
86 // If a scan of available devices has already completed, use material-hybrid
87 // if a touchscreen is present.
85 if (DeviceDataManager::HasInstance() && 88 if (DeviceDataManager::HasInstance() &&
86 DeviceDataManager::GetInstance()->device_lists_complete()) { 89 DeviceDataManager::GetInstance()->device_lists_complete()) {
87 return GetTouchScreensAvailability() == TouchScreensAvailability::ENABLED 90 return GetTouchScreensAvailability() == TouchScreensAvailability::ENABLED
88 ? MATERIAL_HYBRID 91 ? MATERIAL_HYBRID
89 : MATERIAL_NORMAL; 92 : MATERIAL_NORMAL;
90 } 93 }
91 94
92 #if defined(USE_OZONE) 95 #if defined(USE_OZONE)
96 // Otherwise perform our own scan to determine the presence of a touchscreen.
97 // Note this is a one-time call that occurs during device startup or restart.
98 base::ThreadRestrictions::ScopedAllowIO allow_io;
93 base::FileEnumerator file_enum( 99 base::FileEnumerator file_enum(
94 base::FilePath(FILE_PATH_LITERAL("/dev/input")), false, 100 base::FilePath(FILE_PATH_LITERAL("/dev/input")), false,
95 base::FileEnumerator::FILES, FILE_PATH_LITERAL("event*[0-9]")); 101 base::FileEnumerator::FILES, FILE_PATH_LITERAL("event*[0-9]"));
96 for (base::FilePath path = file_enum.Next(); !path.empty(); 102 for (base::FilePath path = file_enum.Next(); !path.empty();
97 path = file_enum.Next()) { 103 path = file_enum.Next()) {
98 EventDeviceInfo devinfo; 104 EventDeviceInfo devinfo;
99 int fd = open(path.value().c_str(), O_RDWR | O_NONBLOCK | O_CLOEXEC); 105 int fd = open(path.value().c_str(), O_RDWR | O_NONBLOCK | O_CLOEXEC);
100 if (fd >= 0) { 106 if (fd >= 0) {
101 if (devinfo.Initialize(fd, path) && devinfo.HasTouchscreen()) { 107 if (devinfo.Initialize(fd, path) && devinfo.HasTouchscreen()) {
102 close(fd); 108 close(fd);
(...skipping 16 matching lines...) Expand all
119 is_mode_initialized_ = false; 125 is_mode_initialized_ = false;
120 } 126 }
121 127
122 // static 128 // static
123 void MaterialDesignController::SetMode(MaterialDesignController::Mode mode) { 129 void MaterialDesignController::SetMode(MaterialDesignController::Mode mode) {
124 mode_ = mode; 130 mode_ = mode;
125 is_mode_initialized_ = true; 131 is_mode_initialized_ = true;
126 } 132 }
127 133
128 } // namespace ui 134 } // namespace ui
OLDNEW
« no previous file with comments | « PRESUBMIT.py ('k') | ui/events/devices/device_util_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698