OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/webui/chromeos/drive_internals_ui.h" | 5 #include "chrome/browser/ui/webui/chromeos/drive_internals_ui.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/files/file_enumerator.h" |
10 #include "base/format_macros.h" | 11 #include "base/format_macros.h" |
11 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
12 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
13 #include "base/path_service.h" | 14 #include "base/path_service.h" |
14 #include "base/prefs/pref_service.h" | 15 #include "base/prefs/pref_service.h" |
15 #include "base/stringprintf.h" | 16 #include "base/stringprintf.h" |
16 #include "base/sys_info.h" | 17 #include "base/sys_info.h" |
17 #include "chrome/browser/chromeos/drive/debug_info_collector.h" | 18 #include "chrome/browser/chromeos/drive/debug_info_collector.h" |
18 #include "chrome/browser/chromeos/drive/drive.pb.h" | 19 #include "chrome/browser/chromeos/drive/drive.pb.h" |
19 #include "chrome/browser/chromeos/drive/drive_system_service.h" | 20 #include "chrome/browser/chromeos/drive/drive_system_service.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 // [{ path: 'GCache/v1/tmp/<resource_id>', | 54 // [{ path: 'GCache/v1/tmp/<resource_id>', |
54 // size: 12345, | 55 // size: 12345, |
55 // is_directory: false, | 56 // is_directory: false, |
56 // last_modified: '2005-08-09T09:57:00-08:00', | 57 // last_modified: '2005-08-09T09:57:00-08:00', |
57 // },...] | 58 // },...] |
58 // | 59 // |
59 // The list is sorted by the path. | 60 // The list is sorted by the path. |
60 void GetGCacheContents(const base::FilePath& root_path, | 61 void GetGCacheContents(const base::FilePath& root_path, |
61 base::ListValue* gcache_contents, | 62 base::ListValue* gcache_contents, |
62 base::DictionaryValue* gcache_summary) { | 63 base::DictionaryValue* gcache_summary) { |
63 using file_util::FileEnumerator; | |
64 // Use this map to sort the result list by the path. | 64 // Use this map to sort the result list by the path. |
65 std::map<base::FilePath, DictionaryValue*> files; | 65 std::map<base::FilePath, DictionaryValue*> files; |
66 | 66 |
67 const int options = (file_util::FileEnumerator::FILES | | 67 const int options = (base::FileEnumerator::FILES | |
68 file_util::FileEnumerator::DIRECTORIES | | 68 base::FileEnumerator::DIRECTORIES | |
69 file_util::FileEnumerator::SHOW_SYM_LINKS); | 69 base::FileEnumerator::SHOW_SYM_LINKS); |
70 FileEnumerator enumerator(root_path, true /* recursive */, options); | 70 base::FileEnumerator enumerator(root_path, true /* recursive */, options); |
71 | 71 |
72 int64 total_size = 0; | 72 int64 total_size = 0; |
73 for (base::FilePath current = enumerator.Next(); !current.empty(); | 73 for (base::FilePath current = enumerator.Next(); !current.empty(); |
74 current = enumerator.Next()) { | 74 current = enumerator.Next()) { |
75 FileEnumerator::FindInfo find_info; | 75 base::FileEnumerator::FileInfo find_info = enumerator.GetInfo(); |
76 enumerator.GetFindInfo(&find_info); | 76 int64 size = find_info.GetSize(); |
77 int64 size = FileEnumerator::GetFilesize(find_info); | 77 const bool is_directory = find_info.IsDirectory(); |
78 const bool is_directory = FileEnumerator::IsDirectory(find_info); | 78 const bool is_symbolic_link = file_util::IsLink(find_info.GetName()); |
79 const bool is_symbolic_link = | 79 const base::Time last_modified = find_info.GetLastModifiedTime(); |
80 file_util::IsLink(FileEnumerator::GetFilename(find_info)); | |
81 const base::Time last_modified = | |
82 FileEnumerator::GetLastModifiedTime(find_info); | |
83 | 80 |
84 base::DictionaryValue* entry = new base::DictionaryValue; | 81 base::DictionaryValue* entry = new base::DictionaryValue; |
85 entry->SetString("path", current.value()); | 82 entry->SetString("path", current.value()); |
86 // Use double instead of integer for large files. | 83 // Use double instead of integer for large files. |
87 entry->SetDouble("size", size); | 84 entry->SetDouble("size", size); |
88 entry->SetBoolean("is_directory", is_directory); | 85 entry->SetBoolean("is_directory", is_directory); |
89 entry->SetBoolean("is_symbolic_link", is_symbolic_link); | 86 entry->SetBoolean("is_symbolic_link", is_symbolic_link); |
90 entry->SetString( | 87 entry->SetString( |
91 "last_modified", | 88 "last_modified", |
92 google_apis::util::FormatTimeAsStringLocaltime(last_modified)); | 89 google_apis::util::FormatTimeAsStringLocaltime(last_modified)); |
93 // Print lower 9 bits in octal format. | 90 // Print lower 9 bits in octal format. |
94 entry->SetString( | 91 entry->SetString( |
95 "permission", | 92 "permission", |
96 base::StringPrintf("%03o", find_info.stat.st_mode & 0x1ff)); | 93 base::StringPrintf("%03o", find_info.stat().st_mode & 0x1ff)); |
97 files[current] = entry; | 94 files[current] = entry; |
98 | 95 |
99 total_size += size; | 96 total_size += size; |
100 } | 97 } |
101 | 98 |
102 // Convert |files| into |gcache_contents|. | 99 // Convert |files| into |gcache_contents|. |
103 for (std::map<base::FilePath, DictionaryValue*>::const_iterator | 100 for (std::map<base::FilePath, DictionaryValue*>::const_iterator |
104 iter = files.begin(); iter != files.end(); ++iter) { | 101 iter = files.begin(); iter != files.end(); ++iter) { |
105 gcache_contents->Append(iter->second); | 102 gcache_contents->Append(iter->second); |
106 } | 103 } |
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
746 content::WebUIDataSource::Create(chrome::kChromeUIDriveInternalsHost); | 743 content::WebUIDataSource::Create(chrome::kChromeUIDriveInternalsHost); |
747 source->AddResourcePath("drive_internals.css", IDR_DRIVE_INTERNALS_CSS); | 744 source->AddResourcePath("drive_internals.css", IDR_DRIVE_INTERNALS_CSS); |
748 source->AddResourcePath("drive_internals.js", IDR_DRIVE_INTERNALS_JS); | 745 source->AddResourcePath("drive_internals.js", IDR_DRIVE_INTERNALS_JS); |
749 source->SetDefaultResource(IDR_DRIVE_INTERNALS_HTML); | 746 source->SetDefaultResource(IDR_DRIVE_INTERNALS_HTML); |
750 | 747 |
751 Profile* profile = Profile::FromWebUI(web_ui); | 748 Profile* profile = Profile::FromWebUI(web_ui); |
752 content::WebUIDataSource::Add(profile, source); | 749 content::WebUIDataSource::Add(profile, source); |
753 } | 750 } |
754 | 751 |
755 } // namespace chromeos | 752 } // namespace chromeos |
OLD | NEW |