OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/profiles/file_path_verifier_win.h" | 5 #include "chrome/browser/profiles/file_path_verifier_win.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "chrome_elf/create_file/chrome_create_file.h" |
12 | 13 |
13 namespace { | 14 namespace { |
14 | 15 |
15 // This enum is used in UMA histograms and should never be re-ordered. | 16 // This enum is used in UMA histograms and should never be re-ordered. |
16 enum FileVerificationResult { | 17 enum FileVerificationResult { |
17 FILE_VERIFICATION_SUCCESS, | 18 FILE_VERIFICATION_SUCCESS, |
18 FILE_VERIFICATION_FILE_NOT_FOUND, | 19 FILE_VERIFICATION_FILE_NOT_FOUND, |
19 FILE_VERIFICATION_INTERNAL_ERROR, | 20 FILE_VERIFICATION_INTERNAL_ERROR, |
20 FILE_VERIFICATION_FAILED_UNKNOWN, | 21 FILE_VERIFICATION_FAILED_UNKNOWN, |
21 FILE_VERIFICATION_FAILED_SAMEBASE, | 22 FILE_VERIFICATION_FAILED_SAMEBASE, |
22 FILE_VERIFICATION_FAILED_SAMEDIR, | 23 FILE_VERIFICATION_FAILED_SAMEDIR, |
| 24 FILE_VERIFICATION_SUCCESS_REDIRECT, |
| 25 FILE_VERIFICATION_FAILED_SAMEBASE_REDIRECT, |
| 26 FILE_VERIFICATION_FAILED_SAMEDIR_REDIRECT, |
23 NUM_FILE_VERIFICATION_RESULTS | 27 NUM_FILE_VERIFICATION_RESULTS |
24 }; | 28 }; |
25 | 29 |
26 // Returns a FileVerificationResult based on the state of |file| on disk. | 30 // Returns a FileVerificationResult based on the state of |file| on disk. |
27 FileVerificationResult VerifyFileAtPath(const base::FilePath& file) { | 31 FileVerificationResult VerifyFileAtPath(const base::FilePath& file) { |
28 FileVerificationResult file_verification_result = | 32 FileVerificationResult file_verification_result = |
29 FILE_VERIFICATION_FAILED_UNKNOWN; | 33 FILE_VERIFICATION_FAILED_UNKNOWN; |
30 base::FilePath normalized_path; | 34 base::FilePath normalized_path; |
| 35 int redirect_count_before = ::GetRedirectCount(); |
31 if (!base::NormalizeFilePath(file, &normalized_path)) { | 36 if (!base::NormalizeFilePath(file, &normalized_path)) { |
32 if (::GetLastError() == ERROR_FILE_NOT_FOUND) | 37 if (::GetLastError() == ERROR_FILE_NOT_FOUND) |
33 file_verification_result = FILE_VERIFICATION_FILE_NOT_FOUND; | 38 file_verification_result = FILE_VERIFICATION_FILE_NOT_FOUND; |
34 else | 39 else |
35 file_verification_result = FILE_VERIFICATION_INTERNAL_ERROR; | 40 file_verification_result = FILE_VERIFICATION_INTERNAL_ERROR; |
36 } else { | 41 } else { |
37 internal::PathComparisonReason path_comparison_reason = | 42 internal::PathComparisonReason path_comparison_reason = |
38 internal::ComparePathsIgnoreCase(file, normalized_path); | 43 internal::ComparePathsIgnoreCase(file, normalized_path); |
| 44 // GetRedirectCount() tracks the number of CreateFile() calls that were |
| 45 // redirected. If it has increased then the CreateFile() call made by |
| 46 // base::NormalizeFilePath() was redirected. |
| 47 bool was_redirected = ::GetRedirectCount() > redirect_count_before; |
39 switch (path_comparison_reason) { | 48 switch (path_comparison_reason) { |
40 case internal::PATH_COMPARISON_EQUAL: | 49 case internal::PATH_COMPARISON_EQUAL: |
41 file_verification_result = FILE_VERIFICATION_SUCCESS; | 50 file_verification_result = was_redirected ? |
| 51 FILE_VERIFICATION_SUCCESS_REDIRECT : FILE_VERIFICATION_SUCCESS; |
42 break; | 52 break; |
43 case internal::PATH_COMPARISON_FAILED_SAMEBASE: | 53 case internal::PATH_COMPARISON_FAILED_SAMEBASE: |
44 file_verification_result = FILE_VERIFICATION_FAILED_SAMEBASE; | 54 file_verification_result = was_redirected ? |
| 55 FILE_VERIFICATION_FAILED_SAMEBASE_REDIRECT : |
| 56 FILE_VERIFICATION_FAILED_SAMEBASE; |
45 break; | 57 break; |
46 case internal::PATH_COMPARISON_FAILED_SAMEDIR: | 58 case internal::PATH_COMPARISON_FAILED_SAMEDIR: |
47 file_verification_result = FILE_VERIFICATION_FAILED_SAMEDIR; | 59 file_verification_result = was_redirected ? |
| 60 FILE_VERIFICATION_FAILED_SAMEDIR_REDIRECT : |
| 61 FILE_VERIFICATION_FAILED_SAMEDIR; |
48 break; | 62 break; |
49 } | 63 } |
50 } | 64 } |
51 return file_verification_result; | 65 return file_verification_result; |
52 } | 66 } |
53 | 67 |
54 } // namespace | 68 } // namespace |
55 | 69 |
56 namespace internal { | 70 namespace internal { |
57 | 71 |
(...skipping 16 matching lines...) Expand all Loading... |
74 | 88 |
75 } // namespace internal | 89 } // namespace internal |
76 | 90 |
77 void VerifyPreferencesFile(const base::FilePath& pref_file_path) { | 91 void VerifyPreferencesFile(const base::FilePath& pref_file_path) { |
78 FileVerificationResult file_verification_result = | 92 FileVerificationResult file_verification_result = |
79 VerifyFileAtPath(pref_file_path); | 93 VerifyFileAtPath(pref_file_path); |
80 UMA_HISTOGRAM_ENUMERATION("Stability.FileAtPath.Preferences", | 94 UMA_HISTOGRAM_ENUMERATION("Stability.FileAtPath.Preferences", |
81 file_verification_result, | 95 file_verification_result, |
82 NUM_FILE_VERIFICATION_RESULTS); | 96 NUM_FILE_VERIFICATION_RESULTS); |
83 } | 97 } |
OLD | NEW |