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_browser_private_api.h" | 5 #include "chrome/browser/chromeos/extensions/file_browser_private_api.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
379 } | 379 } |
380 | 380 |
381 mount_info->SetString("mountCondition", | 381 mount_info->SetString("mountCondition", |
382 DiskMountManager::MountConditionToString( | 382 DiskMountManager::MountConditionToString( |
383 mount_point_info.mount_condition)); | 383 mount_point_info.mount_condition)); |
384 | 384 |
385 return mount_info; | 385 return mount_info; |
386 } | 386 } |
387 #endif // defined(OS_CHROMEOS) | 387 #endif // defined(OS_CHROMEOS) |
388 | 388 |
389 // Delegate used to find file properties. | |
390 class FilePropertiesDelegate : public gdata::FindFileDelegate { | |
391 public: | |
392 FilePropertiesDelegate(); | |
393 virtual ~FilePropertiesDelegate(); | |
394 | |
395 // Builds a dictionary from the GDataFile file property information | |
396 void CopyProperties(base::DictionaryValue* property_dict); | |
397 | |
398 base::PlatformFileError error() const { return error_; } | |
399 | |
400 private: | |
401 // GDataFileSystem::FindFileDelegate overrides. | |
402 virtual void OnFileFound(gdata::GDataFile* file) OVERRIDE; | |
403 virtual void OnDirectoryFound(const FilePath&, | |
404 gdata::GDataDirectory* dir) OVERRIDE; | |
405 virtual FindFileTraversalCommand OnEnterDirectory( | |
406 const FilePath&, | |
407 gdata::GDataDirectory*) OVERRIDE; | |
408 virtual void OnError(base::PlatformFileError error) OVERRIDE; | |
409 | |
410 GURL thumbnail_url_; | |
411 int pinned_state_; | |
412 base::PlatformFileError error_; | |
413 }; | |
414 | |
415 // FilePropertiesDelegate class implementation. | |
416 | |
417 FilePropertiesDelegate::FilePropertiesDelegate() | |
418 : pinned_state_(0), error_(base::PLATFORM_FILE_OK) { | |
419 } | |
420 | |
421 FilePropertiesDelegate::~FilePropertiesDelegate() { } | |
422 | |
423 void FilePropertiesDelegate::CopyProperties( | |
424 base::DictionaryValue* property_dict) { | |
425 DCHECK(property_dict); | |
426 DCHECK(!property_dict->HasKey("thumbnailUrl")); | |
427 DCHECK(!property_dict->HasKey("pinnedState")); | |
428 DCHECK(!property_dict->HasKey("error")); | |
429 | |
430 if (error_ != base::PLATFORM_FILE_OK) { | |
431 property_dict->SetInteger("error", error_); | |
432 return; | |
433 } | |
434 | |
435 property_dict->SetString("thumbnailUrl", thumbnail_url_.spec()); | |
436 | |
437 base::ListValue *pinned_list = new base::ListValue; | |
438 if (pinned_state_ & gdata::GDataFile::PINNED_STATE_PINNED) | |
439 pinned_list->Append(new base::StringValue("pinned")); | |
440 if (pinned_state_ & gdata::GDataFile::PINNED_STATE_PRESENT) | |
441 pinned_list->Append(new base::StringValue("present")); | |
442 property_dict->Set("pinnedState", pinned_list); | |
443 } | |
444 | |
445 void FilePropertiesDelegate::OnFileFound(gdata::GDataFile* file) { | |
446 DCHECK(!file->file_info().is_directory); | |
447 thumbnail_url_ = file->thumbnail_url(); | |
448 pinned_state_ = file->pinned_state(); | |
449 } | |
450 | |
451 void FilePropertiesDelegate::OnDirectoryFound(const FilePath&, | |
452 gdata::GDataDirectory* dir) { | |
453 DCHECK(dir->file_info().is_directory); | |
454 // We don't set anything here because we don't have any properties for | |
455 // directories yet. | |
456 } | |
457 | |
458 gdata::FindFileDelegate::FindFileTraversalCommand | |
459 FilePropertiesDelegate::OnEnterDirectory(const FilePath&, | |
460 gdata::GDataDirectory*) { | |
461 // Keep traversing while doing read only lookups. | |
462 return FIND_FILE_CONTINUES; | |
463 } | |
464 | |
465 void FilePropertiesDelegate::OnError(base::PlatformFileError error) { | |
466 error_ = error; | |
467 } | |
468 | |
469 FilePath GetVirtualPathFromURL(const GURL& file_url) { | |
470 FilePath virtual_path; | |
471 fileapi::FileSystemType type = fileapi::kFileSystemTypeUnknown; | |
472 GURL file_origin_url; | |
473 if (!CrackFileSystemURL(file_url, &file_origin_url, &type, &virtual_path) || | |
474 type != fileapi::kFileSystemTypeExternal) { | |
475 NOTREACHED(); | |
476 return FilePath(); | |
477 } | |
478 return virtual_path; | |
479 } | |
480 | |
389 } // namespace | 481 } // namespace |
390 | 482 |
391 class RequestLocalFileSystemFunction::LocalFileSystemCallbackDispatcher { | 483 class RequestLocalFileSystemFunction::LocalFileSystemCallbackDispatcher { |
392 public: | 484 public: |
393 static fileapi::FileSystemContext::OpenFileSystemCallback CreateCallback( | 485 static fileapi::FileSystemContext::OpenFileSystemCallback CreateCallback( |
394 RequestLocalFileSystemFunction* function, | 486 RequestLocalFileSystemFunction* function, |
395 Profile* profile, | 487 Profile* profile, |
396 int child_id, | 488 int child_id, |
397 scoped_refptr<const Extension> extension) { | 489 scoped_refptr<const Extension> extension) { |
398 return base::Bind( | 490 return base::Bind( |
(...skipping 1398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1797 ChromeURLDataManager::DataSource::SetFontAndTextDirection(dict); | 1889 ChromeURLDataManager::DataSource::SetFontAndTextDirection(dict); |
1798 | 1890 |
1799 dict->SetString("PLAY_MEDIA", | 1891 dict->SetString("PLAY_MEDIA", |
1800 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_PLAY)); | 1892 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_PLAY)); |
1801 | 1893 |
1802 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableGData)) | 1894 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableGData)) |
1803 dict->SetString("ENABLE_GDATA", "1"); | 1895 dict->SetString("ENABLE_GDATA", "1"); |
1804 | 1896 |
1805 return true; | 1897 return true; |
1806 } | 1898 } |
1899 | |
1900 GetGDataFilePropertiesFunction::GetGDataFilePropertiesFunction() { | |
1901 } | |
1902 | |
1903 GetGDataFilePropertiesFunction::~GetGDataFilePropertiesFunction() { | |
1904 } | |
1905 | |
1906 bool GetGDataFilePropertiesFunction::RunImpl() { | |
1907 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
1908 if (args_->GetSize() != 1) | |
1909 return false; | |
1910 | |
1911 ListValue* path_list = NULL; | |
1912 args_->GetList(0, &path_list); | |
1913 DCHECK(path_list); | |
1914 | |
1915 std::string virtual_path; | |
1916 size_t len = path_list->GetSize(); | |
1917 FilePathList files; | |
1918 files.reserve(len); | |
1919 for (size_t i = 0; i < len; ++i) { | |
1920 path_list->GetString(i, &virtual_path); | |
zel
2012/03/01 02:37:38
s/virtual_path/file_url/
| |
1921 files.push_back(GetVirtualPathFromURL(GURL(virtual_path))); | |
1922 } | |
1923 | |
1924 base::ListValue* file_info = new base::ListValue; | |
1925 result_.reset(file_info); | |
1926 | |
1927 gdata::GDataFileSystem* file_system = | |
1928 gdata::GDataFileSystemFactory::GetForProfile(profile_); | |
1929 DCHECK(file_system); | |
1930 | |
1931 for (FilePathList::const_iterator iter = files.begin(); | |
1932 iter != files.end(); ++iter) { | |
1933 scoped_refptr<FilePropertiesDelegate> property_delegate( | |
1934 new FilePropertiesDelegate()); | |
1935 file_system->FindFileByPath(*iter, property_delegate); | |
1936 base::DictionaryValue* property_dict = new base::DictionaryValue; | |
1937 property_delegate->CopyProperties(property_dict); | |
1938 file_info->Append(property_dict); | |
1939 } | |
1940 | |
1941 return true; | |
1942 } | |
OLD | NEW |