OLD | NEW |
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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 using drive::DriveIntegrationServiceFactory; | 47 using drive::DriveIntegrationServiceFactory; |
48 | 48 |
49 namespace file_browser_private = extensions::api::file_browser_private; | 49 namespace file_browser_private = extensions::api::file_browser_private; |
50 | 50 |
51 namespace file_manager { | 51 namespace file_manager { |
52 namespace { | 52 namespace { |
53 | 53 |
54 const char kPathChanged[] = "changed"; | 54 const char kPathChanged[] = "changed"; |
55 const char kPathWatchError[] = "error"; | 55 const char kPathWatchError[] = "error"; |
56 | 56 |
57 // Used as a callback for FileSystem::MarkCacheFileAsUnmounted(). | |
58 void OnMarkAsUnmounted(drive::FileError error) { | |
59 // Do nothing. | |
60 } | |
61 void DirectoryExistsOnBlockingPool(const base::FilePath& directory_path, | 57 void DirectoryExistsOnBlockingPool(const base::FilePath& directory_path, |
62 const base::Closure& success_callback, | 58 const base::Closure& success_callback, |
63 const base::Closure& failure_callback) { | 59 const base::Closure& failure_callback) { |
64 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); | 60 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
65 | 61 |
66 if (base::DirectoryExists(directory_path)) | 62 if (base::DirectoryExists(directory_path)) |
67 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, success_callback); | 63 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, success_callback); |
68 else | 64 else |
69 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, failure_callback); | 65 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, failure_callback); |
70 }; | 66 }; |
71 | 67 |
72 void DirectoryExistsOnUIThread(const base::FilePath& directory_path, | 68 void DirectoryExistsOnUIThread(const base::FilePath& directory_path, |
73 const base::Closure& success_callback, | 69 const base::Closure& success_callback, |
74 const base::Closure& failure_callback) { | 70 const base::Closure& failure_callback) { |
75 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 71 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
76 | 72 |
77 content::BrowserThread::PostBlockingPoolTask( | 73 content::BrowserThread::PostBlockingPoolTask( |
78 FROM_HERE, | 74 FROM_HERE, |
79 base::Bind(&DirectoryExistsOnBlockingPool, | 75 base::Bind(&DirectoryExistsOnBlockingPool, |
80 directory_path, | 76 directory_path, |
81 success_callback, | 77 success_callback, |
82 failure_callback)); | 78 failure_callback)); |
83 }; | 79 }; |
84 | 80 |
85 // Creates a base::FilePathWatcher and starts watching at |watch_path| with | |
86 // |callback|. Returns NULL on failure. | |
87 base::FilePathWatcher* CreateAndStartFilePathWatcher( | |
88 const base::FilePath& watch_path, | |
89 const base::FilePathWatcher::Callback& callback) { | |
90 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | |
91 DCHECK(!callback.is_null()); | |
92 | |
93 base::FilePathWatcher* watcher(new base::FilePathWatcher); | |
94 if (!watcher->Watch(watch_path, false /* recursive */, callback)) { | |
95 delete watcher; | |
96 return NULL; | |
97 } | |
98 | |
99 return watcher; | |
100 } | |
101 | |
102 // Constants for the "transferState" field of onFileTransferUpdated event. | 81 // Constants for the "transferState" field of onFileTransferUpdated event. |
103 const char kFileTransferStateStarted[] = "started"; | 82 const char kFileTransferStateStarted[] = "started"; |
104 const char kFileTransferStateInProgress[] = "in_progress"; | 83 const char kFileTransferStateInProgress[] = "in_progress"; |
105 const char kFileTransferStateCompleted[] = "completed"; | 84 const char kFileTransferStateCompleted[] = "completed"; |
106 const char kFileTransferStateFailed[] = "failed"; | 85 const char kFileTransferStateFailed[] = "failed"; |
107 | 86 |
108 // Frequency of sending onFileTransferUpdated. | 87 // Frequency of sending onFileTransferUpdated. |
109 const int64 kFileTransferEventFrequencyInMilliseconds = 1000; | 88 const int64 kFileTransferEventFrequencyInMilliseconds = 1000; |
110 | 89 |
111 // Utility function to check if |job_info| is a file uploading job. | 90 // Utility function to check if |job_info| is a file uploading job. |
112 bool IsUploadJob(drive::JobType type) { | 91 bool IsUploadJob(drive::JobType type) { |
113 return (type == drive::TYPE_UPLOAD_NEW_FILE || | 92 return (type == drive::TYPE_UPLOAD_NEW_FILE || |
114 type == drive::TYPE_UPLOAD_EXISTING_FILE); | 93 type == drive::TYPE_UPLOAD_EXISTING_FILE); |
115 } | 94 } |
116 | 95 |
117 // Utility function to check if |job_info| is a file downloading job. | |
118 bool IsDownloadJob(drive::JobType type) { | |
119 return type == drive::TYPE_DOWNLOAD_FILE; | |
120 } | |
121 | |
122 // Converts the job info to its JSON (Value) form. | 96 // Converts the job info to its JSON (Value) form. |
123 scoped_ptr<base::DictionaryValue> JobInfoToDictionaryValue( | 97 scoped_ptr<base::DictionaryValue> JobInfoToDictionaryValue( |
124 const std::string& extension_id, | 98 const std::string& extension_id, |
125 const std::string& job_status, | 99 const std::string& job_status, |
126 const drive::JobInfo& job_info) { | 100 const drive::JobInfo& job_info) { |
127 DCHECK(IsActiveFileTransferJobInfo(job_info)); | 101 DCHECK(IsActiveFileTransferJobInfo(job_info)); |
128 | 102 |
129 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue); | 103 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue); |
130 GURL url = util::ConvertRelativeFilePathToFileSystemUrl( | 104 GURL url = util::ConvertRelativeFilePathToFileSystemUrl( |
131 job_info.file_path, extension_id); | 105 job_info.file_path, extension_id); |
(...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
775 base::TimeDelta::FromSeconds(4)); | 749 base::TimeDelta::FromSeconds(4)); |
776 } else { | 750 } else { |
777 notifications_->HideNotification(DesktopNotifications::FORMAT_START, | 751 notifications_->HideNotification(DesktopNotifications::FORMAT_START, |
778 device_path); | 752 device_path); |
779 notifications_->ShowNotification(DesktopNotifications::FORMAT_FAIL, | 753 notifications_->ShowNotification(DesktopNotifications::FORMAT_FAIL, |
780 device_path); | 754 device_path); |
781 } | 755 } |
782 } | 756 } |
783 | 757 |
784 } // namespace file_manager | 758 } // namespace file_manager |
OLD | NEW |