Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1577)

Unified Diff: chrome/browser/chromeos/extensions/file_browser_private_api.cc

Issue 9545006: This adds some GData private API to the file manager (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Adding dirty bit and edit url Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 c5cc7c48efffa82f9814b60465186aadf858306d..74ffe4436e778aebf27897d50d4e0b59422c75c7 100644
--- a/chrome/browser/chromeos/extensions/file_browser_private_api.cc
+++ b/chrome/browser/chromeos/extensions/file_browser_private_api.cc
@@ -386,6 +386,112 @@ 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_;
+ GURL edit_url_;
+ int cache_state_;
+ base::PlatformFileError error_;
+};
+
+// FilePropertiesDelegate class implementation.
+
+FilePropertiesDelegate::FilePropertiesDelegate()
+ : cache_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("editUrl"));
+ DCHECK(!property_dict->HasKey("isPinned"));
+ DCHECK(!property_dict->HasKey("isPresent"));
+ DCHECK(!property_dict->HasKey("isDirty"));
+ DCHECK(!property_dict->HasKey("errorCode"));
+
+ if (error_ != base::PLATFORM_FILE_OK) {
+ property_dict->SetInteger("errorCode", error_);
+ return;
+ }
+
+ property_dict->SetString("thumbnailUrl", thumbnail_url_.spec());
+ property_dict->SetString("editUrl", edit_url_.spec());
zel 2012/03/01 22:16:12 let's check if we even have it - only hosted doc i
+
+ base::FundamentalValue* pinned =
+ new base::FundamentalValue(static_cast<bool>(cache_state_ &
+ gdata::GDataFile::CACHE_STATE_PINNED));
+ property_dict->Set("isPinned", pinned);
+
+ base::FundamentalValue* present =
+ new base::FundamentalValue(static_cast<bool>(cache_state_ &
+ gdata::GDataFile::CACHE_STATE_PRESENT));
+ property_dict->Set("isPresent", present);
+
+ base::FundamentalValue* dirty =
+ new base::FundamentalValue(static_cast<bool>(cache_state_ &
+ gdata::GDataFile::CACHE_STATE_DIRTY));
+ property_dict->Set("isDirty", dirty);
+}
+
+void FilePropertiesDelegate::OnFileFound(gdata::GDataFile* file) {
+ DCHECK(!file->file_info().is_directory);
+ thumbnail_url_ = file->thumbnail_url();
+ edit_url_ = file->edit_url();
+ cache_state_ = file->cache_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 {
@@ -1792,3 +1898,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 file_url;
+ size_t len = path_list->GetSize();
+ FilePathList files;
+ files.reserve(len);
+ for (size_t i = 0; i < len; ++i) {
+ path_list->GetString(i, &file_url);
+ files.push_back(GetVirtualPathFromURL(GURL(file_url)));
+ }
+
+ 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;
+}

Powered by Google App Engine
This is Rietveld 408576698