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

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

Issue 10828422: drive: Add information about in-flight operations to chrome:drive-internals (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: rebase, simplify a for-loop Created 8 years, 3 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
« 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"
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
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
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 gdata::OperationRegistry::ProgressStatus status = progress_status_list[i];
satorux1 2012/08/28 23:19:10 I think you can make it a const ref const gdata::
Haruki Sato 2012/08/29 17:15:45 Done. Thanks.
414
415 base::DictionaryValue* dict = new DictionaryValue;
416 dict->SetInteger("operation_id", status.operation_id);
417 dict->SetString(
418 "operation_type",
419 gdata::OperationRegistry::OperationTypeToString(status.operation_type));
420 dict->SetString("file_path", status.file_path.AsUTF8Unsafe());
421 dict->SetString(
422 "transfer_state",
423 gdata::OperationRegistry::OperationTransferStateToString(
424 status.transfer_state));
425 dict->SetString(
426 "start_time",
427 gdata::util::FormatTimeAsStringLocaltime(status.start_time));
428 dict->SetDouble("progress_current", status.progress_current);
429 dict->SetDouble("progress_total", status.progress_total);
430 in_flight_operations.Append(dict);
431 }
432 web_ui()->CallJavascriptFunction("updateInFlightOperations",
433 in_flight_operations);
434 }
435
379 } // namespace 436 } // namespace
380 437
381 DriveInternalsUI::DriveInternalsUI(content::WebUI* web_ui) 438 DriveInternalsUI::DriveInternalsUI(content::WebUI* web_ui)
382 : WebUIController(web_ui) { 439 : WebUIController(web_ui) {
383 web_ui->AddMessageHandler(new DriveInternalsWebUIHandler()); 440 web_ui->AddMessageHandler(new DriveInternalsWebUIHandler());
384 441
385 ChromeWebUIDataSource* source = 442 ChromeWebUIDataSource* source =
386 new ChromeWebUIDataSource(chrome::kChromeUIDriveInternalsHost); 443 new ChromeWebUIDataSource(chrome::kChromeUIDriveInternalsHost);
387 source->add_resource_path("drive_internals.css", IDR_DRIVE_INTERNALS_CSS); 444 source->add_resource_path("drive_internals.css", IDR_DRIVE_INTERNALS_CSS);
388 source->add_resource_path("drive_internals.js", IDR_DRIVE_INTERNALS_JS); 445 source->add_resource_path("drive_internals.js", IDR_DRIVE_INTERNALS_JS);
389 source->set_default_resource(IDR_DRIVE_INTERNALS_HTML); 446 source->set_default_resource(IDR_DRIVE_INTERNALS_HTML);
390 447
391 Profile* profile = Profile::FromWebUI(web_ui); 448 Profile* profile = Profile::FromWebUI(web_ui);
392 ChromeURLDataManager::AddDataSource(profile, source); 449 ChromeURLDataManager::AddDataSource(profile, source);
393 } 450 }
394 451
395 } // namespace chromeos 452 } // 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