| 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.pb.h" |
| 16 #include "chrome/browser/chromeos/gdata/drive_cache.h" | 16 #include "chrome/browser/chromeos/gdata/drive_cache.h" |
| 17 #include "chrome/browser/chromeos/gdata/drive_file_system_interface.h" | 17 #include "chrome/browser/chromeos/gdata/drive_file_system_interface.h" |
| 18 #include "chrome/browser/chromeos/gdata/drive_service_interface.h" | 18 #include "chrome/browser/chromeos/gdata/drive_service_interface.h" |
| 19 #include "chrome/browser/chromeos/gdata/drive_system_service.h" | 19 #include "chrome/browser/chromeos/gdata/drive_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/chromeos/gdata/operation_registry.h" |
| 21 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
| 22 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" | 23 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" |
| 23 #include "chrome/common/url_constants.h" | 24 #include "chrome/common/url_constants.h" |
| 24 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
| 25 #include "content/public/browser/web_ui.h" | 26 #include "content/public/browser/web_ui.h" |
| 26 #include "content/public/browser/web_ui_message_handler.h" | 27 #include "content/public/browser/web_ui_message_handler.h" |
| 27 #include "grit/browser_resources.h" | 28 #include "grit/browser_resources.h" |
| 28 | 29 |
| 29 using content::BrowserThread; | 30 using content::BrowserThread; |
| 30 | 31 |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 const std::vector<std::string>& resource_ids); | 190 const std::vector<std::string>& resource_ids); |
| 190 | 191 |
| 191 // Called when GetCacheEntryOnUIThread() is complete. | 192 // Called when GetCacheEntryOnUIThread() is complete. |
| 192 void OnGetCacheEntry(const std::string& resource_id, | 193 void OnGetCacheEntry(const std::string& resource_id, |
| 193 bool success, | 194 bool success, |
| 194 const gdata::DriveCacheEntry& cache_entry); | 195 const gdata::DriveCacheEntry& cache_entry); |
| 195 | 196 |
| 196 // Called when GetFreeDiskSpace() is complete. | 197 // Called when GetFreeDiskSpace() is complete. |
| 197 void OnGetFreeDiskSpace(base::DictionaryValue* local_storage_summary); | 198 void OnGetFreeDiskSpace(base::DictionaryValue* local_storage_summary); |
| 198 | 199 |
| 200 // Called when the page requests periodic update. |
| 201 void OnPeriodicUpdate(const base::ListValue* args); |
| 202 |
| 203 // Updates the summary about in-flight operations. |
| 204 void UpdateInFlightOperations( |
| 205 const gdata::DriveServiceInterface* drive_service); |
| 206 |
| 199 // The number of pending ReadDirectoryByPath() calls. | 207 // The number of pending ReadDirectoryByPath() calls. |
| 200 int num_pending_reads_; | 208 int num_pending_reads_; |
| 201 base::WeakPtrFactory<DriveInternalsWebUIHandler> weak_ptr_factory_; | 209 base::WeakPtrFactory<DriveInternalsWebUIHandler> weak_ptr_factory_; |
| 202 DISALLOW_COPY_AND_ASSIGN(DriveInternalsWebUIHandler); | 210 DISALLOW_COPY_AND_ASSIGN(DriveInternalsWebUIHandler); |
| 203 }; | 211 }; |
| 204 | 212 |
| 205 void DriveInternalsWebUIHandler::RegisterMessages() { | 213 void DriveInternalsWebUIHandler::RegisterMessages() { |
| 206 web_ui()->RegisterMessageCallback( | 214 web_ui()->RegisterMessageCallback( |
| 207 "pageLoaded", | 215 "pageLoaded", |
| 208 base::Bind(&DriveInternalsWebUIHandler::OnPageLoaded, | 216 base::Bind(&DriveInternalsWebUIHandler::OnPageLoaded, |
| 209 weak_ptr_factory_.GetWeakPtr())); | 217 weak_ptr_factory_.GetWeakPtr())); |
| 218 web_ui()->RegisterMessageCallback( |
| 219 "periodicUpdate", |
| 220 base::Bind(&DriveInternalsWebUIHandler::OnPeriodicUpdate, |
| 221 weak_ptr_factory_.GetWeakPtr())); |
| 210 } | 222 } |
| 211 | 223 |
| 212 gdata::DriveSystemService* DriveInternalsWebUIHandler::GetSystemService() { | 224 gdata::DriveSystemService* DriveInternalsWebUIHandler::GetSystemService() { |
| 213 Profile* profile = Profile::FromWebUI(web_ui()); | 225 Profile* profile = Profile::FromWebUI(web_ui()); |
| 214 return gdata::DriveSystemServiceFactory::GetForProfile(profile); | 226 return gdata::DriveSystemServiceFactory::GetForProfile(profile); |
| 215 } | 227 } |
| 216 | 228 |
| 217 void DriveInternalsWebUIHandler::OnPageLoaded(const base::ListValue* args) { | 229 void DriveInternalsWebUIHandler::OnPageLoaded(const base::ListValue* args) { |
| 218 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 230 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 219 | 231 |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 | 381 |
| 370 void DriveInternalsWebUIHandler::OnGetFreeDiskSpace( | 382 void DriveInternalsWebUIHandler::OnGetFreeDiskSpace( |
| 371 base::DictionaryValue* local_storage_summary) { | 383 base::DictionaryValue* local_storage_summary) { |
| 372 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 384 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 373 DCHECK(local_storage_summary); | 385 DCHECK(local_storage_summary); |
| 374 | 386 |
| 375 web_ui()->CallJavascriptFunction( | 387 web_ui()->CallJavascriptFunction( |
| 376 "updateLocalStorageUsage", *local_storage_summary); | 388 "updateLocalStorageUsage", *local_storage_summary); |
| 377 } | 389 } |
| 378 | 390 |
| 391 void DriveInternalsWebUIHandler::OnPeriodicUpdate(const base::ListValue* args) { |
| 392 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 393 |
| 394 gdata::DriveSystemService* system_service = GetSystemService(); |
| 395 // |system_service| may be NULL in the guest/incognito mode. |
| 396 if (!system_service) |
| 397 return; |
| 398 |
| 399 gdata::DriveServiceInterface* drive_service = system_service->drive_service(); |
| 400 DCHECK(drive_service); |
| 401 |
| 402 UpdateInFlightOperations(drive_service); |
| 403 } |
| 404 |
| 405 void DriveInternalsWebUIHandler::UpdateInFlightOperations( |
| 406 const gdata::DriveServiceInterface* drive_service) { |
| 407 std::vector<gdata::OperationRegistry::ProgressStatus> |
| 408 progress_status_list = drive_service->operation_registry()-> |
| 409 GetProgressStatusList(); |
| 410 |
| 411 base::ListValue in_flight_operations; |
| 412 for (size_t i = 0; i < progress_status_list.size(); ++i) { |
| 413 const gdata::OperationRegistry::ProgressStatus status = |
| 414 progress_status_list[i]; |
| 415 |
| 416 base::DictionaryValue* dict = new DictionaryValue; |
| 417 dict->SetInteger("operation_id", status.operation_id); |
| 418 dict->SetString( |
| 419 "operation_type", |
| 420 gdata::OperationRegistry::OperationTypeToString(status.operation_type)); |
| 421 dict->SetString("file_path", status.file_path.AsUTF8Unsafe()); |
| 422 dict->SetString( |
| 423 "transfer_state", |
| 424 gdata::OperationRegistry::OperationTransferStateToString( |
| 425 status.transfer_state)); |
| 426 dict->SetString( |
| 427 "start_time", |
| 428 gdata::util::FormatTimeAsStringLocaltime(status.start_time)); |
| 429 dict->SetDouble("progress_current", status.progress_current); |
| 430 dict->SetDouble("progress_total", status.progress_total); |
| 431 in_flight_operations.Append(dict); |
| 432 } |
| 433 web_ui()->CallJavascriptFunction("updateInFlightOperations", |
| 434 in_flight_operations); |
| 435 } |
| 436 |
| 379 } // namespace | 437 } // namespace |
| 380 | 438 |
| 381 DriveInternalsUI::DriveInternalsUI(content::WebUI* web_ui) | 439 DriveInternalsUI::DriveInternalsUI(content::WebUI* web_ui) |
| 382 : WebUIController(web_ui) { | 440 : WebUIController(web_ui) { |
| 383 web_ui->AddMessageHandler(new DriveInternalsWebUIHandler()); | 441 web_ui->AddMessageHandler(new DriveInternalsWebUIHandler()); |
| 384 | 442 |
| 385 ChromeWebUIDataSource* source = | 443 ChromeWebUIDataSource* source = |
| 386 new ChromeWebUIDataSource(chrome::kChromeUIDriveInternalsHost); | 444 new ChromeWebUIDataSource(chrome::kChromeUIDriveInternalsHost); |
| 387 source->add_resource_path("drive_internals.css", IDR_DRIVE_INTERNALS_CSS); | 445 source->add_resource_path("drive_internals.css", IDR_DRIVE_INTERNALS_CSS); |
| 388 source->add_resource_path("drive_internals.js", IDR_DRIVE_INTERNALS_JS); | 446 source->add_resource_path("drive_internals.js", IDR_DRIVE_INTERNALS_JS); |
| 389 source->set_default_resource(IDR_DRIVE_INTERNALS_HTML); | 447 source->set_default_resource(IDR_DRIVE_INTERNALS_HTML); |
| 390 | 448 |
| 391 Profile* profile = Profile::FromWebUI(web_ui); | 449 Profile* profile = Profile::FromWebUI(web_ui); |
| 392 ChromeURLDataManager::AddDataSource(profile, source); | 450 ChromeURLDataManager::AddDataSource(profile, source); |
| 393 } | 451 } |
| 394 | 452 |
| 395 } // namespace chromeos | 453 } // namespace chromeos |
| OLD | NEW |