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 bool was_redirected = ::GetRedirectCount() > redirect_count_before; | |
noms (inactive)
2014/02/19 16:48:13
nit: If possible, I would add a small comment here
Cait (Slow)
2014/02/19 18:58:09
Done.
| |
39 switch (path_comparison_reason) { | 45 switch (path_comparison_reason) { |
40 case internal::PATH_COMPARISON_EQUAL: | 46 case internal::PATH_COMPARISON_EQUAL: |
41 file_verification_result = FILE_VERIFICATION_SUCCESS; | 47 file_verification_result = was_redirected ? |
48 FILE_VERIFICATION_SUCCESS_REDIRECT : FILE_VERIFICATION_SUCCESS; | |
42 break; | 49 break; |
43 case internal::PATH_COMPARISON_FAILED_SAMEBASE: | 50 case internal::PATH_COMPARISON_FAILED_SAMEBASE: |
44 file_verification_result = FILE_VERIFICATION_FAILED_SAMEBASE; | 51 file_verification_result = was_redirected ? |
52 FILE_VERIFICATION_FAILED_SAMEBASE_REDIRECT : | |
53 FILE_VERIFICATION_FAILED_SAMEBASE; | |
45 break; | 54 break; |
46 case internal::PATH_COMPARISON_FAILED_SAMEDIR: | 55 case internal::PATH_COMPARISON_FAILED_SAMEDIR: |
47 file_verification_result = FILE_VERIFICATION_FAILED_SAMEDIR; | 56 file_verification_result = was_redirected ? |
57 FILE_VERIFICATION_FAILED_SAMEDIR_REDIRECT : | |
58 FILE_VERIFICATION_FAILED_SAMEDIR; | |
48 break; | 59 break; |
49 } | 60 } |
50 } | 61 } |
51 return file_verification_result; | 62 return file_verification_result; |
52 } | 63 } |
53 | 64 |
54 } // namespace | 65 } // namespace |
55 | 66 |
56 namespace internal { | 67 namespace internal { |
57 | 68 |
(...skipping 16 matching lines...) Expand all Loading... | |
74 | 85 |
75 } // namespace internal | 86 } // namespace internal |
76 | 87 |
77 void VerifyPreferencesFile(const base::FilePath& pref_file_path) { | 88 void VerifyPreferencesFile(const base::FilePath& pref_file_path) { |
78 FileVerificationResult file_verification_result = | 89 FileVerificationResult file_verification_result = |
79 VerifyFileAtPath(pref_file_path); | 90 VerifyFileAtPath(pref_file_path); |
80 UMA_HISTOGRAM_ENUMERATION("Stability.FileAtPath.Preferences", | 91 UMA_HISTOGRAM_ENUMERATION("Stability.FileAtPath.Preferences", |
81 file_verification_result, | 92 file_verification_result, |
82 NUM_FILE_VERIFICATION_RESULTS); | 93 NUM_FILE_VERIFICATION_RESULTS); |
83 } | 94 } |
OLD | NEW |