Chromium Code Reviews| Index: chrome/browser/metrics/drive_metrics_provider_linux.cc |
| diff --git a/chrome/browser/metrics/drive_metrics_provider_linux.cc b/chrome/browser/metrics/drive_metrics_provider_linux.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..bcdfe34b7226b132dab10265c7cbe70980a80404 |
| --- /dev/null |
| +++ b/chrome/browser/metrics/drive_metrics_provider_linux.cc |
| @@ -0,0 +1,63 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/metrics/drive_metrics_provider.h" |
| + |
| +#include <linux/kdev_t.h> // For MAJOR()/MINOR(). |
| +#include <sys/stat.h> |
| +#include <string> |
| + |
| +#include "base/files/file.h" |
| +#include "base/files/file_path.h" |
| +#include "base/files/file_util.h" |
| +#include "base/strings/stringprintf.h" |
| + |
| +#if defined(OS_CHROMEOS) |
| +#include "base/sys_info.h" |
| +#endif |
| + |
| +namespace { |
| + |
| +// See http://www.kernel.org/doc/Documentation/devices.txt for more info. |
| +const int kScsiMajorNumber = 8; |
| +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.
|
| + |
| +} // namespace |
| + |
| +#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.
|
| +// static |
| +bool DriveMetricsProvider::HasSeekPenalty(const base::FilePath& path, |
| + bool* has_seek_penalty) { |
| +#if defined(OS_CHROMEOS) |
| + 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.
|
| + // 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.
|
| + *has_seek_penalty = false; |
| + return true; |
| + } |
| +#endif |
| + |
| + base::File file(path, base::File::FLAG_OPEN); |
| + if (!file.IsValid()) |
| + return false; |
| + |
| + struct stat path_stat; |
| + int error = fstat(file.GetPlatformFile(), &path_stat); |
| + if (error < 0 || MAJOR(path_stat.st_dev) != kScsiMajorNumber) { |
| + // TODO(dbeam): support non-SCSI drives (e.g., LVM)? |
| + return false; |
| + } |
| + |
| + char sdX = 'a' + MINOR(path_stat.st_dev) / 16; |
| + base::FilePath rotational_file(base::StringPrintf(kRotationalFormat, sdX)); |
| + |
| + std::string rotates; |
| + if (!base::ReadFileToString(rotational_file, &rotates)) { |
| + // 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.
|
| + return false; |
| + } |
| + |
| + *has_seek_penalty = rotates == "1"; |
| + return true; |
| +} |
| +#endif // !defined(OS_ANDROID) |