OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/prefs/pref_change_registrar.h" | 10 #include "base/prefs/pref_change_registrar.h" |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 file_manager_private::CopyProgressStatusType | 173 file_manager_private::CopyProgressStatusType |
174 CopyProgressTypeToCopyProgressStatusType( | 174 CopyProgressTypeToCopyProgressStatusType( |
175 storage::FileSystemOperation::CopyProgressType type) { | 175 storage::FileSystemOperation::CopyProgressType type) { |
176 switch (type) { | 176 switch (type) { |
177 case storage::FileSystemOperation::BEGIN_COPY_ENTRY: | 177 case storage::FileSystemOperation::BEGIN_COPY_ENTRY: |
178 return file_manager_private::COPY_PROGRESS_STATUS_TYPE_BEGIN_COPY_ENTRY; | 178 return file_manager_private::COPY_PROGRESS_STATUS_TYPE_BEGIN_COPY_ENTRY; |
179 case storage::FileSystemOperation::END_COPY_ENTRY: | 179 case storage::FileSystemOperation::END_COPY_ENTRY: |
180 return file_manager_private::COPY_PROGRESS_STATUS_TYPE_END_COPY_ENTRY; | 180 return file_manager_private::COPY_PROGRESS_STATUS_TYPE_END_COPY_ENTRY; |
181 case storage::FileSystemOperation::PROGRESS: | 181 case storage::FileSystemOperation::PROGRESS: |
182 return file_manager_private::COPY_PROGRESS_STATUS_TYPE_PROGRESS; | 182 return file_manager_private::COPY_PROGRESS_STATUS_TYPE_PROGRESS; |
| 183 case storage::FileSystemOperation::ERROR_COPY_ENTRY: |
| 184 return file_manager_private::COPY_PROGRESS_STATUS_TYPE_ERROR; |
183 } | 185 } |
184 NOTREACHED(); | 186 NOTREACHED(); |
185 return file_manager_private::COPY_PROGRESS_STATUS_TYPE_NONE; | 187 return file_manager_private::COPY_PROGRESS_STATUS_TYPE_NONE; |
186 } | 188 } |
187 | 189 |
188 file_manager_private::ChangeType ConvertChangeTypeFromDriveToApi( | 190 file_manager_private::ChangeType ConvertChangeTypeFromDriveToApi( |
189 drive::FileChange::ChangeType type) { | 191 drive::FileChange::ChangeType type) { |
190 switch (type) { | 192 switch (type) { |
191 case drive::FileChange::CHANGE_TYPE_ADD_OR_UPDATE: | 193 case drive::FileChange::CHANGE_TYPE_ADD_OR_UPDATE: |
192 return file_manager_private::CHANGE_TYPE_ADD_OR_UPDATE; | 194 return file_manager_private::CHANGE_TYPE_ADD_OR_UPDATE; |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 int copy_id, | 539 int copy_id, |
538 storage::FileSystemOperation::CopyProgressType type, | 540 storage::FileSystemOperation::CopyProgressType type, |
539 const GURL& source_url, | 541 const GURL& source_url, |
540 const GURL& destination_url, | 542 const GURL& destination_url, |
541 int64 size) { | 543 int64 size) { |
542 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 544 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
543 | 545 |
544 file_manager_private::CopyProgressStatus status; | 546 file_manager_private::CopyProgressStatus status; |
545 status.type = CopyProgressTypeToCopyProgressStatusType(type); | 547 status.type = CopyProgressTypeToCopyProgressStatusType(type); |
546 status.source_url.reset(new std::string(source_url.spec())); | 548 status.source_url.reset(new std::string(source_url.spec())); |
547 if (type == storage::FileSystemOperation::END_COPY_ENTRY) | 549 if (type == storage::FileSystemOperation::END_COPY_ENTRY || |
| 550 type == storage::FileSystemOperation::ERROR_COPY_ENTRY) |
548 status.destination_url.reset(new std::string(destination_url.spec())); | 551 status.destination_url.reset(new std::string(destination_url.spec())); |
| 552 if (type == storage::FileSystemOperation::ERROR_COPY_ENTRY) |
| 553 status.error.reset( |
| 554 new std::string(FileErrorToErrorName(base::File::FILE_ERROR_FAILED))); |
549 if (type == storage::FileSystemOperation::PROGRESS) | 555 if (type == storage::FileSystemOperation::PROGRESS) |
550 status.size.reset(new double(size)); | 556 status.size.reset(new double(size)); |
551 | 557 |
| 558 // Discard error progress since current JS code cannot handle this properly. |
| 559 // TODO(yawano): Remove this after JS side is implemented correctly. |
| 560 if (type == storage::FileSystemOperation::ERROR_COPY_ENTRY) |
| 561 return; |
| 562 |
552 // Should not skip events other than TYPE_PROGRESS. | 563 // Should not skip events other than TYPE_PROGRESS. |
553 const bool always = | 564 const bool always = |
554 status.type != file_manager_private::COPY_PROGRESS_STATUS_TYPE_PROGRESS; | 565 status.type != file_manager_private::COPY_PROGRESS_STATUS_TYPE_PROGRESS; |
555 if (!ShouldSendProgressEvent(always, &last_copy_progress_event_)) | 566 if (!ShouldSendProgressEvent(always, &last_copy_progress_event_)) |
556 return; | 567 return; |
557 | 568 |
558 BroadcastEvent( | 569 BroadcastEvent( |
559 profile_, | 570 profile_, |
560 file_manager_private::OnCopyProgress::kEventName, | 571 file_manager_private::OnCopyProgress::kEventName, |
561 file_manager_private::OnCopyProgress::Create(copy_id, status)); | 572 file_manager_private::OnCopyProgress::Create(copy_id, status)); |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
918 void EventRouter::SetDispatchDirectoryChangeEventImplForTesting( | 929 void EventRouter::SetDispatchDirectoryChangeEventImplForTesting( |
919 const DispatchDirectoryChangeEventImplCallback& callback) { | 930 const DispatchDirectoryChangeEventImplCallback& callback) { |
920 dispatch_directory_change_event_impl_ = callback; | 931 dispatch_directory_change_event_impl_ = callback; |
921 } | 932 } |
922 | 933 |
923 base::WeakPtr<EventRouter> EventRouter::GetWeakPtr() { | 934 base::WeakPtr<EventRouter> EventRouter::GetWeakPtr() { |
924 return weak_factory_.GetWeakPtr(); | 935 return weak_factory_.GetWeakPtr(); |
925 } | 936 } |
926 | 937 |
927 } // namespace file_manager | 938 } // namespace file_manager |
OLD | NEW |