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 // Builds a dictionary from the GDataFile file property information | |
390 void BuildFilePropertyDictionary(const gdata::GDataFile& file, | |
391 base::DictionaryValue* property_dict) { | |
392 property_dict->SetString("thumbnailUrl", file.thumbnail_url().spec()); | |
393 | |
394 base::ListValue *pinned_list = new base::ListValue; | |
395 if (file.pinned_state() & gdata::GDataFile::PINNED_STATE_PINNED) | |
396 pinned_list->Append(new base::StringValue("pinned")); | |
397 if (file.pinned_state() & gdata::GDataFile::PINNED_STATE_PRESENT) | |
398 pinned_list->Append(new base::StringValue("present")); | |
399 property_dict->Set("pinnedState", pinned_list); | |
400 | |
401 base::ListValue* authors_list = new base::ListValue; | |
402 const gdata::GDataFile::AuthorList& authors = file.authors(); | |
403 for (gdata::GDataFile::AuthorList::const_iterator iter = authors.begin(); | |
404 iter != authors.end(); ++iter) { | |
405 base::DictionaryValue* author_info = new base::DictionaryValue; | |
406 author_info->SetString("name", iter->first); | |
407 author_info->SetString("email", iter->second); | |
408 authors_list->Append(author_info); | |
409 } | |
410 property_dict->Set("authors", authors_list); | |
zel
2012/02/29 23:46:38
remove authors
Greg Spencer (Chromium)
2012/03/01 02:26:32
Done.
| |
411 } | |
412 | |
389 } // namespace | 413 } // namespace |
390 | 414 |
391 class RequestLocalFileSystemFunction::LocalFileSystemCallbackDispatcher { | 415 class RequestLocalFileSystemFunction::LocalFileSystemCallbackDispatcher { |
392 public: | 416 public: |
393 static fileapi::FileSystemContext::OpenFileSystemCallback CreateCallback( | 417 static fileapi::FileSystemContext::OpenFileSystemCallback CreateCallback( |
394 RequestLocalFileSystemFunction* function, | 418 RequestLocalFileSystemFunction* function, |
395 Profile* profile, | 419 Profile* profile, |
396 int child_id, | 420 int child_id, |
397 scoped_refptr<const Extension> extension) { | 421 scoped_refptr<const Extension> extension) { |
398 return base::Bind( | 422 return base::Bind( |
(...skipping 1398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1797 ChromeURLDataManager::DataSource::SetFontAndTextDirection(dict); | 1821 ChromeURLDataManager::DataSource::SetFontAndTextDirection(dict); |
1798 | 1822 |
1799 dict->SetString("PLAY_MEDIA", | 1823 dict->SetString("PLAY_MEDIA", |
1800 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_PLAY)); | 1824 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_PLAY)); |
1801 | 1825 |
1802 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableGData)) | 1826 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableGData)) |
1803 dict->SetString("ENABLE_GDATA", "1"); | 1827 dict->SetString("ENABLE_GDATA", "1"); |
1804 | 1828 |
1805 return true; | 1829 return true; |
1806 } | 1830 } |
1831 | |
1832 GetGDataFilePropertiesFunction::GetGDataFilePropertiesFunction() { | |
1833 } | |
1834 | |
1835 GetGDataFilePropertiesFunction::~GetGDataFilePropertiesFunction() { | |
1836 } | |
1837 | |
1838 bool GetGDataFilePropertiesFunction::RunImpl() { | |
1839 if (args_->GetSize() != 1) { | |
1840 return false; | |
1841 } | |
1842 | |
1843 ListValue* path_list = NULL; | |
1844 args_->GetList(0, &path_list); | |
1845 DCHECK(path_list); | |
1846 | |
1847 std::string virtual_path; | |
1848 size_t len = path_list->GetSize(); | |
1849 UrlList file_urls; | |
1850 file_urls.reserve(len); | |
1851 for (size_t i = 0; i < len; ++i) { | |
1852 path_list->GetString(i, &virtual_path); | |
1853 file_urls.push_back(GURL(virtual_path)); | |
1854 } | |
1855 | |
1856 GetLocalPathsOnFileThreadAndRunCallbackOnUIThread( | |
zel
2012/02/29 23:46:38
You don't need to move things to file thread for g
Greg Spencer (Chromium)
2012/03/01 02:26:32
Done.
| |
1857 file_urls, | |
1858 base::Bind( | |
1859 &GetGDataFilePropertiesFunction::GetLocalPathsResponseOnUIThread, | |
1860 this)); | |
1861 return true; | |
1862 } | |
1863 | |
1864 // If we don't find an entry for a file in the list, we insert an empty | |
1865 // attribute list | |
1866 // If we find an entry, but it's a dictionary instead of a file, then we | |
1867 // insert an empty attribute list. | |
1868 void GetGDataFilePropertiesFunction::GetLocalPathsResponseOnUIThread( | |
1869 const FilePathList& files) { | |
1870 base::ListValue* file_info = new base::ListValue; | |
achuithb
2012/02/29 23:33:06
Could you please add a DCHECK for CurrentlyOn(Brow
Greg Spencer (Chromium)
2012/03/01 02:26:32
Actually, removed this because Zel says I don't ne
| |
1871 result_.reset(file_info); | |
1872 | |
1873 gdata::GDataFileSystem* file_system = | |
1874 gdata::GDataFileSystemFactory::GetForProfile(profile_); | |
1875 DCHECK(file_system); | |
1876 | |
1877 for (FilePathList::const_iterator iter = files.begin(); | |
1878 iter != files.end(); ++iter) { | |
1879 scoped_refptr<gdata::ReadOnlyFindFileDelegate> find_delegate( | |
zel
2012/02/29 23:46:38
yeah, you need a better one here, one that extract
Greg Spencer (Chromium)
2012/03/01 02:26:32
Done.
| |
1880 new gdata::ReadOnlyFindFileDelegate()); | |
1881 file_system->FindFileByPath(*iter, find_delegate); | |
1882 base::DictionaryValue* property_dict = new base::DictionaryValue; | |
1883 file_info->Append(property_dict); | |
1884 | |
1885 gdata::GDataFileBase* entry = find_delegate->file(); | |
1886 if (!entry) { | |
1887 property_dict->SetString("error", "NOT_FOUND"); | |
1888 continue; // Didn't find the file. | |
1889 } | |
1890 gdata::GDataFile* file = entry->AsGDataFile(); | |
1891 if (!file) | |
1892 continue; // Found a directory, just leave the empty attribute dict. | |
1893 BuildFilePropertyDictionary(*file, property_dict); | |
1894 file_info->Append(property_dict); | |
1895 } | |
1896 SendResponse(true); | |
1897 } | |
OLD | NEW |