filemanager: Retrieve 'shared-with-me' property using getDriveEntryProperties API.

This CL renames getDriveFileProperties to getDriveEntryProperties and
add "sharedWithMe" property in the result type.

BUG=232992
TEST=No UI change. unittests.
R=kalman@chromium.org, satorux@chromium.org

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@197576 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/chromeos/extensions/file_manager/file_browser_private_api.cc b/chrome/browser/chromeos/extensions/file_manager/file_browser_private_api.cc
index 9f2fcca..181db6e 100644
--- a/chrome/browser/chromeos/extensions/file_manager/file_browser_private_api.cc
+++ b/chrome/browser/chromeos/extensions/file_manager/file_browser_private_api.cc
@@ -363,9 +363,14 @@
 void DoNothingWithBool(bool /* success */) {
 }
 
-void FillDriveFilePropertiesValue(
+void FillDriveEntryPropertiesValue(
     const drive::DriveEntryProto& entry_proto,
     DictionaryValue* property_dict) {
+  property_dict->SetBoolean("sharedWithMe", entry_proto.shared_with_me());
+
+  if (!entry_proto.has_file_specific_info())
+    return;
+
   const drive::DriveFileSpecificInfo& file_specific_info =
       entry_proto.file_specific_info();
 
@@ -565,7 +570,7 @@
   registry->RegisterFunction<GetSizeStatsFunction>();
   registry->RegisterFunction<FormatDeviceFunction>();
   registry->RegisterFunction<ViewFilesFunction>();
-  registry->RegisterFunction<GetDriveFilePropertiesFunction>();
+  registry->RegisterFunction<GetDriveEntryPropertiesFunction>();
   registry->RegisterFunction<PinDriveFileFunction>();
   registry->RegisterFunction<GetFileLocationsFunction>();
   registry->RegisterFunction<GetDriveFilesFunction>();
@@ -2305,13 +2310,13 @@
   return true;
 }
 
-GetDriveFilePropertiesFunction::GetDriveFilePropertiesFunction() {
+GetDriveEntryPropertiesFunction::GetDriveEntryPropertiesFunction() {
 }
 
-GetDriveFilePropertiesFunction::~GetDriveFilePropertiesFunction() {
+GetDriveEntryPropertiesFunction::~GetDriveEntryPropertiesFunction() {
 }
 
-bool GetDriveFilePropertiesFunction::RunImpl() {
+bool GetDriveEntryPropertiesFunction::RunImpl() {
   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
 
   std::string file_url_str;
@@ -2335,28 +2340,22 @@
 
   system_service->file_system()->GetEntryInfoByPath(
       file_path_,
-      base::Bind(&GetDriveFilePropertiesFunction::OnGetFileInfo, this));
+      base::Bind(&GetDriveEntryPropertiesFunction::OnGetFileInfo, this));
   return true;
 }
 
-void GetDriveFilePropertiesFunction::OnGetFileInfo(
+void GetDriveEntryPropertiesFunction::OnGetFileInfo(
     drive::FileError error,
     scoped_ptr<drive::DriveEntryProto> entry) {
   DCHECK(properties_);
 
-  if (entry.get() && !entry->has_file_specific_info())
-    error = drive::FILE_ERROR_NOT_FOUND;
-
   if (error != drive::FILE_ERROR_OK) {
     CompleteGetFileProperties(error);
     return;
   }
   DCHECK(entry);
 
-  const drive::DriveFileSpecificInfo& file_specific_info =
-      entry->file_specific_info();
-
-  FillDriveFilePropertiesValue(*entry, properties_.get());
+  FillDriveEntryPropertiesValue(*entry, properties_.get());
 
   drive::DriveSystemService* system_service =
       drive::DriveSystemServiceFactory::GetForProfile(profile_);
@@ -2366,6 +2365,16 @@
     return;
   }
 
+  // The properties meaningful for directories are already filled in
+  // FillDriveEntryPropertiesValue().
+  if (entry.get() && !entry->has_file_specific_info()) {
+    CompleteGetFileProperties(error);
+    return;
+  }
+
+  const drive::DriveFileSpecificInfo& file_specific_info =
+      entry->file_specific_info();
+
   // Get drive WebApps that can accept this file.
   ScopedVector<drive::DriveWebAppInfo> web_apps;
   system_service->webapps_registry()->GetWebAppsForFile(
@@ -2405,10 +2414,10 @@
   system_service->file_system()->GetCacheEntryByResourceId(
       entry->resource_id(),
       file_specific_info.file_md5(),
-      base::Bind(&GetDriveFilePropertiesFunction::CacheStateReceived, this));
+      base::Bind(&GetDriveEntryPropertiesFunction::CacheStateReceived, this));
 }
 
-void GetDriveFilePropertiesFunction::CacheStateReceived(
+void GetDriveEntryPropertiesFunction::CacheStateReceived(
     bool /* success */,
     const drive::FileCacheEntry& cache_entry) {
   // In case of an error (i.e. success is false), cache_entry.is_*() all
@@ -2420,7 +2429,7 @@
   CompleteGetFileProperties(drive::FILE_ERROR_OK);
 }
 
-void GetDriveFilePropertiesFunction::CompleteGetFileProperties(
+void GetDriveEntryPropertiesFunction::CompleteGetFileProperties(
     drive::FileError error) {
   if (error != drive::FILE_ERROR_OK)
     properties_->SetInteger("errorCode", error);
diff --git a/chrome/browser/chromeos/extensions/file_manager/file_browser_private_api.h b/chrome/browser/chromeos/extensions/file_manager/file_browser_private_api.h
index df7e69b..1a31b537 100644
--- a/chrome/browser/chromeos/extensions/file_manager/file_browser_private_api.h
+++ b/chrome/browser/chromeos/extensions/file_manager/file_browser_private_api.h
@@ -497,18 +497,18 @@
   virtual bool RunImpl() OVERRIDE;
 };
 
-// Retrieves property information for a file and returns it as a dictionary.
+// Retrieves property information for an entry and returns it as a dictionary.
 // On error, returns a dictionary with the key "error" set to the error number
 // (drive::FileError).
-class GetDriveFilePropertiesFunction : public FileBrowserFunction {
+class GetDriveEntryPropertiesFunction : public FileBrowserFunction {
  public:
-  DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.getDriveFileProperties",
+  DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.getDriveEntryProperties",
                              FILEBROWSERPRIVATE_GETDRIVEFILEPROPERTIES)
 
-  GetDriveFilePropertiesFunction();
+  GetDriveEntryPropertiesFunction();
 
  protected:
-  virtual ~GetDriveFilePropertiesFunction();
+  virtual ~GetDriveEntryPropertiesFunction();
 
   // AsyncExtensionFunction overrides.
   virtual bool RunImpl() OVERRIDE;
diff --git a/chrome/browser/resources/file_manager/js/metadata/metadata_cache.js b/chrome/browser/resources/file_manager/js/metadata/metadata_cache.js
index 525e2d6..976fe99 100644
--- a/chrome/browser/resources/file_manager/js/metadata/metadata_cache.js
+++ b/chrome/browser/resources/file_manager/js/metadata/metadata_cache.js
@@ -799,9 +799,10 @@
   var self = this;
 
   var task = function(url, callback) {
-    chrome.fileBrowserPrivate.getDriveFileProperties(url, function(properties) {
-      callback(self.convert_(properties, url));
-    });
+    chrome.fileBrowserPrivate.getDriveEntryProperties(url,
+        function(properties) {
+          callback(self.convert_(properties, url));
+        });
   };
 
   for (var i = 0; i < urls.length; i++)
@@ -809,7 +810,7 @@
 };
 
 /**
- * @param {DriveFileProperties} data Drive file properties.
+ * @param {DriveEntryProperties} data Drive entry properties.
  * @param {string} url File url.
  * @return {boolean} True if the file is available offline.
  */
@@ -825,7 +826,7 @@
 };
 
 /**
- * @param {DriveFileProperties} data Drive file properties.
+ * @param {DriveEntryProperties} data Drive entry properties.
  * @return {boolean} True if opening the file does not require downloading it
  *    via a metered connection.
  */
@@ -852,7 +853,8 @@
     contentUrl: (data.contentUrl || '').replace(/\?.*$/gi, ''),
     editUrl: data.editUrl || '',
     driveApps: data.driveApps || [],
-    contentMimeType: data.contentMimeType || ''
+    contentMimeType: data.contentMimeType || '',
+    sharedWithMe: data.sharedWithMe
   };
 
   if (!data.isPresent) {
diff --git a/chrome/common/extensions/api/file_browser_private.json b/chrome/common/extensions/api/file_browser_private.json
index 2c90237..7603f826 100644
--- a/chrome/common/extensions/api/file_browser_private.json
+++ b/chrome/common/extensions/api/file_browser_private.json
@@ -85,7 +85,7 @@
         }
       },
       {
-        "id": "DriveFileProperties",
+        "id": "DriveEntryProperties",
         "type": "object",
         "description": "Drive file properties.",
         "properties": {
@@ -149,6 +149,11 @@
             "type": "string",
             "optional": true,
             "description": "Drive MIME type for this file."
+          },
+          "sharedWithMe": {
+            "type": "boolean",
+            "optional": true,
+            "description": "True if the entry is labeled as shared-with-me."
           }
         }
       },
@@ -659,7 +664,7 @@
         ]
       },
       {
-        "name": "getDriveFileProperties",
+        "name": "getDriveEntryProperties",
         "description": "Requests Drive file properties for a file",
         "parameters": [
           {
@@ -673,8 +678,8 @@
             "parameters": [
               {
                 "name" : "fileProperties",
-                "$ref": "DriveFileProperties",
-                "description": "A dictionary containing properties of the requested file."
+                "$ref": "DriveEntryProperties",
+                "description": "A dictionary containing properties of the requested entry."
               }
             ]
           }