Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/metrics/drive_metrics_provider.h" | |
| 6 | |
| 7 #include <linux/kdev_t.h> // For MAJOR()/MINOR(). | |
| 8 #include <sys/stat.h> | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/files/file.h" | |
| 12 #include "base/files/file_path.h" | |
| 13 #include "base/files/file_util.h" | |
| 14 #include "base/strings/stringprintf.h" | |
| 15 | |
| 16 #if defined(OS_CHROMEOS) | |
| 17 #include "base/sys_info.h" | |
| 18 #endif | |
| 19 | |
| 20 namespace { | |
| 21 | |
| 22 // See http://www.kernel.org/doc/Documentation/devices.txt for more info. | |
| 23 const int kScsiMajorNumber = 8; | |
| 24 const char kRotationalFormat[] = "/sys/block/sd%c/queue/rotational"; | |
|
Lei Zhang
2015/04/03 05:12:08
I believe after sdz comes sdaa.
Dan Beam
2015/04/03 18:25:06
Done.
| |
| 25 | |
| 26 } // namespace | |
| 27 | |
| 28 #if !defined(OS_ANDROID) | |
|
Lei Zhang
2015/04/03 05:12:07
just exclude the file for android entirely?
Dan Beam
2015/04/03 18:25:06
Done.
| |
| 29 // static | |
| 30 bool DriveMetricsProvider::HasSeekPenalty(const base::FilePath& path, | |
| 31 bool* has_seek_penalty) { | |
| 32 #if defined(OS_CHROMEOS) | |
| 33 if (base::SysInfo::GetLsbReleaseBoard() != "parrot") { | |
|
Lei Zhang
2015/04/03 05:12:07
What if this returns "unknown" ?
Dan Beam
2015/04/03 18:25:05
Done.
| |
| 34 // All ChromeOS devices that have ever shipped have SSDs. Except parrots. | |
|
Lei Zhang
2015/04/03 05:12:08
some parrots...
Dan Beam
2015/04/03 18:25:06
Done.
| |
| 35 *has_seek_penalty = false; | |
| 36 return true; | |
| 37 } | |
| 38 #endif | |
| 39 | |
| 40 base::File file(path, base::File::FLAG_OPEN); | |
| 41 if (!file.IsValid()) | |
| 42 return false; | |
| 43 | |
| 44 struct stat path_stat; | |
| 45 int error = fstat(file.GetPlatformFile(), &path_stat); | |
| 46 if (error < 0 || MAJOR(path_stat.st_dev) != kScsiMajorNumber) { | |
| 47 // TODO(dbeam): support non-SCSI drives (e.g., LVM)? | |
| 48 return false; | |
| 49 } | |
| 50 | |
| 51 char sdX = 'a' + MINOR(path_stat.st_dev) / 16; | |
| 52 base::FilePath rotational_file(base::StringPrintf(kRotationalFormat, sdX)); | |
| 53 | |
| 54 std::string rotates; | |
| 55 if (!base::ReadFileToString(rotational_file, &rotates)) { | |
| 56 // Old Linux kernel? | |
|
Lei Zhang
2015/04/03 05:12:07
How old? Kernels that are too old won't run Chrome
Dan Beam
2015/04/03 18:25:05
don't know. removed.
| |
| 57 return false; | |
| 58 } | |
| 59 | |
| 60 *has_seek_penalty = rotates == "1"; | |
| 61 return true; | |
| 62 } | |
| 63 #endif // !defined(OS_ANDROID) | |
| OLD | NEW |