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

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

Issue 23531027: Replace directly use of DriveIntegrationService to drive::util::GetXxxByProfile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | 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/command_line.h" 8 #include "base/command_line.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/files/file_enumerator.h" 10 #include "base/files/file_enumerator.h"
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 virtual ~DriveInternalsWebUIHandler() { 208 virtual ~DriveInternalsWebUIHandler() {
209 } 209 }
210 210
211 private: 211 private:
212 // WebUIMessageHandler override. 212 // WebUIMessageHandler override.
213 virtual void RegisterMessages() OVERRIDE; 213 virtual void RegisterMessages() OVERRIDE;
214 214
215 // Returns a DriveIntegrationService. 215 // Returns a DriveIntegrationService.
216 drive::DriveIntegrationService* GetIntegrationService(); 216 drive::DriveIntegrationService* GetIntegrationService();
217 217
218 // Returns a DriveService instance.
219 drive::DriveServiceInterface* GetDriveService();
220
221 // Returns a FileSystem instance.
222 drive::FileSystemInterface* GetFileSystem();
223
218 // Called when the page is first loaded. 224 // Called when the page is first loaded.
219 void OnPageLoaded(const base::ListValue* args); 225 void OnPageLoaded(const base::ListValue* args);
220 226
221 // Updates respective sections. 227 // Updates respective sections.
222 void UpdateDriveRelatedFlagsSection(); 228 void UpdateDriveRelatedFlagsSection();
223 void UpdateDriveRelatedPreferencesSection(); 229 void UpdateDriveRelatedPreferencesSection();
224 void UpdateAuthStatusSection( 230 void UpdateAuthStatusSection(
225 drive::DriveServiceInterface* drive_service); 231 drive::DriveServiceInterface* drive_service);
226 void UpdateAboutResourceSection( 232 void UpdateAboutResourceSection(
227 drive::DriveServiceInterface* drive_service); 233 drive::DriveServiceInterface* drive_service);
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 web_ui()->RegisterMessageCallback( 373 web_ui()->RegisterMessageCallback(
368 "listFileEntries", 374 "listFileEntries",
369 base::Bind(&DriveInternalsWebUIHandler::ListFileEntries, 375 base::Bind(&DriveInternalsWebUIHandler::ListFileEntries,
370 weak_ptr_factory_.GetWeakPtr())); 376 weak_ptr_factory_.GetWeakPtr()));
371 } 377 }
372 378
373 drive::DriveIntegrationService* 379 drive::DriveIntegrationService*
374 DriveInternalsWebUIHandler::GetIntegrationService() { 380 DriveInternalsWebUIHandler::GetIntegrationService() {
375 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 381 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
376 382
383 // TODO(hidehiko): GetForProfile will return the instance always even if it
384 // is disabled. Needs to check the mounting state then. crbug.com/284972.
377 Profile* profile = Profile::FromWebUI(web_ui()); 385 Profile* profile = Profile::FromWebUI(web_ui());
378 return drive::DriveIntegrationServiceFactory::GetForProfile(profile); 386 return drive::DriveIntegrationServiceFactory::GetForProfile(profile);
379 } 387 }
380 388
389 drive::DriveServiceInterface* DriveInternalsWebUIHandler::GetDriveService() {
390 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
391
392 Profile* profile = Profile::FromWebUI(web_ui());
393 return drive::util::GetDriveServiceByProfile(profile);
394 }
395
396 drive::FileSystemInterface* DriveInternalsWebUIHandler::GetFileSystem() {
397 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
398
399 Profile* profile = Profile::FromWebUI(web_ui());
400 return drive::util::GetFileSystemByProfile(profile);
401 }
402
381 void DriveInternalsWebUIHandler::OnPageLoaded(const base::ListValue* args) { 403 void DriveInternalsWebUIHandler::OnPageLoaded(const base::ListValue* args) {
382 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 404 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
383 405
384 drive::DriveIntegrationService* integration_service = 406 drive::DriveIntegrationService* integration_service =
385 GetIntegrationService(); 407 GetIntegrationService();
386 // |integration_service| may be NULL in the guest/incognito mode. 408 // |integration_service| may be NULL in the guest/incognito mode.
387 if (!integration_service) 409 if (!integration_service)
388 return; 410 return;
389 411
390 drive::DriveServiceInterface* drive_service = 412 drive::DriveServiceInterface* drive_service =
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 base::DictionaryValue local_metadata; 537 base::DictionaryValue local_metadata;
516 local_metadata.SetDouble("account-largest-changestamp-local", 538 local_metadata.SetDouble("account-largest-changestamp-local",
517 metadata.largest_changestamp); 539 metadata.largest_changestamp);
518 local_metadata.SetBoolean("account-metadata-refreshing", metadata.refreshing); 540 local_metadata.SetBoolean("account-metadata-refreshing", metadata.refreshing);
519 web_ui()->CallJavascriptFunction("updateLocalMetadata", local_metadata); 541 web_ui()->CallJavascriptFunction("updateLocalMetadata", local_metadata);
520 } 542 }
521 543
522 void DriveInternalsWebUIHandler::ClearAccessToken(const base::ListValue* args) { 544 void DriveInternalsWebUIHandler::ClearAccessToken(const base::ListValue* args) {
523 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 545 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
524 546
525 drive::DriveIntegrationService* integration_service = 547 drive::DriveServiceInterface* drive_service = GetDriveService();
526 GetIntegrationService(); 548 if (drive_service)
527 if (!integration_service) 549 drive_service->ClearAccessToken();
528 return;
529 integration_service->drive_service()->ClearAccessToken();
530 } 550 }
531 551
532 void DriveInternalsWebUIHandler::ClearRefreshToken( 552 void DriveInternalsWebUIHandler::ClearRefreshToken(
533 const base::ListValue* args) { 553 const base::ListValue* args) {
534 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 554 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
535 555
536 drive::DriveIntegrationService* integration_service = 556 drive::DriveServiceInterface* drive_service = GetDriveService();
537 GetIntegrationService(); 557 if (drive_service)
538 if (!integration_service) 558 drive_service->ClearRefreshToken();
539 return;
540 integration_service->drive_service()->ClearRefreshToken();
541 } 559 }
542 560
543 void DriveInternalsWebUIHandler::ListFileEntries(const base::ListValue* args) { 561 void DriveInternalsWebUIHandler::ListFileEntries(const base::ListValue* args) {
544 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 562 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
545 563
546 UpdateFileSystemContentsSection(); 564 UpdateFileSystemContentsSection();
547 } 565 }
548 566
549 void DriveInternalsWebUIHandler::UpdateDeltaUpdateStatusSection( 567 void DriveInternalsWebUIHandler::UpdateDeltaUpdateStatusSection(
550 drive::DebugInfoCollector* debug_info_collector) { 568 drive::DebugInfoCollector* debug_info_collector) {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 gcache_summary), 641 gcache_summary),
624 base::Bind(&DriveInternalsWebUIHandler::OnGetGCacheContents, 642 base::Bind(&DriveInternalsWebUIHandler::OnGetGCacheContents,
625 weak_ptr_factory_.GetWeakPtr(), 643 weak_ptr_factory_.GetWeakPtr(),
626 base::Owned(gcache_contents), 644 base::Owned(gcache_contents),
627 base::Owned(gcache_summary))); 645 base::Owned(gcache_summary)));
628 } 646 }
629 647
630 void DriveInternalsWebUIHandler::UpdateFileSystemContentsSection() { 648 void DriveInternalsWebUIHandler::UpdateFileSystemContentsSection() {
631 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 649 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
632 650
633 drive::DriveIntegrationService* integration_service = 651 drive::DriveServiceInterface* drive_service = GetDriveService();
634 GetIntegrationService(); 652 drive::FileSystemInterface* file_system = GetFileSystem();
635 if (!integration_service) 653 if (!drive_service || !file_system)
636 return; 654 return;
655
637 // Start updating the file system tree section, if we have access token. 656 // Start updating the file system tree section, if we have access token.
638 if (!integration_service->drive_service()->HasAccessToken()) 657 if (!drive_service->HasAccessToken())
639 return; 658 return;
640 659
641 // Start rendering the file system tree as text. 660 // Start rendering the file system tree as text.
642 const base::FilePath root_path = drive::util::GetDriveGrandRootPath(); 661 const base::FilePath root_path = drive::util::GetDriveGrandRootPath();
643 662
644 integration_service->file_system()->GetResourceEntryByPath( 663 file_system->GetResourceEntryByPath(
645 root_path, 664 root_path,
646 base::Bind(&DriveInternalsWebUIHandler::OnGetResourceEntryByPath, 665 base::Bind(&DriveInternalsWebUIHandler::OnGetResourceEntryByPath,
647 weak_ptr_factory_.GetWeakPtr(), 666 weak_ptr_factory_.GetWeakPtr(),
648 root_path)); 667 root_path));
649 668
650 integration_service->file_system()->ReadDirectoryByPath( 669 file_system->ReadDirectoryByPath(
651 root_path, 670 root_path,
652 base::Bind(&DriveInternalsWebUIHandler::OnReadDirectoryByPath, 671 base::Bind(&DriveInternalsWebUIHandler::OnReadDirectoryByPath,
653 weak_ptr_factory_.GetWeakPtr(), 672 weak_ptr_factory_.GetWeakPtr(),
654 root_path)); 673 root_path));
655 } 674 }
656 675
657 void DriveInternalsWebUIHandler::UpdateLocalStorageUsageSection() { 676 void DriveInternalsWebUIHandler::UpdateLocalStorageUsageSection() {
658 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 677 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
659 678
660 // Propagate the amount of local free space in bytes. 679 // Propagate the amount of local free space in bytes.
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 755
737 void DriveInternalsWebUIHandler::OnReadDirectoryByPath( 756 void DriveInternalsWebUIHandler::OnReadDirectoryByPath(
738 const base::FilePath& parent_path, 757 const base::FilePath& parent_path,
739 drive::FileError error, 758 drive::FileError error,
740 scoped_ptr<drive::ResourceEntryVector> entries) { 759 scoped_ptr<drive::ResourceEntryVector> entries) {
741 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 760 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
742 761
743 if (error == drive::FILE_ERROR_OK) { 762 if (error == drive::FILE_ERROR_OK) {
744 DCHECK(entries.get()); 763 DCHECK(entries.get());
745 764
765 drive::FileSystemInterface* file_system = GetFileSystem();
746 std::string file_system_as_text; 766 std::string file_system_as_text;
747 for (size_t i = 0; i < entries->size(); ++i) { 767 for (size_t i = 0; i < entries->size(); ++i) {
748 const drive::ResourceEntry& entry = (*entries)[i]; 768 const drive::ResourceEntry& entry = (*entries)[i];
749 const base::FilePath current_path = parent_path.Append( 769 const base::FilePath current_path = parent_path.Append(
750 base::FilePath::FromUTF8Unsafe(entry.base_name())); 770 base::FilePath::FromUTF8Unsafe(entry.base_name()));
751 771
752 file_system_as_text.append(FormatEntry(current_path, entry) + "\n"); 772 file_system_as_text.append(FormatEntry(current_path, entry) + "\n");
753 773
754 if (entry.file_info().is_directory()) { 774 if (entry.file_info().is_directory()) {
755 GetIntegrationService()->file_system()->ReadDirectoryByPath( 775 file_system->ReadDirectoryByPath(
756 current_path, 776 current_path,
757 base::Bind(&DriveInternalsWebUIHandler::OnReadDirectoryByPath, 777 base::Bind(&DriveInternalsWebUIHandler::OnReadDirectoryByPath,
758 weak_ptr_factory_.GetWeakPtr(), 778 weak_ptr_factory_.GetWeakPtr(),
759 current_path)); 779 current_path));
760 } 780 }
761 } 781 }
762 782
763 // There may be pending ReadDirectoryByPath() calls, but we can update 783 // There may be pending ReadDirectoryByPath() calls, but we can update
764 // the page with what we have now. This results in progressive 784 // the page with what we have now. This results in progressive
765 // updates, which is good for a large file system. 785 // updates, which is good for a large file system.
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 content::WebUIDataSource::Create(chrome::kChromeUIDriveInternalsHost); 836 content::WebUIDataSource::Create(chrome::kChromeUIDriveInternalsHost);
817 source->AddResourcePath("drive_internals.css", IDR_DRIVE_INTERNALS_CSS); 837 source->AddResourcePath("drive_internals.css", IDR_DRIVE_INTERNALS_CSS);
818 source->AddResourcePath("drive_internals.js", IDR_DRIVE_INTERNALS_JS); 838 source->AddResourcePath("drive_internals.js", IDR_DRIVE_INTERNALS_JS);
819 source->SetDefaultResource(IDR_DRIVE_INTERNALS_HTML); 839 source->SetDefaultResource(IDR_DRIVE_INTERNALS_HTML);
820 840
821 Profile* profile = Profile::FromWebUI(web_ui); 841 Profile* profile = Profile::FromWebUI(web_ui);
822 content::WebUIDataSource::Add(profile, source); 842 content::WebUIDataSource::Add(profile, source);
823 } 843 }
824 844
825 } // namespace chromeos 845 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698