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/chromeos/extensions/file_manager/private_api_drive.h" | 5 #include "chrome/browser/chromeos/extensions/file_manager/private_api_drive.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
9 #include "chrome/browser/chromeos/drive/drive_integration_service.h" | 9 #include "chrome/browser/chromeos/drive/drive_integration_service.h" |
10 #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h" | 10 #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h" |
11 #include "chrome/browser/chromeos/file_manager/file_tasks.h" | 11 #include "chrome/browser/chromeos/file_manager/file_tasks.h" |
12 #include "chrome/browser/chromeos/file_manager/fileapi_util.h" | 12 #include "chrome/browser/chromeos/file_manager/fileapi_util.h" |
13 #include "chrome/browser/chromeos/file_manager/url_util.h" | 13 #include "chrome/browser/chromeos/file_manager/url_util.h" |
| 14 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h" |
| 15 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte
rface.h" |
14 #include "chrome/browser/chromeos/fileapi/file_system_backend.h" | 16 #include "chrome/browser/chromeos/fileapi/file_system_backend.h" |
15 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 17 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
16 #include "chrome/browser/drive/drive_app_registry.h" | 18 #include "chrome/browser/drive/drive_app_registry.h" |
17 #include "chrome/browser/drive/event_logger.h" | 19 #include "chrome/browser/drive/event_logger.h" |
18 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/browser/profiles/profile_manager.h" | 21 #include "chrome/browser/profiles/profile_manager.h" |
20 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 22 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
21 #include "chrome/browser/signin/signin_manager_factory.h" | 23 #include "chrome/browser/signin/signin_manager_factory.h" |
22 #include "chromeos/chromeos_switches.h" | 24 #include "chromeos/chromeos_switches.h" |
23 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 25 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
24 #include "components/signin/core/browser/signin_manager.h" | 26 #include "components/signin/core/browser/signin_manager.h" |
25 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
26 #include "google_apis/drive/auth_service.h" | 28 #include "google_apis/drive/auth_service.h" |
27 #include "webkit/common/fileapi/file_system_info.h" | 29 #include "webkit/common/fileapi/file_system_info.h" |
28 #include "webkit/common/fileapi/file_system_util.h" | 30 #include "webkit/common/fileapi/file_system_util.h" |
29 | 31 |
30 using content::BrowserThread; | 32 using content::BrowserThread; |
31 | 33 |
| 34 using chromeos::file_system_provider::EntryMetadata; |
| 35 using chromeos::file_system_provider::ProvidedFileSystemInterface; |
| 36 using chromeos::file_system_provider::util::FileSystemURLParser; |
| 37 using extensions::api::file_browser_private::EntryProperties; |
32 using file_manager::util::EntryDefinition; | 38 using file_manager::util::EntryDefinition; |
33 using file_manager::util::EntryDefinitionCallback; | 39 using file_manager::util::EntryDefinitionCallback; |
34 using file_manager::util::EntryDefinitionList; | 40 using file_manager::util::EntryDefinitionList; |
35 using file_manager::util::EntryDefinitionListCallback; | 41 using file_manager::util::EntryDefinitionListCallback; |
36 using file_manager::util::FileDefinition; | 42 using file_manager::util::FileDefinition; |
37 using file_manager::util::FileDefinitionList; | 43 using file_manager::util::FileDefinitionList; |
38 using extensions::api::file_browser_private::EntryProperties; | |
39 | 44 |
40 namespace extensions { | 45 namespace extensions { |
41 namespace { | 46 namespace { |
42 | 47 |
43 // List of connection types of drive. | 48 // List of connection types of drive. |
44 // Keep this in sync with the DriveConnectionType in common/js/util.js. | 49 // Keep this in sync with the DriveConnectionType in common/js/util.js. |
45 const char kDriveConnectionTypeOffline[] = "offline"; | 50 const char kDriveConnectionTypeOffline[] = "offline"; |
46 const char kDriveConnectionTypeMetered[] = "metered"; | 51 const char kDriveConnectionTypeMetered[] = "metered"; |
47 const char kDriveConnectionTypeOnline[] = "online"; | 52 const char kDriveConnectionTypeOnline[] = "online"; |
48 | 53 |
49 // List of reasons of kDriveConnectionType*. | 54 // List of reasons of kDriveConnectionType*. |
50 // Keep this in sync with the DriveConnectionReason in common/js/util.js. | 55 // Keep this in sync with the DriveConnectionReason in common/js/util.js. |
51 const char kDriveConnectionReasonNotReady[] = "not_ready"; | 56 const char kDriveConnectionReasonNotReady[] = "not_ready"; |
52 const char kDriveConnectionReasonNoNetwork[] = "no_network"; | 57 const char kDriveConnectionReasonNoNetwork[] = "no_network"; |
53 const char kDriveConnectionReasonNoService[] = "no_service"; | 58 const char kDriveConnectionReasonNoService[] = "no_service"; |
54 | 59 |
55 // Copies properties from |entry_proto| to |properties|. |shared_with_me| is | 60 // Copies properties from |entry_proto| to |properties|. |shared_with_me| is |
56 // given from the running profile. | 61 // given from the running profile. |
57 void FillEntryPropertiesValue(const drive::ResourceEntry& entry_proto, | 62 void FillEntryPropertiesValueForDrive(const drive::ResourceEntry& entry_proto, |
58 bool shared_with_me, | 63 bool shared_with_me, |
59 EntryProperties* properties) { | 64 EntryProperties* properties) { |
60 properties->shared_with_me.reset(new bool(shared_with_me)); | 65 properties->shared_with_me.reset(new bool(shared_with_me)); |
61 properties->shared.reset(new bool(entry_proto.shared())); | 66 properties->shared.reset(new bool(entry_proto.shared())); |
62 | 67 |
63 const drive::PlatformFileInfoProto& file_info = entry_proto.file_info(); | 68 const drive::PlatformFileInfoProto& file_info = entry_proto.file_info(); |
64 properties->file_size.reset(new double(file_info.size())); | 69 properties->file_size.reset(new double(file_info.size())); |
65 properties->last_modified_time.reset(new double( | 70 properties->last_modified_time.reset(new double( |
66 base::Time::FromInternalValue(file_info.last_modified()).ToJsTime())); | 71 base::Time::FromInternalValue(file_info.last_modified()).ToJsTime())); |
67 | 72 |
68 if (!entry_proto.has_file_specific_info()) | 73 if (!entry_proto.has_file_specific_info()) |
69 return; | 74 return; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 | 152 |
148 class SingleEntryPropertiesGetterForDrive { | 153 class SingleEntryPropertiesGetterForDrive { |
149 public: | 154 public: |
150 typedef base::Callback<void(scoped_ptr<EntryProperties> properties, | 155 typedef base::Callback<void(scoped_ptr<EntryProperties> properties, |
151 base::File::Error error)> ResultCallback; | 156 base::File::Error error)> ResultCallback; |
152 | 157 |
153 // Creates an instance and starts the process. | 158 // Creates an instance and starts the process. |
154 static void Start(const base::FilePath local_path, | 159 static void Start(const base::FilePath local_path, |
155 Profile* const profile, | 160 Profile* const profile, |
156 const ResultCallback& callback) { | 161 const ResultCallback& callback) { |
| 162 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 163 |
157 SingleEntryPropertiesGetterForDrive* instance = | 164 SingleEntryPropertiesGetterForDrive* instance = |
158 new SingleEntryPropertiesGetterForDrive(local_path, profile, callback); | 165 new SingleEntryPropertiesGetterForDrive(local_path, profile, callback); |
159 instance->StartProcess(); | 166 instance->StartProcess(); |
160 | 167 |
161 // The instance will be destroyed by itself. | 168 // The instance will be destroyed by itself. |
162 } | 169 } |
163 | 170 |
164 virtual ~SingleEntryPropertiesGetterForDrive() {} | 171 virtual ~SingleEntryPropertiesGetterForDrive() {} |
165 | 172 |
166 private: | 173 private: |
167 // Given parameters. | |
168 const ResultCallback callback_; | |
169 const base::FilePath local_path_; | |
170 Profile* const running_profile_; | |
171 | |
172 // Values used in the process. | |
173 scoped_ptr<EntryProperties> properties_; | |
174 Profile* file_owner_profile_; | |
175 base::FilePath file_path_; | |
176 scoped_ptr<drive::ResourceEntry> owner_resource_entry_; | |
177 | |
178 base::WeakPtrFactory<SingleEntryPropertiesGetterForDrive> weak_ptr_factory_; | |
179 | |
180 SingleEntryPropertiesGetterForDrive(const base::FilePath local_path, | 174 SingleEntryPropertiesGetterForDrive(const base::FilePath local_path, |
181 Profile* const profile, | 175 Profile* const profile, |
182 const ResultCallback& callback) | 176 const ResultCallback& callback) |
183 : callback_(callback), | 177 : callback_(callback), |
184 local_path_(local_path), | 178 local_path_(local_path), |
185 running_profile_(profile), | 179 running_profile_(profile), |
186 properties_(new EntryProperties), | 180 properties_(new EntryProperties), |
187 file_owner_profile_(NULL), | 181 file_owner_profile_(NULL), |
188 weak_ptr_factory_(this) { | 182 weak_ptr_factory_(this) { |
189 DCHECK(!callback_.is_null()); | 183 DCHECK(!callback_.is_null()); |
190 DCHECK(profile); | 184 DCHECK(profile); |
191 } | 185 } |
192 | 186 |
193 base::WeakPtr<SingleEntryPropertiesGetterForDrive> GetWeakPtr() { | |
194 return weak_ptr_factory_.GetWeakPtr(); | |
195 } | |
196 | |
197 void StartProcess() { | 187 void StartProcess() { |
198 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 188 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
199 | 189 |
200 file_path_ = drive::util::ExtractDrivePath(local_path_); | 190 file_path_ = drive::util::ExtractDrivePath(local_path_); |
201 file_owner_profile_ = drive::util::ExtractProfileFromPath(local_path_); | 191 file_owner_profile_ = drive::util::ExtractProfileFromPath(local_path_); |
202 | 192 |
203 if (!file_owner_profile_ || | 193 if (!file_owner_profile_ || |
204 !g_browser_process->profile_manager()->IsValidProfile( | 194 !g_browser_process->profile_manager()->IsValidProfile( |
205 file_owner_profile_)) { | 195 file_owner_profile_)) { |
206 CompleteGetEntryProperties(drive::FILE_ERROR_FAILED); | 196 CompleteGetEntryProperties(drive::FILE_ERROR_FAILED); |
207 return; | 197 return; |
208 } | 198 } |
209 | 199 |
210 // Start getting the file info. | 200 // Start getting the file info. |
211 drive::FileSystemInterface* const file_system = | 201 drive::FileSystemInterface* const file_system = |
212 drive::util::GetFileSystemByProfile(file_owner_profile_); | 202 drive::util::GetFileSystemByProfile(file_owner_profile_); |
213 if (!file_system) { | 203 if (!file_system) { |
214 // |file_system| is NULL if Drive is disabled or not mounted. | 204 // |file_system| is NULL if Drive is disabled or not mounted. |
215 CompleteGetEntryProperties(drive::FILE_ERROR_FAILED); | 205 CompleteGetEntryProperties(drive::FILE_ERROR_FAILED); |
216 return; | 206 return; |
217 } | 207 } |
218 | 208 |
219 file_system->GetResourceEntry( | 209 file_system->GetResourceEntry( |
220 file_path_, | 210 file_path_, |
221 base::Bind(&SingleEntryPropertiesGetterForDrive::OnGetFileInfo, | 211 base::Bind(&SingleEntryPropertiesGetterForDrive::OnGetFileInfo, |
222 GetWeakPtr())); | 212 weak_ptr_factory_.GetWeakPtr())); |
223 } | 213 } |
224 | 214 |
225 void OnGetFileInfo(drive::FileError error, | 215 void OnGetFileInfo(drive::FileError error, |
226 scoped_ptr<drive::ResourceEntry> entry) { | 216 scoped_ptr<drive::ResourceEntry> entry) { |
227 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 217 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
228 | 218 |
229 if (error != drive::FILE_ERROR_OK) { | 219 if (error != drive::FILE_ERROR_OK) { |
230 CompleteGetEntryProperties(error); | 220 CompleteGetEntryProperties(error); |
231 return; | 221 return; |
232 } | 222 } |
(...skipping 10 matching lines...) Expand all Loading... |
243 // flag from the running profile's value. | 233 // flag from the running profile's value. |
244 drive::FileSystemInterface* const file_system = | 234 drive::FileSystemInterface* const file_system = |
245 drive::util::GetFileSystemByProfile(running_profile_); | 235 drive::util::GetFileSystemByProfile(running_profile_); |
246 if (!file_system) { | 236 if (!file_system) { |
247 CompleteGetEntryProperties(drive::FILE_ERROR_FAILED); | 237 CompleteGetEntryProperties(drive::FILE_ERROR_FAILED); |
248 return; | 238 return; |
249 } | 239 } |
250 file_system->GetPathFromResourceId( | 240 file_system->GetPathFromResourceId( |
251 owner_resource_entry_->resource_id(), | 241 owner_resource_entry_->resource_id(), |
252 base::Bind(&SingleEntryPropertiesGetterForDrive::OnGetRunningPath, | 242 base::Bind(&SingleEntryPropertiesGetterForDrive::OnGetRunningPath, |
253 GetWeakPtr())); | 243 weak_ptr_factory_.GetWeakPtr())); |
254 } | 244 } |
255 | 245 |
256 void OnGetRunningPath(drive::FileError error, | 246 void OnGetRunningPath(drive::FileError error, |
257 const base::FilePath& file_path) { | 247 const base::FilePath& file_path) { |
258 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 248 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
259 | 249 |
260 if (error != drive::FILE_ERROR_OK) { | 250 if (error != drive::FILE_ERROR_OK) { |
261 // The running profile does not know the file. | 251 // The running profile does not know the file. |
262 StartParseFileInfo(false); | 252 StartParseFileInfo(false); |
263 return; | 253 return; |
264 } | 254 } |
265 | 255 |
266 drive::FileSystemInterface* const file_system = | 256 drive::FileSystemInterface* const file_system = |
267 drive::util::GetFileSystemByProfile(running_profile_); | 257 drive::util::GetFileSystemByProfile(running_profile_); |
268 if (!file_system) { | 258 if (!file_system) { |
269 // The drive is disable for the running profile. | 259 // The drive is disable for the running profile. |
270 StartParseFileInfo(false); | 260 StartParseFileInfo(false); |
271 return; | 261 return; |
272 } | 262 } |
273 | 263 |
274 file_system->GetResourceEntry( | 264 file_system->GetResourceEntry( |
275 file_path, | 265 file_path, |
276 base::Bind(&SingleEntryPropertiesGetterForDrive::OnGetShareInfo, | 266 base::Bind(&SingleEntryPropertiesGetterForDrive::OnGetShareInfo, |
277 GetWeakPtr())); | 267 weak_ptr_factory_.GetWeakPtr())); |
278 } | 268 } |
279 | 269 |
280 void OnGetShareInfo(drive::FileError error, | 270 void OnGetShareInfo(drive::FileError error, |
281 scoped_ptr<drive::ResourceEntry> entry) { | 271 scoped_ptr<drive::ResourceEntry> entry) { |
282 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 272 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
283 | 273 |
284 if (error != drive::FILE_ERROR_OK) { | 274 if (error != drive::FILE_ERROR_OK) { |
285 CompleteGetEntryProperties(error); | 275 CompleteGetEntryProperties(error); |
286 return; | 276 return; |
287 } | 277 } |
288 | 278 |
289 DCHECK(entry); | 279 DCHECK(entry.get()); |
290 StartParseFileInfo(entry->shared_with_me()); | 280 StartParseFileInfo(entry->shared_with_me()); |
291 } | 281 } |
292 | 282 |
293 void StartParseFileInfo(bool shared_with_me) { | 283 void StartParseFileInfo(bool shared_with_me) { |
294 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 284 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
295 | 285 |
296 FillEntryPropertiesValue( | 286 FillEntryPropertiesValueForDrive( |
297 *owner_resource_entry_, shared_with_me, properties_.get()); | 287 *owner_resource_entry_, shared_with_me, properties_.get()); |
298 | 288 |
299 drive::FileSystemInterface* const file_system = | 289 drive::FileSystemInterface* const file_system = |
300 drive::util::GetFileSystemByProfile(file_owner_profile_); | 290 drive::util::GetFileSystemByProfile(file_owner_profile_); |
301 drive::DriveAppRegistry* const app_registry = | 291 drive::DriveAppRegistry* const app_registry = |
302 drive::util::GetDriveAppRegistryByProfile(file_owner_profile_); | 292 drive::util::GetDriveAppRegistryByProfile(file_owner_profile_); |
303 if (!file_system || !app_registry) { | 293 if (!file_system || !app_registry) { |
304 // |file_system| or |app_registry| is NULL if Drive is disabled. | 294 // |file_system| or |app_registry| is NULL if Drive is disabled. |
305 CompleteGetEntryProperties(drive::FILE_ERROR_FAILED); | 295 CompleteGetEntryProperties(drive::FILE_ERROR_FAILED); |
306 return; | 296 return; |
307 } | 297 } |
308 | 298 |
309 // The properties meaningful for directories are already filled in | 299 // The properties meaningful for directories are already filled in |
310 // FillEntryPropertiesValue(). | 300 // FillEntryPropertiesValueForDrive(). |
311 if (!owner_resource_entry_->has_file_specific_info()) { | 301 if (!owner_resource_entry_->has_file_specific_info()) { |
312 CompleteGetEntryProperties(drive::FILE_ERROR_OK); | 302 CompleteGetEntryProperties(drive::FILE_ERROR_OK); |
313 return; | 303 return; |
314 } | 304 } |
315 | 305 |
316 const drive::FileSpecificInfo& file_specific_info = | 306 const drive::FileSpecificInfo& file_specific_info = |
317 owner_resource_entry_->file_specific_info(); | 307 owner_resource_entry_->file_specific_info(); |
318 | 308 |
319 // Get drive WebApps that can accept this file. We just need to extract the | 309 // Get drive WebApps that can accept this file. We just need to extract the |
320 // doc icon for the drive app, which is set as default. | 310 // doc icon for the drive app, which is set as default. |
(...skipping 22 matching lines...) Expand all Loading... |
343 } | 333 } |
344 | 334 |
345 CompleteGetEntryProperties(drive::FILE_ERROR_OK); | 335 CompleteGetEntryProperties(drive::FILE_ERROR_OK); |
346 } | 336 } |
347 | 337 |
348 void CompleteGetEntryProperties(drive::FileError error) { | 338 void CompleteGetEntryProperties(drive::FileError error) { |
349 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 339 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
350 DCHECK(!callback_.is_null()); | 340 DCHECK(!callback_.is_null()); |
351 | 341 |
352 callback_.Run(properties_.Pass(), drive::FileErrorToBaseFileError(error)); | 342 callback_.Run(properties_.Pass(), drive::FileErrorToBaseFileError(error)); |
| 343 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this); |
| 344 } |
353 | 345 |
354 delete this; | 346 // Given parameters. |
| 347 const ResultCallback callback_; |
| 348 const base::FilePath local_path_; |
| 349 Profile* const running_profile_; |
| 350 |
| 351 // Values used in the process. |
| 352 scoped_ptr<EntryProperties> properties_; |
| 353 Profile* file_owner_profile_; |
| 354 base::FilePath file_path_; |
| 355 scoped_ptr<drive::ResourceEntry> owner_resource_entry_; |
| 356 |
| 357 base::WeakPtrFactory<SingleEntryPropertiesGetterForDrive> weak_ptr_factory_; |
| 358 }; // class SingleEntryPropertiesGetterForDrive |
| 359 |
| 360 class SingleEntryPropertiesGetterForFileSystemProvider { |
| 361 public: |
| 362 typedef base::Callback<void(scoped_ptr<EntryProperties> properties, |
| 363 base::File::Error error)> ResultCallback; |
| 364 |
| 365 // Creates an instance and starts the process. |
| 366 static void Start(const storage::FileSystemURL file_system_url, |
| 367 const ResultCallback& callback) { |
| 368 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 369 |
| 370 SingleEntryPropertiesGetterForFileSystemProvider* instance = |
| 371 new SingleEntryPropertiesGetterForFileSystemProvider(file_system_url, |
| 372 callback); |
| 373 instance->StartProcess(); |
| 374 |
| 375 // The instance will be destroyed by itself. |
355 } | 376 } |
| 377 |
| 378 virtual ~SingleEntryPropertiesGetterForFileSystemProvider() {} |
| 379 |
| 380 private: |
| 381 SingleEntryPropertiesGetterForFileSystemProvider( |
| 382 const storage::FileSystemURL& file_system_url, |
| 383 const ResultCallback& callback) |
| 384 : callback_(callback), |
| 385 file_system_url_(file_system_url), |
| 386 properties_(new EntryProperties), |
| 387 weak_ptr_factory_(this) { |
| 388 DCHECK(!callback_.is_null()); |
| 389 } |
| 390 |
| 391 void StartProcess() { |
| 392 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 393 |
| 394 FileSystemURLParser parser(file_system_url_); |
| 395 if (!parser.Parse()) { |
| 396 CompleteGetEntryProperties(base::File::FILE_ERROR_NOT_FOUND); |
| 397 return; |
| 398 } |
| 399 |
| 400 parser.file_system()->GetMetadata( |
| 401 parser.file_path(), |
| 402 ProvidedFileSystemInterface::METADATA_FIELD_THUMBNAIL, |
| 403 base::Bind(&SingleEntryPropertiesGetterForFileSystemProvider:: |
| 404 OnGetMetadataCompleted, |
| 405 weak_ptr_factory_.GetWeakPtr())); |
| 406 } |
| 407 |
| 408 void OnGetMetadataCompleted(scoped_ptr<EntryMetadata> metadata, |
| 409 base::File::Error result) { |
| 410 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 411 |
| 412 if (result != base::File::FILE_OK) { |
| 413 CompleteGetEntryProperties(result); |
| 414 return; |
| 415 } |
| 416 |
| 417 properties_->file_size.reset(new double(metadata->size)); |
| 418 properties_->last_modified_time.reset( |
| 419 new double(metadata->modification_time.ToJsTime())); |
| 420 |
| 421 if (!metadata->thumbnail.empty()) |
| 422 properties_->thumbnail_url.reset(new std::string(metadata->thumbnail)); |
| 423 |
| 424 CompleteGetEntryProperties(base::File::FILE_OK); |
| 425 } |
| 426 |
| 427 void CompleteGetEntryProperties(base::File::Error result) { |
| 428 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 429 DCHECK(!callback_.is_null()); |
| 430 |
| 431 callback_.Run(properties_.Pass(), result); |
| 432 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this); |
| 433 } |
| 434 |
| 435 // Given parameters. |
| 436 const ResultCallback callback_; |
| 437 const storage::FileSystemURL file_system_url_; |
| 438 |
| 439 // Values used in the process. |
| 440 scoped_ptr<EntryProperties> properties_; |
| 441 |
| 442 base::WeakPtrFactory<SingleEntryPropertiesGetterForFileSystemProvider> |
| 443 weak_ptr_factory_; |
356 }; // class SingleEntryPropertiesGetterForDrive | 444 }; // class SingleEntryPropertiesGetterForDrive |
357 | 445 |
358 } // namespace | 446 } // namespace |
359 | 447 |
360 FileBrowserPrivateGetEntryPropertiesFunction:: | 448 FileBrowserPrivateGetEntryPropertiesFunction:: |
361 FileBrowserPrivateGetEntryPropertiesFunction() | 449 FileBrowserPrivateGetEntryPropertiesFunction() |
362 : processed_count_(0) { | 450 : processed_count_(0) { |
363 } | 451 } |
364 | 452 |
365 FileBrowserPrivateGetEntryPropertiesFunction:: | 453 FileBrowserPrivateGetEntryPropertiesFunction:: |
(...skipping 20 matching lines...) Expand all Loading... |
386 case storage::kFileSystemTypeDrive: | 474 case storage::kFileSystemTypeDrive: |
387 SingleEntryPropertiesGetterForDrive::Start( | 475 SingleEntryPropertiesGetterForDrive::Start( |
388 file_system_url.path(), | 476 file_system_url.path(), |
389 GetProfile(), | 477 GetProfile(), |
390 base::Bind(&FileBrowserPrivateGetEntryPropertiesFunction:: | 478 base::Bind(&FileBrowserPrivateGetEntryPropertiesFunction:: |
391 CompleteGetEntryProperties, | 479 CompleteGetEntryProperties, |
392 this, | 480 this, |
393 i)); | 481 i)); |
394 break; | 482 break; |
395 case storage::kFileSystemTypeProvided: | 483 case storage::kFileSystemTypeProvided: |
396 // TODO(mtomasz): Add support for provided file systems. | 484 SingleEntryPropertiesGetterForFileSystemProvider::Start( |
397 NOTIMPLEMENTED(); | 485 file_system_url, |
| 486 base::Bind(&FileBrowserPrivateGetEntryPropertiesFunction:: |
| 487 CompleteGetEntryProperties, |
| 488 this, |
| 489 i)); |
398 break; | 490 break; |
399 default: | 491 default: |
400 LOG(ERROR) << "Not supported file system type."; | 492 LOG(ERROR) << "Not supported file system type."; |
401 CompleteGetEntryProperties(i, | 493 CompleteGetEntryProperties(i, |
402 make_scoped_ptr(new EntryProperties), | 494 make_scoped_ptr(new EntryProperties), |
403 base::File::FILE_ERROR_INVALID_OPERATION); | 495 base::File::FILE_ERROR_INVALID_OPERATION); |
404 } | 496 } |
405 } | 497 } |
406 | 498 |
407 return true; | 499 return true; |
408 } | 500 } |
409 | 501 |
410 void FileBrowserPrivateGetEntryPropertiesFunction::CompleteGetEntryProperties( | 502 void FileBrowserPrivateGetEntryPropertiesFunction::CompleteGetEntryProperties( |
411 size_t index, | 503 size_t index, |
412 scoped_ptr<EntryProperties> properties, | 504 scoped_ptr<EntryProperties> properties, |
413 base::File::Error error) { | 505 base::File::Error error) { |
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1014 return; | 1106 return; |
1015 } | 1107 } |
1016 | 1108 |
1017 const std::string url = download_url_ + "?access_token=" + access_token; | 1109 const std::string url = download_url_ + "?access_token=" + access_token; |
1018 SetResult(new base::StringValue(url)); | 1110 SetResult(new base::StringValue(url)); |
1019 | 1111 |
1020 SendResponse(true); | 1112 SendResponse(true); |
1021 } | 1113 } |
1022 | 1114 |
1023 } // namespace extensions | 1115 } // namespace extensions |
OLD | NEW |