From 51ed7bd425d4b42e8bb6b5e1db0fe260289f99d7 Mon Sep 17 00:00:00 2001 From: "fukino@chromium.org" Date: Mon, 14 Jul 2014 13:58:22 +0000 Subject: Get rid of DriveEntryKind. Basically DriveEntryKind is used for clasifying files into one of {Folder, Hosted document, Normal file}. We can classify them without DriveEntryKind by using FileResource::IsDirectory() and their mime type. Utility functions for clasification are now indepenent with ResourceEntry, and placed in drive_api_util.h. ResourceEntryKind is defined to provide users of ResourceEntry (e.g. sync file system) with similar accessor to file kind. BUG=357038 TBR=rogerta@chromium.org for one line removal in .gyp file and .gn file. TEST=run google_apis_unittests and unit_tests Review URL: https://codereview.chromium.org/384543004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282941 0039d316-1c4b-4281-b951-d872f2087c98 --- .../drive/change_list_processor_unittest.cc | 1 - chrome/browser/chromeos/drive/file_system_util.cc | 7 +- .../chromeos/drive/file_system_util_unittest.cc | 7 - .../chromeos/drive/resource_entry_conversion.cc | 31 +--- chrome/browser/chromeos/drive/search_metadata.cc | 18 +-- .../chromeos/drive/sync/entry_update_performer.cc | 1 - chrome/browser/chromeos/file_manager/file_tasks.cc | 9 +- chrome/browser/drive/drive_api_util.cc | 163 +++++++-------------- chrome/browser/drive/drive_api_util.h | 27 ++-- chrome/browser/drive/drive_api_util_unittest.cc | 45 ------ .../drive_backend/conflict_resolver_unittest.cc | 19 +-- .../drive_backend/drive_backend_test_util.cc | 1 - .../local_to_remote_syncer_unittest.cc | 51 ++++--- .../drive_backend/metadata_database.cc | 10 +- .../sync_file_system/drive_backend_v1/api_util.cc | 2 +- .../drive_backend_v1/api_util_unittest.cc | 29 ++-- .../drive_backend_v1/fake_api_util.cc | 7 +- .../ui/webui/chromeos/drive_internals_ui.cc | 1 - google_apis/BUILD.gn | 1 - google_apis/drive/drive_entry_kinds.h | 40 ----- google_apis/drive/gdata_wapi_parser.cc | 116 +-------------- google_apis/drive/gdata_wapi_parser.h | 67 ++------- google_apis/drive/gdata_wapi_parser_unittest.cc | 104 ++----------- google_apis/google_apis.gyp | 1 - 24 files changed, 183 insertions(+), 575 deletions(-) delete mode 100644 google_apis/drive/drive_entry_kinds.h diff --git a/chrome/browser/chromeos/drive/change_list_processor_unittest.cc b/chrome/browser/chromeos/drive/change_list_processor_unittest.cc index 1f25817..2771e2a 100644 --- a/chrome/browser/chromeos/drive/change_list_processor_unittest.cc +++ b/chrome/browser/chromeos/drive/change_list_processor_unittest.cc @@ -16,7 +16,6 @@ #include "chrome/browser/chromeos/drive/test_util.h" #include "content/public/test/test_browser_thread_bundle.h" #include "google_apis/drive/drive_api_parser.h" -#include "google_apis/drive/gdata_wapi_parser.h" #include "google_apis/drive/test_util.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/chrome/browser/chromeos/drive/file_system_util.cc b/chrome/browser/chromeos/drive/file_system_util.cc index d0b5be2..5990113 100644 --- a/chrome/browser/chromeos/drive/file_system_util.cc +++ b/chrome/browser/chromeos/drive/file_system_util.cc @@ -29,6 +29,7 @@ #include "chrome/browser/chromeos/drive/write_on_cache_file.h" #include "chrome/browser/chromeos/profiles/profile_helper.h" #include "chrome/browser/chromeos/profiles/profile_util.h" +#include "chrome/browser/drive/drive_api_util.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile_manager.h" #include "chrome/common/chrome_constants.h" @@ -37,7 +38,6 @@ #include "chrome/common/url_constants.h" #include "chromeos/chromeos_constants.h" #include "content/public/browser/browser_thread.h" -#include "google_apis/drive/gdata_wapi_parser.h" #include "net/base/escape.h" #include "webkit/browser/fileapi/file_system_url.h" @@ -345,9 +345,8 @@ bool CreateGDocFile(const base::FilePath& file_path, } bool HasGDocFileExtension(const base::FilePath& file_path) { - return google_apis::ResourceEntry::ClassifyEntryKindByFileExtension( - file_path) & - google_apis::ResourceEntry::KIND_OF_HOSTED_DOCUMENT; + std::string extension = base::FilePath(file_path.Extension()).AsUTF8Unsafe(); + return IsHostedDocumentByExtension(extension); } GURL ReadUrlFromGDocFile(const base::FilePath& file_path) { diff --git a/chrome/browser/chromeos/drive/file_system_util_unittest.cc b/chrome/browser/chromeos/drive/file_system_util_unittest.cc index d60e738..c894b04 100644 --- a/chrome/browser/chromeos/drive/file_system_util_unittest.cc +++ b/chrome/browser/chromeos/drive/file_system_util_unittest.cc @@ -284,13 +284,6 @@ TEST(FileSystemUtilTest, GDocFile) { EXPECT_EQ(url, ReadUrlFromGDocFile(file)); EXPECT_EQ(resource_id, ReadResourceIdFromGDocFile(file)); - // Read and write glink. - file = temp_dir.path().AppendASCII("test.glink"); - EXPECT_TRUE(CreateGDocFile(file, url, resource_id)); - EXPECT_TRUE(HasGDocFileExtension(file)); - EXPECT_EQ(url, ReadUrlFromGDocFile(file)); - EXPECT_EQ(resource_id, ReadResourceIdFromGDocFile(file)); - // Non GDoc file. file = temp_dir.path().AppendASCII("test.txt"); std::string data = "Hello world!"; diff --git a/chrome/browser/chromeos/drive/resource_entry_conversion.cc b/chrome/browser/chromeos/drive/resource_entry_conversion.cc index ebaaadb..a6568bc 100644 --- a/chrome/browser/chromeos/drive/resource_entry_conversion.cc +++ b/chrome/browser/chromeos/drive/resource_entry_conversion.cc @@ -12,7 +12,6 @@ #include "chrome/browser/chromeos/drive/file_system_util.h" #include "chrome/browser/drive/drive_api_util.h" #include "google_apis/drive/drive_api_parser.h" -#include "google_apis/drive/gdata_wapi_parser.h" namespace drive { @@ -77,30 +76,22 @@ bool ConvertFileResourceToResourceEntry( input.last_viewed_by_me_date().ToInternalValue()); file_info->set_creation_time(input.created_date().ToInternalValue()); - // TODO(hashimoto): Get rid of WAPI stuff. crbug.com/357038 - const google_apis::DriveEntryKind entry_kind = util::GetKind(input); - const int entry_kind_class = - google_apis::ResourceEntry::ClassifyEntryKind(entry_kind); - const bool is_file = entry_kind_class & - google_apis::ResourceEntry::KIND_OF_FILE; - const bool is_hosted_document = entry_kind_class & - google_apis::ResourceEntry::KIND_OF_HOSTED_DOCUMENT; - const bool is_folder = entry_kind_class & - google_apis::ResourceEntry::KIND_OF_FOLDER; - - if (is_file || is_hosted_document) { + if (input.IsDirectory()) { + file_info->set_is_directory(true); + } else { FileSpecificInfo* file_specific_info = converted.mutable_file_specific_info(); - if (is_file) { + if (!drive::util::IsHostedDocument(input.mime_type())) { file_info->set_size(input.file_size()); file_specific_info->set_md5(input.md5_checksum()); - } else if (is_hosted_document) { + file_specific_info->set_is_hosted_document(false); + } else { // Attach .g extension to hosted documents so we can special // case their handling in UI. // TODO(satorux): Figure out better way how to pass input info like kind // to UI through the File API stack. const std::string document_extension = - google_apis::ResourceEntry::GetHostedDocumentExtension(entry_kind); + drive::util::GetHostedDocumentExtension(input.mime_type()); file_specific_info->set_document_extension(document_extension); converted.set_base_name( util::NormalizeFileName(converted.title() + document_extension)); @@ -108,10 +99,10 @@ bool ConvertFileResourceToResourceEntry( // We don't know the size of hosted docs and it does not matter since // it has no effect on the quota. file_info->set_size(0); + file_specific_info->set_is_hosted_document(true); } file_info->set_is_directory(false); file_specific_info->set_content_mime_type(input.mime_type()); - file_specific_info->set_is_hosted_document(is_hosted_document); if (!input.alternate_link().is_empty()) file_specific_info->set_alternate_url(input.alternate_link().spec()); @@ -127,12 +118,6 @@ bool ConvertFileResourceToResourceEntry( const int64 image_rotation = input.image_media_metadata().rotation(); if (image_rotation != -1) file_specific_info->set_image_rotation(image_rotation); - } else if (is_folder) { - file_info->set_is_directory(true); - } else { - // The entry is something that doesn't map into files (i.e. sites). - // We don't handle these kind of entries hence return false. - return false; } out_entry->Swap(&converted); diff --git a/chrome/browser/chromeos/drive/search_metadata.cc b/chrome/browser/chromeos/drive/search_metadata.cc index e08463f..04409fa 100644 --- a/chrome/browser/chromeos/drive/search_metadata.cc +++ b/chrome/browser/chromeos/drive/search_metadata.cc @@ -13,8 +13,8 @@ #include "base/strings/utf_string_conversions.h" #include "base/time/time.h" #include "chrome/browser/chromeos/drive/file_system_util.h" +#include "chrome/browser/drive/drive_api_util.h" #include "content/public/browser/browser_thread.h" -#include "google_apis/drive/gdata_wapi_parser.h" #include "net/base/escape.h" using content::BrowserThread; @@ -166,16 +166,12 @@ bool IsEligibleEntry(const ResourceEntry& entry, int options) { if (entry.file_specific_info().is_hosted_document()) { // Not all hosted documents are cached by Drive offline app. // http://support.google.com/drive/bin/answer.py?hl=en&answer=1628467 - switch (google_apis::ResourceEntry::GetEntryKindFromExtension( - entry.file_specific_info().document_extension())) { - case google_apis::ENTRY_KIND_DOCUMENT: - case google_apis::ENTRY_KIND_SPREADSHEET: - case google_apis::ENTRY_KIND_PRESENTATION: - case google_apis::ENTRY_KIND_DRAWING: - return true; - default: - return false; - } + std::string mime_type = drive::util::GetHostedDocumentMimeType( + entry.file_specific_info().document_extension()); + return mime_type == drive::util::kGoogleDocumentMimeType || + mime_type == drive::util::kGoogleSpreadsheetMimeType || + mime_type == drive::util::kGooglePresentationMimeType || + mime_type == drive::util::kGoogleDrawingMimeType; } else { return entry.file_specific_info().cache_state().is_present(); } diff --git a/chrome/browser/chromeos/drive/sync/entry_update_performer.cc b/chrome/browser/chromeos/drive/sync/entry_update_performer.cc index 167b9de..f9e8409 100644 --- a/chrome/browser/chromeos/drive/sync/entry_update_performer.cc +++ b/chrome/browser/chromeos/drive/sync/entry_update_performer.cc @@ -18,7 +18,6 @@ #include "chrome/browser/chromeos/drive/sync/remove_performer.h" #include "content/public/browser/browser_thread.h" #include "google_apis/drive/drive_api_parser.h" -#include "google_apis/drive/gdata_wapi_parser.h" using content::BrowserThread; diff --git a/chrome/browser/chromeos/file_manager/file_tasks.cc b/chrome/browser/chromeos/file_manager/file_tasks.cc index 3fc7ec0..e348489 100644 --- a/chrome/browser/chromeos/file_manager/file_tasks.cc +++ b/chrome/browser/chromeos/file_manager/file_tasks.cc @@ -17,6 +17,7 @@ #include "chrome/browser/chromeos/file_manager/fileapi_util.h" #include "chrome/browser/chromeos/file_manager/open_util.h" #include "chrome/browser/chromeos/fileapi/file_system_backend.h" +#include "chrome/browser/drive/drive_api_util.h" #include "chrome/browser/drive/drive_app_registry.h" #include "chrome/browser/extensions/extension_tab_util.h" #include "chrome/browser/extensions/extension_util.h" @@ -32,7 +33,6 @@ #include "extensions/browser/extension_util.h" #include "extensions/common/constants.h" #include "extensions/common/extension_set.h" -#include "google_apis/drive/gdata_wapi_parser.h" #include "webkit/browser/fileapi/file_system_context.h" #include "webkit/browser/fileapi/file_system_url.h" @@ -90,11 +90,10 @@ const size_t kDriveTaskExtensionPrefixLength = bool ContainsGoogleDocument(const PathAndMimeTypeSet& path_mime_set) { for (PathAndMimeTypeSet::const_iterator iter = path_mime_set.begin(); iter != path_mime_set.end(); ++iter) { - if (google_apis::ResourceEntry::ClassifyEntryKindByFileExtension( - iter->first) & - google_apis::ResourceEntry::KIND_OF_GOOGLE_DOCUMENT) { + std::string extension = + base::FilePath(iter->first.Extension()).AsUTF8Unsafe(); + if (drive::util::IsHostedDocumentByExtension(extension)) return true; - } } return false; } diff --git a/chrome/browser/drive/drive_api_util.cc b/chrome/browser/drive/drive_api_util.cc index 13cefa6..2a3dbd4 100644 --- a/chrome/browser/drive/drive_api_util.cc +++ b/chrome/browser/drive/drive_api_util.cc @@ -25,28 +25,23 @@ namespace drive { namespace util { namespace { -std::string GetMimeTypeFromEntryKind(google_apis::DriveEntryKind kind) { - switch (kind) { - case google_apis::ENTRY_KIND_DOCUMENT: - return kGoogleDocumentMimeType; - case google_apis::ENTRY_KIND_SPREADSHEET: - return kGoogleSpreadsheetMimeType; - case google_apis::ENTRY_KIND_PRESENTATION: - return kGooglePresentationMimeType; - case google_apis::ENTRY_KIND_DRAWING: - return kGoogleDrawingMimeType; - case google_apis::ENTRY_KIND_TABLE: - return kGoogleTableMimeType; - case google_apis::ENTRY_KIND_FORM: - return kGoogleFormMimeType; - default: - return std::string(); - } -} - // Returns the argument string. std::string Identity(const std::string& resource_id) { return resource_id; } +struct HostedDocumentKind { + const char* mime_type; + const char* extension; +}; + +const HostedDocumentKind kHostedDocumentKinds[] = { + {kGoogleDocumentMimeType, ".gdoc"}, + {kGoogleSpreadsheetMimeType, ".gsheet"}, + {kGooglePresentationMimeType, ".gslides"}, + {kGoogleDrawingMimeType, ".gdraw"}, + {kGoogleTableMimeType, ".gtable"}, + {kGoogleFormMimeType, ".gform"} +}; + } // namespace @@ -173,97 +168,6 @@ void ParseShareUrlAndRun(const google_apis::GetShareUrlCallback& callback, callback.Run(error, share_link ? share_link->href() : GURL()); } -scoped_ptr ConvertResourceEntryToFileResource( - const google_apis::ResourceEntry& entry) { - scoped_ptr file(new google_apis::FileResource); - - file->set_file_id(entry.resource_id()); - file->set_title(entry.title()); - file->set_created_date(entry.published_time()); - - if (std::find(entry.labels().begin(), entry.labels().end(), - "shared-with-me") != entry.labels().end()) { - // Set current time to mark the file is shared_with_me, since ResourceEntry - // doesn't have |shared_with_me_date| equivalent. - file->set_shared_with_me_date(base::Time::Now()); - } - - file->set_shared(std::find(entry.labels().begin(), entry.labels().end(), - "shared") != entry.labels().end()); - - if (entry.is_folder()) { - file->set_mime_type(kDriveFolderMimeType); - } else { - std::string mime_type = GetMimeTypeFromEntryKind(entry.kind()); - if (mime_type.empty()) - mime_type = entry.content_mime_type(); - file->set_mime_type(mime_type); - } - - file->set_md5_checksum(entry.file_md5()); - file->set_file_size(entry.file_size()); - - file->mutable_labels()->set_trashed(entry.deleted()); - file->set_etag(entry.etag()); - - google_apis::ImageMediaMetadata* image_media_metadata = - file->mutable_image_media_metadata(); - image_media_metadata->set_width(entry.image_width()); - image_media_metadata->set_height(entry.image_height()); - image_media_metadata->set_rotation(entry.image_rotation()); - - std::vector* parents = file->mutable_parents(); - for (size_t i = 0; i < entry.links().size(); ++i) { - using google_apis::Link; - const Link& link = *entry.links()[i]; - switch (link.type()) { - case Link::LINK_PARENT: { - google_apis::ParentReference parent; - parent.set_parent_link(link.href()); - - std::string file_id = - drive::util::ExtractResourceIdFromUrl(link.href()); - parent.set_file_id(file_id); - parents->push_back(parent); - break; - } - case Link::LINK_ALTERNATE: - file->set_alternate_link(link.href()); - break; - default: - break; - } - } - - file->set_modified_date(entry.updated_time()); - file->set_last_viewed_by_me_date(entry.last_viewed_time()); - - return file.Pass(); -} - -google_apis::DriveEntryKind GetKind( - const google_apis::FileResource& file_resource) { - if (file_resource.IsDirectory()) - return google_apis::ENTRY_KIND_FOLDER; - - const std::string& mime_type = file_resource.mime_type(); - if (mime_type == kGoogleDocumentMimeType) - return google_apis::ENTRY_KIND_DOCUMENT; - if (mime_type == kGoogleSpreadsheetMimeType) - return google_apis::ENTRY_KIND_SPREADSHEET; - if (mime_type == kGooglePresentationMimeType) - return google_apis::ENTRY_KIND_PRESENTATION; - if (mime_type == kGoogleDrawingMimeType) - return google_apis::ENTRY_KIND_DRAWING; - if (mime_type == kGoogleTableMimeType) - return google_apis::ENTRY_KIND_TABLE; - if (mime_type == kGoogleFormMimeType) - return google_apis::ENTRY_KIND_FORM; - if (mime_type == "application/pdf") - return google_apis::ENTRY_KIND_PDF; - return google_apis::ENTRY_KIND_FILE; -} - scoped_ptr ConvertFileResourceToResourceEntry( const google_apis::FileResource& file_resource) { @@ -272,7 +176,12 @@ ConvertFileResourceToResourceEntry( // ResourceEntry entry->set_resource_id(file_resource.file_id()); entry->set_id(file_resource.file_id()); - entry->set_kind(GetKind(file_resource)); + if (file_resource.IsDirectory()) + entry->set_kind(google_apis::ResourceEntry::ENTRY_KIND_FOLDER); + else if (IsHostedDocument(file_resource.mime_type())) + entry->set_kind(google_apis::ResourceEntry::ENTRY_KIND_UNKNOWN); + else + entry->set_kind(google_apis::ResourceEntry::ENTRY_KIND_FILE); entry->set_title(file_resource.title()); entry->set_published_time(file_resource.created_date()); @@ -435,5 +344,37 @@ std::string GetMd5Digest(const base::FilePath& file_path) { const char kWapiRootDirectoryResourceId[] = "folder:root"; +std::string GetHostedDocumentExtension(const std::string& mime_type) { + for (size_t i = 0; i < arraysize(kHostedDocumentKinds); ++i) { + if (mime_type == kHostedDocumentKinds[i].mime_type) + return kHostedDocumentKinds[i].extension; + } + return std::string(); +} + +std::string GetHostedDocumentMimeType(const std::string& extension) { + for (size_t i = 0; i < arraysize(kHostedDocumentKinds); ++i) { + if (extension == kHostedDocumentKinds[i].extension) + return kHostedDocumentKinds[i].mime_type; + } + return std::string(); +} + +bool IsHostedDocument(const std::string& mime_type) { + for (size_t i = 0; i < arraysize(kHostedDocumentKinds); ++i) { + if (mime_type == kHostedDocumentKinds[i].mime_type) + return true; + } + return false; +} + +bool IsHostedDocumentByExtension(const std::string& extension) { + for (size_t i = 0; i < arraysize(kHostedDocumentKinds); ++i) { + if (extension == kHostedDocumentKinds[i].extension) + return true; + } + return false; +} + } // namespace util } // namespace drive diff --git a/chrome/browser/drive/drive_api_util.h b/chrome/browser/drive/drive_api_util.h index a574320..e038b2d1 100644 --- a/chrome/browser/drive/drive_api_util.h +++ b/chrome/browser/drive/drive_api_util.h @@ -10,7 +10,6 @@ #include "base/memory/scoped_ptr.h" #include "chrome/browser/drive/drive_service_interface.h" #include "google_apis/drive/drive_common_callbacks.h" -#include "google_apis/drive/drive_entry_kinds.h" #include "google_apis/drive/gdata_errorcode.h" class GURL; @@ -88,14 +87,6 @@ void ParseShareUrlAndRun(const google_apis::GetShareUrlCallback& callback, google_apis::GDataErrorCode error, scoped_ptr value); -// Converts ResourceEntry to FileResource. -scoped_ptr -ConvertResourceEntryToFileResource(const google_apis::ResourceEntry& entry); - -// Returns the GData WAPI's Kind of the FileResource. -google_apis::DriveEntryKind GetKind( - const google_apis::FileResource& file_resource); - // Converts FileResource to ResourceEntry. scoped_ptr ConvertFileResourceToResourceEntry( @@ -122,6 +113,24 @@ std::string GetMd5Digest(const base::FilePath& file_path); // https://developers.google.com/google-apps/documents-list/ extern const char kWapiRootDirectoryResourceId[]; +// Returns preferred file extension for hosted documents which have given mime +// type. If the given mime type is not known as one for hosted documents, +// returns empty string. +std::string GetHostedDocumentExtension(const std::string& mime_type); + +// Returns mime type for hosted documents which have given extension in form +// ".xxx". If the given extension is not known as one for hosted documents, +// returns empty string. +std::string GetHostedDocumentMimeType(const std::string& extension); + +// Returns true if the given mime type is corresponding to one of hosted +// documents. +bool IsHostedDocument(const std::string& mime_type); + +// Returns true if the given extension is corresponding to one of hosted +// documents. +bool IsHostedDocumentByExtension(const std::string& extension); + } // namespace util } // namespace drive diff --git a/chrome/browser/drive/drive_api_util_unittest.cc b/chrome/browser/drive/drive_api_util_unittest.cc index 7a72db7..7d32a42 100644 --- a/chrome/browser/drive/drive_api_util_unittest.cc +++ b/chrome/browser/drive/drive_api_util_unittest.cc @@ -153,51 +153,6 @@ TEST(FileSystemUtilTest, ConvertFileResourceToResourceEntryImageMediaMetadata) { } } -TEST(FileSystemUtilTest, ConvertResourceEntryToFileResourceImageMediaMetadata) { - google_apis::ResourceEntry resource_entry_all_fields; - google_apis::ResourceEntry resource_entry_zero_fields; - google_apis::ResourceEntry resource_entry_no_fields; - // Set up FileResource instances; - { - resource_entry_all_fields.set_image_width(640); - resource_entry_all_fields.set_image_height(480); - resource_entry_all_fields.set_image_rotation(90); - - resource_entry_zero_fields.set_image_width(0); - resource_entry_zero_fields.set_image_height(0); - resource_entry_zero_fields.set_image_rotation(0); - } - - // Verify the converted values. - { - scoped_ptr file_resource( - ConvertResourceEntryToFileResource(resource_entry_all_fields)); - const google_apis::ImageMediaMetadata& image_media_metadata = - file_resource->image_media_metadata(); - EXPECT_EQ(640, image_media_metadata.width()); - EXPECT_EQ(480, image_media_metadata.height()); - EXPECT_EQ(90, image_media_metadata.rotation()); - } - { - scoped_ptr file_resource( - ConvertResourceEntryToFileResource(resource_entry_zero_fields)); - const google_apis::ImageMediaMetadata& image_media_metadata = - file_resource->image_media_metadata(); - EXPECT_EQ(0, image_media_metadata.width()); - EXPECT_EQ(0, image_media_metadata.height()); - EXPECT_EQ(0, image_media_metadata.rotation()); - } - { - scoped_ptr file_resource( - ConvertResourceEntryToFileResource(resource_entry_no_fields)); - const google_apis::ImageMediaMetadata& image_media_metadata = - file_resource->image_media_metadata(); - EXPECT_EQ(-1, image_media_metadata.width()); - EXPECT_EQ(-1, image_media_metadata.height()); - EXPECT_EQ(-1, image_media_metadata.rotation()); - } -} - TEST(DriveAPIUtilTest, GetMd5Digest) { base::ScopedTempDir temp_dir; ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); diff --git a/chrome/browser/sync_file_system/drive_backend/conflict_resolver_unittest.cc b/chrome/browser/sync_file_system/drive_backend/conflict_resolver_unittest.cc index 10715a2..0cfc3ef 100644 --- a/chrome/browser/sync_file_system/drive_backend/conflict_resolver_unittest.cc +++ b/chrome/browser/sync_file_system/drive_backend/conflict_resolver_unittest.cc @@ -245,10 +245,11 @@ class ConflictResolverTest : public testing::Test { return entries.Pass(); } - void VerifyConflictResolution(const std::string& parent_folder_id, - const std::string& title, - const std::string& primary_file_id, - google_apis::DriveEntryKind kind) { + void VerifyConflictResolution( + const std::string& parent_folder_id, + const std::string& title, + const std::string& primary_file_id, + google_apis::ResourceEntry::ResourceEntryKind kind) { ScopedVector entries; EXPECT_EQ(google_apis::HTTP_SUCCESS, fake_drive_helper_->SearchByTitle( @@ -311,7 +312,7 @@ TEST_F(ConflictResolverTest, ResolveConflict_Files) { // Only primary file should survive. EXPECT_EQ(SYNC_STATUS_OK, RunConflictResolver()); VerifyConflictResolution(app_root, kTitle, primary, - google_apis::ENTRY_KIND_FILE); + google_apis::ResourceEntry::ENTRY_KIND_FILE); } TEST_F(ConflictResolverTest, ResolveConflict_Folders) { @@ -337,7 +338,7 @@ TEST_F(ConflictResolverTest, ResolveConflict_Folders) { // Only primary file should survive. EXPECT_EQ(SYNC_STATUS_OK, RunConflictResolver()); VerifyConflictResolution(app_root, kTitle, primary, - google_apis::ENTRY_KIND_FOLDER); + google_apis::ResourceEntry::ENTRY_KIND_FOLDER); } TEST_F(ConflictResolverTest, ResolveConflict_FilesAndFolders) { @@ -363,7 +364,7 @@ TEST_F(ConflictResolverTest, ResolveConflict_FilesAndFolders) { // Only primary file should survive. EXPECT_EQ(SYNC_STATUS_OK, RunConflictResolver()); VerifyConflictResolution(app_root, kTitle, primary, - google_apis::ENTRY_KIND_FOLDER); + google_apis::ResourceEntry::ENTRY_KIND_FOLDER); } TEST_F(ConflictResolverTest, ResolveConflict_RemoteFolderOnLocalFile) { @@ -395,7 +396,7 @@ TEST_F(ConflictResolverTest, ResolveConflict_RemoteFolderOnLocalFile) { // Run conflict resolver. Only primary file should survive. EXPECT_EQ(SYNC_STATUS_OK, RunConflictResolver()); VerifyConflictResolution(app_root, kTitle, primary, - google_apis::ENTRY_KIND_FOLDER); + google_apis::ResourceEntry::ENTRY_KIND_FOLDER); // Continue to run remote-to-local sync. EXPECT_EQ(SYNC_STATUS_OK, ListChanges()); @@ -443,7 +444,7 @@ TEST_F(ConflictResolverTest, ResolveConflict_RemoteNestedFolderOnLocalFile) { // Run conflict resolver. Only primary file should survive. EXPECT_EQ(SYNC_STATUS_OK, RunConflictResolver()); VerifyConflictResolution(app_root, kTitle, primary, - google_apis::ENTRY_KIND_FOLDER); + google_apis::ResourceEntry::ENTRY_KIND_FOLDER); // Continue to run remote-to-local sync. EXPECT_EQ(SYNC_STATUS_OK, ListChanges()); diff --git a/chrome/browser/sync_file_system/drive_backend/drive_backend_test_util.cc b/chrome/browser/sync_file_system/drive_backend/drive_backend_test_util.cc index a646a81..6c6d689 100644 --- a/chrome/browser/sync_file_system/drive_backend/drive_backend_test_util.cc +++ b/chrome/browser/sync_file_system/drive_backend/drive_backend_test_util.cc @@ -12,7 +12,6 @@ #include "chrome/browser/sync_file_system/drive_backend/metadata_database.h" #include "chrome/browser/sync_file_system/drive_backend/metadata_database.pb.h" #include "google_apis/drive/drive_api_parser.h" -#include "google_apis/drive/drive_entry_kinds.h" #include "google_apis/drive/gdata_wapi_parser.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/chrome/browser/sync_file_system/drive_backend/local_to_remote_syncer_unittest.cc b/chrome/browser/sync_file_system/drive_backend/local_to_remote_syncer_unittest.cc index 4782098..d84edb7 100644 --- a/chrome/browser/sync_file_system/drive_backend/local_to_remote_syncer_unittest.cc +++ b/chrome/browser/sync_file_system/drive_backend/local_to_remote_syncer_unittest.cc @@ -221,9 +221,10 @@ class LocalToRemoteSyncerTest : public testing::Test { return entries[0]->resource_id(); } - void VerifyTitleUniqueness(const std::string& parent_folder_id, - const std::string& title, - google_apis::DriveEntryKind kind) { + void VerifyTitleUniqueness( + const std::string& parent_folder_id, + const std::string& title, + google_apis::ResourceEntry::ResourceEntryKind kind) { ScopedVector entries; EXPECT_EQ(google_apis::HTTP_SUCCESS, fake_drive_helper_->SearchByTitle( @@ -278,9 +279,12 @@ TEST_F(LocalToRemoteSyncerTest, CreateFile) { std::string folder_id = GetFileIDForParentAndTitle(app_root, "folder"); ASSERT_FALSE(folder_id.empty()); - VerifyTitleUniqueness(app_root, "file1", google_apis::ENTRY_KIND_FILE); - VerifyTitleUniqueness(app_root, "folder", google_apis::ENTRY_KIND_FOLDER); - VerifyTitleUniqueness(folder_id, "file2", google_apis::ENTRY_KIND_FILE); + VerifyTitleUniqueness( + app_root, "file1", google_apis::ResourceEntry::ENTRY_KIND_FILE); + VerifyTitleUniqueness( + app_root, "folder", google_apis::ResourceEntry::ENTRY_KIND_FOLDER); + VerifyTitleUniqueness( + folder_id, "file2", google_apis::ResourceEntry::ENTRY_KIND_FILE); } TEST_F(LocalToRemoteSyncerTest, CreateFileOnMissingPath) { @@ -309,9 +313,12 @@ TEST_F(LocalToRemoteSyncerTest, CreateFileOnMissingPath) { std::string folder_id2 = GetFileIDForParentAndTitle(folder_id1, "folder2"); ASSERT_FALSE(folder_id2.empty()); - VerifyTitleUniqueness(app_root, "folder1", google_apis::ENTRY_KIND_FOLDER); - VerifyTitleUniqueness(folder_id1, "folder2", google_apis::ENTRY_KIND_FOLDER); - VerifyTitleUniqueness(folder_id2, "file", google_apis::ENTRY_KIND_FILE); + VerifyTitleUniqueness( + app_root, "folder1", google_apis::ResourceEntry::ENTRY_KIND_FOLDER); + VerifyTitleUniqueness( + folder_id1, "folder2", google_apis::ResourceEntry::ENTRY_KIND_FOLDER); + VerifyTitleUniqueness( + folder_id2, "file", google_apis::ResourceEntry::ENTRY_KIND_FILE); } TEST_F(LocalToRemoteSyncerTest, DeleteFile) { @@ -330,8 +337,10 @@ TEST_F(LocalToRemoteSyncerTest, DeleteFile) { SYNC_FILE_TYPE_DIRECTORY), URL(kOrigin, "folder"))); - VerifyTitleUniqueness(app_root, "file", google_apis::ENTRY_KIND_FILE); - VerifyTitleUniqueness(app_root, "folder", google_apis::ENTRY_KIND_FOLDER); + VerifyTitleUniqueness( + app_root, "file", google_apis::ResourceEntry::ENTRY_KIND_FILE); + VerifyTitleUniqueness( + app_root, "folder", google_apis::ResourceEntry::ENTRY_KIND_FOLDER); EXPECT_EQ(SYNC_STATUS_OK, RunLocalToRemoteSyncer( FileChange(FileChange::FILE_CHANGE_DELETE, @@ -364,8 +373,8 @@ TEST_F(LocalToRemoteSyncerTest, Conflict_CreateFileOnFolder) { ScopedVector entries = GetResourceEntriesForParentAndTitle(app_root, "foo"); ASSERT_EQ(2u, entries.size()); - EXPECT_EQ(google_apis::ENTRY_KIND_FOLDER, entries[0]->kind()); - EXPECT_EQ(google_apis::ENTRY_KIND_FILE, entries[1]->kind()); + EXPECT_EQ(google_apis::ResourceEntry::ENTRY_KIND_FOLDER, entries[0]->kind()); + EXPECT_EQ(google_apis::ResourceEntry::ENTRY_KIND_FILE, entries[1]->kind()); } TEST_F(LocalToRemoteSyncerTest, Conflict_CreateFolderOnFile) { @@ -387,8 +396,8 @@ TEST_F(LocalToRemoteSyncerTest, Conflict_CreateFolderOnFile) { ScopedVector entries = GetResourceEntriesForParentAndTitle(app_root, "foo"); ASSERT_EQ(2u, entries.size()); - EXPECT_EQ(google_apis::ENTRY_KIND_FILE, entries[0]->kind()); - EXPECT_EQ(google_apis::ENTRY_KIND_FOLDER, entries[1]->kind()); + EXPECT_EQ(google_apis::ResourceEntry::ENTRY_KIND_FILE, entries[0]->kind()); + EXPECT_EQ(google_apis::ResourceEntry::ENTRY_KIND_FOLDER, entries[1]->kind()); } TEST_F(LocalToRemoteSyncerTest, Conflict_CreateFileOnFile) { @@ -410,8 +419,8 @@ TEST_F(LocalToRemoteSyncerTest, Conflict_CreateFileOnFile) { ScopedVector entries = GetResourceEntriesForParentAndTitle(app_root, "foo"); ASSERT_EQ(2u, entries.size()); - EXPECT_EQ(google_apis::ENTRY_KIND_FILE, entries[0]->kind()); - EXPECT_EQ(google_apis::ENTRY_KIND_FILE, entries[1]->kind()); + EXPECT_EQ(google_apis::ResourceEntry::ENTRY_KIND_FILE, entries[0]->kind()); + EXPECT_EQ(google_apis::ResourceEntry::ENTRY_KIND_FILE, entries[1]->kind()); } TEST_F(LocalToRemoteSyncerTest, Conflict_UpdateDeleteOnFile) { @@ -448,7 +457,7 @@ TEST_F(LocalToRemoteSyncerTest, Conflict_UpdateDeleteOnFile) { ScopedVector entries = GetResourceEntriesForParentAndTitle(app_root, "foo"); ASSERT_EQ(1u, entries.size()); - EXPECT_EQ(google_apis::ENTRY_KIND_FILE, entries[0]->kind()); + EXPECT_EQ(google_apis::ResourceEntry::ENTRY_KIND_FILE, entries[0]->kind()); EXPECT_TRUE(!entries[0]->deleted()); EXPECT_NE(file_id, entries[0]->resource_id()); } @@ -484,7 +493,7 @@ TEST_F(LocalToRemoteSyncerTest, Conflict_CreateDeleteOnFile) { ScopedVector entries = GetResourceEntriesForParentAndTitle(app_root, "foo"); ASSERT_EQ(1u, entries.size()); - EXPECT_EQ(google_apis::ENTRY_KIND_FILE, entries[0]->kind()); + EXPECT_EQ(google_apis::ResourceEntry::ENTRY_KIND_FILE, entries[0]->kind()); EXPECT_TRUE(!entries[0]->deleted()); EXPECT_NE(file_id, entries[0]->resource_id()); } @@ -506,8 +515,8 @@ TEST_F(LocalToRemoteSyncerTest, Conflict_CreateFolderOnFolder) { ScopedVector entries = GetResourceEntriesForParentAndTitle(app_root, "foo"); ASSERT_EQ(2u, entries.size()); - EXPECT_EQ(google_apis::ENTRY_KIND_FOLDER, entries[0]->kind()); - EXPECT_EQ(google_apis::ENTRY_KIND_FOLDER, entries[1]->kind()); + EXPECT_EQ(google_apis::ResourceEntry::ENTRY_KIND_FOLDER, entries[0]->kind()); + EXPECT_EQ(google_apis::ResourceEntry::ENTRY_KIND_FOLDER, entries[1]->kind()); EXPECT_TRUE(!entries[0]->deleted()); EXPECT_TRUE(!entries[1]->deleted()); EXPECT_TRUE(folder_id == entries[0]->resource_id() || diff --git a/chrome/browser/sync_file_system/drive_backend/metadata_database.cc b/chrome/browser/sync_file_system/drive_backend/metadata_database.cc index b31f2ab..0cf49ed 100644 --- a/chrome/browser/sync_file_system/drive_backend/metadata_database.cc +++ b/chrome/browser/sync_file_system/drive_backend/metadata_database.cc @@ -31,7 +31,6 @@ #include "chrome/browser/sync_file_system/logger.h" #include "chrome/browser/sync_file_system/syncable_file_system_util.h" #include "google_apis/drive/drive_api_parser.h" -#include "google_apis/drive/drive_entry_kinds.h" #include "third_party/leveldatabase/src/include/leveldb/db.h" #include "third_party/leveldatabase/src/include/leveldb/env.h" #include "third_party/leveldatabase/src/include/leveldb/status.h" @@ -93,13 +92,12 @@ void PopulateFileDetailsByFileResource( } details->set_title(file_resource.title()); - google_apis::DriveEntryKind kind = drive::util::GetKind(file_resource); - if (kind == google_apis::ENTRY_KIND_FILE) - details->set_file_kind(FILE_KIND_FILE); - else if (kind == google_apis::ENTRY_KIND_FOLDER) + if (file_resource.IsDirectory()) details->set_file_kind(FILE_KIND_FOLDER); - else + else if (drive::util::IsHostedDocument(file_resource.mime_type())) details->set_file_kind(FILE_KIND_UNSUPPORTED); + else + details->set_file_kind(FILE_KIND_FILE); details->set_md5(file_resource.md5_checksum()); details->set_etag(file_resource.etag()); diff --git a/chrome/browser/sync_file_system/drive_backend_v1/api_util.cc b/chrome/browser/sync_file_system/drive_backend_v1/api_util.cc index 1d118c8..e865cc3 100644 --- a/chrome/browser/sync_file_system/drive_backend_v1/api_util.cc +++ b/chrome/browser/sync_file_system/drive_backend_v1/api_util.cc @@ -349,7 +349,7 @@ void APIUtil::DidGetDirectory(const std::string& parent_resource_id, DVLOG(2) << "Found Drive directory."; // TODO(tzik): Handle error. - DCHECK_EQ(google_apis::ENTRY_KIND_FOLDER, entry->kind()); + DCHECK_EQ(google_apis::ResourceEntry::ENTRY_KIND_FOLDER, entry->kind()); DCHECK_EQ(directory_name, entry->title()); if (entry->title() == GetSyncRootDirectoryName()) diff --git a/chrome/browser/sync_file_system/drive_backend_v1/api_util_unittest.cc b/chrome/browser/sync_file_system/drive_backend_v1/api_util_unittest.cc index b58bc54..e38b892a 100644 --- a/chrome/browser/sync_file_system/drive_backend_v1/api_util_unittest.cc +++ b/chrome/browser/sync_file_system/drive_backend_v1/api_util_unittest.cc @@ -115,10 +115,11 @@ class APIUtilTest : public testing::Test { entry)); } - void VerifyTitleUniqueness(const std::string& parent_resource_id, - const std::string& title, - const std::string& resource_id, - google_apis::DriveEntryKind kind) { + void VerifyTitleUniqueness( + const std::string& parent_resource_id, + const std::string& title, + const std::string& resource_id, + google_apis::ResourceEntry::ResourceEntryKind kind) { ScopedVector entries; EXPECT_EQ(google_apis::HTTP_SUCCESS, fake_drive_helper_->SearchByTitle( @@ -256,7 +257,7 @@ void APIUtilTest::TestCreateSyncRoot() { VerifyTitleUniqueness(std::string(), // directory_resource_id APIUtil::GetSyncRootDirectoryName(), output.resource_id, - google_apis::ENTRY_KIND_FOLDER); + google_apis::ResourceEntry::ENTRY_KIND_FOLDER); } void APIUtilTest::TestCreateSyncRoot_Conflict() { @@ -274,7 +275,7 @@ void APIUtilTest::TestCreateSyncRoot_Conflict() { VerifyTitleUniqueness(std::string(), // directory_resource_id APIUtil::GetSyncRootDirectoryName(), output.resource_id, - google_apis::ENTRY_KIND_FOLDER); + google_apis::ResourceEntry::ENTRY_KIND_FOLDER); } void APIUtilTest::TestGetOriginDirectory() { @@ -308,7 +309,7 @@ void APIUtilTest::TestCreateOriginDirectory() { VerifyTitleUniqueness(sync_root_id, kOriginDirectoryName, output.resource_id, - google_apis::ENTRY_KIND_FOLDER); + google_apis::ResourceEntry::ENTRY_KIND_FOLDER); } void APIUtilTest::TestCreateOriginDirectory_Conflict() { @@ -329,7 +330,7 @@ void APIUtilTest::TestCreateOriginDirectory_Conflict() { VerifyTitleUniqueness(sync_root_id, kOriginDirectoryName, output.resource_id, - google_apis::ENTRY_KIND_FOLDER); + google_apis::ResourceEntry::ENTRY_KIND_FOLDER); } void APIUtilTest::TestGetLargestChangeStamp() { @@ -482,7 +483,7 @@ void APIUtilTest::TestUploadNewFile() { VerifyTitleUniqueness(origin_root_id, kFileTitle, output.resource_id, - google_apis::ENTRY_KIND_FILE); + google_apis::ResourceEntry::ENTRY_KIND_FILE); } void APIUtilTest::TestUploadNewFile_ConflictWithFile() { @@ -509,7 +510,7 @@ void APIUtilTest::TestUploadNewFile_ConflictWithFile() { VerifyTitleUniqueness(origin_root_id, kFileTitle, output.resource_id, - google_apis::ENTRY_KIND_FILE); + google_apis::ResourceEntry::ENTRY_KIND_FILE); } void APIUtilTest::TestUploadExistingFile() { @@ -536,7 +537,7 @@ void APIUtilTest::TestUploadExistingFile() { VerifyTitleUniqueness(origin_root_id, file->title(), file->file_id(), - google_apis::ENTRY_KIND_FILE); + google_apis::ResourceEntry::ENTRY_KIND_FILE); } void APIUtilTest::TestUploadExistingFileInConflict() { @@ -568,7 +569,7 @@ void APIUtilTest::TestUploadExistingFileInConflict() { VerifyTitleUniqueness(origin_root_id, file->title(), file->file_id(), - google_apis::ENTRY_KIND_FILE); + google_apis::ResourceEntry::ENTRY_KIND_FILE); } void APIUtilTest::TestDeleteFile() { @@ -616,7 +617,7 @@ void APIUtilTest::TestDeleteFileInConflict() { VerifyTitleUniqueness(origin_root_id, file->title(), file->file_id(), - google_apis::ENTRY_KIND_FILE); + google_apis::ResourceEntry::ENTRY_KIND_FILE); } void APIUtilTest::TestCreateDirectory() { @@ -637,7 +638,7 @@ void APIUtilTest::TestCreateDirectory() { VerifyTitleUniqueness(origin_root_id, kDirectoryTitle, output.resource_id, - google_apis::ENTRY_KIND_FOLDER); + google_apis::ResourceEntry::ENTRY_KIND_FOLDER); } TEST_F(APIUtilTest, GetSyncRoot) { diff --git a/chrome/browser/sync_file_system/drive_backend_v1/fake_api_util.cc b/chrome/browser/sync_file_system/drive_backend_v1/fake_api_util.cc index ef8a013..e3ee374 100644 --- a/chrome/browser/sync_file_system/drive_backend_v1/fake_api_util.cc +++ b/chrome/browser/sync_file_system/drive_backend_v1/fake_api_util.cc @@ -10,7 +10,6 @@ #include "base/location.h" #include "base/single_thread_task_runner.h" #include "base/thread_task_runner_handle.h" -#include "google_apis/drive/drive_entry_kinds.h" #include "webkit/common/blob/scoped_file.h" namespace sync_file_system { @@ -253,13 +252,13 @@ scoped_ptr FakeAPIUtil::CreateResourceEntry( switch (resource.type) { case SYNC_FILE_TYPE_FILE: - entry->set_kind(google_apis::ENTRY_KIND_FILE); + entry->set_kind(google_apis::ResourceEntry::ENTRY_KIND_FILE); break; case SYNC_FILE_TYPE_DIRECTORY: - entry->set_kind(google_apis::ENTRY_KIND_FOLDER); + entry->set_kind(google_apis::ResourceEntry::ENTRY_KIND_FOLDER); break; case SYNC_FILE_TYPE_UNKNOWN: - entry->set_kind(google_apis::ENTRY_KIND_UNKNOWN); + entry->set_kind(google_apis::ResourceEntry::ENTRY_KIND_UNKNOWN); break; } diff --git a/chrome/browser/ui/webui/chromeos/drive_internals_ui.cc b/chrome/browser/ui/webui/chromeos/drive_internals_ui.cc index 1370fc8..fa25053 100644 --- a/chrome/browser/ui/webui/chromeos/drive_internals_ui.cc +++ b/chrome/browser/ui/webui/chromeos/drive_internals_ui.cc @@ -35,7 +35,6 @@ #include "google_apis/drive/auth_service.h" #include "google_apis/drive/drive_api_parser.h" #include "google_apis/drive/gdata_errorcode.h" -#include "google_apis/drive/gdata_wapi_parser.h" #include "google_apis/drive/time_util.h" #include "grit/browser_resources.h" diff --git a/google_apis/BUILD.gn b/google_apis/BUILD.gn index f5d5a2e..33ecc00 100644 --- a/google_apis/BUILD.gn +++ b/google_apis/BUILD.gn @@ -154,7 +154,6 @@ source_set("google_apis") { "drive/drive_api_url_generator.cc", "drive/drive_api_url_generator.h", "drive/drive_common_callbacks.h", - "drive/drive_entry_kinds.h", "drive/gdata_errorcode.cc", "drive/gdata_errorcode.h", "drive/gdata_wapi_requests.cc", diff --git a/google_apis/drive/drive_entry_kinds.h b/google_apis/drive/drive_entry_kinds.h deleted file mode 100644 index 27e0f69..0000000 --- a/google_apis/drive/drive_entry_kinds.h +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef GOOGLE_APIS_DRIVE_DRIVE_ENTRY_KINDS_H_ -#define GOOGLE_APIS_DRIVE_DRIVE_ENTRY_KINDS_H_ - -namespace google_apis { - -// DriveEntryKind specifies the kind of a Drive entry. -// -// kEntryKindMap in gdata_wapi_parser.cc should also be updated if you modify -// DriveEntryKind. The compiler will catch if they are not in sync. -enum DriveEntryKind { - ENTRY_KIND_UNKNOWN, - // Special entries. - ENTRY_KIND_ITEM, - ENTRY_KIND_SITE, - // Hosted Google document. - ENTRY_KIND_DOCUMENT, - ENTRY_KIND_SPREADSHEET, - ENTRY_KIND_PRESENTATION, - ENTRY_KIND_DRAWING, - ENTRY_KIND_TABLE, - ENTRY_KIND_FORM, - // Hosted external application document. - ENTRY_KIND_EXTERNAL_APP, - // Folders; collections. - ENTRY_KIND_FOLDER, - // Regular files. - ENTRY_KIND_FILE, - ENTRY_KIND_PDF, - - // This should be the last item. - ENTRY_KIND_MAX_VALUE, -}; - -} // namespace google_apis - -#endif // GOOGLE_APIS_DRIVE_DRIVE_ENTRY_KINDS_H_ diff --git a/google_apis/drive/gdata_wapi_parser.cc b/google_apis/drive/gdata_wapi_parser.cc index 9c50e5a..83beacc 100644 --- a/google_apis/drive/gdata_wapi_parser.cc +++ b/google_apis/drive/gdata_wapi_parser.cc @@ -72,30 +72,6 @@ const char kUpdatedField[] = "updated.$t"; const char kOpenWithPrefix[] = "http://schemas.google.com/docs/2007#open-with-"; const size_t kOpenWithPrefixSize = arraysize(kOpenWithPrefix) - 1; -struct EntryKindMap { - DriveEntryKind kind; - const char* entry; - const char* extension; -}; - -const EntryKindMap kEntryKindMap[] = { - { ENTRY_KIND_UNKNOWN, "unknown", NULL}, - { ENTRY_KIND_ITEM, "item", NULL}, - { ENTRY_KIND_DOCUMENT, "document", ".gdoc"}, - { ENTRY_KIND_SPREADSHEET, "spreadsheet", ".gsheet"}, - { ENTRY_KIND_PRESENTATION, "presentation", ".gslides" }, - { ENTRY_KIND_DRAWING, "drawing", ".gdraw"}, - { ENTRY_KIND_TABLE, "table", ".gtable"}, - { ENTRY_KIND_FORM, "form", ".gform"}, - { ENTRY_KIND_EXTERNAL_APP, "externalapp", ".glink"}, - { ENTRY_KIND_SITE, "site", NULL}, - { ENTRY_KIND_FOLDER, "folder", NULL}, - { ENTRY_KIND_FILE, "file", NULL}, - { ENTRY_KIND_PDF, "pdf", NULL}, -}; -COMPILE_ASSERT(arraysize(kEntryKindMap) == ENTRY_KIND_MAX_VALUE, - EntryKindMap_and_DriveEntryKind_are_not_in_sync); - struct LinkTypeMap { Link::LinkType type; const char* rel; @@ -439,42 +415,7 @@ void ResourceEntry::RegisterJSONConverter( } // static -std::string ResourceEntry::GetHostedDocumentExtension(DriveEntryKind kind) { - for (size_t i = 0; i < arraysize(kEntryKindMap); i++) { - if (kEntryKindMap[i].kind == kind) { - if (kEntryKindMap[i].extension) - return std::string(kEntryKindMap[i].extension); - else - return std::string(); - } - } - return std::string(); -} - -// static -DriveEntryKind ResourceEntry::GetEntryKindFromExtension( - const std::string& extension) { - for (size_t i = 0; i < arraysize(kEntryKindMap); ++i) { - const char* document_extension = kEntryKindMap[i].extension; - if (document_extension && extension == document_extension) - return kEntryKindMap[i].kind; - } - return ENTRY_KIND_UNKNOWN; -} - -// static -int ResourceEntry::ClassifyEntryKindByFileExtension( - const base::FilePath& file_path) { -#if defined(OS_WIN) - std::string file_extension = base::WideToUTF8(file_path.Extension()); -#else - std::string file_extension = file_path.Extension(); -#endif - return ClassifyEntryKind(GetEntryKindFromExtension(file_extension)); -} - -// static -DriveEntryKind ResourceEntry::GetEntryKindFromTerm( +ResourceEntry::ResourceEntryKind ResourceEntry::GetEntryKindFromTerm( const std::string& term) { if (!StartsWithASCII(term, kTermPrefix, false)) { DVLOG(1) << "Unexpected term prefix term " << term; @@ -482,60 +423,15 @@ DriveEntryKind ResourceEntry::GetEntryKindFromTerm( } std::string type = term.substr(strlen(kTermPrefix)); - for (size_t i = 0; i < arraysize(kEntryKindMap); i++) { - if (type == kEntryKindMap[i].entry) - return kEntryKindMap[i].kind; - } + if (type == "folder") + return ENTRY_KIND_FOLDER; + if (type == "file" || type == "pdf") + return ENTRY_KIND_FILE; + DVLOG(1) << "Unknown entry type for term " << term << ", type " << type; return ENTRY_KIND_UNKNOWN; } -// static -int ResourceEntry::ClassifyEntryKind(DriveEntryKind kind) { - int classes = 0; - - // All DriveEntryKind members are listed here, so the compiler catches if a - // newly added member is missing here. - switch (kind) { - case ENTRY_KIND_UNKNOWN: - // Special entries. - case ENTRY_KIND_ITEM: - case ENTRY_KIND_SITE: - break; - - // Hosted Google document. - case ENTRY_KIND_DOCUMENT: - case ENTRY_KIND_SPREADSHEET: - case ENTRY_KIND_PRESENTATION: - case ENTRY_KIND_DRAWING: - case ENTRY_KIND_TABLE: - case ENTRY_KIND_FORM: - classes = KIND_OF_GOOGLE_DOCUMENT | KIND_OF_HOSTED_DOCUMENT; - break; - - // Hosted external application document. - case ENTRY_KIND_EXTERNAL_APP: - classes = KIND_OF_EXTERNAL_DOCUMENT | KIND_OF_HOSTED_DOCUMENT; - break; - - // Folders, collections. - case ENTRY_KIND_FOLDER: - classes = KIND_OF_FOLDER; - break; - - // Regular files. - case ENTRY_KIND_FILE: - case ENTRY_KIND_PDF: - classes = KIND_OF_FILE; - break; - - case ENTRY_KIND_MAX_VALUE: - NOTREACHED(); - } - - return classes; -} - void ResourceEntry::FillRemainingFields() { // Set |kind_| and |labels_| based on the |categories_| in the class. // JSONValueConverter does not have the ability to catch an element in a list diff --git a/google_apis/drive/gdata_wapi_parser.h b/google_apis/drive/gdata_wapi_parser.h index 1081dbc..f7bce81 100644 --- a/google_apis/drive/gdata_wapi_parser.h +++ b/google_apis/drive/gdata_wapi_parser.h @@ -14,7 +14,6 @@ #include "base/memory/scoped_vector.h" #include "base/strings/string_piece.h" #include "base/time/time.h" -#include "google_apis/drive/drive_entry_kinds.h" #include "url/gurl.h" namespace base { @@ -312,6 +311,11 @@ class CommonMetadata { // refers to a file and a directory. class ResourceEntry : public CommonMetadata { public: + enum ResourceEntryKind { + ENTRY_KIND_UNKNOWN, + ENTRY_KIND_FOLDER, + ENTRY_KIND_FILE + }; ResourceEntry(); virtual ~ResourceEntry(); @@ -360,7 +364,7 @@ class ResourceEntry : public CommonMetadata { // The URL is currently not used. const std::string& id() const { return id_; } - DriveEntryKind kind() const { return kind_; } + ResourceEntryKind kind() const { return kind_; } const std::string& title() const { return title_; } base::Time published_time() const { return published_time_; } base::Time last_viewed_time() const { return last_viewed_time_; } @@ -418,65 +422,20 @@ class ResourceEntry : public CommonMetadata { // unknown entry kind. std::string GetEntryKindText() const; - // Returns preferred file extension for hosted documents. If entry is not - // a hosted document, this call returns an empty string. - static std::string GetHostedDocumentExtension(DriveEntryKind kind); - - // True if resource entry is remotely hosted. - bool is_hosted_document() const { - return (ClassifyEntryKind(kind_) & KIND_OF_HOSTED_DOCUMENT) > 0; - } - // True if resource entry hosted by Google Documents. - bool is_google_document() const { - return (ClassifyEntryKind(kind_) & KIND_OF_GOOGLE_DOCUMENT) > 0; - } - // True if resource entry is hosted by an external application. - bool is_external_document() const { - return (ClassifyEntryKind(kind_) & KIND_OF_EXTERNAL_DOCUMENT) > 0; - } // True if resource entry is a folder (collection). bool is_folder() const { - return (ClassifyEntryKind(kind_) & KIND_OF_FOLDER) > 0; + return kind_ == ENTRY_KIND_FOLDER; } // True if resource entry is regular file. bool is_file() const { - return (ClassifyEntryKind(kind_) & KIND_OF_FILE) > 0; - } - // True if resource entry can't be mapped to the file system. - bool is_special() const { - return !is_file() && !is_folder() && !is_hosted_document(); + return kind_ == ENTRY_KIND_FILE; } - // The following constructs are exposed for unit tests. - - // Classes of EntryKind. Used for ClassifyEntryKind(). - enum EntryKindClass { - KIND_OF_NONE = 0, - KIND_OF_HOSTED_DOCUMENT = 1, - KIND_OF_GOOGLE_DOCUMENT = 1 << 1, - KIND_OF_EXTERNAL_DOCUMENT = 1 << 2, - KIND_OF_FOLDER = 1 << 3, - KIND_OF_FILE = 1 << 4, - }; - - // Returns the kind enum corresponding to the extension in form ".xxx". - static DriveEntryKind GetEntryKindFromExtension(const std::string& extension); - - // Classifies the EntryKind. The returned value is a bitmask of - // EntryKindClass. For example, DOCUMENT is classified as - // KIND_OF_HOSTED_DOCUMENT and KIND_OF_GOOGLE_DOCUMENT, hence the returned - // value is KIND_OF_HOSTED_DOCUMENT | KIND_OF_GOOGLE_DOCUMENT. - static int ClassifyEntryKind(DriveEntryKind kind); - - // Classifies the EntryKind by the file extension of specific path. The - // returned value is a bitmask of EntryKindClass. See also ClassifyEntryKind. - static int ClassifyEntryKindByFileExtension(const base::FilePath& file); - void set_resource_id(const std::string& resource_id) { resource_id_ = resource_id; } void set_id(const std::string& id) { id_ = id; } - void set_kind(DriveEntryKind kind) { kind_ = kind; } + void set_kind(ResourceEntryKind kind) { kind_ = kind; } void set_title(const std::string& title) { title_ = title; } void set_published_time(const base::Time& published_time) { published_time_ = published_time; @@ -521,14 +480,12 @@ class ResourceEntry : public CommonMetadata { friend class ResourceList; friend class ResumeUploadRequest; - // Converts categories.term into DriveEntryKind enum. - static DriveEntryKind GetEntryKindFromTerm(const std::string& term); - // Converts |kind| into its text identifier equivalent. - static const char* GetEntryKindDescription(DriveEntryKind kind); + // Converts categories.term into ResourceEntryKind enum. + static ResourceEntryKind GetEntryKindFromTerm(const std::string& term); std::string resource_id_; std::string id_; - DriveEntryKind kind_; + ResourceEntryKind kind_; std::string title_; base::Time published_time_; // Last viewed value may be unreliable. See: crbug.com/152628. diff --git a/google_apis/drive/gdata_wapi_parser_unittest.cc b/google_apis/drive/gdata_wapi_parser_unittest.cc index 6655aed..8f14d92 100644 --- a/google_apis/drive/gdata_wapi_parser_unittest.cc +++ b/google_apis/drive/gdata_wapi_parser_unittest.cc @@ -60,7 +60,7 @@ TEST(GDataWAPIParserTest, ResourceListJsonParser) { // Check a folder entry. const ResourceEntry* folder_entry = feed->entries()[0]; ASSERT_TRUE(folder_entry); - EXPECT_EQ(ENTRY_KIND_FOLDER, folder_entry->kind()); + EXPECT_EQ(ResourceEntry::ENTRY_KIND_FOLDER, folder_entry->kind()); EXPECT_EQ("\"HhMOFgcNHSt7ImBr\"", folder_entry->etag()); EXPECT_EQ("folder:sub_sub_directory_folder_id", folder_entry->resource_id()); EXPECT_EQ("https://1_folder_id", folder_entry->id()); @@ -102,7 +102,7 @@ TEST(GDataWAPIParserTest, ResourceListJsonParser) { // Check a file entry. const ResourceEntry* file_entry = feed->entries()[1]; ASSERT_TRUE(file_entry); - EXPECT_EQ(ENTRY_KIND_FILE, file_entry->kind()); + EXPECT_EQ(ResourceEntry::ENTRY_KIND_FILE, file_entry->kind()); EXPECT_EQ("filename.m4a", file_entry->filename()); EXPECT_EQ("sugg_file_name.m4a", file_entry->suggested_filename()); EXPECT_EQ("3b4382ebefec6e743578c76bbd0575ce", file_entry->file_md5()); @@ -131,18 +131,16 @@ TEST(GDataWAPIParserTest, ResourceListJsonParser) { // Check a file entry. const ResourceEntry* resource_entry = feed->entries()[2]; ASSERT_TRUE(resource_entry); - EXPECT_EQ(ENTRY_KIND_DOCUMENT, resource_entry->kind()); - EXPECT_TRUE(resource_entry->is_hosted_document()); - EXPECT_TRUE(resource_entry->is_google_document()); - EXPECT_FALSE(resource_entry->is_external_document()); + // Hosted documents are treated as unknown kind so that sync file system + // doesn't assume them as neither folders nor normal files. + EXPECT_EQ(ResourceEntry::ENTRY_KIND_UNKNOWN, resource_entry->kind()); // Check an external document entry. const ResourceEntry* app_entry = feed->entries()[3]; ASSERT_TRUE(app_entry); - EXPECT_EQ(ENTRY_KIND_EXTERNAL_APP, app_entry->kind()); - EXPECT_TRUE(app_entry->is_hosted_document()); - EXPECT_TRUE(app_entry->is_external_document()); - EXPECT_FALSE(app_entry->is_google_document()); + // Hosted documents are treated as unknown kind so that sync file system + // doesn't assume them as neither folders nor normal files. + EXPECT_EQ(ResourceEntry::ENTRY_KIND_UNKNOWN, app_entry->kind()); } @@ -156,7 +154,7 @@ TEST(GDataWAPIParserTest, ResourceEntryJsonParser) { scoped_ptr entry(ResourceEntry::ExtractAndParse(*document)); ASSERT_TRUE(entry.get()); - EXPECT_EQ(ENTRY_KIND_FILE, entry->kind()); + EXPECT_EQ(ResourceEntry::ENTRY_KIND_FILE, entry->kind()); EXPECT_EQ("\"HhMOFgxXHit7ImBr\"", entry->etag()); EXPECT_EQ("file:2_file_resource_id", entry->resource_id()); EXPECT_EQ("2_file_id", entry->id()); @@ -222,7 +220,7 @@ TEST(GDataWAPIParserTest, ResourceEntryJsonParser) { EXPECT_EQ("", entry1_unknown_link->app_id()); // Check a file properties. - EXPECT_EQ(ENTRY_KIND_FILE, entry->kind()); + EXPECT_EQ(ResourceEntry::ENTRY_KIND_FILE, entry->kind()); EXPECT_EQ("File 1.mp3", entry->filename()); EXPECT_EQ("File 1.mp3", entry->suggested_filename()); EXPECT_EQ("3b4382ebefec6e743578c76bbd0575ce", entry->file_md5()); @@ -235,86 +233,4 @@ TEST(GDataWAPIParserTest, ResourceEntryJsonParser) { EXPECT_EQ(-1, entry->image_rotation()); } -TEST(GDataWAPIParserTest, ClassifyEntryKindByFileExtension) { - EXPECT_EQ( - ResourceEntry::KIND_OF_GOOGLE_DOCUMENT | - ResourceEntry::KIND_OF_HOSTED_DOCUMENT, - ResourceEntry::ClassifyEntryKindByFileExtension( - base::FilePath(FILE_PATH_LITERAL("Test.gdoc")))); - EXPECT_EQ( - ResourceEntry::KIND_OF_GOOGLE_DOCUMENT | - ResourceEntry::KIND_OF_HOSTED_DOCUMENT, - ResourceEntry::ClassifyEntryKindByFileExtension( - base::FilePath(FILE_PATH_LITERAL("Test.gsheet")))); - EXPECT_EQ( - ResourceEntry::KIND_OF_GOOGLE_DOCUMENT | - ResourceEntry::KIND_OF_HOSTED_DOCUMENT, - ResourceEntry::ClassifyEntryKindByFileExtension( - base::FilePath(FILE_PATH_LITERAL("Test.gslides")))); - EXPECT_EQ( - ResourceEntry::KIND_OF_GOOGLE_DOCUMENT | - ResourceEntry::KIND_OF_HOSTED_DOCUMENT, - ResourceEntry::ClassifyEntryKindByFileExtension( - base::FilePath(FILE_PATH_LITERAL("Test.gdraw")))); - EXPECT_EQ( - ResourceEntry::KIND_OF_GOOGLE_DOCUMENT | - ResourceEntry::KIND_OF_HOSTED_DOCUMENT, - ResourceEntry::ClassifyEntryKindByFileExtension( - base::FilePath(FILE_PATH_LITERAL("Test.gtable")))); - EXPECT_EQ( - ResourceEntry::KIND_OF_EXTERNAL_DOCUMENT | - ResourceEntry::KIND_OF_HOSTED_DOCUMENT, - ResourceEntry::ClassifyEntryKindByFileExtension( - base::FilePath(FILE_PATH_LITERAL("Test.glink")))); - EXPECT_EQ( - ResourceEntry::KIND_OF_NONE, - ResourceEntry::ClassifyEntryKindByFileExtension( - base::FilePath(FILE_PATH_LITERAL("Test.tar.gz")))); - EXPECT_EQ( - ResourceEntry::KIND_OF_NONE, - ResourceEntry::ClassifyEntryKindByFileExtension( - base::FilePath(FILE_PATH_LITERAL("Test.txt")))); - EXPECT_EQ( - ResourceEntry::KIND_OF_NONE, - ResourceEntry::ClassifyEntryKindByFileExtension( - base::FilePath(FILE_PATH_LITERAL("Test")))); - EXPECT_EQ( - ResourceEntry::KIND_OF_NONE, - ResourceEntry::ClassifyEntryKindByFileExtension( - base::FilePath())); -} - -TEST(GDataWAPIParserTest, ResourceEntryClassifyEntryKind) { - EXPECT_EQ(ResourceEntry::KIND_OF_NONE, - ResourceEntry::ClassifyEntryKind(ENTRY_KIND_UNKNOWN)); - EXPECT_EQ(ResourceEntry::KIND_OF_NONE, - ResourceEntry::ClassifyEntryKind(ENTRY_KIND_ITEM)); - EXPECT_EQ(ResourceEntry::KIND_OF_NONE, - ResourceEntry::ClassifyEntryKind(ENTRY_KIND_SITE)); - EXPECT_EQ(ResourceEntry::KIND_OF_GOOGLE_DOCUMENT | - ResourceEntry::KIND_OF_HOSTED_DOCUMENT, - ResourceEntry::ClassifyEntryKind(ENTRY_KIND_DOCUMENT)); - EXPECT_EQ(ResourceEntry::KIND_OF_GOOGLE_DOCUMENT | - ResourceEntry::KIND_OF_HOSTED_DOCUMENT, - ResourceEntry::ClassifyEntryKind(ENTRY_KIND_SPREADSHEET)); - EXPECT_EQ(ResourceEntry::KIND_OF_GOOGLE_DOCUMENT | - ResourceEntry::KIND_OF_HOSTED_DOCUMENT, - ResourceEntry::ClassifyEntryKind(ENTRY_KIND_PRESENTATION)); - EXPECT_EQ(ResourceEntry::KIND_OF_GOOGLE_DOCUMENT | - ResourceEntry::KIND_OF_HOSTED_DOCUMENT, - ResourceEntry::ClassifyEntryKind(ENTRY_KIND_DRAWING)); - EXPECT_EQ(ResourceEntry::KIND_OF_GOOGLE_DOCUMENT | - ResourceEntry::KIND_OF_HOSTED_DOCUMENT, - ResourceEntry::ClassifyEntryKind(ENTRY_KIND_TABLE)); - EXPECT_EQ(ResourceEntry::KIND_OF_EXTERNAL_DOCUMENT | - ResourceEntry::KIND_OF_HOSTED_DOCUMENT, - ResourceEntry::ClassifyEntryKind(ENTRY_KIND_EXTERNAL_APP)); - EXPECT_EQ(ResourceEntry::KIND_OF_FOLDER, - ResourceEntry::ClassifyEntryKind(ENTRY_KIND_FOLDER)); - EXPECT_EQ(ResourceEntry::KIND_OF_FILE, - ResourceEntry::ClassifyEntryKind(ENTRY_KIND_FILE)); - EXPECT_EQ(ResourceEntry::KIND_OF_FILE, - ResourceEntry::ClassifyEntryKind(ENTRY_KIND_PDF)); -} - } // namespace google_apis diff --git a/google_apis/google_apis.gyp b/google_apis/google_apis.gyp index 1d2642f..fd3a525 100644 --- a/google_apis/google_apis.gyp +++ b/google_apis/google_apis.gyp @@ -65,7 +65,6 @@ 'drive/drive_api_url_generator.cc', 'drive/drive_api_url_generator.h', 'drive/drive_common_callbacks.h', - 'drive/drive_entry_kinds.h', 'drive/gdata_errorcode.cc', 'drive/gdata_errorcode.h', 'drive/gdata_wapi_requests.cc', -- cgit v1.1