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

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: Created 8 years, 4 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
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_service_interface.h" 17 #include "chrome/browser/chromeos/gdata/drive_service_interface.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/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 // Updates the summary about in-flight operations.
201 void UpdateInFlightOperations(
202 const gdata::DriveServiceInterface* drive_service);
203
199 // The number of pending ReadDirectoryByPath() calls. 204 // The number of pending ReadDirectoryByPath() calls.
200 int num_pending_reads_; 205 int num_pending_reads_;
201 base::WeakPtrFactory<DriveInternalsWebUIHandler> weak_ptr_factory_; 206 base::WeakPtrFactory<DriveInternalsWebUIHandler> weak_ptr_factory_;
202 DISALLOW_COPY_AND_ASSIGN(DriveInternalsWebUIHandler); 207 DISALLOW_COPY_AND_ASSIGN(DriveInternalsWebUIHandler);
203 }; 208 };
204 209
205 void DriveInternalsWebUIHandler::RegisterMessages() { 210 void DriveInternalsWebUIHandler::RegisterMessages() {
206 web_ui()->RegisterMessageCallback( 211 web_ui()->RegisterMessageCallback(
207 "pageLoaded", 212 "pageLoaded",
208 base::Bind(&DriveInternalsWebUIHandler::OnPageLoaded, 213 base::Bind(&DriveInternalsWebUIHandler::OnPageLoaded,
(...skipping 17 matching lines...) Expand all
226 DCHECK(drive_service); 231 DCHECK(drive_service);
227 232
228 // Update the auth status section. 233 // Update the auth status section.
229 base::DictionaryValue auth_status; 234 base::DictionaryValue auth_status;
230 auth_status.SetBoolean("has-refresh-token", 235 auth_status.SetBoolean("has-refresh-token",
231 drive_service->HasRefreshToken()); 236 drive_service->HasRefreshToken());
232 auth_status.SetBoolean("has-access-token", 237 auth_status.SetBoolean("has-access-token",
233 drive_service->HasAccessToken()); 238 drive_service->HasAccessToken());
234 web_ui()->CallJavascriptFunction("updateAuthStatus", auth_status); 239 web_ui()->CallJavascriptFunction("updateAuthStatus", auth_status);
235 240
241 // Update information about in-flight operations.
242 UpdateInFlightOperations(drive_service);
satorux1 2012/08/22 20:20:02 as mentioned in .js file, I think we should update
Haruki Sato 2012/08/24 19:06:11 Done.
243
236 // Start updating the GCache contents section. 244 // Start updating the GCache contents section.
237 Profile* profile = Profile::FromWebUI(web_ui()); 245 Profile* profile = Profile::FromWebUI(web_ui());
238 const FilePath root_path = 246 const FilePath root_path =
239 gdata::DriveCache::GetCacheRootPath(profile); 247 gdata::DriveCache::GetCacheRootPath(profile);
240 base::ListValue* gcache_contents = new ListValue; 248 base::ListValue* gcache_contents = new ListValue;
241 base::DictionaryValue* gcache_summary = new DictionaryValue; 249 base::DictionaryValue* gcache_summary = new DictionaryValue;
242 BrowserThread::PostBlockingPoolTaskAndReply( 250 BrowserThread::PostBlockingPoolTaskAndReply(
243 FROM_HERE, 251 FROM_HERE,
244 base::Bind(&GetGCacheContents, 252 base::Bind(&GetGCacheContents,
245 root_path, 253 root_path,
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 377
370 void DriveInternalsWebUIHandler::OnGetFreeDiskSpace( 378 void DriveInternalsWebUIHandler::OnGetFreeDiskSpace(
371 base::DictionaryValue* local_storage_summary) { 379 base::DictionaryValue* local_storage_summary) {
372 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 380 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
373 DCHECK(local_storage_summary); 381 DCHECK(local_storage_summary);
374 382
375 web_ui()->CallJavascriptFunction( 383 web_ui()->CallJavascriptFunction(
376 "updateLocalStorageUsage", *local_storage_summary); 384 "updateLocalStorageUsage", *local_storage_summary);
377 } 385 }
378 386
387 void DriveInternalsWebUIHandler::UpdateInFlightOperations(
388 const gdata::DriveServiceInterface* drive_service) {
389 std::vector<gdata::OperationRegistry::ProgressStatus>
390 progress_status_list = drive_service->operation_registry()->
391 GetProgressStatusList();
392
393 base::ListValue in_flight_operations;
394 for (std::vector<gdata::OperationRegistry::ProgressStatus>::iterator i
395 = progress_status_list.begin();
396 i != progress_status_list.end(); ++i) {
397 base::DictionaryValue* status = new DictionaryValue;
398 status->SetInteger("operation_id", i->operation_id);
399 status->SetString(
400 "operation_type",
401 gdata::OperationRegistry::OperationTypeToString(i->operation_type));
402 status->SetString("file_path", i->file_path.AsUTF8Unsafe());
403 status->SetString(
404 "transfer_state",
405 gdata::OperationRegistry::OperationTransferStateToString(
406 i->transfer_state));
407 status->SetString("start_time",
408 gdata::util::FormatTimeAsStringLocaltime(i->start_time));
409 status->SetDouble("progress_current", i->progress_current);
410 status->SetDouble("progress_total", i->progress_total);
411 in_flight_operations.Append(status);
412 }
413 web_ui()->CallJavascriptFunction("updateInFlightOperations",
414 in_flight_operations);
415 }
416
379 } // namespace 417 } // namespace
380 418
381 DriveInternalsUI::DriveInternalsUI(content::WebUI* web_ui) 419 DriveInternalsUI::DriveInternalsUI(content::WebUI* web_ui)
382 : WebUIController(web_ui) { 420 : WebUIController(web_ui) {
383 web_ui->AddMessageHandler(new DriveInternalsWebUIHandler()); 421 web_ui->AddMessageHandler(new DriveInternalsWebUIHandler());
384 422
385 ChromeWebUIDataSource* source = 423 ChromeWebUIDataSource* source =
386 new ChromeWebUIDataSource(chrome::kChromeUIDriveInternalsHost); 424 new ChromeWebUIDataSource(chrome::kChromeUIDriveInternalsHost);
387 source->add_resource_path("drive_internals.css", IDR_DRIVE_INTERNALS_CSS); 425 source->add_resource_path("drive_internals.css", IDR_DRIVE_INTERNALS_CSS);
388 source->add_resource_path("drive_internals.js", IDR_DRIVE_INTERNALS_JS); 426 source->add_resource_path("drive_internals.js", IDR_DRIVE_INTERNALS_JS);
389 source->set_default_resource(IDR_DRIVE_INTERNALS_HTML); 427 source->set_default_resource(IDR_DRIVE_INTERNALS_HTML);
390 428
391 Profile* profile = Profile::FromWebUI(web_ui); 429 Profile* profile = Profile::FromWebUI(web_ui);
392 ChromeURLDataManager::AddDataSource(profile, source); 430 ChromeURLDataManager::AddDataSource(profile, source);
393 } 431 }
394 432
395 } // namespace chromeos 433 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698