OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/diagnostics/recon_diagnostics.h" | 5 #include "chrome/browser/diagnostics/recon_diagnostics.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
11 #include "base/stringprintf.h" | 11 #include "base/stringprintf.h" |
12 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
15 #include "base/sys_info.h" | 15 #include "base/sys_info.h" |
16 #include "base/path_service.h" | 16 #include "base/path_service.h" |
17 #include "chrome/browser/diagnostics/diagnostics_test.h" | 17 #include "chrome/browser/diagnostics/diagnostics_test.h" |
18 #include "chrome/browser/platform_util.h" | 18 #include "chrome/browser/platform_util.h" |
19 #include "chrome/common/chrome_constants.h" | 19 #include "chrome/common/chrome_constants.h" |
20 #include "chrome/common/chrome_paths.h" | 20 #include "chrome/common/chrome_paths.h" |
21 #include "chrome/common/chrome_version_info.h" | 21 #include "chrome/common/chrome_version_info.h" |
22 #include "content/common/json_value_serializer.h" | 22 #include "content/common/json_value_serializer.h" |
| 23 #include "ui/base/text/bytes_formatting.h" |
23 | 24 |
24 #if defined(OS_WIN) | 25 #if defined(OS_WIN) |
25 #include "base/win/windows_version.h" | 26 #include "base/win/windows_version.h" |
26 #include "chrome/browser/enumerate_modules_model_win.h" | 27 #include "chrome/browser/enumerate_modules_model_win.h" |
27 #include "chrome/installer/util/install_util.h" | 28 #include "chrome/installer/util/install_util.h" |
28 #endif | 29 #endif |
29 | 30 |
30 // Reconnaissance diagnostics. These are the first and most critical | 31 // Reconnaissance diagnostics. These are the first and most critical |
31 // diagnostic tests. Here we check for the existence of critical files. | 32 // diagnostic tests. Here we check for the existence of critical files. |
32 // TODO(cpu): Define if it makes sense to localize strings. | 33 // TODO(cpu): Define if it makes sense to localize strings. |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 if (path_info_.is_directory) { | 245 if (path_info_.is_directory) { |
245 dir_or_file_size = file_util::ComputeDirectorySize(dir_or_file); | 246 dir_or_file_size = file_util::ComputeDirectorySize(dir_or_file); |
246 } else { | 247 } else { |
247 file_util::GetFileSize(dir_or_file, &dir_or_file_size); | 248 file_util::GetFileSize(dir_or_file, &dir_or_file_size); |
248 } | 249 } |
249 if (!dir_or_file_size && !path_info_.is_optional) { | 250 if (!dir_or_file_size && !path_info_.is_optional) { |
250 RecordFailure(ASCIIToUTF16("Cannot obtain size for: ") + | 251 RecordFailure(ASCIIToUTF16("Cannot obtain size for: ") + |
251 dir_or_file.LossyDisplayName()); | 252 dir_or_file.LossyDisplayName()); |
252 return true; | 253 return true; |
253 } | 254 } |
254 DataUnits units = GetByteDisplayUnits(dir_or_file_size); | 255 string16 printable_size = ui::FormatBytes(dir_or_file_size, |
255 string16 printable_size = FormatBytes(dir_or_file_size, units, true); | 256 ui::DATA_UNITS_NATURAL, |
| 257 true); |
256 | 258 |
257 if (path_info_.max_size > 0) { | 259 if (path_info_.max_size > 0) { |
258 if (dir_or_file_size > path_info_.max_size) { | 260 if (dir_or_file_size > path_info_.max_size) { |
259 RecordFailure(ASCIIToUTF16("Path contents too large (") + | 261 RecordFailure(ASCIIToUTF16("Path contents too large (") + |
260 printable_size + | 262 printable_size + |
261 ASCIIToUTF16(") for: ") + | 263 ASCIIToUTF16(") for: ") + |
262 dir_or_file.LossyDisplayName()); | 264 dir_or_file.LossyDisplayName()); |
263 return true; | 265 return true; |
264 } | 266 } |
265 } | 267 } |
(...skipping 26 matching lines...) Expand all Loading... |
292 | 294 |
293 virtual bool ExecuteImpl(DiagnosticsModel::Observer* observer) { | 295 virtual bool ExecuteImpl(DiagnosticsModel::Observer* observer) { |
294 FilePath data_dir; | 296 FilePath data_dir; |
295 if (!PathService::Get(chrome::DIR_USER_DATA, &data_dir)) | 297 if (!PathService::Get(chrome::DIR_USER_DATA, &data_dir)) |
296 return false; | 298 return false; |
297 int64 disk_space = base::SysInfo::AmountOfFreeDiskSpace(data_dir); | 299 int64 disk_space = base::SysInfo::AmountOfFreeDiskSpace(data_dir); |
298 if (disk_space < 0) { | 300 if (disk_space < 0) { |
299 RecordFailure(ASCIIToUTF16("Unable to query free space")); | 301 RecordFailure(ASCIIToUTF16("Unable to query free space")); |
300 return true; | 302 return true; |
301 } | 303 } |
302 DataUnits units = GetByteDisplayUnits(disk_space); | 304 string16 printable_size = ui::FormatBytes(disk_space, |
303 string16 printable_size = FormatBytes(disk_space, units, true); | 305 ui::DATA_UNITS_NATURAL, |
| 306 true); |
304 if (disk_space < 80 * kOneMeg) { | 307 if (disk_space < 80 * kOneMeg) { |
305 RecordFailure(ASCIIToUTF16("Low disk space : ") + printable_size); | 308 RecordFailure(ASCIIToUTF16("Low disk space : ") + printable_size); |
306 return true; | 309 return true; |
307 } | 310 } |
308 RecordSuccess(ASCIIToUTF16("Free space : ") + printable_size); | 311 RecordSuccess(ASCIIToUTF16("Free space : ") + printable_size); |
309 return true; | 312 return true; |
310 } | 313 } |
311 | 314 |
312 private: | 315 private: |
313 DISALLOW_COPY_AND_ASSIGN(DiskSpaceTest); | 316 DISALLOW_COPY_AND_ASSIGN(DiskSpaceTest); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 path = path.Append(chrome::kBookmarksFileName); | 419 path = path.Append(chrome::kBookmarksFileName); |
417 return new JSONTest(path, ASCIIToUTF16("BookMarks JSON"), 2 * kOneMeg); | 420 return new JSONTest(path, ASCIIToUTF16("BookMarks JSON"), 2 * kOneMeg); |
418 } | 421 } |
419 | 422 |
420 DiagnosticTest* MakeLocalStateTest() { | 423 DiagnosticTest* MakeLocalStateTest() { |
421 FilePath path; | 424 FilePath path; |
422 PathService::Get(chrome::DIR_USER_DATA, &path); | 425 PathService::Get(chrome::DIR_USER_DATA, &path); |
423 path = path.Append(chrome::kLocalStateFilename); | 426 path = path.Append(chrome::kLocalStateFilename); |
424 return new JSONTest(path, ASCIIToUTF16("Local State JSON"), 50 * kOneKilo); | 427 return new JSONTest(path, ASCIIToUTF16("Local State JSON"), 50 * kOneKilo); |
425 } | 428 } |
OLD | NEW |