Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(309)

Side by Side Diff: chrome/browser/ui/webui/chromeos/drive_internals_ui.cc

Issue 10834168: Drive: Show the total size of cache files at chrome://drive-internals. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review (#2) fix & rebase Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/resources/chromeos/drive_internals.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/file_util.h" 8 #include "base/file_util.h"
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/stringprintf.h" 10 #include "base/stringprintf.h"
(...skipping 21 matching lines...) Expand all
32 // recursively. Stores the result as a list of dictionaries like: 32 // recursively. Stores the result as a list of dictionaries like:
33 // 33 //
34 // [{ path: 'GCache/v1/tmp/<resource_id>', 34 // [{ path: 'GCache/v1/tmp/<resource_id>',
35 // size: 12345, 35 // size: 12345,
36 // is_directory: false, 36 // is_directory: false,
37 // last_modified: '2005-08-09T09:57:00-08:00', 37 // last_modified: '2005-08-09T09:57:00-08:00',
38 // },...] 38 // },...]
39 // 39 //
40 // The list is sorted by the path. 40 // The list is sorted by the path.
41 void GetGCacheContents(const FilePath& root_path, 41 void GetGCacheContents(const FilePath& root_path,
42 base::ListValue* gcache_contents) { 42 base::ListValue* gcache_contents,
43 base::DictionaryValue* gcache_summary) {
43 using file_util::FileEnumerator; 44 using file_util::FileEnumerator;
44 // Use this map to sort the result list by the path. 45 // Use this map to sort the result list by the path.
45 std::map<FilePath, DictionaryValue*> files; 46 std::map<FilePath, DictionaryValue*> files;
46 47
47 const int options = (file_util::FileEnumerator::FILES | 48 const int options = (file_util::FileEnumerator::FILES |
48 file_util::FileEnumerator::DIRECTORIES | 49 file_util::FileEnumerator::DIRECTORIES |
49 file_util::FileEnumerator::SHOW_SYM_LINKS); 50 file_util::FileEnumerator::SHOW_SYM_LINKS);
50 FileEnumerator enumerator( 51 FileEnumerator enumerator(
51 root_path, 52 root_path,
52 true, // recursive 53 true, // recursive
53 static_cast<FileEnumerator::FileType>(options)); 54 static_cast<FileEnumerator::FileType>(options));
54 55
56 int64 total_size = 0;
55 for (FilePath current = enumerator.Next(); !current.empty(); 57 for (FilePath current = enumerator.Next(); !current.empty();
56 current = enumerator.Next()) { 58 current = enumerator.Next()) {
57 FileEnumerator::FindInfo find_info; 59 FileEnumerator::FindInfo find_info;
58 enumerator.GetFindInfo(&find_info); 60 enumerator.GetFindInfo(&find_info);
59 int64 size = FileEnumerator::GetFilesize(find_info); 61 int64 size = FileEnumerator::GetFilesize(find_info);
60 const bool is_directory = FileEnumerator::IsDirectory(find_info); 62 const bool is_directory = FileEnumerator::IsDirectory(find_info);
61 const bool is_symbolic_link = FileEnumerator::IsLink(find_info); 63 const bool is_symbolic_link = FileEnumerator::IsLink(find_info);
62 const base::Time last_modified = 64 const base::Time last_modified =
63 FileEnumerator::GetLastModifiedTime(find_info); 65 FileEnumerator::GetLastModifiedTime(find_info);
64 66
65 base::DictionaryValue* entry = new base::DictionaryValue; 67 base::DictionaryValue* entry = new base::DictionaryValue;
66 entry->SetString("path", current.value()); 68 entry->SetString("path", current.value());
67 // Use double instead of integer for large files. 69 // Use double instead of integer for large files.
68 entry->SetDouble("size", size); 70 entry->SetDouble("size", size);
69 entry->SetBoolean("is_directory", is_directory); 71 entry->SetBoolean("is_directory", is_directory);
70 entry->SetBoolean("is_symbolic_link", is_symbolic_link); 72 entry->SetBoolean("is_symbolic_link", is_symbolic_link);
71 entry->SetString("last_modified", 73 entry->SetString("last_modified",
72 gdata::util::FormatTimeAsString(last_modified)); 74 gdata::util::FormatTimeAsString(last_modified));
75 files[current] = entry;
73 76
74 files[current] = entry; 77 total_size += size;
75 } 78 }
76 79
77 // Convert |files| into |gcache_contents|. 80 // Convert |files| into |gcache_contents|.
78 for (std::map<FilePath, DictionaryValue*>::const_iterator 81 for (std::map<FilePath, DictionaryValue*>::const_iterator
79 iter = files.begin(); iter != files.end(); ++iter) { 82 iter = files.begin(); iter != files.end(); ++iter) {
80 gcache_contents->Append(iter->second); 83 gcache_contents->Append(iter->second);
81 } 84 }
85
86 gcache_summary->SetDouble("total_size", total_size);
82 } 87 }
83 88
84 // Formats |entry| into text. 89 // Formats |entry| into text.
85 std::string FormatEntry(const FilePath& path, 90 std::string FormatEntry(const FilePath& path,
86 const gdata::GDataEntryProto& entry) { 91 const gdata::GDataEntryProto& entry) {
87 using base::StringAppendF; 92 using base::StringAppendF;
88 using gdata::util::FormatTimeAsString; 93 using gdata::util::FormatTimeAsString;
89 94
90 std::string out; 95 std::string out;
91 StringAppendF(&out, "%s\n", path.AsUTF8Unsafe().c_str()); 96 StringAppendF(&out, "%s\n", path.AsUTF8Unsafe().c_str());
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 // WebUIMessageHandler override. 157 // WebUIMessageHandler override.
153 virtual void RegisterMessages() OVERRIDE; 158 virtual void RegisterMessages() OVERRIDE;
154 159
155 // Returns a GDataSystemService. 160 // Returns a GDataSystemService.
156 gdata::GDataSystemService* GetSystemService(); 161 gdata::GDataSystemService* GetSystemService();
157 162
158 // Called when the page is first loaded. 163 // Called when the page is first loaded.
159 void OnPageLoaded(const base::ListValue* args); 164 void OnPageLoaded(const base::ListValue* args);
160 165
161 // Called when GetGCacheContents() is complete. 166 // Called when GetGCacheContents() is complete.
162 void OnGetGCacheContents(base::ListValue* gcache_contents); 167 void OnGetGCacheContents(base::ListValue* gcache_contents,
168 base::DictionaryValue* cache_summary);
163 169
164 // Called when ReadDirectoryByPath() is complete. 170 // Called when ReadDirectoryByPath() is complete.
165 void OnReadDirectoryByPath(const FilePath& parent_path, 171 void OnReadDirectoryByPath(const FilePath& parent_path,
166 gdata::GDataFileError error, 172 gdata::GDataFileError error,
167 bool hide_hosted_documents, 173 bool hide_hosted_documents,
168 scoped_ptr<gdata::GDataEntryProtoVector> entries); 174 scoped_ptr<gdata::GDataEntryProtoVector> entries);
169 175
170 // Called when GetResourceIdsOfAllFilesOnUIThread() is complete. 176 // Called when GetResourceIdsOfAllFilesOnUIThread() is complete.
171 void OnGetResourceIdsOfAllFiles( 177 void OnGetResourceIdsOfAllFiles(
172 const std::vector<std::string>& resource_ids); 178 const std::vector<std::string>& resource_ids);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 documents_service->HasRefreshToken()); 216 documents_service->HasRefreshToken());
211 auth_status.SetBoolean("has-access-token", 217 auth_status.SetBoolean("has-access-token",
212 documents_service->HasAccessToken()); 218 documents_service->HasAccessToken());
213 web_ui()->CallJavascriptFunction("updateAuthStatus", auth_status); 219 web_ui()->CallJavascriptFunction("updateAuthStatus", auth_status);
214 220
215 // Start updating the GCache contents section. 221 // Start updating the GCache contents section.
216 Profile* profile = Profile::FromWebUI(web_ui()); 222 Profile* profile = Profile::FromWebUI(web_ui());
217 const FilePath root_path = 223 const FilePath root_path =
218 gdata::GDataCache::GetCacheRootPath(profile); 224 gdata::GDataCache::GetCacheRootPath(profile);
219 base::ListValue* gcache_contents = new ListValue; 225 base::ListValue* gcache_contents = new ListValue;
226 base::DictionaryValue* gcache_summary = new DictionaryValue;
220 content::BrowserThread::PostBlockingPoolTaskAndReply( 227 content::BrowserThread::PostBlockingPoolTaskAndReply(
221 FROM_HERE, 228 FROM_HERE,
222 base::Bind(&GetGCacheContents, root_path, gcache_contents), 229 base::Bind(&GetGCacheContents,
230 root_path,
231 gcache_contents,
232 gcache_summary),
223 base::Bind(&DriveInternalsWebUIHandler::OnGetGCacheContents, 233 base::Bind(&DriveInternalsWebUIHandler::OnGetGCacheContents,
224 weak_ptr_factory_.GetWeakPtr(), 234 weak_ptr_factory_.GetWeakPtr(),
225 base::Owned(gcache_contents))); 235 base::Owned(gcache_contents),
236 base::Owned(gcache_summary)));
226 } 237 }
227 238
228 void DriveInternalsWebUIHandler::OnGetGCacheContents( 239 void DriveInternalsWebUIHandler::OnGetGCacheContents(
229 base::ListValue* gcache_contents) { 240 base::ListValue* gcache_contents,
241 base::DictionaryValue* gcache_summary) {
230 DCHECK(gcache_contents); 242 DCHECK(gcache_contents);
231 web_ui()->CallJavascriptFunction("updateGCacheContents", *gcache_contents); 243 DCHECK(gcache_summary);
244 web_ui()->CallJavascriptFunction("updateGCacheContents",
245 *gcache_contents,
246 *gcache_summary);
232 247
233 // Start updating the file system tree section, if we have access token. 248 // Start updating the file system tree section, if we have access token.
234 gdata::GDataSystemService* system_service = GetSystemService(); 249 gdata::GDataSystemService* system_service = GetSystemService();
235 if (!system_service->docs_service()->HasAccessToken()) 250 if (!system_service->docs_service()->HasAccessToken())
236 return; 251 return;
237 252
238 // Start rendering the file system tree as text. 253 // Start rendering the file system tree as text.
239 const FilePath root_path = FilePath(gdata::kGDataRootDirectory); 254 const FilePath root_path = FilePath(gdata::kGDataRootDirectory);
240 ++num_pending_reads_; 255 ++num_pending_reads_;
241 system_service->file_system()->ReadDirectoryByPath( 256 system_service->file_system()->ReadDirectoryByPath(
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 new ChromeWebUIDataSource(chrome::kChromeUIDriveInternalsHost); 348 new ChromeWebUIDataSource(chrome::kChromeUIDriveInternalsHost);
334 source->add_resource_path("drive_internals.css", IDR_DRIVE_INTERNALS_CSS); 349 source->add_resource_path("drive_internals.css", IDR_DRIVE_INTERNALS_CSS);
335 source->add_resource_path("drive_internals.js", IDR_DRIVE_INTERNALS_JS); 350 source->add_resource_path("drive_internals.js", IDR_DRIVE_INTERNALS_JS);
336 source->set_default_resource(IDR_DRIVE_INTERNALS_HTML); 351 source->set_default_resource(IDR_DRIVE_INTERNALS_HTML);
337 352
338 Profile* profile = Profile::FromWebUI(web_ui); 353 Profile* profile = Profile::FromWebUI(web_ui);
339 ChromeURLDataManager::AddDataSource(profile, source); 354 ChromeURLDataManager::AddDataSource(profile, source);
340 } 355 }
341 356
342 } // namespace chromeos 357 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/resources/chromeos/drive_internals.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698