Index: chrome/browser/chromeos/extensions/file_browser_private_api.cc |
diff --git a/chrome/browser/chromeos/extensions/file_browser_private_api.cc b/chrome/browser/chromeos/extensions/file_browser_private_api.cc |
index a088918e523926562717e33eefdb69331221b15c..a9bbd8126fe1493a4298ba437490da977c1d57ed 100644 |
--- a/chrome/browser/chromeos/extensions/file_browser_private_api.cc |
+++ b/chrome/browser/chromeos/extensions/file_browser_private_api.cc |
@@ -386,6 +386,98 @@ base::DictionaryValue* CreateValueFromMountPoint(Profile* profile, |
} |
#endif // defined(OS_CHROMEOS) |
+// Delegate used to find file properties. |
+class FilePropertiesDelegate : public gdata::FindFileDelegate { |
+ public: |
+ FilePropertiesDelegate(); |
+ virtual ~FilePropertiesDelegate(); |
+ |
+ // Builds a dictionary from the GDataFile file property information |
+ void CopyProperties(base::DictionaryValue* property_dict); |
+ |
+ base::PlatformFileError error() const { return error_; } |
+ |
+ private: |
+ // GDataFileSystem::FindFileDelegate overrides. |
+ virtual void OnFileFound(gdata::GDataFile* file) OVERRIDE; |
+ virtual void OnDirectoryFound(const FilePath&, |
+ gdata::GDataDirectory* dir) OVERRIDE; |
+ virtual FindFileTraversalCommand OnEnterDirectory( |
+ const FilePath&, |
+ gdata::GDataDirectory*) OVERRIDE; |
+ virtual void OnError(base::PlatformFileError error) OVERRIDE; |
+ |
+ GURL thumbnail_url_; |
+ int pinned_state_; |
+ base::PlatformFileError error_; |
+}; |
+ |
+// FilePropertiesDelegate class implementation. |
+ |
+FilePropertiesDelegate::FilePropertiesDelegate() |
+ : pinned_state_(0), error_(base::PLATFORM_FILE_OK) { |
+} |
+ |
+FilePropertiesDelegate::~FilePropertiesDelegate() { } |
+ |
+void FilePropertiesDelegate::CopyProperties( |
+ base::DictionaryValue* property_dict) { |
+ DCHECK(property_dict); |
+ DCHECK(!property_dict->HasKey("thumbnailUrl")); |
+ DCHECK(!property_dict->HasKey("pinnedState")); |
+ DCHECK(!property_dict->HasKey("error")); |
+ |
+ if (error_ != base::PLATFORM_FILE_OK) { |
+ property_dict->SetInteger("error", error_); |
+ return; |
+ } |
+ |
+ property_dict->SetString("thumbnailUrl", thumbnail_url_.spec()); |
+ |
+ base::ListValue *pinned_list = new base::ListValue; |
+ if (pinned_state_ & gdata::GDataFile::PINNED_STATE_PINNED) |
+ pinned_list->Append(new base::StringValue("pinned")); |
+ if (pinned_state_ & gdata::GDataFile::PINNED_STATE_PRESENT) |
+ pinned_list->Append(new base::StringValue("present")); |
+ property_dict->Set("pinnedState", pinned_list); |
+} |
+ |
+void FilePropertiesDelegate::OnFileFound(gdata::GDataFile* file) { |
+ DCHECK(!file->file_info().is_directory); |
+ thumbnail_url_ = file->thumbnail_url(); |
+ pinned_state_ = file->pinned_state(); |
+} |
+ |
+void FilePropertiesDelegate::OnDirectoryFound(const FilePath&, |
+ gdata::GDataDirectory* dir) { |
+ DCHECK(dir->file_info().is_directory); |
+ // We don't set anything here because we don't have any properties for |
+ // directories yet. |
+} |
+ |
+gdata::FindFileDelegate::FindFileTraversalCommand |
+FilePropertiesDelegate::OnEnterDirectory(const FilePath&, |
+ gdata::GDataDirectory*) { |
+ // Keep traversing while doing read only lookups. |
+ return FIND_FILE_CONTINUES; |
+} |
+ |
+void FilePropertiesDelegate::OnError(base::PlatformFileError error) { |
+ error_ = error; |
+} |
+ |
+FilePath GetVirtualPathFromURL(const GURL& file_url) { |
+ FilePath virtual_path; |
+ fileapi::FileSystemType type = fileapi::kFileSystemTypeUnknown; |
+ GURL file_origin_url; |
+ if (!CrackFileSystemURL(file_url, &file_origin_url, &type, &virtual_path) || |
+ type != fileapi::kFileSystemTypeExternal) { |
+ NOTREACHED(); |
+ return FilePath(); |
+ } |
+ return virtual_path; |
+} |
+ |
} // namespace |
class RequestLocalFileSystemFunction::LocalFileSystemCallbackDispatcher { |
@@ -1804,3 +1896,47 @@ bool FileDialogStringsFunction::RunImpl() { |
return true; |
} |
+ |
+GetGDataFilePropertiesFunction::GetGDataFilePropertiesFunction() { |
+} |
+ |
+GetGDataFilePropertiesFunction::~GetGDataFilePropertiesFunction() { |
+} |
+ |
+bool GetGDataFilePropertiesFunction::RunImpl() { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ if (args_->GetSize() != 1) |
+ return false; |
+ |
+ ListValue* path_list = NULL; |
+ args_->GetList(0, &path_list); |
+ DCHECK(path_list); |
+ |
+ std::string virtual_path; |
+ size_t len = path_list->GetSize(); |
+ FilePathList files; |
+ files.reserve(len); |
+ for (size_t i = 0; i < len; ++i) { |
+ path_list->GetString(i, &virtual_path); |
zel
2012/03/01 02:37:38
s/virtual_path/file_url/
|
+ files.push_back(GetVirtualPathFromURL(GURL(virtual_path))); |
+ } |
+ |
+ base::ListValue* file_info = new base::ListValue; |
+ result_.reset(file_info); |
+ |
+ gdata::GDataFileSystem* file_system = |
+ gdata::GDataFileSystemFactory::GetForProfile(profile_); |
+ DCHECK(file_system); |
+ |
+ for (FilePathList::const_iterator iter = files.begin(); |
+ iter != files.end(); ++iter) { |
+ scoped_refptr<FilePropertiesDelegate> property_delegate( |
+ new FilePropertiesDelegate()); |
+ file_system->FindFileByPath(*iter, property_delegate); |
+ base::DictionaryValue* property_dict = new base::DictionaryValue; |
+ property_delegate->CopyProperties(property_dict); |
+ file_info->Append(property_dict); |
+ } |
+ |
+ return true; |
+} |