drive: Stop using DictionaryValue to store data in FakeDriveService


Replace the giant DictionaryValue with std::map.
No behavior change is intended.

Remove unused FakeDriveService::FindEntryByContentUrl().
Fix util::ConvertResourceEntryToFileResource() to set EntryKind of hosted documents correctly.
Stop depending on the results' order in SearchOperationTest.

BUG=334544
TEST=unit_tests

Review URL: https://codereview.chromium.org/135643005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@245487 0039d316-1c4b-4281-b951-d872f2087c98
parent 858d789c
...@@ -39,6 +39,25 @@ const char kGoogleTableMimeType[] = "application/vnd.google-apps.table"; ...@@ -39,6 +39,25 @@ const char kGoogleTableMimeType[] = "application/vnd.google-apps.table";
const char kGoogleFormMimeType[] = "application/vnd.google-apps.form"; const char kGoogleFormMimeType[] = "application/vnd.google-apps.form";
const char kDriveFolderMimeType[] = "application/vnd.google-apps.folder"; const char kDriveFolderMimeType[] = "application/vnd.google-apps.folder";
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();
}
}
ScopedVector<std::string> CopyScopedVectorString( ScopedVector<std::string> CopyScopedVectorString(
const ScopedVector<std::string>& source) { const ScopedVector<std::string>& source) {
ScopedVector<std::string> result; ScopedVector<std::string> result;
...@@ -323,10 +342,14 @@ scoped_ptr<google_apis::FileResource> ConvertResourceEntryToFileResource( ...@@ -323,10 +342,14 @@ scoped_ptr<google_apis::FileResource> ConvertResourceEntryToFileResource(
"shared") != entry.labels().end()); "shared") != entry.labels().end());
file->set_download_url(entry.download_url()); file->set_download_url(entry.download_url());
if (entry.is_folder()) if (entry.is_folder()) {
file->set_mime_type(kDriveFolderMimeType); file->set_mime_type(kDriveFolderMimeType);
else } else {
file->set_mime_type(entry.content_mime_type()); 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_md5_checksum(entry.file_md5());
file->set_file_size(entry.file_size()); file->set_file_size(entry.file_size());
......
This diff is collapsed.
...@@ -10,6 +10,11 @@ ...@@ -10,6 +10,11 @@
#include "chrome/browser/drive/drive_service_interface.h" #include "chrome/browser/drive/drive_service_interface.h"
#include "google_apis/drive/auth_service_interface.h" #include "google_apis/drive/auth_service_interface.h"
namespace google_apis {
class ChangeResource;
class FileResource;
}
namespace drive { namespace drive {
// This class implements a fake DriveService which acts like a real Drive // This class implements a fake DriveService which acts like a real Drive
...@@ -249,36 +254,31 @@ class FakeDriveService : public DriveServiceInterface { ...@@ -249,36 +254,31 @@ class FakeDriveService : public DriveServiceInterface {
const google_apis::GetResourceEntryCallback& callback); const google_apis::GetResourceEntryCallback& callback);
private: private:
struct EntryInfo;
struct UploadSession; struct UploadSession;
// Returns a pointer to the entry that matches |resource_id|, or NULL if // Returns a pointer to the entry that matches |resource_id|, or NULL if
// not found. // not found.
base::DictionaryValue* FindEntryByResourceId(const std::string& resource_id); EntryInfo* FindEntryByResourceId(const std::string& resource_id);
// Returns a pointer to the entry that matches |content_url|, or NULL if
// not found.
base::DictionaryValue* FindEntryByContentUrl(const GURL& content_url);
// Returns a new resource ID, which looks like "resource_id_<num>" where // Returns a new resource ID, which looks like "resource_id_<num>" where
// <num> is a monotonically increasing number starting from 1. // <num> is a monotonically increasing number starting from 1.
std::string GetNewResourceId(); std::string GetNewResourceId();
// Increments |largest_changestamp_| and adds the new changestamp. // Increments |largest_changestamp_| and adds the new changestamp.
void AddNewChangestamp(base::DictionaryValue* entry); void AddNewChangestamp(google_apis::ChangeResource* change);
// Update ETag of |entry| based on |largest_changestamp_|. // Update ETag of |file| based on |largest_changestamp_|.
void UpdateETag(base::DictionaryValue* entry); void UpdateETag(google_apis::FileResource* file);
// Adds a new entry based on the given parameters. |entry_kind| should be // Adds a new entry based on the given parameters.
// "file" or "folder". Returns a pointer to the newly added entry, or NULL // Returns a pointer to the newly added entry, or NULL if failed.
// if failed. const EntryInfo* AddNewEntry(
const base::DictionaryValue* AddNewEntry(
const std::string& content_type, const std::string& content_type,
const std::string& content_data, const std::string& content_data,
const std::string& parent_resource_id, const std::string& parent_resource_id,
const std::string& title, const std::string& title,
bool shared_with_me, bool shared_with_me);
const std::string& entry_kind);
// Core implementation of GetResourceList. // Core implementation of GetResourceList.
// This method returns the slice of the all matched entries, and its range // This method returns the slice of the all matched entries, and its range
...@@ -297,7 +297,8 @@ class FakeDriveService : public DriveServiceInterface { ...@@ -297,7 +297,8 @@ class FakeDriveService : public DriveServiceInterface {
// Returns new upload session URL. // Returns new upload session URL.
GURL GetNewUploadSessionUrl(); GURL GetNewUploadSessionUrl();
scoped_ptr<base::DictionaryValue> resource_list_value_; typedef std::map<std::string, EntryInfo*> EntryInfoMap;
EntryInfoMap entries_;
scoped_ptr<base::DictionaryValue> account_metadata_value_; scoped_ptr<base::DictionaryValue> account_metadata_value_;
scoped_ptr<base::DictionaryValue> app_info_value_; scoped_ptr<base::DictionaryValue> app_info_value_;
std::map<GURL, UploadSession> upload_sessions_; std::map<GURL, UploadSession> upload_sessions_;
......
...@@ -557,6 +557,7 @@ class FileResource { ...@@ -557,6 +557,7 @@ class FileResource {
// Returns parent references (directories) of this file. // Returns parent references (directories) of this file.
const ScopedVector<ParentReference>& parents() const { return parents_; } const ScopedVector<ParentReference>& parents() const { return parents_; }
ScopedVector<ParentReference>* mutable_parents() { return &parents_; }
// Returns the link to the file's thumbnail. // Returns the link to the file's thumbnail.
const GURL& thumbnail_link() const { return thumbnail_link_; } const GURL& thumbnail_link() const { return thumbnail_link_; }
...@@ -761,6 +762,7 @@ class ChangeResource { ...@@ -761,6 +762,7 @@ class ChangeResource {
// Returns FileResource of the file which the change refers to. // Returns FileResource of the file which the change refers to.
const FileResource* file() const { return file_.get(); } const FileResource* file() const { return file_.get(); }
FileResource* mutable_file() { return file_.get(); }
void set_change_id(int64 change_id) { void set_change_id(int64 change_id) {
change_id_ = change_id; change_id_ = change_id;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment