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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 // | 63 // |
64 // The list is sorted by the path. | 64 // The list is sorted by the path. |
65 void GetGCacheContents(const base::FilePath& root_path, | 65 void GetGCacheContents(const base::FilePath& root_path, |
66 base::ListValue* gcache_contents, | 66 base::ListValue* gcache_contents, |
67 base::DictionaryValue* gcache_summary) { | 67 base::DictionaryValue* gcache_summary) { |
68 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); | 68 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); |
69 DCHECK(gcache_contents); | 69 DCHECK(gcache_contents); |
70 DCHECK(gcache_summary); | 70 DCHECK(gcache_summary); |
71 | 71 |
72 // Use this map to sort the result list by the path. | 72 // Use this map to sort the result list by the path. |
73 std::map<base::FilePath, base::DictionaryValue*> files; | 73 std::map<base::FilePath, std::unique_ptr<base::DictionaryValue>> files; |
74 | 74 |
75 const int options = (base::FileEnumerator::FILES | | 75 const int options = (base::FileEnumerator::FILES | |
76 base::FileEnumerator::DIRECTORIES | | 76 base::FileEnumerator::DIRECTORIES | |
77 base::FileEnumerator::SHOW_SYM_LINKS); | 77 base::FileEnumerator::SHOW_SYM_LINKS); |
78 base::FileEnumerator enumerator(root_path, true /* recursive */, options); | 78 base::FileEnumerator enumerator(root_path, true /* recursive */, options); |
79 | 79 |
80 int64_t total_size = 0; | 80 int64_t total_size = 0; |
81 for (base::FilePath current = enumerator.Next(); !current.empty(); | 81 for (base::FilePath current = enumerator.Next(); !current.empty(); |
82 current = enumerator.Next()) { | 82 current = enumerator.Next()) { |
83 base::FileEnumerator::FileInfo info = enumerator.GetInfo(); | 83 base::FileEnumerator::FileInfo info = enumerator.GetInfo(); |
84 int64_t size = info.GetSize(); | 84 int64_t size = info.GetSize(); |
85 const bool is_directory = info.IsDirectory(); | 85 const bool is_directory = info.IsDirectory(); |
86 const bool is_symbolic_link = base::IsLink(info.GetName()); | 86 const bool is_symbolic_link = base::IsLink(info.GetName()); |
87 const base::Time last_modified = info.GetLastModifiedTime(); | 87 const base::Time last_modified = info.GetLastModifiedTime(); |
88 | 88 |
89 base::DictionaryValue* entry = new base::DictionaryValue; | 89 auto entry = base::MakeUnique<base::DictionaryValue>(); |
90 entry->SetString("path", current.value()); | 90 entry->SetString("path", current.value()); |
91 // Use double instead of integer for large files. | 91 // Use double instead of integer for large files. |
92 entry->SetDouble("size", size); | 92 entry->SetDouble("size", size); |
93 entry->SetBoolean("is_directory", is_directory); | 93 entry->SetBoolean("is_directory", is_directory); |
94 entry->SetBoolean("is_symbolic_link", is_symbolic_link); | 94 entry->SetBoolean("is_symbolic_link", is_symbolic_link); |
95 entry->SetString( | 95 entry->SetString( |
96 "last_modified", | 96 "last_modified", |
97 google_apis::util::FormatTimeAsStringLocaltime(last_modified)); | 97 google_apis::util::FormatTimeAsStringLocaltime(last_modified)); |
98 // Print lower 9 bits in octal format. | 98 // Print lower 9 bits in octal format. |
99 entry->SetString( | 99 entry->SetString( |
100 "permission", | 100 "permission", |
101 base::StringPrintf("%03o", info.stat().st_mode & 0x1ff)); | 101 base::StringPrintf("%03o", info.stat().st_mode & 0x1ff)); |
102 files[current] = entry; | 102 files[current] = std::move(entry); |
103 | 103 |
104 total_size += size; | 104 total_size += size; |
105 } | 105 } |
106 | 106 |
107 // Convert |files| into |gcache_contents|. | 107 // Convert |files| into |gcache_contents|. |
108 for (std::map<base::FilePath, base::DictionaryValue*>::const_iterator | 108 for (auto& it : files) |
109 iter = files.begin(); iter != files.end(); ++iter) { | 109 gcache_contents->Append(std::move(it.second)); |
110 gcache_contents->Append(iter->second); | |
111 } | |
112 | 110 |
113 gcache_summary->SetDouble("total_size", total_size); | 111 gcache_summary->SetDouble("total_size", total_size); |
114 } | 112 } |
115 | 113 |
116 // Gets the available disk space for the path |home_path|. | 114 // Gets the available disk space for the path |home_path|. |
117 void GetFreeDiskSpace(const base::FilePath& home_path, | 115 void GetFreeDiskSpace(const base::FilePath& home_path, |
118 base::DictionaryValue* local_storage_summary) { | 116 base::DictionaryValue* local_storage_summary) { |
119 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); | 117 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); |
120 DCHECK(local_storage_summary); | 118 DCHECK(local_storage_summary); |
121 | 119 |
(...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
901 content::WebUIDataSource::Create(chrome::kChromeUIDriveInternalsHost); | 899 content::WebUIDataSource::Create(chrome::kChromeUIDriveInternalsHost); |
902 source->AddResourcePath("drive_internals.css", IDR_DRIVE_INTERNALS_CSS); | 900 source->AddResourcePath("drive_internals.css", IDR_DRIVE_INTERNALS_CSS); |
903 source->AddResourcePath("drive_internals.js", IDR_DRIVE_INTERNALS_JS); | 901 source->AddResourcePath("drive_internals.js", IDR_DRIVE_INTERNALS_JS); |
904 source->SetDefaultResource(IDR_DRIVE_INTERNALS_HTML); | 902 source->SetDefaultResource(IDR_DRIVE_INTERNALS_HTML); |
905 | 903 |
906 Profile* profile = Profile::FromWebUI(web_ui); | 904 Profile* profile = Profile::FromWebUI(web_ui); |
907 content::WebUIDataSource::Add(profile, source); | 905 content::WebUIDataSource::Add(profile, source); |
908 } | 906 } |
909 | 907 |
910 } // namespace chromeos | 908 } // namespace chromeos |
OLD | NEW |