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

Side by Side Diff: chrome/browser/chromeos/extensions/file_manager/event_router.cc

Issue 147993003: Clarify and separate the concept of "Drive path" and "Filesystem relative path". (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 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
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/chromeos/extensions/file_manager/event_router.h" 5 #include "chrome/browser/chromeos/extensions/file_manager/event_router.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/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/prefs/pref_change_registrar.h" 10 #include "base/prefs/pref_change_registrar.h"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 const int64 kFileTransferEventFrequencyInMilliseconds = 1000; 85 const int64 kFileTransferEventFrequencyInMilliseconds = 1000;
86 86
87 // Utility function to check if |job_info| is a file uploading job. 87 // Utility function to check if |job_info| is a file uploading job.
88 bool IsUploadJob(drive::JobType type) { 88 bool IsUploadJob(drive::JobType type) {
89 return (type == drive::TYPE_UPLOAD_NEW_FILE || 89 return (type == drive::TYPE_UPLOAD_NEW_FILE ||
90 type == drive::TYPE_UPLOAD_EXISTING_FILE); 90 type == drive::TYPE_UPLOAD_EXISTING_FILE);
91 } 91 }
92 92
93 // Converts the job info to a IDL generated type. 93 // Converts the job info to a IDL generated type.
94 void JobInfoToTransferStatus( 94 void JobInfoToTransferStatus(
95 Profile* profile,
95 const std::string& extension_id, 96 const std::string& extension_id,
96 const std::string& job_status, 97 const std::string& job_status,
97 const drive::JobInfo& job_info, 98 const drive::JobInfo& job_info,
98 file_browser_private::FileTransferStatus* status) { 99 file_browser_private::FileTransferStatus* status) {
99 DCHECK(IsActiveFileTransferJobInfo(job_info)); 100 DCHECK(IsActiveFileTransferJobInfo(job_info));
100 101
101 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue); 102 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue);
102 GURL url = util::ConvertRelativeFilePathToFileSystemUrl( 103 GURL url = util::ConvertDrivePathToFileSystemUrl(
103 job_info.file_path, extension_id); 104 profile, job_info.file_path, extension_id);
104 status->file_url = url.spec(); 105 status->file_url = url.spec();
105 status->transfer_state = file_browser_private::ParseTransferState(job_status); 106 status->transfer_state = file_browser_private::ParseTransferState(job_status);
106 status->transfer_type = 107 status->transfer_type =
107 IsUploadJob(job_info.job_type) ? 108 IsUploadJob(job_info.job_type) ?
108 file_browser_private::TRANSFER_TYPE_UPLOAD : 109 file_browser_private::TRANSFER_TYPE_UPLOAD :
109 file_browser_private::TRANSFER_TYPE_DOWNLOAD; 110 file_browser_private::TRANSFER_TYPE_DOWNLOAD;
110 // JavaScript does not have 64-bit integers. Instead we use double, which 111 // JavaScript does not have 64-bit integers. Instead we use double, which
111 // is in IEEE 754 formant and accurate up to 52-bits in JS, and in practice 112 // is in IEEE 754 formant and accurate up to 52-bits in JS, and in practice
112 // in C++. Larger values are rounded. 113 // in C++. Larger values are rounded.
113 status->processed.reset( 114 status->processed.reset(
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 return; 541 return;
541 } 542 }
542 543
543 // Convert the current |drive_jobs_| to IDL type. 544 // Convert the current |drive_jobs_| to IDL type.
544 std::vector<linked_ptr<file_browser_private::FileTransferStatus> > 545 std::vector<linked_ptr<file_browser_private::FileTransferStatus> >
545 status_list; 546 status_list;
546 for (std::map<drive::JobID, DriveJobInfoWithStatus>::iterator 547 for (std::map<drive::JobID, DriveJobInfoWithStatus>::iterator
547 iter = drive_jobs_.begin(); iter != drive_jobs_.end(); ++iter) { 548 iter = drive_jobs_.begin(); iter != drive_jobs_.end(); ++iter) {
548 linked_ptr<file_browser_private::FileTransferStatus> status( 549 linked_ptr<file_browser_private::FileTransferStatus> status(
549 new file_browser_private::FileTransferStatus()); 550 new file_browser_private::FileTransferStatus());
550 JobInfoToTransferStatus(kFileManagerAppId, 551 JobInfoToTransferStatus(profile_,
552 kFileManagerAppId,
551 iter->second.status, 553 iter->second.status,
552 iter->second.job_info, 554 iter->second.job_info,
553 status.get()); 555 status.get());
554 status_list.push_back(status); 556 status_list.push_back(status);
555 } 557 }
556 BroadcastEvent( 558 BroadcastEvent(
557 profile_, 559 profile_,
558 file_browser_private::OnFileTransfersUpdated::kEventName, 560 file_browser_private::OnFileTransfersUpdated::kEventName,
559 file_browser_private::OnFileTransfersUpdated::Create(status_list)); 561 file_browser_private::OnFileTransfersUpdated::Create(status_list));
560 last_file_transfer_event_ = now; 562 last_file_transfer_event_ = now;
561 } 563 }
562 564
563 void EventRouter::OnDirectoryChanged(const base::FilePath& directory_path) { 565 void EventRouter::OnDirectoryChanged(const base::FilePath& drive_path) {
564 HandleFileWatchNotification(directory_path, false); 566 HandleFileWatchNotification(drive_path, false);
565 } 567 }
566 568
567 void EventRouter::OnDriveSyncError( 569 void EventRouter::OnDriveSyncError(drive::file_system::DriveSyncErrorType type,
568 drive::file_system::DriveSyncErrorType type, 570 const base::FilePath& drive_path) {
569 const base::FilePath& file_path) {
570 file_browser_private::DriveSyncErrorEvent event; 571 file_browser_private::DriveSyncErrorEvent event;
571 switch (type) { 572 switch (type) {
572 case drive::file_system::DRIVE_SYNC_ERROR_DELETE_WITHOUT_PERMISSION: 573 case drive::file_system::DRIVE_SYNC_ERROR_DELETE_WITHOUT_PERMISSION:
573 event.type = 574 event.type =
574 file_browser_private::DRIVE_SYNC_ERROR_TYPE_DELETE_WITHOUT_PERMISSION; 575 file_browser_private::DRIVE_SYNC_ERROR_TYPE_DELETE_WITHOUT_PERMISSION;
575 break; 576 break;
576 case drive::file_system::DRIVE_SYNC_ERROR_SERVICE_UNAVAILABLE: 577 case drive::file_system::DRIVE_SYNC_ERROR_SERVICE_UNAVAILABLE:
577 event.type = 578 event.type =
578 file_browser_private::DRIVE_SYNC_ERROR_TYPE_SERVICE_UNAVAILABLE; 579 file_browser_private::DRIVE_SYNC_ERROR_TYPE_SERVICE_UNAVAILABLE;
579 break; 580 break;
580 case drive::file_system::DRIVE_SYNC_ERROR_MISC: 581 case drive::file_system::DRIVE_SYNC_ERROR_MISC:
581 event.type = 582 event.type =
582 file_browser_private::DRIVE_SYNC_ERROR_TYPE_MISC; 583 file_browser_private::DRIVE_SYNC_ERROR_TYPE_MISC;
583 break; 584 break;
584 } 585 }
585 event.file_url = util::ConvertRelativeFilePathToFileSystemUrl( 586 event.file_url = util::ConvertDrivePathToFileSystemUrl(
586 file_path, kFileManagerAppId).spec(); 587 profile_, drive_path, kFileManagerAppId).spec();
587 BroadcastEvent( 588 BroadcastEvent(
588 profile_, 589 profile_,
589 file_browser_private::OnDriveSyncError::kEventName, 590 file_browser_private::OnDriveSyncError::kEventName,
590 file_browser_private::OnDriveSyncError::Create(event)); 591 file_browser_private::OnDriveSyncError::Create(event));
591 } 592 }
592 593
593 void EventRouter::OnRefreshTokenInvalid() { 594 void EventRouter::OnRefreshTokenInvalid() {
594 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 595 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
595 596
596 // Raise a DriveConnectionStatusChanged event to notify the status offline. 597 // Raise a DriveConnectionStatusChanged event to notify the status offline.
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 void EventRouter::OnFormatCompleted(const std::string& device_path, 782 void EventRouter::OnFormatCompleted(const std::string& device_path,
782 bool success) { 783 bool success) {
783 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 784 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
784 DispatchDeviceEvent(success ? 785 DispatchDeviceEvent(success ?
785 file_browser_private::DEVICE_EVENT_TYPE_FORMAT_SUCCESS : 786 file_browser_private::DEVICE_EVENT_TYPE_FORMAT_SUCCESS :
786 file_browser_private::DEVICE_EVENT_TYPE_FORMAT_FAIL, 787 file_browser_private::DEVICE_EVENT_TYPE_FORMAT_FAIL,
787 device_path); 788 device_path);
788 } 789 }
789 790
790 } // namespace file_manager 791 } // namespace file_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698