Chromium Code Reviews| 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/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/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::GDataSystemService* DriveInternalsWebUIHandler::GetSystemService() { | 224 gdata::GDataSystemService* DriveInternalsWebUIHandler::GetSystemService() { |
| 213 Profile* profile = Profile::FromWebUI(web_ui()); | 225 Profile* profile = Profile::FromWebUI(web_ui()); |
| 214 return gdata::GDataSystemServiceFactory::GetForProfile(profile); | 226 return gdata::GDataSystemServiceFactory::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::GDataSystemService* 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 (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.
| |
| 413 = progress_status_list.begin(); | |
| 414 i != progress_status_list.end(); ++i) { | |
| 415 base::DictionaryValue* status = new DictionaryValue; | |
| 416 status->SetInteger("operation_id", i->operation_id); | |
| 417 status->SetString( | |
| 418 "operation_type", | |
| 419 gdata::OperationRegistry::OperationTypeToString(i->operation_type)); | |
| 420 status->SetString("file_path", i->file_path.AsUTF8Unsafe()); | |
| 421 status->SetString( | |
| 422 "transfer_state", | |
| 423 gdata::OperationRegistry::OperationTransferStateToString( | |
| 424 i->transfer_state)); | |
| 425 status->SetString("start_time", | |
| 426 gdata::util::FormatTimeAsStringLocaltime(i->start_time)); | |
| 427 status->SetDouble("progress_current", i->progress_current); | |
| 428 status->SetDouble("progress_total", i->progress_total); | |
| 429 in_flight_operations.Append(status); | |
| 430 } | |
| 431 web_ui()->CallJavascriptFunction("updateInFlightOperations", | |
| 432 in_flight_operations); | |
| 433 } | |
| 434 | |
| 379 } // namespace | 435 } // namespace |
| 380 | 436 |
| 381 DriveInternalsUI::DriveInternalsUI(content::WebUI* web_ui) | 437 DriveInternalsUI::DriveInternalsUI(content::WebUI* web_ui) |
| 382 : WebUIController(web_ui) { | 438 : WebUIController(web_ui) { |
| 383 web_ui->AddMessageHandler(new DriveInternalsWebUIHandler()); | 439 web_ui->AddMessageHandler(new DriveInternalsWebUIHandler()); |
| 384 | 440 |
| 385 ChromeWebUIDataSource* source = | 441 ChromeWebUIDataSource* source = |
| 386 new ChromeWebUIDataSource(chrome::kChromeUIDriveInternalsHost); | 442 new ChromeWebUIDataSource(chrome::kChromeUIDriveInternalsHost); |
| 387 source->add_resource_path("drive_internals.css", IDR_DRIVE_INTERNALS_CSS); | 443 source->add_resource_path("drive_internals.css", IDR_DRIVE_INTERNALS_CSS); |
| 388 source->add_resource_path("drive_internals.js", IDR_DRIVE_INTERNALS_JS); | 444 source->add_resource_path("drive_internals.js", IDR_DRIVE_INTERNALS_JS); |
| 389 source->set_default_resource(IDR_DRIVE_INTERNALS_HTML); | 445 source->set_default_resource(IDR_DRIVE_INTERNALS_HTML); |
| 390 | 446 |
| 391 Profile* profile = Profile::FromWebUI(web_ui); | 447 Profile* profile = Profile::FromWebUI(web_ui); |
| 392 ChromeURLDataManager::AddDataSource(profile, source); | 448 ChromeURLDataManager::AddDataSource(profile, source); |
| 393 } | 449 } |
| 394 | 450 |
| 395 } // namespace chromeos | 451 } // namespace chromeos |
| OLD | NEW |