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_integration_service.h" | 20 #include "chrome/browser/chromeos/drive/drive_integration_service.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 // },...] | 59 // },...] |
59 // | 60 // |
60 // The list is sorted by the path. | 61 // The list is sorted by the path. |
61 void GetGCacheContents(const base::FilePath& root_path, | 62 void GetGCacheContents(const base::FilePath& root_path, |
62 base::ListValue* gcache_contents, | 63 base::ListValue* gcache_contents, |
63 base::DictionaryValue* gcache_summary) { | 64 base::DictionaryValue* gcache_summary) { |
64 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); | 65 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); |
65 DCHECK(gcache_contents); | 66 DCHECK(gcache_contents); |
66 DCHECK(gcache_summary); | 67 DCHECK(gcache_summary); |
67 | 68 |
68 using file_util::FileEnumerator; | |
69 // Use this map to sort the result list by the path. | 69 // Use this map to sort the result list by the path. |
70 std::map<base::FilePath, DictionaryValue*> files; | 70 std::map<base::FilePath, DictionaryValue*> files; |
71 | 71 |
72 const int options = (file_util::FileEnumerator::FILES | | 72 const int options = (base::FileEnumerator::FILES | |
73 file_util::FileEnumerator::DIRECTORIES | | 73 base::FileEnumerator::DIRECTORIES | |
74 file_util::FileEnumerator::SHOW_SYM_LINKS); | 74 base::FileEnumerator::SHOW_SYM_LINKS); |
75 FileEnumerator enumerator(root_path, true /* recursive */, options); | 75 base::FileEnumerator enumerator(root_path, true /* recursive */, options); |
76 | 76 |
77 int64 total_size = 0; | 77 int64 total_size = 0; |
78 for (base::FilePath current = enumerator.Next(); !current.empty(); | 78 for (base::FilePath current = enumerator.Next(); !current.empty(); |
79 current = enumerator.Next()) { | 79 current = enumerator.Next()) { |
80 FileEnumerator::FindInfo find_info; | 80 base::FileEnumerator::FileInfo info = enumerator.GetInfo(); |
81 enumerator.GetFindInfo(&find_info); | 81 int64 size = info.GetSize(); |
82 int64 size = FileEnumerator::GetFilesize(find_info); | 82 const bool is_directory = info.IsDirectory(); |
83 const bool is_directory = FileEnumerator::IsDirectory(find_info); | 83 const bool is_symbolic_link = file_util::IsLink(info.GetName()); |
84 const bool is_symbolic_link = | 84 const base::Time last_modified = info.GetLastModifiedTime(); |
85 file_util::IsLink(FileEnumerator::GetFilename(find_info)); | |
86 const base::Time last_modified = | |
87 FileEnumerator::GetLastModifiedTime(find_info); | |
88 | 85 |
89 base::DictionaryValue* entry = new base::DictionaryValue; | 86 base::DictionaryValue* entry = new base::DictionaryValue; |
90 entry->SetString("path", current.value()); | 87 entry->SetString("path", current.value()); |
91 // Use double instead of integer for large files. | 88 // Use double instead of integer for large files. |
92 entry->SetDouble("size", size); | 89 entry->SetDouble("size", size); |
93 entry->SetBoolean("is_directory", is_directory); | 90 entry->SetBoolean("is_directory", is_directory); |
94 entry->SetBoolean("is_symbolic_link", is_symbolic_link); | 91 entry->SetBoolean("is_symbolic_link", is_symbolic_link); |
95 entry->SetString( | 92 entry->SetString( |
96 "last_modified", | 93 "last_modified", |
97 google_apis::util::FormatTimeAsStringLocaltime(last_modified)); | 94 google_apis::util::FormatTimeAsStringLocaltime(last_modified)); |
98 // Print lower 9 bits in octal format. | 95 // Print lower 9 bits in octal format. |
99 entry->SetString( | 96 entry->SetString( |
100 "permission", | 97 "permission", |
101 base::StringPrintf("%03o", find_info.stat.st_mode & 0x1ff)); | 98 base::StringPrintf("%03o", info.stat().st_mode & 0x1ff)); |
102 files[current] = entry; | 99 files[current] = entry; |
103 | 100 |
104 total_size += size; | 101 total_size += size; |
105 } | 102 } |
106 | 103 |
107 // Convert |files| into |gcache_contents|. | 104 // Convert |files| into |gcache_contents|. |
108 for (std::map<base::FilePath, DictionaryValue*>::const_iterator | 105 for (std::map<base::FilePath, DictionaryValue*>::const_iterator |
109 iter = files.begin(); iter != files.end(); ++iter) { | 106 iter = files.begin(); iter != files.end(); ++iter) { |
110 gcache_contents->Append(iter->second); | 107 gcache_contents->Append(iter->second); |
111 } | 108 } |
(...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
807 content::WebUIDataSource::Create(chrome::kChromeUIDriveInternalsHost); | 804 content::WebUIDataSource::Create(chrome::kChromeUIDriveInternalsHost); |
808 source->AddResourcePath("drive_internals.css", IDR_DRIVE_INTERNALS_CSS); | 805 source->AddResourcePath("drive_internals.css", IDR_DRIVE_INTERNALS_CSS); |
809 source->AddResourcePath("drive_internals.js", IDR_DRIVE_INTERNALS_JS); | 806 source->AddResourcePath("drive_internals.js", IDR_DRIVE_INTERNALS_JS); |
810 source->SetDefaultResource(IDR_DRIVE_INTERNALS_HTML); | 807 source->SetDefaultResource(IDR_DRIVE_INTERNALS_HTML); |
811 | 808 |
812 Profile* profile = Profile::FromWebUI(web_ui); | 809 Profile* profile = Profile::FromWebUI(web_ui); |
813 content::WebUIDataSource::Add(profile, source); | 810 content::WebUIDataSource::Add(profile, source); |
814 } | 811 } |
815 | 812 |
816 } // namespace chromeos | 813 } // namespace chromeos |
OLD | NEW |