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

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: Created 4 years, 8 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 | « no previous file | 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 "ui/base/material_design/material_design_controller.h" 9 #include "ui/base/material_design/material_design_controller.h"
10 #include "ui/base/ui_base_switches.h" 10 #include "ui/base/ui_base_switches.h"
11 11
12 #if defined(OS_CHROMEOS) 12 #if defined(OS_CHROMEOS)
13 #include "ui/base/touch/touch_device.h" 13 #include "ui/base/touch/touch_device.h"
14 #include "ui/events/devices/device_data_manager.h" 14 #include "ui/events/devices/device_data_manager.h"
15 15
16 #if defined(USE_OZONE) 16 #if defined(USE_OZONE)
17 #include <fcntl.h> 17 #include <fcntl.h>
18 18
19 #include "base/files/file_enumerator.h" 19 #include "base/files/file_enumerator.h"
20 #include "base/threading/thread_restrictions.h"
20 #include "ui/events/ozone/evdev/event_device_info.h" 21 #include "ui/events/ozone/evdev/event_device_info.h"
21 #endif // defined(USE_OZONE) 22 #endif // defined(USE_OZONE)
22 23
23 #endif // defined(OS_CHROMEOS) 24 #endif // defined(OS_CHROMEOS)
24 25
25 namespace ui { 26 namespace ui {
26 27
27 bool MaterialDesignController::is_mode_initialized_ = false; 28 bool MaterialDesignController::is_mode_initialized_ = false;
28 29
29 MaterialDesignController::Mode MaterialDesignController::mode_ = 30 MaterialDesignController::Mode MaterialDesignController::mode_ =
30 MaterialDesignController::Mode::NON_MATERIAL; 31 MaterialDesignController::Mode::NON_MATERIAL;
31 32
32 MaterialDesignController::Mode MaterialDesignController::GetMode() { 33 MaterialDesignController::Mode MaterialDesignController::GetMode() {
33 if (!is_mode_initialized_) 34 if (!is_mode_initialized_)
34 InitializeMode(); 35 InitializeMode();
35 CHECK(is_mode_initialized_); 36 CHECK(is_mode_initialized_);
36 return mode_; 37 return mode_;
37 } 38 }
38 39
39 bool MaterialDesignController::IsModeMaterial() { 40 bool MaterialDesignController::IsModeMaterial() {
40 return GetMode() == Mode::MATERIAL_NORMAL || 41 return GetMode() == Mode::MATERIAL_NORMAL ||
41 GetMode() == Mode::MATERIAL_HYBRID; 42 GetMode() == Mode::MATERIAL_HYBRID;
42 } 43 }
43 44
44 MaterialDesignController::Mode MaterialDesignController::DefaultMode() { 45 MaterialDesignController::Mode MaterialDesignController::DefaultMode() {
45 #if defined(OS_CHROMEOS) 46 #if defined(OS_CHROMEOS)
47 // If a scan of available devices has already completed, use material-hybrid
48 // if a touchscreen is present.
46 if (DeviceDataManager::HasInstance() && 49 if (DeviceDataManager::HasInstance() &&
47 DeviceDataManager::GetInstance()->device_lists_complete()) { 50 DeviceDataManager::GetInstance()->device_lists_complete()) {
48 return GetTouchScreensAvailability() == TouchScreensAvailability::ENABLED ? 51 return GetTouchScreensAvailability() == TouchScreensAvailability::ENABLED ?
49 Mode::MATERIAL_HYBRID : Mode::MATERIAL_NORMAL; 52 Mode::MATERIAL_HYBRID : Mode::MATERIAL_NORMAL;
50 } 53 }
51 54
52 #if defined(USE_OZONE) 55 #if defined(USE_OZONE)
56 // Otherwise perform our own scan to determine the presence of a touchscreen.
57 // Note this is a one-time call that occurs during device startup or restart.
58 base::ThreadRestrictions::ScopedAllowIO allow_io;
sadrul 2016/03/30 19:14:18 I am not a fan of this. Can we just stick with the
tdanderson 2016/03/30 19:26:12 The block above is insufficient since whenever the
53 base::FileEnumerator file_enum( 59 base::FileEnumerator file_enum(
54 base::FilePath(FILE_PATH_LITERAL("/dev/input")), false, 60 base::FilePath(FILE_PATH_LITERAL("/dev/input")), false,
55 base::FileEnumerator::FILES, FILE_PATH_LITERAL("event*[0-9]")); 61 base::FileEnumerator::FILES, FILE_PATH_LITERAL("event*[0-9]"));
56 for (base::FilePath path = file_enum.Next(); !path.empty(); 62 for (base::FilePath path = file_enum.Next(); !path.empty();
57 path = file_enum.Next()) { 63 path = file_enum.Next()) {
58 EventDeviceInfo devinfo; 64 EventDeviceInfo devinfo;
59 int fd = open(path.value().c_str(), O_RDWR | O_NONBLOCK | O_CLOEXEC); 65 int fd = open(path.value().c_str(), O_RDWR | O_NONBLOCK | O_CLOEXEC);
60 if (fd >= 0) { 66 if (fd >= 0) {
61 if (devinfo.Initialize(fd, path) && devinfo.HasTouchscreen()) { 67 if (devinfo.Initialize(fd, path) && devinfo.HasTouchscreen()) {
62 close(fd); 68 close(fd);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 MaterialDesignController::Mode::NON_MATERIAL); 110 MaterialDesignController::Mode::NON_MATERIAL);
105 is_mode_initialized_ = false; 111 is_mode_initialized_ = false;
106 } 112 }
107 113
108 void MaterialDesignController::SetMode(MaterialDesignController::Mode mode) { 114 void MaterialDesignController::SetMode(MaterialDesignController::Mode mode) {
109 mode_ = mode; 115 mode_ = mode;
110 is_mode_initialized_ = true; 116 is_mode_initialized_ = true;
111 } 117 }
112 118
113 } // namespace ui 119 } // namespace ui
OLDNEW
« no previous file with comments | « no previous file | ui/events/devices/device_util_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698