OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/media_galleries/fileapi/iphoto_file_util.h" | 5 #include "chrome/browser/media_galleries/fileapi/iphoto_file_util.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
| 9 #include <utility> |
9 #include <vector> | 10 #include <vector> |
10 | 11 |
11 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
12 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
13 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
14 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
15 #include "chrome/browser/media_galleries/fileapi/iphoto_data_provider.h" | 16 #include "chrome/browser/media_galleries/fileapi/iphoto_data_provider.h" |
16 #include "chrome/browser/media_galleries/fileapi/media_path_filter.h" | 17 #include "chrome/browser/media_galleries/fileapi/media_path_filter.h" |
17 #include "chrome/browser/media_galleries/imported_media_gallery_registry.h" | 18 #include "chrome/browser/media_galleries/imported_media_gallery_registry.h" |
18 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 } | 78 } |
78 | 79 |
79 void IPhotoFileUtil::GetFileInfoOnTaskRunnerThread( | 80 void IPhotoFileUtil::GetFileInfoOnTaskRunnerThread( |
80 scoped_ptr<storage::FileSystemOperationContext> context, | 81 scoped_ptr<storage::FileSystemOperationContext> context, |
81 const storage::FileSystemURL& url, | 82 const storage::FileSystemURL& url, |
82 const GetFileInfoCallback& callback) { | 83 const GetFileInfoCallback& callback) { |
83 IPhotoDataProvider* data_provider = GetDataProvider(); | 84 IPhotoDataProvider* data_provider = GetDataProvider(); |
84 // |data_provider| may be NULL if the file system was revoked before this | 85 // |data_provider| may be NULL if the file system was revoked before this |
85 // operation had a chance to run. | 86 // operation had a chance to run. |
86 if (!data_provider) { | 87 if (!data_provider) { |
87 GetFileInfoWithFreshDataProvider(context.Pass(), url, callback, false); | 88 GetFileInfoWithFreshDataProvider(std::move(context), url, callback, false); |
88 } else { | 89 } else { |
89 data_provider->RefreshData( | 90 data_provider->RefreshData( |
90 base::Bind(&IPhotoFileUtil::GetFileInfoWithFreshDataProvider, | 91 base::Bind(&IPhotoFileUtil::GetFileInfoWithFreshDataProvider, |
91 weak_factory_.GetWeakPtr(), base::Passed(&context), url, | 92 weak_factory_.GetWeakPtr(), base::Passed(&context), url, |
92 callback)); | 93 callback)); |
93 } | 94 } |
94 } | 95 } |
95 | 96 |
96 void IPhotoFileUtil::ReadDirectoryOnTaskRunnerThread( | 97 void IPhotoFileUtil::ReadDirectoryOnTaskRunnerThread( |
97 scoped_ptr<storage::FileSystemOperationContext> context, | 98 scoped_ptr<storage::FileSystemOperationContext> context, |
98 const storage::FileSystemURL& url, | 99 const storage::FileSystemURL& url, |
99 const ReadDirectoryCallback& callback) { | 100 const ReadDirectoryCallback& callback) { |
100 IPhotoDataProvider* data_provider = GetDataProvider(); | 101 IPhotoDataProvider* data_provider = GetDataProvider(); |
101 // |data_provider| may be NULL if the file system was revoked before this | 102 // |data_provider| may be NULL if the file system was revoked before this |
102 // operation had a chance to run. | 103 // operation had a chance to run. |
103 if (!data_provider) { | 104 if (!data_provider) { |
104 ReadDirectoryWithFreshDataProvider(context.Pass(), url, callback, false); | 105 ReadDirectoryWithFreshDataProvider(std::move(context), url, callback, |
| 106 false); |
105 } else { | 107 } else { |
106 data_provider->RefreshData( | 108 data_provider->RefreshData( |
107 base::Bind(&IPhotoFileUtil::ReadDirectoryWithFreshDataProvider, | 109 base::Bind(&IPhotoFileUtil::ReadDirectoryWithFreshDataProvider, |
108 weak_factory_.GetWeakPtr(), base::Passed(&context), url, | 110 weak_factory_.GetWeakPtr(), base::Passed(&context), url, |
109 callback)); | 111 callback)); |
110 } | 112 } |
111 } | 113 } |
112 | 114 |
113 void IPhotoFileUtil::CreateSnapshotFileOnTaskRunnerThread( | 115 void IPhotoFileUtil::CreateSnapshotFileOnTaskRunnerThread( |
114 scoped_ptr<storage::FileSystemOperationContext> context, | 116 scoped_ptr<storage::FileSystemOperationContext> context, |
115 const storage::FileSystemURL& url, | 117 const storage::FileSystemURL& url, |
116 const CreateSnapshotFileCallback& callback) { | 118 const CreateSnapshotFileCallback& callback) { |
117 IPhotoDataProvider* data_provider = GetDataProvider(); | 119 IPhotoDataProvider* data_provider = GetDataProvider(); |
118 // |data_provider| may be NULL if the file system was revoked before this | 120 // |data_provider| may be NULL if the file system was revoked before this |
119 // operation had a chance to run. | 121 // operation had a chance to run. |
120 if (!data_provider) { | 122 if (!data_provider) { |
121 CreateSnapshotFileWithFreshDataProvider(context.Pass(), url, callback, | 123 CreateSnapshotFileWithFreshDataProvider(std::move(context), url, callback, |
122 false); | 124 false); |
123 } else { | 125 } else { |
124 data_provider->RefreshData( | 126 data_provider->RefreshData( |
125 base::Bind(&IPhotoFileUtil::CreateSnapshotFileWithFreshDataProvider, | 127 base::Bind(&IPhotoFileUtil::CreateSnapshotFileWithFreshDataProvider, |
126 weak_factory_.GetWeakPtr(), base::Passed(&context), url, | 128 weak_factory_.GetWeakPtr(), base::Passed(&context), url, |
127 callback)); | 129 callback)); |
128 } | 130 } |
129 } | 131 } |
130 | 132 |
131 void IPhotoFileUtil::GetFileInfoWithFreshDataProvider( | 133 void IPhotoFileUtil::GetFileInfoWithFreshDataProvider( |
132 scoped_ptr<storage::FileSystemOperationContext> context, | 134 scoped_ptr<storage::FileSystemOperationContext> context, |
133 const storage::FileSystemURL& url, | 135 const storage::FileSystemURL& url, |
134 const GetFileInfoCallback& callback, | 136 const GetFileInfoCallback& callback, |
135 bool valid_parse) { | 137 bool valid_parse) { |
136 if (!valid_parse) { | 138 if (!valid_parse) { |
137 if (!callback.is_null()) { | 139 if (!callback.is_null()) { |
138 content::BrowserThread::PostTask( | 140 content::BrowserThread::PostTask( |
139 content::BrowserThread::IO, | 141 content::BrowserThread::IO, |
140 FROM_HERE, | 142 FROM_HERE, |
141 base::Bind(callback, base::File::FILE_ERROR_IO, base::File::Info())); | 143 base::Bind(callback, base::File::FILE_ERROR_IO, base::File::Info())); |
142 } | 144 } |
143 return; | 145 return; |
144 } | 146 } |
145 NativeMediaFileUtil::GetFileInfoOnTaskRunnerThread(context.Pass(), url, | 147 NativeMediaFileUtil::GetFileInfoOnTaskRunnerThread(std::move(context), url, |
146 callback); | 148 callback); |
147 } | 149 } |
148 | 150 |
149 void IPhotoFileUtil::ReadDirectoryWithFreshDataProvider( | 151 void IPhotoFileUtil::ReadDirectoryWithFreshDataProvider( |
150 scoped_ptr<storage::FileSystemOperationContext> context, | 152 scoped_ptr<storage::FileSystemOperationContext> context, |
151 const storage::FileSystemURL& url, | 153 const storage::FileSystemURL& url, |
152 const ReadDirectoryCallback& callback, | 154 const ReadDirectoryCallback& callback, |
153 bool valid_parse) { | 155 bool valid_parse) { |
154 if (!valid_parse) { | 156 if (!valid_parse) { |
155 if (!callback.is_null()) { | 157 if (!callback.is_null()) { |
156 content::BrowserThread::PostTask( | 158 content::BrowserThread::PostTask( |
157 content::BrowserThread::IO, | 159 content::BrowserThread::IO, |
158 FROM_HERE, | 160 FROM_HERE, |
159 base::Bind(callback, base::File::FILE_ERROR_IO, EntryList(), false)); | 161 base::Bind(callback, base::File::FILE_ERROR_IO, EntryList(), false)); |
160 } | 162 } |
161 return; | 163 return; |
162 } | 164 } |
163 NativeMediaFileUtil::ReadDirectoryOnTaskRunnerThread(context.Pass(), url, | 165 NativeMediaFileUtil::ReadDirectoryOnTaskRunnerThread(std::move(context), url, |
164 callback); | 166 callback); |
165 } | 167 } |
166 | 168 |
167 void IPhotoFileUtil::CreateSnapshotFileWithFreshDataProvider( | 169 void IPhotoFileUtil::CreateSnapshotFileWithFreshDataProvider( |
168 scoped_ptr<storage::FileSystemOperationContext> context, | 170 scoped_ptr<storage::FileSystemOperationContext> context, |
169 const storage::FileSystemURL& url, | 171 const storage::FileSystemURL& url, |
170 const CreateSnapshotFileCallback& callback, | 172 const CreateSnapshotFileCallback& callback, |
171 bool valid_parse) { | 173 bool valid_parse) { |
172 if (!valid_parse) { | 174 if (!valid_parse) { |
173 if (!callback.is_null()) { | 175 if (!callback.is_null()) { |
174 base::File::Info file_info; | 176 base::File::Info file_info; |
175 base::FilePath platform_path; | 177 base::FilePath platform_path; |
176 scoped_refptr<storage::ShareableFileReference> file_ref; | 178 scoped_refptr<storage::ShareableFileReference> file_ref; |
177 content::BrowserThread::PostTask( | 179 content::BrowserThread::PostTask( |
178 content::BrowserThread::IO, | 180 content::BrowserThread::IO, |
179 FROM_HERE, | 181 FROM_HERE, |
180 base::Bind(callback, base::File::FILE_ERROR_IO, file_info, | 182 base::Bind(callback, base::File::FILE_ERROR_IO, file_info, |
181 platform_path, file_ref)); | 183 platform_path, file_ref)); |
182 } | 184 } |
183 return; | 185 return; |
184 } | 186 } |
185 NativeMediaFileUtil::CreateSnapshotFileOnTaskRunnerThread(context.Pass(), url, | 187 NativeMediaFileUtil::CreateSnapshotFileOnTaskRunnerThread(std::move(context), |
186 callback); | 188 url, callback); |
187 } | 189 } |
188 | 190 |
189 // Begin actual implementation. | 191 // Begin actual implementation. |
190 | 192 |
191 base::File::Error IPhotoFileUtil::GetFileInfoSync( | 193 base::File::Error IPhotoFileUtil::GetFileInfoSync( |
192 storage::FileSystemOperationContext* context, | 194 storage::FileSystemOperationContext* context, |
193 const storage::FileSystemURL& url, | 195 const storage::FileSystemURL& url, |
194 base::File::Info* file_info, | 196 base::File::Info* file_info, |
195 base::FilePath* platform_path) { | 197 base::FilePath* platform_path) { |
196 std::vector<std::string> components = GetVirtualPathComponents(url); | 198 std::vector<std::string> components = GetVirtualPathComponents(url); |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 return base::File::FILE_ERROR_NOT_FOUND; | 346 return base::File::FILE_ERROR_NOT_FOUND; |
345 } | 347 } |
346 | 348 |
347 IPhotoDataProvider* IPhotoFileUtil::GetDataProvider() { | 349 IPhotoDataProvider* IPhotoFileUtil::GetDataProvider() { |
348 if (!imported_registry_) | 350 if (!imported_registry_) |
349 imported_registry_ = ImportedMediaGalleryRegistry::GetInstance(); | 351 imported_registry_ = ImportedMediaGalleryRegistry::GetInstance(); |
350 return imported_registry_->IPhotoDataProvider(); | 352 return imported_registry_->IPhotoDataProvider(); |
351 } | 353 } |
352 | 354 |
353 } // namespace iphoto | 355 } // namespace iphoto |
OLD | NEW |