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

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

Issue 550863003: Rename fileBrowserPrivate to fileManagerPrivate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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
OLDNEW
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/files/file_util.h" 8 #include "base/files/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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 #include "storage/common/fileapi/file_system_util.h" 49 #include "storage/common/fileapi/file_system_util.h"
50 50
51 using chromeos::disks::DiskMountManager; 51 using chromeos::disks::DiskMountManager;
52 using chromeos::NetworkHandler; 52 using chromeos::NetworkHandler;
53 using content::BrowserThread; 53 using content::BrowserThread;
54 using drive::DriveIntegrationService; 54 using drive::DriveIntegrationService;
55 using drive::DriveIntegrationServiceFactory; 55 using drive::DriveIntegrationServiceFactory;
56 using file_manager::util::EntryDefinition; 56 using file_manager::util::EntryDefinition;
57 using file_manager::util::FileDefinition; 57 using file_manager::util::FileDefinition;
58 58
59 namespace file_browser_private = extensions::api::file_browser_private; 59 namespace file_manager_private = extensions::api::file_manager_private;
60 60
61 namespace file_manager { 61 namespace file_manager {
62 namespace { 62 namespace {
63 // Constants for the "transferState" field of onFileTransferUpdated event. 63 // Constants for the "transferState" field of onFileTransferUpdated event.
64 const char kFileTransferStateAdded[] = "added"; 64 const char kFileTransferStateAdded[] = "added";
65 const char kFileTransferStateStarted[] = "started"; 65 const char kFileTransferStateStarted[] = "started";
66 const char kFileTransferStateInProgress[] = "in_progress"; 66 const char kFileTransferStateInProgress[] = "in_progress";
67 const char kFileTransferStateCompleted[] = "completed"; 67 const char kFileTransferStateCompleted[] = "completed";
68 const char kFileTransferStateFailed[] = "failed"; 68 const char kFileTransferStateFailed[] = "failed";
69 69
(...skipping 23 matching lines...) Expand all
93 } 93 }
94 return num_active_file_transfer_job_info; 94 return num_active_file_transfer_job_info;
95 } 95 }
96 96
97 // Converts the job info to a IDL generated type. 97 // Converts the job info to a IDL generated type.
98 void JobInfoToTransferStatus( 98 void JobInfoToTransferStatus(
99 Profile* profile, 99 Profile* profile,
100 const std::string& extension_id, 100 const std::string& extension_id,
101 const std::string& job_status, 101 const std::string& job_status,
102 const drive::JobInfo& job_info, 102 const drive::JobInfo& job_info,
103 file_browser_private::FileTransferStatus* status) { 103 file_manager_private::FileTransferStatus* status) {
104 DCHECK(IsActiveFileTransferJobInfo(job_info)); 104 DCHECK(IsActiveFileTransferJobInfo(job_info));
105 105
106 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue); 106 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue);
107 GURL url = util::ConvertDrivePathToFileSystemUrl( 107 GURL url = util::ConvertDrivePathToFileSystemUrl(
108 profile, job_info.file_path, extension_id); 108 profile, job_info.file_path, extension_id);
109 status->file_url = url.spec(); 109 status->file_url = url.spec();
110 status->transfer_state = file_browser_private::ParseTransferState(job_status); 110 status->transfer_state = file_manager_private::ParseTransferState(job_status);
111 status->transfer_type = 111 status->transfer_type =
112 IsUploadJob(job_info.job_type) ? 112 IsUploadJob(job_info.job_type) ?
113 file_browser_private::TRANSFER_TYPE_UPLOAD : 113 file_manager_private::TRANSFER_TYPE_UPLOAD :
114 file_browser_private::TRANSFER_TYPE_DOWNLOAD; 114 file_manager_private::TRANSFER_TYPE_DOWNLOAD;
115 DriveIntegrationService* const integration_service = 115 DriveIntegrationService* const integration_service =
116 DriveIntegrationServiceFactory::FindForProfile(profile); 116 DriveIntegrationServiceFactory::FindForProfile(profile);
117 status->num_total_jobs = CountActiveFileTransferJobInfo( 117 status->num_total_jobs = CountActiveFileTransferJobInfo(
118 integration_service->job_list()->GetJobInfoList()); 118 integration_service->job_list()->GetJobInfoList());
119 // JavaScript does not have 64-bit integers. Instead we use double, which 119 // JavaScript does not have 64-bit integers. Instead we use double, which
120 // is in IEEE 754 formant and accurate up to 52-bits in JS, and in practice 120 // is in IEEE 754 formant and accurate up to 52-bits in JS, and in practice
121 // in C++. Larger values are rounded. 121 // in C++. Larger values are rounded.
122 status->processed.reset( 122 status->processed.reset(
123 new double(static_cast<double>(job_info.num_completed_bytes))); 123 new double(static_cast<double>(job_info.num_completed_bytes)));
124 status->total.reset( 124 status->total.reset(
(...skipping 23 matching lines...) Expand all
148 } 148 }
149 149
150 // Sends an event named |event_name| with arguments |event_args| to extensions. 150 // Sends an event named |event_name| with arguments |event_args| to extensions.
151 void BroadcastEvent(Profile* profile, 151 void BroadcastEvent(Profile* profile,
152 const std::string& event_name, 152 const std::string& event_name,
153 scoped_ptr<base::ListValue> event_args) { 153 scoped_ptr<base::ListValue> event_args) {
154 extensions::EventRouter::Get(profile)->BroadcastEvent( 154 extensions::EventRouter::Get(profile)->BroadcastEvent(
155 make_scoped_ptr(new extensions::Event(event_name, event_args.Pass()))); 155 make_scoped_ptr(new extensions::Event(event_name, event_args.Pass())));
156 } 156 }
157 157
158 file_browser_private::MountCompletedStatus 158 file_manager_private::MountCompletedStatus
159 MountErrorToMountCompletedStatus(chromeos::MountError error) { 159 MountErrorToMountCompletedStatus(chromeos::MountError error) {
160 switch (error) { 160 switch (error) {
161 case chromeos::MOUNT_ERROR_NONE: 161 case chromeos::MOUNT_ERROR_NONE:
162 return file_browser_private::MOUNT_COMPLETED_STATUS_SUCCESS; 162 return file_manager_private::MOUNT_COMPLETED_STATUS_SUCCESS;
163 case chromeos::MOUNT_ERROR_UNKNOWN: 163 case chromeos::MOUNT_ERROR_UNKNOWN:
164 return file_browser_private::MOUNT_COMPLETED_STATUS_ERROR_UNKNOWN; 164 return file_manager_private::MOUNT_COMPLETED_STATUS_ERROR_UNKNOWN;
165 case chromeos::MOUNT_ERROR_INTERNAL: 165 case chromeos::MOUNT_ERROR_INTERNAL:
166 return file_browser_private::MOUNT_COMPLETED_STATUS_ERROR_INTERNAL; 166 return file_manager_private::MOUNT_COMPLETED_STATUS_ERROR_INTERNAL;
167 case chromeos::MOUNT_ERROR_INVALID_ARGUMENT: 167 case chromeos::MOUNT_ERROR_INVALID_ARGUMENT:
168 return file_browser_private:: 168 return file_manager_private::
169 MOUNT_COMPLETED_STATUS_ERROR_INVALID_ARGUMENT; 169 MOUNT_COMPLETED_STATUS_ERROR_INVALID_ARGUMENT;
170 case chromeos::MOUNT_ERROR_INVALID_PATH: 170 case chromeos::MOUNT_ERROR_INVALID_PATH:
171 return file_browser_private::MOUNT_COMPLETED_STATUS_ERROR_INVALID_PATH; 171 return file_manager_private::MOUNT_COMPLETED_STATUS_ERROR_INVALID_PATH;
172 case chromeos::MOUNT_ERROR_PATH_ALREADY_MOUNTED: 172 case chromeos::MOUNT_ERROR_PATH_ALREADY_MOUNTED:
173 return file_browser_private:: 173 return file_manager_private::
174 MOUNT_COMPLETED_STATUS_ERROR_PATH_ALREADY_MOUNTED; 174 MOUNT_COMPLETED_STATUS_ERROR_PATH_ALREADY_MOUNTED;
175 case chromeos::MOUNT_ERROR_PATH_NOT_MOUNTED: 175 case chromeos::MOUNT_ERROR_PATH_NOT_MOUNTED:
176 return file_browser_private:: 176 return file_manager_private::
177 MOUNT_COMPLETED_STATUS_ERROR_PATH_NOT_MOUNTED; 177 MOUNT_COMPLETED_STATUS_ERROR_PATH_NOT_MOUNTED;
178 case chromeos::MOUNT_ERROR_DIRECTORY_CREATION_FAILED: 178 case chromeos::MOUNT_ERROR_DIRECTORY_CREATION_FAILED:
179 return file_browser_private 179 return file_manager_private
180 ::MOUNT_COMPLETED_STATUS_ERROR_DIRECTORY_CREATION_FAILED; 180 ::MOUNT_COMPLETED_STATUS_ERROR_DIRECTORY_CREATION_FAILED;
181 case chromeos::MOUNT_ERROR_INVALID_MOUNT_OPTIONS: 181 case chromeos::MOUNT_ERROR_INVALID_MOUNT_OPTIONS:
182 return file_browser_private 182 return file_manager_private
183 ::MOUNT_COMPLETED_STATUS_ERROR_INVALID_MOUNT_OPTIONS; 183 ::MOUNT_COMPLETED_STATUS_ERROR_INVALID_MOUNT_OPTIONS;
184 case chromeos::MOUNT_ERROR_INVALID_UNMOUNT_OPTIONS: 184 case chromeos::MOUNT_ERROR_INVALID_UNMOUNT_OPTIONS:
185 return file_browser_private:: 185 return file_manager_private::
186 MOUNT_COMPLETED_STATUS_ERROR_INVALID_UNMOUNT_OPTIONS; 186 MOUNT_COMPLETED_STATUS_ERROR_INVALID_UNMOUNT_OPTIONS;
187 case chromeos::MOUNT_ERROR_INSUFFICIENT_PERMISSIONS: 187 case chromeos::MOUNT_ERROR_INSUFFICIENT_PERMISSIONS:
188 return file_browser_private:: 188 return file_manager_private::
189 MOUNT_COMPLETED_STATUS_ERROR_INSUFFICIENT_PERMISSIONS; 189 MOUNT_COMPLETED_STATUS_ERROR_INSUFFICIENT_PERMISSIONS;
190 case chromeos::MOUNT_ERROR_MOUNT_PROGRAM_NOT_FOUND: 190 case chromeos::MOUNT_ERROR_MOUNT_PROGRAM_NOT_FOUND:
191 return file_browser_private:: 191 return file_manager_private::
192 MOUNT_COMPLETED_STATUS_ERROR_MOUNT_PROGRAM_NOT_FOUND; 192 MOUNT_COMPLETED_STATUS_ERROR_MOUNT_PROGRAM_NOT_FOUND;
193 case chromeos::MOUNT_ERROR_MOUNT_PROGRAM_FAILED: 193 case chromeos::MOUNT_ERROR_MOUNT_PROGRAM_FAILED:
194 return file_browser_private:: 194 return file_manager_private::
195 MOUNT_COMPLETED_STATUS_ERROR_MOUNT_PROGRAM_FAILED; 195 MOUNT_COMPLETED_STATUS_ERROR_MOUNT_PROGRAM_FAILED;
196 case chromeos::MOUNT_ERROR_INVALID_DEVICE_PATH: 196 case chromeos::MOUNT_ERROR_INVALID_DEVICE_PATH:
197 return file_browser_private:: 197 return file_manager_private::
198 MOUNT_COMPLETED_STATUS_ERROR_INVALID_DEVICE_PATH; 198 MOUNT_COMPLETED_STATUS_ERROR_INVALID_DEVICE_PATH;
199 case chromeos::MOUNT_ERROR_UNKNOWN_FILESYSTEM: 199 case chromeos::MOUNT_ERROR_UNKNOWN_FILESYSTEM:
200 return file_browser_private:: 200 return file_manager_private::
201 MOUNT_COMPLETED_STATUS_ERROR_UNKNOWN_FILESYSTEM; 201 MOUNT_COMPLETED_STATUS_ERROR_UNKNOWN_FILESYSTEM;
202 case chromeos::MOUNT_ERROR_UNSUPPORTED_FILESYSTEM: 202 case chromeos::MOUNT_ERROR_UNSUPPORTED_FILESYSTEM:
203 return file_browser_private:: 203 return file_manager_private::
204 MOUNT_COMPLETED_STATUS_ERROR_UNSUPPORTED_FILESYSTEM; 204 MOUNT_COMPLETED_STATUS_ERROR_UNSUPPORTED_FILESYSTEM;
205 case chromeos::MOUNT_ERROR_INVALID_ARCHIVE: 205 case chromeos::MOUNT_ERROR_INVALID_ARCHIVE:
206 return file_browser_private::MOUNT_COMPLETED_STATUS_ERROR_INVALID_ARCHIVE; 206 return file_manager_private::MOUNT_COMPLETED_STATUS_ERROR_INVALID_ARCHIVE;
207 case chromeos::MOUNT_ERROR_NOT_AUTHENTICATED: 207 case chromeos::MOUNT_ERROR_NOT_AUTHENTICATED:
208 return file_browser_private::MOUNT_COMPLETED_STATUS_ERROR_AUTHENTICATION; 208 return file_manager_private::MOUNT_COMPLETED_STATUS_ERROR_AUTHENTICATION;
209 case chromeos::MOUNT_ERROR_PATH_UNMOUNTED: 209 case chromeos::MOUNT_ERROR_PATH_UNMOUNTED:
210 return file_browser_private::MOUNT_COMPLETED_STATUS_ERROR_PATH_UNMOUNTED; 210 return file_manager_private::MOUNT_COMPLETED_STATUS_ERROR_PATH_UNMOUNTED;
211 } 211 }
212 NOTREACHED(); 212 NOTREACHED();
213 return file_browser_private::MOUNT_COMPLETED_STATUS_NONE; 213 return file_manager_private::MOUNT_COMPLETED_STATUS_NONE;
214 } 214 }
215 215
216 file_browser_private::CopyProgressStatusType 216 file_manager_private::CopyProgressStatusType
217 CopyProgressTypeToCopyProgressStatusType( 217 CopyProgressTypeToCopyProgressStatusType(
218 storage::FileSystemOperation::CopyProgressType type) { 218 storage::FileSystemOperation::CopyProgressType type) {
219 switch (type) { 219 switch (type) {
220 case storage::FileSystemOperation::BEGIN_COPY_ENTRY: 220 case storage::FileSystemOperation::BEGIN_COPY_ENTRY:
221 return file_browser_private::COPY_PROGRESS_STATUS_TYPE_BEGIN_COPY_ENTRY; 221 return file_manager_private::COPY_PROGRESS_STATUS_TYPE_BEGIN_COPY_ENTRY;
222 case storage::FileSystemOperation::END_COPY_ENTRY: 222 case storage::FileSystemOperation::END_COPY_ENTRY:
223 return file_browser_private::COPY_PROGRESS_STATUS_TYPE_END_COPY_ENTRY; 223 return file_manager_private::COPY_PROGRESS_STATUS_TYPE_END_COPY_ENTRY;
224 case storage::FileSystemOperation::PROGRESS: 224 case storage::FileSystemOperation::PROGRESS:
225 return file_browser_private::COPY_PROGRESS_STATUS_TYPE_PROGRESS; 225 return file_manager_private::COPY_PROGRESS_STATUS_TYPE_PROGRESS;
226 } 226 }
227 NOTREACHED(); 227 NOTREACHED();
228 return file_browser_private::COPY_PROGRESS_STATUS_TYPE_NONE; 228 return file_manager_private::COPY_PROGRESS_STATUS_TYPE_NONE;
229 } 229 }
230 230
231 file_browser_private::ChangeType ConvertChangeTypeFromDriveToApi( 231 file_manager_private::ChangeType ConvertChangeTypeFromDriveToApi(
232 drive::FileChange::ChangeType type) { 232 drive::FileChange::ChangeType type) {
233 switch (type) { 233 switch (type) {
234 case drive::FileChange::ADD_OR_UPDATE: 234 case drive::FileChange::ADD_OR_UPDATE:
235 return file_browser_private::CHANGE_TYPE_ADD_OR_UPDATE; 235 return file_manager_private::CHANGE_TYPE_ADD_OR_UPDATE;
236 case drive::FileChange::DELETE: 236 case drive::FileChange::DELETE:
237 return file_browser_private::CHANGE_TYPE_DELETE; 237 return file_manager_private::CHANGE_TYPE_DELETE;
238 } 238 }
239 NOTREACHED(); 239 NOTREACHED();
240 return file_browser_private::CHANGE_TYPE_ADD_OR_UPDATE; 240 return file_manager_private::CHANGE_TYPE_ADD_OR_UPDATE;
241 } 241 }
242 242
243 std::string FileErrorToErrorName(base::File::Error error_code) { 243 std::string FileErrorToErrorName(base::File::Error error_code) {
244 namespace js = extensions::api::file_browser_private; 244 namespace js = extensions::api::file_manager_private;
245 switch (error_code) { 245 switch (error_code) {
246 case base::File::FILE_ERROR_NOT_FOUND: 246 case base::File::FILE_ERROR_NOT_FOUND:
247 return "NotFoundError"; 247 return "NotFoundError";
248 case base::File::FILE_ERROR_INVALID_OPERATION: 248 case base::File::FILE_ERROR_INVALID_OPERATION:
249 case base::File::FILE_ERROR_EXISTS: 249 case base::File::FILE_ERROR_EXISTS:
250 case base::File::FILE_ERROR_NOT_EMPTY: 250 case base::File::FILE_ERROR_NOT_EMPTY:
251 return "InvalidModificationError"; 251 return "InvalidModificationError";
252 case base::File::FILE_ERROR_NOT_A_DIRECTORY: 252 case base::File::FILE_ERROR_NOT_A_DIRECTORY:
253 case base::File::FILE_ERROR_NOT_A_FILE: 253 case base::File::FILE_ERROR_NOT_A_FILE:
254 return "TypeMismatchError"; 254 return "TypeMismatchError";
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 322
323 return true; 323 return true;
324 } 324 }
325 325
326 // Sub-part of the event router for handling device events. 326 // Sub-part of the event router for handling device events.
327 class DeviceEventRouterImpl : public DeviceEventRouter { 327 class DeviceEventRouterImpl : public DeviceEventRouter {
328 public: 328 public:
329 explicit DeviceEventRouterImpl(Profile* profile) : profile_(profile) {} 329 explicit DeviceEventRouterImpl(Profile* profile) : profile_(profile) {}
330 330
331 // DeviceEventRouter overrides. 331 // DeviceEventRouter overrides.
332 virtual void OnDeviceEvent(file_browser_private::DeviceEventType type, 332 virtual void OnDeviceEvent(file_manager_private::DeviceEventType type,
333 const std::string& device_path) OVERRIDE { 333 const std::string& device_path) OVERRIDE {
334 DCHECK_CURRENTLY_ON(BrowserThread::UI); 334 DCHECK_CURRENTLY_ON(BrowserThread::UI);
335 335
336 file_browser_private::DeviceEvent event; 336 file_manager_private::DeviceEvent event;
337 event.type = type; 337 event.type = type;
338 event.device_path = device_path; 338 event.device_path = device_path;
339 339
340 BroadcastEvent(profile_, 340 BroadcastEvent(profile_,
341 file_browser_private::OnDeviceChanged::kEventName, 341 file_manager_private::OnDeviceChanged::kEventName,
342 file_browser_private::OnDeviceChanged::Create(event)); 342 file_manager_private::OnDeviceChanged::Create(event));
343 } 343 }
344 344
345 // DeviceEventRouter overrides. 345 // DeviceEventRouter overrides.
346 virtual bool IsExternalStorageDisabled() OVERRIDE { 346 virtual bool IsExternalStorageDisabled() OVERRIDE {
347 DCHECK_CURRENTLY_ON(BrowserThread::UI); 347 DCHECK_CURRENTLY_ON(BrowserThread::UI);
348 return profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled); 348 return profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled);
349 } 349 }
350 350
351 private: 351 private:
352 Profile* const profile_; 352 Profile* const profile_;
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 file_watchers_.erase(iter); 530 file_watchers_.erase(iter);
531 } 531 }
532 } 532 }
533 533
534 void EventRouter::OnCopyCompleted(int copy_id, 534 void EventRouter::OnCopyCompleted(int copy_id,
535 const GURL& source_url, 535 const GURL& source_url,
536 const GURL& destination_url, 536 const GURL& destination_url,
537 base::File::Error error) { 537 base::File::Error error) {
538 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 538 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
539 539
540 file_browser_private::CopyProgressStatus status; 540 file_manager_private::CopyProgressStatus status;
541 if (error == base::File::FILE_OK) { 541 if (error == base::File::FILE_OK) {
542 // Send success event. 542 // Send success event.
543 status.type = file_browser_private::COPY_PROGRESS_STATUS_TYPE_SUCCESS; 543 status.type = file_manager_private::COPY_PROGRESS_STATUS_TYPE_SUCCESS;
544 status.source_url.reset(new std::string(source_url.spec())); 544 status.source_url.reset(new std::string(source_url.spec()));
545 status.destination_url.reset(new std::string(destination_url.spec())); 545 status.destination_url.reset(new std::string(destination_url.spec()));
546 } else { 546 } else {
547 // Send error event. 547 // Send error event.
548 status.type = file_browser_private::COPY_PROGRESS_STATUS_TYPE_ERROR; 548 status.type = file_manager_private::COPY_PROGRESS_STATUS_TYPE_ERROR;
549 status.error.reset(new std::string(FileErrorToErrorName(error))); 549 status.error.reset(new std::string(FileErrorToErrorName(error)));
550 } 550 }
551 551
552 BroadcastEvent( 552 BroadcastEvent(
553 profile_, 553 profile_,
554 file_browser_private::OnCopyProgress::kEventName, 554 file_manager_private::OnCopyProgress::kEventName,
555 file_browser_private::OnCopyProgress::Create(copy_id, status)); 555 file_manager_private::OnCopyProgress::Create(copy_id, status));
556 } 556 }
557 557
558 void EventRouter::OnCopyProgress( 558 void EventRouter::OnCopyProgress(
559 int copy_id, 559 int copy_id,
560 storage::FileSystemOperation::CopyProgressType type, 560 storage::FileSystemOperation::CopyProgressType type,
561 const GURL& source_url, 561 const GURL& source_url,
562 const GURL& destination_url, 562 const GURL& destination_url,
563 int64 size) { 563 int64 size) {
564 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 564 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
565 565
566 file_browser_private::CopyProgressStatus status; 566 file_manager_private::CopyProgressStatus status;
567 status.type = CopyProgressTypeToCopyProgressStatusType(type); 567 status.type = CopyProgressTypeToCopyProgressStatusType(type);
568 status.source_url.reset(new std::string(source_url.spec())); 568 status.source_url.reset(new std::string(source_url.spec()));
569 if (type == storage::FileSystemOperation::END_COPY_ENTRY) 569 if (type == storage::FileSystemOperation::END_COPY_ENTRY)
570 status.destination_url.reset(new std::string(destination_url.spec())); 570 status.destination_url.reset(new std::string(destination_url.spec()));
571 if (type == storage::FileSystemOperation::PROGRESS) 571 if (type == storage::FileSystemOperation::PROGRESS)
572 status.size.reset(new double(size)); 572 status.size.reset(new double(size));
573 573
574 // Should not skip events other than TYPE_PROGRESS. 574 // Should not skip events other than TYPE_PROGRESS.
575 const bool always = 575 const bool always =
576 status.type != file_browser_private::COPY_PROGRESS_STATUS_TYPE_PROGRESS; 576 status.type != file_manager_private::COPY_PROGRESS_STATUS_TYPE_PROGRESS;
577 if (!ShouldSendProgressEvent(always, &last_copy_progress_event_)) 577 if (!ShouldSendProgressEvent(always, &last_copy_progress_event_))
578 return; 578 return;
579 579
580 BroadcastEvent( 580 BroadcastEvent(
581 profile_, 581 profile_,
582 file_browser_private::OnCopyProgress::kEventName, 582 file_manager_private::OnCopyProgress::kEventName,
583 file_browser_private::OnCopyProgress::Create(copy_id, status)); 583 file_manager_private::OnCopyProgress::Create(copy_id, status));
584 } 584 }
585 585
586 void EventRouter::DefaultNetworkChanged(const chromeos::NetworkState* network) { 586 void EventRouter::DefaultNetworkChanged(const chromeos::NetworkState* network) {
587 if (!profile_ || !extensions::EventRouter::Get(profile_)) { 587 if (!profile_ || !extensions::EventRouter::Get(profile_)) {
588 NOTREACHED(); 588 NOTREACHED();
589 return; 589 return;
590 } 590 }
591 591
592 BroadcastEvent( 592 BroadcastEvent(
593 profile_, 593 profile_,
594 file_browser_private::OnDriveConnectionStatusChanged::kEventName, 594 file_manager_private::OnDriveConnectionStatusChanged::kEventName,
595 file_browser_private::OnDriveConnectionStatusChanged::Create()); 595 file_manager_private::OnDriveConnectionStatusChanged::Create());
596 } 596 }
597 597
598 void EventRouter::OnFileManagerPrefsChanged() { 598 void EventRouter::OnFileManagerPrefsChanged() {
599 if (!profile_ || !extensions::EventRouter::Get(profile_)) { 599 if (!profile_ || !extensions::EventRouter::Get(profile_)) {
600 NOTREACHED(); 600 NOTREACHED();
601 return; 601 return;
602 } 602 }
603 603
604 BroadcastEvent( 604 BroadcastEvent(
605 profile_, 605 profile_,
606 file_browser_private::OnPreferencesChanged::kEventName, 606 file_manager_private::OnPreferencesChanged::kEventName,
607 file_browser_private::OnPreferencesChanged::Create()); 607 file_manager_private::OnPreferencesChanged::Create());
608 } 608 }
609 609
610 void EventRouter::OnJobAdded(const drive::JobInfo& job_info) { 610 void EventRouter::OnJobAdded(const drive::JobInfo& job_info) {
611 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 611 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
612 if (!drive::IsActiveFileTransferJobInfo(job_info)) 612 if (!drive::IsActiveFileTransferJobInfo(job_info))
613 return; 613 return;
614 ScheduleDriveFileTransferEvent( 614 ScheduleDriveFileTransferEvent(
615 job_info, kFileTransferStateAdded, false /* immediate */); 615 job_info, kFileTransferStateAdded, false /* immediate */);
616 } 616 }
617 617
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 base::Bind(&EventRouter::SendDriveFileTransferEvent, 664 base::Bind(&EventRouter::SendDriveFileTransferEvent,
665 weak_factory_.GetWeakPtr()), 665 weak_factory_.GetWeakPtr()),
666 delay); 666 delay);
667 } 667 }
668 } 668 }
669 669
670 void EventRouter::SendDriveFileTransferEvent() { 670 void EventRouter::SendDriveFileTransferEvent() {
671 if (!drive_job_info_for_scheduled_event_) 671 if (!drive_job_info_for_scheduled_event_)
672 return; 672 return;
673 673
674 file_browser_private::FileTransferStatus status; 674 file_manager_private::FileTransferStatus status;
675 JobInfoToTransferStatus(profile_, 675 JobInfoToTransferStatus(profile_,
676 kFileManagerAppId, 676 kFileManagerAppId,
677 drive_job_info_for_scheduled_event_->status, 677 drive_job_info_for_scheduled_event_->status,
678 drive_job_info_for_scheduled_event_->job_info, 678 drive_job_info_for_scheduled_event_->job_info,
679 &status); 679 &status);
680 680
681 drive_job_info_for_scheduled_event_.reset(); 681 drive_job_info_for_scheduled_event_.reset();
682 682
683 BroadcastEvent(profile_, 683 BroadcastEvent(profile_,
684 file_browser_private::OnFileTransfersUpdated::kEventName, 684 file_manager_private::OnFileTransfersUpdated::kEventName,
685 file_browser_private::OnFileTransfersUpdated::Create(status)); 685 file_manager_private::OnFileTransfersUpdated::Create(status));
686 } 686 }
687 687
688 void EventRouter::OnDirectoryChanged(const base::FilePath& drive_path) { 688 void EventRouter::OnDirectoryChanged(const base::FilePath& drive_path) {
689 HandleFileWatchNotification(NULL, drive_path, false); 689 HandleFileWatchNotification(NULL, drive_path, false);
690 } 690 }
691 691
692 void EventRouter::OnFileChanged(const drive::FileChange& changed_files) { 692 void EventRouter::OnFileChanged(const drive::FileChange& changed_files) {
693 typedef std::map<base::FilePath, drive::FileChange> FileChangeMap; 693 typedef std::map<base::FilePath, drive::FileChange> FileChangeMap;
694 694
695 FileChangeMap map; 695 FileChangeMap map;
696 const drive::FileChange::Map& changed_file_map = changed_files.map(); 696 const drive::FileChange::Map& changed_file_map = changed_files.map();
697 for (drive::FileChange::Map::const_iterator it = changed_file_map.begin(); 697 for (drive::FileChange::Map::const_iterator it = changed_file_map.begin();
698 it != changed_file_map.end(); 698 it != changed_file_map.end();
699 it++) { 699 it++) {
700 const base::FilePath& path = it->first; 700 const base::FilePath& path = it->first;
701 map[path.DirName()].Update(path, it->second); 701 map[path.DirName()].Update(path, it->second);
702 } 702 }
703 703
704 for (FileChangeMap::const_iterator it = map.begin(); it != map.end(); it++) { 704 for (FileChangeMap::const_iterator it = map.begin(); it != map.end(); it++) {
705 HandleFileWatchNotification(&(it->second), it->first, false); 705 HandleFileWatchNotification(&(it->second), it->first, false);
706 } 706 }
707 } 707 }
708 708
709 void EventRouter::OnDriveSyncError(drive::file_system::DriveSyncErrorType type, 709 void EventRouter::OnDriveSyncError(drive::file_system::DriveSyncErrorType type,
710 const base::FilePath& drive_path) { 710 const base::FilePath& drive_path) {
711 file_browser_private::DriveSyncErrorEvent event; 711 file_manager_private::DriveSyncErrorEvent event;
712 switch (type) { 712 switch (type) {
713 case drive::file_system::DRIVE_SYNC_ERROR_DELETE_WITHOUT_PERMISSION: 713 case drive::file_system::DRIVE_SYNC_ERROR_DELETE_WITHOUT_PERMISSION:
714 event.type = 714 event.type =
715 file_browser_private::DRIVE_SYNC_ERROR_TYPE_DELETE_WITHOUT_PERMISSION; 715 file_manager_private::DRIVE_SYNC_ERROR_TYPE_DELETE_WITHOUT_PERMISSION;
716 break; 716 break;
717 case drive::file_system::DRIVE_SYNC_ERROR_SERVICE_UNAVAILABLE: 717 case drive::file_system::DRIVE_SYNC_ERROR_SERVICE_UNAVAILABLE:
718 event.type = 718 event.type =
719 file_browser_private::DRIVE_SYNC_ERROR_TYPE_SERVICE_UNAVAILABLE; 719 file_manager_private::DRIVE_SYNC_ERROR_TYPE_SERVICE_UNAVAILABLE;
720 break; 720 break;
721 case drive::file_system::DRIVE_SYNC_ERROR_MISC: 721 case drive::file_system::DRIVE_SYNC_ERROR_MISC:
722 event.type = 722 event.type =
723 file_browser_private::DRIVE_SYNC_ERROR_TYPE_MISC; 723 file_manager_private::DRIVE_SYNC_ERROR_TYPE_MISC;
724 break; 724 break;
725 } 725 }
726 event.file_url = util::ConvertDrivePathToFileSystemUrl( 726 event.file_url = util::ConvertDrivePathToFileSystemUrl(
727 profile_, drive_path, kFileManagerAppId).spec(); 727 profile_, drive_path, kFileManagerAppId).spec();
728 BroadcastEvent( 728 BroadcastEvent(
729 profile_, 729 profile_,
730 file_browser_private::OnDriveSyncError::kEventName, 730 file_manager_private::OnDriveSyncError::kEventName,
731 file_browser_private::OnDriveSyncError::Create(event)); 731 file_manager_private::OnDriveSyncError::Create(event));
732 } 732 }
733 733
734 void EventRouter::OnRefreshTokenInvalid() { 734 void EventRouter::OnRefreshTokenInvalid() {
735 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 735 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
736 736
737 // Raise a DriveConnectionStatusChanged event to notify the status offline. 737 // Raise a DriveConnectionStatusChanged event to notify the status offline.
738 BroadcastEvent( 738 BroadcastEvent(
739 profile_, 739 profile_,
740 file_browser_private::OnDriveConnectionStatusChanged::kEventName, 740 file_manager_private::OnDriveConnectionStatusChanged::kEventName,
741 file_browser_private::OnDriveConnectionStatusChanged::Create()); 741 file_manager_private::OnDriveConnectionStatusChanged::Create());
742 } 742 }
743 743
744 void EventRouter::HandleFileWatchNotification(const drive::FileChange* list, 744 void EventRouter::HandleFileWatchNotification(const drive::FileChange* list,
745 const base::FilePath& local_path, 745 const base::FilePath& local_path,
746 bool got_error) { 746 bool got_error) {
747 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 747 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
748 748
749 WatcherMap::const_iterator iter = file_watchers_.find(local_path); 749 WatcherMap::const_iterator iter = file_watchers_.find(local_path);
750 if (iter == file_watchers_.end()) { 750 if (iter == file_watchers_.end()) {
751 return; 751 return;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 const EntryDefinition& entry_definition) { 805 const EntryDefinition& entry_definition) {
806 typedef std::map<base::FilePath, drive::FileChange::ChangeList> ChangeListMap; 806 typedef std::map<base::FilePath, drive::FileChange::ChangeList> ChangeListMap;
807 807
808 if (entry_definition.error != base::File::FILE_OK || 808 if (entry_definition.error != base::File::FILE_OK ||
809 !entry_definition.is_directory) { 809 !entry_definition.is_directory) {
810 DVLOG(1) << "Unable to dispatch event because resolving the directory " 810 DVLOG(1) << "Unable to dispatch event because resolving the directory "
811 << "entry definition failed."; 811 << "entry definition failed.";
812 return; 812 return;
813 } 813 }
814 814
815 file_browser_private::FileWatchEvent event; 815 file_manager_private::FileWatchEvent event;
816 event.event_type = watcher_error 816 event.event_type = watcher_error
817 ? file_browser_private::FILE_WATCH_EVENT_TYPE_ERROR 817 ? file_manager_private::FILE_WATCH_EVENT_TYPE_ERROR
818 : file_browser_private::FILE_WATCH_EVENT_TYPE_CHANGED; 818 : file_manager_private::FILE_WATCH_EVENT_TYPE_CHANGED;
819 819
820 // Detailed information is available. 820 // Detailed information is available.
821 if (list.get()) { 821 if (list.get()) {
822 event.changed_files.reset( 822 event.changed_files.reset(
823 new std::vector<linked_ptr<file_browser_private::FileChange> >); 823 new std::vector<linked_ptr<file_manager_private::FileChange> >);
824 824
825 if (list->map().empty()) 825 if (list->map().empty())
826 return; 826 return;
827 827
828 for (drive::FileChange::Map::const_iterator it = list->map().begin(); 828 for (drive::FileChange::Map::const_iterator it = list->map().begin();
829 it != list->map().end(); 829 it != list->map().end();
830 it++) { 830 it++) {
831 linked_ptr<file_browser_private::FileChange> change_list( 831 linked_ptr<file_manager_private::FileChange> change_list(
832 new file_browser_private::FileChange); 832 new file_manager_private::FileChange);
833 833
834 GURL url = util::ConvertDrivePathToFileSystemUrl( 834 GURL url = util::ConvertDrivePathToFileSystemUrl(
835 profile_, it->first, *extension_id); 835 profile_, it->first, *extension_id);
836 change_list->url = url.spec(); 836 change_list->url = url.spec();
837 837
838 for (drive::FileChange::ChangeList::List::const_iterator change = 838 for (drive::FileChange::ChangeList::List::const_iterator change =
839 it->second.list().begin(); 839 it->second.list().begin();
840 change != it->second.list().end(); 840 change != it->second.list().end();
841 change++) { 841 change++) {
842 change_list->changes.push_back( 842 change_list->changes.push_back(
843 ConvertChangeTypeFromDriveToApi(change->change())); 843 ConvertChangeTypeFromDriveToApi(change->change()));
844 } 844 }
845 845
846 event.changed_files->push_back(change_list); 846 event.changed_files->push_back(change_list);
847 } 847 }
848 } 848 }
849 849
850 event.entry.additional_properties.SetString( 850 event.entry.additional_properties.SetString(
851 "fileSystemName", entry_definition.file_system_name); 851 "fileSystemName", entry_definition.file_system_name);
852 event.entry.additional_properties.SetString( 852 event.entry.additional_properties.SetString(
853 "fileSystemRoot", entry_definition.file_system_root_url); 853 "fileSystemRoot", entry_definition.file_system_root_url);
854 event.entry.additional_properties.SetString( 854 event.entry.additional_properties.SetString(
855 "fileFullPath", "/" + entry_definition.full_path.value()); 855 "fileFullPath", "/" + entry_definition.full_path.value());
856 event.entry.additional_properties.SetBoolean("fileIsDirectory", 856 event.entry.additional_properties.SetBoolean("fileIsDirectory",
857 entry_definition.is_directory); 857 entry_definition.is_directory);
858 858
859 BroadcastEvent(profile_, 859 BroadcastEvent(profile_,
860 file_browser_private::OnDirectoryChanged::kEventName, 860 file_manager_private::OnDirectoryChanged::kEventName,
861 file_browser_private::OnDirectoryChanged::Create(event)); 861 file_manager_private::OnDirectoryChanged::Create(event));
862 } 862 }
863 863
864 void EventRouter::OnDiskAdded( 864 void EventRouter::OnDiskAdded(
865 const DiskMountManager::Disk& disk, bool mounting) { 865 const DiskMountManager::Disk& disk, bool mounting) {
866 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 866 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
867 // Do nothing. 867 // Do nothing.
868 } 868 }
869 869
870 void EventRouter::OnDiskRemoved(const DiskMountManager::Disk& disk) { 870 void EventRouter::OnDiskRemoved(const DiskMountManager::Disk& disk) {
871 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 871 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
(...skipping 14 matching lines...) Expand all
886 const VolumeInfo& volume_info) { 886 const VolumeInfo& volume_info) {
887 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 887 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
888 // profile_ is NULL if ShutdownOnUIThread() is called earlier. This can 888 // profile_ is NULL if ShutdownOnUIThread() is called earlier. This can
889 // happen at shutdown. This should be removed after removing Drive mounting 889 // happen at shutdown. This should be removed after removing Drive mounting
890 // code in addMount. (addMount -> OnFileSystemMounted -> OnVolumeMounted is 890 // code in addMount. (addMount -> OnFileSystemMounted -> OnVolumeMounted is
891 // the only path to come here after Shutdown is called). 891 // the only path to come here after Shutdown is called).
892 if (!profile_) 892 if (!profile_)
893 return; 893 return;
894 894
895 DispatchMountCompletedEvent( 895 DispatchMountCompletedEvent(
896 file_browser_private::MOUNT_COMPLETED_EVENT_TYPE_MOUNT, 896 file_manager_private::MOUNT_COMPLETED_EVENT_TYPE_MOUNT,
897 error_code, 897 error_code,
898 volume_info); 898 volume_info);
899 } 899 }
900 900
901 void EventRouter::OnVolumeUnmounted(chromeos::MountError error_code, 901 void EventRouter::OnVolumeUnmounted(chromeos::MountError error_code,
902 const VolumeInfo& volume_info) { 902 const VolumeInfo& volume_info) {
903 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 903 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
904 DispatchMountCompletedEvent( 904 DispatchMountCompletedEvent(
905 file_browser_private::MOUNT_COMPLETED_EVENT_TYPE_UNMOUNT, 905 file_manager_private::MOUNT_COMPLETED_EVENT_TYPE_UNMOUNT,
906 error_code, 906 error_code,
907 volume_info); 907 volume_info);
908 } 908 }
909 909
910 void EventRouter::DispatchMountCompletedEvent( 910 void EventRouter::DispatchMountCompletedEvent(
911 file_browser_private::MountCompletedEventType event_type, 911 file_manager_private::MountCompletedEventType event_type,
912 chromeos::MountError error, 912 chromeos::MountError error,
913 const VolumeInfo& volume_info) { 913 const VolumeInfo& volume_info) {
914 // Build an event object. 914 // Build an event object.
915 file_browser_private::MountCompletedEvent event; 915 file_manager_private::MountCompletedEvent event;
916 event.event_type = event_type; 916 event.event_type = event_type;
917 event.status = MountErrorToMountCompletedStatus(error); 917 event.status = MountErrorToMountCompletedStatus(error);
918 util::VolumeInfoToVolumeMetadata( 918 util::VolumeInfoToVolumeMetadata(
919 profile_, volume_info, &event.volume_metadata); 919 profile_, volume_info, &event.volume_metadata);
920 event.should_notify = ShouldShowNotificationForVolume( 920 event.should_notify = ShouldShowNotificationForVolume(
921 profile_, *device_event_router_, volume_info); 921 profile_, *device_event_router_, volume_info);
922 BroadcastEvent(profile_, 922 BroadcastEvent(profile_,
923 file_browser_private::OnMountCompleted::kEventName, 923 file_manager_private::OnMountCompleted::kEventName,
924 file_browser_private::OnMountCompleted::Create(event)); 924 file_manager_private::OnMountCompleted::Create(event));
925 } 925 }
926 926
927 void EventRouter::OnFormatStarted(const std::string& device_path, 927 void EventRouter::OnFormatStarted(const std::string& device_path,
928 bool success) { 928 bool success) {
929 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 929 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
930 // Do nothing. 930 // Do nothing.
931 } 931 }
932 932
933 void EventRouter::OnFormatCompleted(const std::string& device_path, 933 void EventRouter::OnFormatCompleted(const std::string& device_path,
934 bool success) { 934 bool success) {
935 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 935 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
936 // Do nothing. 936 // Do nothing.
937 } 937 }
938 938
939 } // namespace file_manager 939 } // namespace file_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698