diff options
author | hidehiko@chromium.org <hidehiko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-12 11:11:50 +0000 |
---|---|---|
committer | hidehiko@chromium.org <hidehiko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-12 11:11:50 +0000 |
commit | ed4a72aa71a0dd0b626e209ba6c63b771634154d (patch) | |
tree | dc7816adbb7d4c52f52568de874423d5e8f9d3d1 /chrome/browser/drive | |
parent | 424bf6b47ba02d4000ea75ff1cb1a0bc4f9e118c (diff) | |
download | chromium_src-ed4a72aa71a0dd0b626e209ba6c63b771634154d.zip chromium_src-ed4a72aa71a0dd0b626e209ba6c63b771634154d.tar.gz chromium_src-ed4a72aa71a0dd0b626e209ba6c63b771634154d.tar.bz2 |
Move CreateFrom{Drive V2 class} to drive_api_util.
By this CL, gdata_wapi_parser is freed from the dependency to Drive API v2's
modules.
BUG=231125
TEST=Ran unit_tests
Review URL: https://chromiumcodereview.appspot.com/23865005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@222760 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/drive')
-rw-r--r-- | chrome/browser/drive/drive_api_service.cc | 12 | ||||
-rw-r--r-- | chrome/browser/drive/drive_api_util.cc | 148 | ||||
-rw-r--r-- | chrome/browser/drive/drive_api_util.h | 22 |
3 files changed, 176 insertions, 6 deletions
diff --git a/chrome/browser/drive/drive_api_service.cc b/chrome/browser/drive/drive_api_service.cc index dbc7325..7b5e6e6e 100644 --- a/chrome/browser/drive/drive_api_service.cc +++ b/chrome/browser/drive/drive_api_service.cc @@ -115,7 +115,7 @@ void ConvertFileEntryToResourceEntryAndRun( // Converting to ResourceEntry is cheap enough to do on UI thread. scoped_ptr<ResourceEntry> entry = - ResourceEntry::CreateFromFileResource(*value); + util::ConvertFileResourceToResourceEntry(*value); if (!entry) { callback.Run(GDATA_PARSE_ERROR, scoped_ptr<ResourceEntry>()); return; @@ -124,10 +124,10 @@ void ConvertFileEntryToResourceEntryAndRun( callback.Run(error, entry.Pass()); } -// Thin adapter of CreateFromFileList. +// Thin adapter of ConvertFileListToResourceList. scoped_ptr<ResourceList> ConvertFileListToResourceList( scoped_ptr<FileList> file_list) { - return ResourceList::CreateFromFileList(*file_list); + return util::ConvertFileListToResourceList(*file_list); } // Converts the FileList value to ResourceList on blocking pool and runs @@ -153,10 +153,10 @@ void ConvertFileListToResourceListOnBlockingPoolAndRun( base::Bind(&DidConvertToResourceListOnBlockingPool, callback)); } -// Thin adapter of CreateFromChangeList. +// Thin adapter of ConvertChangeListToResourceList. scoped_ptr<ResourceList> ConvertChangeListToResourceList( scoped_ptr<ChangeList> change_list) { - return ResourceList::CreateFromChangeList(*change_list); + return util::ConvertChangeListToResourceList(*change_list); } // Converts the FileList value to ResourceList on blocking pool and runs @@ -198,7 +198,7 @@ void ConvertFileResourceToResourceEntryForUploadRangeAndRun( // Converting to ResourceEntry is cheap enough to do on UI thread. scoped_ptr<ResourceEntry> entry = - ResourceEntry::CreateFromFileResource(*value); + util::ConvertFileResourceToResourceEntry(*value); if (!entry) { callback.Run(UploadRangeResponse(GDATA_PARSE_ERROR, response.start_position_received, diff --git a/chrome/browser/drive/drive_api_util.cc b/chrome/browser/drive/drive_api_util.cc index e14df7c..75a8c91 100644 --- a/chrome/browser/drive/drive_api_util.cc +++ b/chrome/browser/drive/drive_api_util.cc @@ -222,6 +222,154 @@ scoped_ptr<google_apis::FileResource> ConvertResourceEntryToFileResource( return file.Pass(); } +scoped_ptr<google_apis::ResourceEntry> +ConvertFileResourceToResourceEntry( + const google_apis::FileResource& file_resource) { + scoped_ptr<google_apis::ResourceEntry> entry(new google_apis::ResourceEntry); + + // ResourceEntry + entry->set_resource_id(file_resource.file_id()); + entry->set_id(file_resource.file_id()); + entry->set_kind(file_resource.GetKind()); + entry->set_title(file_resource.title()); + entry->set_published_time(file_resource.created_date()); + // TODO(kochi): entry->labels_ + if (!file_resource.shared_with_me_date().is_null()) { + std::vector<std::string> labels; + labels.push_back("shared-with-me"); + entry->set_labels(labels); + } + + // This should be the url to download the file_resource. + { + google_apis::Content content; + content.set_url(file_resource.download_url()); + content.set_mime_type(file_resource.mime_type()); + entry->set_content(content); + } + // TODO(kochi): entry->resource_links_ + + // For file entries + entry->set_filename(file_resource.title()); + entry->set_suggested_filename(file_resource.title()); + entry->set_file_md5(file_resource.md5_checksum()); + entry->set_file_size(file_resource.file_size()); + + // If file is removed completely, that information is only available in + // ChangeResource, and is reflected in |removed_|. If file is trashed, the + // file entry still exists but with its "trashed" label true. + entry->set_deleted(file_resource.labels().is_trashed()); + + // CommonMetadata + entry->set_etag(file_resource.etag()); + // entry->authors_ + // entry->links_. + ScopedVector<google_apis::Link> links; + if (!file_resource.parents().empty()) { + google_apis::Link* link = new google_apis::Link; + link->set_type(google_apis::Link::LINK_PARENT); + link->set_href(file_resource.parents()[0]->parent_link()); + links.push_back(link); + } + if (!file_resource.self_link().is_empty()) { + google_apis::Link* link = new google_apis::Link; + link->set_type(google_apis::Link::LINK_EDIT); + link->set_href(file_resource.self_link()); + links.push_back(link); + } + if (!file_resource.thumbnail_link().is_empty()) { + google_apis::Link* link = new google_apis::Link; + link->set_type(google_apis::Link::LINK_THUMBNAIL); + link->set_href(file_resource.thumbnail_link()); + links.push_back(link); + } + if (!file_resource.alternate_link().is_empty()) { + google_apis::Link* link = new google_apis::Link; + link->set_type(google_apis::Link::LINK_ALTERNATE); + link->set_href(file_resource.alternate_link()); + links.push_back(link); + } + if (!file_resource.embed_link().is_empty()) { + google_apis::Link* link = new google_apis::Link; + link->set_type(google_apis::Link::LINK_EMBED); + link->set_href(file_resource.embed_link()); + links.push_back(link); + } + entry->set_links(links.Pass()); + + // entry->categories_ + entry->set_updated_time(file_resource.modified_date()); + entry->set_last_viewed_time(file_resource.last_viewed_by_me_date()); + + entry->FillRemainingFields(); + return entry.Pass(); +} + +scoped_ptr<google_apis::ResourceEntry> +ConvertChangeResourceToResourceEntry( + const google_apis::ChangeResource& change_resource) { + scoped_ptr<google_apis::ResourceEntry> entry; + if (change_resource.file()) + entry = ConvertFileResourceToResourceEntry(*change_resource.file()).Pass(); + else + entry.reset(new google_apis::ResourceEntry); + + entry->set_resource_id(change_resource.file_id()); + // If |is_deleted()| returns true, the file is removed from Drive. + entry->set_removed(change_resource.is_deleted()); + entry->set_changestamp(change_resource.change_id()); + + return entry.Pass(); +} + +scoped_ptr<google_apis::ResourceList> +ConvertFileListToResourceList(const google_apis::FileList& file_list) { + scoped_ptr<google_apis::ResourceList> feed(new google_apis::ResourceList); + + const ScopedVector<google_apis::FileResource>& items = file_list.items(); + ScopedVector<google_apis::ResourceEntry> entries; + for (size_t i = 0; i < items.size(); ++i) + entries.push_back(ConvertFileResourceToResourceEntry(*items[i]).release()); + feed->set_entries(entries.Pass()); + + ScopedVector<google_apis::Link> links; + if (!file_list.next_link().is_empty()) { + google_apis::Link* link = new google_apis::Link; + link->set_type(google_apis::Link::LINK_NEXT); + link->set_href(file_list.next_link()); + links.push_back(link); + } + feed->set_links(links.Pass()); + + return feed.Pass(); +} + +scoped_ptr<google_apis::ResourceList> +ConvertChangeListToResourceList(const google_apis::ChangeList& change_list) { + scoped_ptr<google_apis::ResourceList> feed(new google_apis::ResourceList); + + const ScopedVector<google_apis::ChangeResource>& items = change_list.items(); + ScopedVector<google_apis::ResourceEntry> entries; + for (size_t i = 0; i < items.size(); ++i) { + entries.push_back( + ConvertChangeResourceToResourceEntry(*items[i]).release()); + } + feed->set_entries(entries.Pass()); + + feed->set_largest_changestamp(change_list.largest_change_id()); + + ScopedVector<google_apis::Link> links; + if (!change_list.next_link().is_empty()) { + google_apis::Link* link = new google_apis::Link; + link->set_type(google_apis::Link::LINK_NEXT); + link->set_href(change_list.next_link()); + links.push_back(link); + } + feed->set_links(links.Pass()); + + return feed.Pass(); +} + const char kWapiRootDirectoryResourceId[] = "folder:root"; } // namespace util diff --git a/chrome/browser/drive/drive_api_util.h b/chrome/browser/drive/drive_api_util.h index afeb2c3..f57c992 100644 --- a/chrome/browser/drive/drive_api_util.h +++ b/chrome/browser/drive/drive_api_util.h @@ -18,8 +18,12 @@ class Value; } // namespace base namespace google_apis { +class ChangeList; +class ChangeResource; +class FileList; class FileResource; class ResourceEntry; +class ResourceList; } // namespace google_apis namespace drive { @@ -71,6 +75,24 @@ void ParseShareUrlAndRun(const google_apis::GetShareUrlCallback& callback, scoped_ptr<google_apis::FileResource> ConvertResourceEntryToFileResource(const google_apis::ResourceEntry& entry); +// Converts FileResource to ResourceEntry. +scoped_ptr<google_apis::ResourceEntry> +ConvertFileResourceToResourceEntry( + const google_apis::FileResource& file_resource); + +// Converts ChangeResource to ResourceEntry. +scoped_ptr<google_apis::ResourceEntry> +ConvertChangeResourceToResourceEntry( + const google_apis::ChangeResource& change_resource); + +// Converts FileList to ResourceList. +scoped_ptr<google_apis::ResourceList> +ConvertFileListToResourceList(const google_apis::FileList& file_list); + +// Converts ChangeList to ResourceList. +scoped_ptr<google_apis::ResourceList> +ConvertChangeListToResourceList(const google_apis::ChangeList& change_list); + // The resource ID for the root directory for WAPI is defined in the spec: // https://developers.google.com/google-apps/documents-list/ extern const char kWapiRootDirectoryResourceId[]; |