Chromium Code Reviews| Index: chrome/browser/ui/webui/chromeos/drive_internals_ui.cc |
| diff --git a/chrome/browser/ui/webui/chromeos/drive_internals_ui.cc b/chrome/browser/ui/webui/chromeos/drive_internals_ui.cc |
| index 762afb13ffc645a371c8b7418c15738abf7dc665..1d1215d6586bb9e91648699e468bb3c88afeb282 100644 |
| --- a/chrome/browser/ui/webui/chromeos/drive_internals_ui.cc |
| +++ b/chrome/browser/ui/webui/chromeos/drive_internals_ui.cc |
| @@ -18,6 +18,7 @@ |
| #include "chrome/browser/chromeos/gdata/drive_service_interface.h" |
| #include "chrome/browser/chromeos/gdata/gdata_system_service.h" |
| #include "chrome/browser/chromeos/gdata/gdata_util.h" |
| +#include "chrome/browser/chromeos/gdata/operation_registry.h" |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" |
| #include "chrome/common/url_constants.h" |
| @@ -196,6 +197,13 @@ class DriveInternalsWebUIHandler : public content::WebUIMessageHandler { |
| // Called when GetFreeDiskSpace() is complete. |
| void OnGetFreeDiskSpace(base::DictionaryValue* local_storage_summary); |
| + // Called when the page requests periodic update. |
| + void OnPeriodicUpdate(const base::ListValue* args); |
| + |
| + // Updates the summary about in-flight operations. |
| + void UpdateInFlightOperations( |
| + const gdata::DriveServiceInterface* drive_service); |
| + |
| // The number of pending ReadDirectoryByPath() calls. |
| int num_pending_reads_; |
| base::WeakPtrFactory<DriveInternalsWebUIHandler> weak_ptr_factory_; |
| @@ -207,6 +215,10 @@ void DriveInternalsWebUIHandler::RegisterMessages() { |
| "pageLoaded", |
| base::Bind(&DriveInternalsWebUIHandler::OnPageLoaded, |
| weak_ptr_factory_.GetWeakPtr())); |
| + web_ui()->RegisterMessageCallback( |
| + "periodicUpdate", |
| + base::Bind(&DriveInternalsWebUIHandler::OnPeriodicUpdate, |
| + weak_ptr_factory_.GetWeakPtr())); |
| } |
| gdata::GDataSystemService* DriveInternalsWebUIHandler::GetSystemService() { |
| @@ -376,6 +388,50 @@ void DriveInternalsWebUIHandler::OnGetFreeDiskSpace( |
| "updateLocalStorageUsage", *local_storage_summary); |
| } |
| +void DriveInternalsWebUIHandler::OnPeriodicUpdate(const base::ListValue* args) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + |
| + gdata::GDataSystemService* system_service = GetSystemService(); |
| + // |system_service| may be NULL in the guest/incognito mode. |
| + if (!system_service) |
| + return; |
| + |
| + gdata::DriveServiceInterface* drive_service = system_service->drive_service(); |
| + DCHECK(drive_service); |
| + |
| + UpdateInFlightOperations(drive_service); |
| +} |
| + |
| +void DriveInternalsWebUIHandler::UpdateInFlightOperations( |
| + const gdata::DriveServiceInterface* drive_service) { |
| + std::vector<gdata::OperationRegistry::ProgressStatus> |
| + progress_status_list = drive_service->operation_registry()-> |
| + GetProgressStatusList(); |
| + |
| + base::ListValue in_flight_operations; |
| + for (std::vector<gdata::OperationRegistry::ProgressStatus>::iterator i |
|
satorux1
2012/08/24 22:46:26
i is not used for iterators (iter is usually used)
Haruki Sato
2012/08/28 23:12:56
Done.
Thanks.
|
| + = progress_status_list.begin(); |
| + i != progress_status_list.end(); ++i) { |
| + base::DictionaryValue* status = new DictionaryValue; |
| + status->SetInteger("operation_id", i->operation_id); |
| + status->SetString( |
| + "operation_type", |
| + gdata::OperationRegistry::OperationTypeToString(i->operation_type)); |
| + status->SetString("file_path", i->file_path.AsUTF8Unsafe()); |
| + status->SetString( |
| + "transfer_state", |
| + gdata::OperationRegistry::OperationTransferStateToString( |
| + i->transfer_state)); |
| + status->SetString("start_time", |
| + gdata::util::FormatTimeAsStringLocaltime(i->start_time)); |
| + status->SetDouble("progress_current", i->progress_current); |
| + status->SetDouble("progress_total", i->progress_total); |
| + in_flight_operations.Append(status); |
| + } |
| + web_ui()->CallJavascriptFunction("updateInFlightOperations", |
| + in_flight_operations); |
| +} |
| + |
| } // namespace |
| DriveInternalsUI::DriveInternalsUI(content::WebUI* web_ui) |