| 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/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" |
| 11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 13 #include "base/sys_info.h" | 13 #include "base/sys_info.h" |
| 14 #include "chrome/browser/chromeos/gdata/auth_service.h" | 14 #include "chrome/browser/chromeos/gdata/auth_service.h" |
| 15 #include "chrome/browser/chromeos/gdata/drive.pb.h" |
| 15 #include "chrome/browser/chromeos/gdata/drive_service_interface.h" | 16 #include "chrome/browser/chromeos/gdata/drive_service_interface.h" |
| 16 #include "chrome/browser/chromeos/gdata/gdata.pb.h" | |
| 17 #include "chrome/browser/chromeos/gdata/gdata_cache.h" | 17 #include "chrome/browser/chromeos/gdata/gdata_cache.h" |
| 18 #include "chrome/browser/chromeos/gdata/gdata_file_system_interface.h" | 18 #include "chrome/browser/chromeos/gdata/gdata_file_system_interface.h" |
| 19 #include "chrome/browser/chromeos/gdata/gdata_system_service.h" | 19 #include "chrome/browser/chromeos/gdata/gdata_system_service.h" |
| 20 #include "chrome/browser/chromeos/gdata/gdata_util.h" | 20 #include "chrome/browser/chromeos/gdata/gdata_util.h" |
| 21 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 22 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" | 22 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" |
| 23 #include "chrome/common/url_constants.h" | 23 #include "chrome/common/url_constants.h" |
| 24 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
| 25 #include "content/public/browser/web_ui.h" | 25 #include "content/public/browser/web_ui.h" |
| 26 #include "content/public/browser/web_ui_message_handler.h" | 26 #include "content/public/browser/web_ui_message_handler.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 base::DictionaryValue* local_storage_summary) { | 92 base::DictionaryValue* local_storage_summary) { |
| 93 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); | 93 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 94 DCHECK(local_storage_summary); | 94 DCHECK(local_storage_summary); |
| 95 | 95 |
| 96 const int64 free_space = base::SysInfo::AmountOfFreeDiskSpace(home_path); | 96 const int64 free_space = base::SysInfo::AmountOfFreeDiskSpace(home_path); |
| 97 local_storage_summary->SetDouble("free_space", free_space); | 97 local_storage_summary->SetDouble("free_space", free_space); |
| 98 } | 98 } |
| 99 | 99 |
| 100 // Formats |entry| into text. | 100 // Formats |entry| into text. |
| 101 std::string FormatEntry(const FilePath& path, | 101 std::string FormatEntry(const FilePath& path, |
| 102 const gdata::GDataEntryProto& entry) { | 102 const gdata::DriveEntryProto& entry) { |
| 103 using base::StringAppendF; | 103 using base::StringAppendF; |
| 104 using gdata::util::FormatTimeAsString; | 104 using gdata::util::FormatTimeAsString; |
| 105 | 105 |
| 106 std::string out; | 106 std::string out; |
| 107 StringAppendF(&out, "%s\n", path.AsUTF8Unsafe().c_str()); | 107 StringAppendF(&out, "%s\n", path.AsUTF8Unsafe().c_str()); |
| 108 StringAppendF(&out, " title: %s\n", entry.title().c_str()); | 108 StringAppendF(&out, " title: %s\n", entry.title().c_str()); |
| 109 StringAppendF(&out, " resource_id: %s\n", entry.resource_id().c_str()); | 109 StringAppendF(&out, " resource_id: %s\n", entry.resource_id().c_str()); |
| 110 StringAppendF(&out, " edit_url: %s\n", entry.edit_url().c_str()); | 110 StringAppendF(&out, " edit_url: %s\n", entry.edit_url().c_str()); |
| 111 StringAppendF(&out, " content_url: %s\n", entry.content_url().c_str()); | 111 StringAppendF(&out, " content_url: %s\n", entry.content_url().c_str()); |
| 112 StringAppendF(&out, " parent_resource_id: %s\n", | 112 StringAppendF(&out, " parent_resource_id: %s\n", |
| (...skipping 14 matching lines...) Expand all Loading... |
| 127 const base::Time creation_time = base::Time::FromInternalValue( | 127 const base::Time creation_time = base::Time::FromInternalValue( |
| 128 file_info.creation_time()); | 128 file_info.creation_time()); |
| 129 StringAppendF(&out, " last_modified: %s\n", | 129 StringAppendF(&out, " last_modified: %s\n", |
| 130 FormatTimeAsString(last_modified).c_str()); | 130 FormatTimeAsString(last_modified).c_str()); |
| 131 StringAppendF(&out, " last_accessed: %s\n", | 131 StringAppendF(&out, " last_accessed: %s\n", |
| 132 FormatTimeAsString(last_accessed).c_str()); | 132 FormatTimeAsString(last_accessed).c_str()); |
| 133 StringAppendF(&out, " creation_time: %s\n", | 133 StringAppendF(&out, " creation_time: %s\n", |
| 134 FormatTimeAsString(creation_time).c_str()); | 134 FormatTimeAsString(creation_time).c_str()); |
| 135 | 135 |
| 136 if (entry.has_file_specific_info()) { | 136 if (entry.has_file_specific_info()) { |
| 137 const gdata::GDataFileSpecificInfo& file_specific_info = | 137 const gdata::DriveFileSpecificInfo& file_specific_info = |
| 138 entry.file_specific_info(); | 138 entry.file_specific_info(); |
| 139 StringAppendF(&out, " thumbnail_url: %s\n", | 139 StringAppendF(&out, " thumbnail_url: %s\n", |
| 140 file_specific_info.thumbnail_url().c_str()); | 140 file_specific_info.thumbnail_url().c_str()); |
| 141 StringAppendF(&out, " alternate_url: %s\n", | 141 StringAppendF(&out, " alternate_url: %s\n", |
| 142 file_specific_info.alternate_url().c_str()); | 142 file_specific_info.alternate_url().c_str()); |
| 143 StringAppendF(&out, " content_mime_type: %s\n", | 143 StringAppendF(&out, " content_mime_type: %s\n", |
| 144 file_specific_info.content_mime_type().c_str()); | 144 file_specific_info.content_mime_type().c_str()); |
| 145 StringAppendF(&out, " file_md5: %s\n", | 145 StringAppendF(&out, " file_md5: %s\n", |
| 146 file_specific_info.file_md5().c_str()); | 146 file_specific_info.file_md5().c_str()); |
| 147 StringAppendF(&out, " document_extension: %s\n", | 147 StringAppendF(&out, " document_extension: %s\n", |
| (...skipping 27 matching lines...) Expand all Loading... |
| 175 void OnPageLoaded(const base::ListValue* args); | 175 void OnPageLoaded(const base::ListValue* args); |
| 176 | 176 |
| 177 // Called when GetGCacheContents() is complete. | 177 // Called when GetGCacheContents() is complete. |
| 178 void OnGetGCacheContents(base::ListValue* gcache_contents, | 178 void OnGetGCacheContents(base::ListValue* gcache_contents, |
| 179 base::DictionaryValue* cache_summary); | 179 base::DictionaryValue* cache_summary); |
| 180 | 180 |
| 181 // Called when ReadDirectoryByPath() is complete. | 181 // Called when ReadDirectoryByPath() is complete. |
| 182 void OnReadDirectoryByPath(const FilePath& parent_path, | 182 void OnReadDirectoryByPath(const FilePath& parent_path, |
| 183 gdata::GDataFileError error, | 183 gdata::GDataFileError error, |
| 184 bool hide_hosted_documents, | 184 bool hide_hosted_documents, |
| 185 scoped_ptr<gdata::GDataEntryProtoVector> entries); | 185 scoped_ptr<gdata::DriveEntryProtoVector> entries); |
| 186 | 186 |
| 187 // Called when GetResourceIdsOfAllFilesOnUIThread() is complete. | 187 // Called when GetResourceIdsOfAllFilesOnUIThread() is complete. |
| 188 void OnGetResourceIdsOfAllFiles( | 188 void OnGetResourceIdsOfAllFiles( |
| 189 const std::vector<std::string>& resource_ids); | 189 const std::vector<std::string>& resource_ids); |
| 190 | 190 |
| 191 // Called when GetCacheEntryOnUIThread() is complete. | 191 // Called when GetCacheEntryOnUIThread() is complete. |
| 192 void OnGetCacheEntry(const std::string& resource_id, | 192 void OnGetCacheEntry(const std::string& resource_id, |
| 193 bool success, | 193 bool success, |
| 194 const gdata::GDataCacheEntry& cache_entry); | 194 const gdata::DriveCacheEntry& cache_entry); |
| 195 | 195 |
| 196 // Called when GetFreeDiskSpace() is complete. | 196 // Called when GetFreeDiskSpace() is complete. |
| 197 void OnGetFreeDiskSpace(base::DictionaryValue* local_storage_summary); | 197 void OnGetFreeDiskSpace(base::DictionaryValue* local_storage_summary); |
| 198 | 198 |
| 199 // The number of pending ReadDirectoryByPath() calls. | 199 // The number of pending ReadDirectoryByPath() calls. |
| 200 int num_pending_reads_; | 200 int num_pending_reads_; |
| 201 base::WeakPtrFactory<DriveInternalsWebUIHandler> weak_ptr_factory_; | 201 base::WeakPtrFactory<DriveInternalsWebUIHandler> weak_ptr_factory_; |
| 202 DISALLOW_COPY_AND_ASSIGN(DriveInternalsWebUIHandler); | 202 DISALLOW_COPY_AND_ASSIGN(DriveInternalsWebUIHandler); |
| 203 }; | 203 }; |
| 204 | 204 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 root_path, | 286 root_path, |
| 287 base::Bind(&DriveInternalsWebUIHandler::OnReadDirectoryByPath, | 287 base::Bind(&DriveInternalsWebUIHandler::OnReadDirectoryByPath, |
| 288 weak_ptr_factory_.GetWeakPtr(), | 288 weak_ptr_factory_.GetWeakPtr(), |
| 289 root_path)); | 289 root_path)); |
| 290 } | 290 } |
| 291 | 291 |
| 292 void DriveInternalsWebUIHandler::OnReadDirectoryByPath( | 292 void DriveInternalsWebUIHandler::OnReadDirectoryByPath( |
| 293 const FilePath& parent_path, | 293 const FilePath& parent_path, |
| 294 gdata::GDataFileError error, | 294 gdata::GDataFileError error, |
| 295 bool hide_hosted_documents, | 295 bool hide_hosted_documents, |
| 296 scoped_ptr<gdata::GDataEntryProtoVector> entries) { | 296 scoped_ptr<gdata::DriveEntryProtoVector> entries) { |
| 297 --num_pending_reads_; | 297 --num_pending_reads_; |
| 298 if (error == gdata::GDATA_FILE_OK) { | 298 if (error == gdata::GDATA_FILE_OK) { |
| 299 DCHECK(entries.get()); | 299 DCHECK(entries.get()); |
| 300 | 300 |
| 301 std::string file_system_as_text; | 301 std::string file_system_as_text; |
| 302 for (size_t i = 0; i < entries->size(); ++i) { | 302 for (size_t i = 0; i < entries->size(); ++i) { |
| 303 const gdata::GDataEntryProto& entry = (*entries)[i]; | 303 const gdata::DriveEntryProto& entry = (*entries)[i]; |
| 304 const FilePath current_path = parent_path.Append( | 304 const FilePath current_path = parent_path.Append( |
| 305 FilePath::FromUTF8Unsafe(entry.base_name())); | 305 FilePath::FromUTF8Unsafe(entry.base_name())); |
| 306 | 306 |
| 307 file_system_as_text.append(FormatEntry(current_path, entry) + "\n"); | 307 file_system_as_text.append(FormatEntry(current_path, entry) + "\n"); |
| 308 | 308 |
| 309 if (entry.file_info().is_directory()) { | 309 if (entry.file_info().is_directory()) { |
| 310 ++num_pending_reads_; | 310 ++num_pending_reads_; |
| 311 GetSystemService()->file_system()->ReadDirectoryByPath( | 311 GetSystemService()->file_system()->ReadDirectoryByPath( |
| 312 current_path, | 312 current_path, |
| 313 base::Bind(&DriveInternalsWebUIHandler::OnReadDirectoryByPath, | 313 base::Bind(&DriveInternalsWebUIHandler::OnReadDirectoryByPath, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 341 "", // Don't check MD5. | 341 "", // Don't check MD5. |
| 342 base::Bind(&DriveInternalsWebUIHandler::OnGetCacheEntry, | 342 base::Bind(&DriveInternalsWebUIHandler::OnGetCacheEntry, |
| 343 weak_ptr_factory_.GetWeakPtr(), | 343 weak_ptr_factory_.GetWeakPtr(), |
| 344 resource_id)); | 344 resource_id)); |
| 345 } | 345 } |
| 346 } | 346 } |
| 347 | 347 |
| 348 void DriveInternalsWebUIHandler::OnGetCacheEntry( | 348 void DriveInternalsWebUIHandler::OnGetCacheEntry( |
| 349 const std::string& resource_id, | 349 const std::string& resource_id, |
| 350 bool success, | 350 bool success, |
| 351 const gdata::GDataCacheEntry& cache_entry) { | 351 const gdata::DriveCacheEntry& cache_entry) { |
| 352 if (!success) { | 352 if (!success) { |
| 353 LOG(ERROR) << "Failed to get cache entry: " << resource_id; | 353 LOG(ERROR) << "Failed to get cache entry: " << resource_id; |
| 354 return; | 354 return; |
| 355 } | 355 } |
| 356 | 356 |
| 357 // Convert |cache_entry| into a dictionary. | 357 // Convert |cache_entry| into a dictionary. |
| 358 base::DictionaryValue value; | 358 base::DictionaryValue value; |
| 359 value.SetString("resource_id", resource_id); | 359 value.SetString("resource_id", resource_id); |
| 360 value.SetString("md5", cache_entry.md5()); | 360 value.SetString("md5", cache_entry.md5()); |
| 361 value.SetBoolean("is_present", cache_entry.is_present()); | 361 value.SetBoolean("is_present", cache_entry.is_present()); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 386 new ChromeWebUIDataSource(chrome::kChromeUIDriveInternalsHost); | 386 new ChromeWebUIDataSource(chrome::kChromeUIDriveInternalsHost); |
| 387 source->add_resource_path("drive_internals.css", IDR_DRIVE_INTERNALS_CSS); | 387 source->add_resource_path("drive_internals.css", IDR_DRIVE_INTERNALS_CSS); |
| 388 source->add_resource_path("drive_internals.js", IDR_DRIVE_INTERNALS_JS); | 388 source->add_resource_path("drive_internals.js", IDR_DRIVE_INTERNALS_JS); |
| 389 source->set_default_resource(IDR_DRIVE_INTERNALS_HTML); | 389 source->set_default_resource(IDR_DRIVE_INTERNALS_HTML); |
| 390 | 390 |
| 391 Profile* profile = Profile::FromWebUI(web_ui); | 391 Profile* profile = Profile::FromWebUI(web_ui); |
| 392 ChromeURLDataManager::AddDataSource(profile, source); | 392 ChromeURLDataManager::AddDataSource(profile, source); |
| 393 } | 393 } |
| 394 | 394 |
| 395 } // namespace chromeos | 395 } // namespace chromeos |
| OLD | NEW |