Differentiate remote quota error and local cache shortage error code in Drive.

Before r214970:
Cache shortage => FILE_ERROR_NO_SPACE => QUOTA_EXCEEDED_ERR (!!)
Quota error    => FILE_ERROR_FAILED   => FILE_ERROR_GENERIC

After r214970:
Cache shortage => FILE_ERROR_NO_SPACE => QUOTA_EXCEEDED_ERR (!!)
Quota error    => FILE_ERROR_NO_SPACE => QUOTA_EXCEEDED_ERR

Now:
Cache shortage => FILE_ERROR_NO_LOCAL_SPACE => FILE_ERROR_GENERIC
Quota error    => FILE_ERROR_NO_SPACE       => QUOTA_EXCEEDED_ERR

Generic error message is not so useful, but it is much better than the
false alert. At least, this should become the basis for setting up
proper error message.

BUG=259104

Review URL: https://chromiumcodereview.appspot.com/20750004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@215010 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/chromeos/drive/file_cache.cc b/chrome/browser/chromeos/drive/file_cache.cc
index ed94c02..7b190c0 100644
--- a/chrome/browser/chromeos/drive/file_cache.cc
+++ b/chrome/browser/chromeos/drive/file_cache.cc
@@ -518,7 +518,7 @@
     }
   }
   if (!FreeDiskSpaceIfNeededFor(file_size))
-    return FILE_ERROR_NO_SPACE;
+    return FILE_ERROR_NO_LOCAL_SPACE;
 
   FileCacheEntry cache_entry;
   storage_->GetCacheEntry(resource_id, &cache_entry);
diff --git a/chrome/browser/chromeos/drive/file_cache.h b/chrome/browser/chromeos/drive/file_cache.h
index 0c32481..41573ee9 100644
--- a/chrome/browser/chromeos/drive/file_cache.h
+++ b/chrome/browser/chromeos/drive/file_cache.h
@@ -16,12 +16,8 @@
 #include "chrome/browser/chromeos/drive/file_errors.h"
 #include "chrome/browser/chromeos/drive/resource_metadata_storage.h"
 
-class Profile;
-
 namespace base {
-
 class SequencedTaskRunner;
-
 }  // namespace base
 
 namespace drive {
@@ -293,8 +289,8 @@
   DISALLOW_COPY_AND_ASSIGN(FileCache);
 };
 
-// The minimum free space to keep. FileSystem::GetFileByPath() returns
-// GDATA_FILE_ERROR_NO_SPACE if the available space is smaller than
+// The minimum free space to keep. Operations that add cache files return
+// FILE_ERROR_NO_LOCAL_SPACE if the available space is smaller than
 // this value.
 //
 // Copied from cryptohome/homedirs.h.
diff --git a/chrome/browser/chromeos/drive/file_cache_unittest.cc b/chrome/browser/chromeos/drive/file_cache_unittest.cc
index f0ae710..34435064 100644
--- a/chrome/browser/chromeos/drive/file_cache_unittest.cc
+++ b/chrome/browser/chromeos/drive/file_cache_unittest.cc
@@ -775,7 +775,8 @@
   std::string md5("abcdef0123456789");
 
   // Try to store an existing file.
-  TestStoreToCache(resource_id, md5, dummy_file_path_, FILE_ERROR_NO_SPACE,
+  TestStoreToCache(resource_id, md5, dummy_file_path_,
+                   FILE_ERROR_NO_LOCAL_SPACE,
                    TEST_CACHE_STATE_NONE);
 
   // Verify that there's no files added.
diff --git a/chrome/browser/chromeos/drive/file_errors.cc b/chrome/browser/chromeos/drive/file_errors.cc
index 787612f7..05d76f9 100644
--- a/chrome/browser/chromeos/drive/file_errors.cc
+++ b/chrome/browser/chromeos/drive/file_errors.cc
@@ -34,8 +34,8 @@
     case FILE_ERROR_NO_MEMORY:
       return "FILE_ERROR_NO_MEMORY";
 
-    case FILE_ERROR_NO_SPACE:
-      return "FILE_ERROR_NO_SPACE";
+    case FILE_ERROR_NO_SERVER_SPACE:
+      return "FILE_ERROR_NO_SERVER_SPACE";
 
     case FILE_ERROR_NOT_A_DIRECTORY:
       return "FILE_ERROR_NOT_A_DIRECTORY";
@@ -60,6 +60,9 @@
 
     case FILE_ERROR_NO_CONNECTION:
       return "FILE_ERROR_NO_CONNECTION";
+
+    case FILE_ERROR_NO_LOCAL_SPACE:
+      return "FILE_ERROR_NO_LOCAL_SPACE";
   }
 
   NOTREACHED();
@@ -92,7 +95,7 @@
     case FILE_ERROR_NO_MEMORY:
       return base::PLATFORM_FILE_ERROR_NO_MEMORY;
 
-    case FILE_ERROR_NO_SPACE:
+    case FILE_ERROR_NO_SERVER_SPACE:
       return base::PLATFORM_FILE_ERROR_NO_SPACE;
 
     case FILE_ERROR_NOT_A_DIRECTORY:
@@ -118,6 +121,9 @@
 
     case FILE_ERROR_NO_CONNECTION:
       return base::PLATFORM_FILE_ERROR_FAILED;
+
+    case FILE_ERROR_NO_LOCAL_SPACE:
+      return base::PLATFORM_FILE_ERROR_FAILED;
   }
 
   NOTREACHED();
@@ -142,7 +148,7 @@
     case google_apis::GDATA_NO_CONNECTION:
       return FILE_ERROR_NO_CONNECTION;
     case google_apis::GDATA_NO_SPACE:
-      return FILE_ERROR_NO_SPACE;
+      return FILE_ERROR_NO_SERVER_SPACE;
     default:
       return FILE_ERROR_FAILED;
   }
diff --git a/chrome/browser/chromeos/drive/file_errors.h b/chrome/browser/chromeos/drive/file_errors.h
index d0a51db..08cf5a15 100644
--- a/chrome/browser/chromeos/drive/file_errors.h
+++ b/chrome/browser/chromeos/drive/file_errors.h
@@ -20,7 +20,7 @@
   FILE_ERROR_ACCESS_DENIED = -5,
   FILE_ERROR_TOO_MANY_OPENED = -6,
   FILE_ERROR_NO_MEMORY = -7,
-  FILE_ERROR_NO_SPACE = -8,
+  FILE_ERROR_NO_SERVER_SPACE = -8,
   FILE_ERROR_NOT_A_DIRECTORY = -9,
   FILE_ERROR_INVALID_OPERATION = -10,
   FILE_ERROR_SECURITY = -11,
@@ -29,6 +29,7 @@
   FILE_ERROR_NOT_EMPTY = -14,
   FILE_ERROR_INVALID_URL = -15,
   FILE_ERROR_NO_CONNECTION = -16,
+  FILE_ERROR_NO_LOCAL_SPACE = -17,
 };
 
 // Used as callbacks for file operations.
diff --git a/chrome/browser/chromeos/drive/file_system/download_operation.cc b/chrome/browser/chromeos/drive/file_system/download_operation.cc
index bac2ccb..eaa2cb59 100644
--- a/chrome/browser/chromeos/drive/file_system/download_operation.cc
+++ b/chrome/browser/chromeos/drive/file_system/download_operation.cc
@@ -164,7 +164,7 @@
 
   // Ensure enough space in the cache.
   if (!cache->FreeDiskSpaceIfNeededFor(expected_file_size))
-    return FILE_ERROR_NO_SPACE;
+    return FILE_ERROR_NO_LOCAL_SPACE;
 
   // Create the temporary file which will store the downloaded content.
   return CreateTemporaryReadableFileInDir(
diff --git a/chrome/browser/chromeos/drive/file_system/download_operation_unittest.cc b/chrome/browser/chromeos/drive/file_system/download_operation_unittest.cc
index 5fdddedd..2b55291 100644
--- a/chrome/browser/chromeos/drive/file_system/download_operation_unittest.cc
+++ b/chrome/browser/chromeos/drive/file_system/download_operation_unittest.cc
@@ -89,7 +89,7 @@
           &error, &file_path, &entry));
   test_util::RunBlockingPoolTask();
 
-  EXPECT_EQ(FILE_ERROR_NO_SPACE, error);
+  EXPECT_EQ(FILE_ERROR_NO_LOCAL_SPACE, error);
 }
 
 TEST_F(DownloadOperationTest,
@@ -183,7 +183,7 @@
           &error, &file_path, &entry));
   test_util::RunBlockingPoolTask();
 
-  EXPECT_EQ(FILE_ERROR_NO_SPACE, error);
+  EXPECT_EQ(FILE_ERROR_NO_LOCAL_SPACE, error);
 }
 
 TEST_F(DownloadOperationTest, EnsureFileDownloadedByPath_FromCache) {
diff --git a/chrome/browser/chromeos/drive/resource_metadata.cc b/chrome/browser/chromeos/drive/resource_metadata.cc
index b0ad6a1..38852a8 100644
--- a/chrome/browser/chromeos/drive/resource_metadata.cc
+++ b/chrome/browser/chromeos/drive/resource_metadata.cc
@@ -137,7 +137,7 @@
   DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread());
 
   if (!EnoughDiskSpaceIsAvailableForDBOperation(storage_->directory_path()))
-    return FILE_ERROR_NO_SPACE;
+    return FILE_ERROR_NO_LOCAL_SPACE;
 
   if (!SetUpDefaultEntries())
     return FILE_ERROR_FAILED;
@@ -170,7 +170,7 @@
   DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread());
 
   if (!EnoughDiskSpaceIsAvailableForDBOperation(storage_->directory_path()))
-    return FILE_ERROR_NO_SPACE;
+    return FILE_ERROR_NO_LOCAL_SPACE;
 
   if (!storage_->SetLargestChangestamp(0) ||
       !RemoveEntryRecursively(util::kDriveGrandRootSpecialResourceId) ||
@@ -245,7 +245,7 @@
   DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread());
 
   if (!EnoughDiskSpaceIsAvailableForDBOperation(storage_->directory_path()))
-    return FILE_ERROR_NO_SPACE;
+    return FILE_ERROR_NO_LOCAL_SPACE;
 
   storage_->SetLargestChangestamp(value);
   return FILE_ERROR_OK;
@@ -266,7 +266,7 @@
   DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread());
 
   if (!EnoughDiskSpaceIsAvailableForDBOperation(storage_->directory_path()))
-    return FILE_ERROR_NO_SPACE;
+    return FILE_ERROR_NO_LOCAL_SPACE;
 
   ResourceEntry existing_entry;
   if (storage_->GetEntry(entry.resource_id(), &existing_entry))
@@ -316,7 +316,7 @@
   DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread());
 
   if (!EnoughDiskSpaceIsAvailableForDBOperation(storage_->directory_path()))
-    return FILE_ERROR_NO_SPACE;
+    return FILE_ERROR_NO_LOCAL_SPACE;
 
   // Disallow deletion of special entries "/drive" and "/drive/other".
   if (util::IsSpecialResourceId(resource_id))
@@ -434,7 +434,7 @@
   DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread());
 
   if (!EnoughDiskSpaceIsAvailableForDBOperation(storage_->directory_path()))
-    return FILE_ERROR_NO_SPACE;
+    return FILE_ERROR_NO_LOCAL_SPACE;
 
   ResourceEntry old_entry;
   if (!storage_->GetEntry(entry.resource_id(), &old_entry))
@@ -525,7 +525,7 @@
   DCHECK(out_file_path);
 
   if (!EnoughDiskSpaceIsAvailableForDBOperation(storage_->directory_path()))
-    return FILE_ERROR_NO_SPACE;
+    return FILE_ERROR_NO_LOCAL_SPACE;
 
   ResourceEntry entry, destination;
   if (!FindEntryByPathSync(file_path, &entry) ||
@@ -554,7 +554,7 @@
   DVLOG(1) << "RenameEntry " << file_path.value() << " to " << new_title;
 
   if (!EnoughDiskSpaceIsAvailableForDBOperation(storage_->directory_path()))
-    return FILE_ERROR_NO_SPACE;
+    return FILE_ERROR_NO_LOCAL_SPACE;
 
   ResourceEntry entry;
   if (!FindEntryByPathSync(file_path, &entry))
@@ -627,7 +627,7 @@
   DCHECK(!directory_fetch_info.empty());
 
   if (!EnoughDiskSpaceIsAvailableForDBOperation(storage_->directory_path()))
-    return FILE_ERROR_NO_SPACE;
+    return FILE_ERROR_NO_LOCAL_SPACE;
 
   ResourceEntry directory;
   if (!storage_->GetEntry(directory_fetch_info.resource_id(), &directory))
@@ -645,7 +645,7 @@
   for (ResourceEntryMap::const_iterator it = entry_map.begin();
        it != entry_map.end(); ++it) {
     if (!EnoughDiskSpaceIsAvailableForDBOperation(storage_->directory_path()))
-      return FILE_ERROR_NO_SPACE;
+      return FILE_ERROR_NO_LOCAL_SPACE;
 
     const ResourceEntry& entry = it->second;
     // Skip if the parent resource ID does not match. This is needed to
@@ -670,7 +670,7 @@
   storage_->GetChildren(directory.resource_id(), &children);
   for (size_t i = 0; i < children.size(); ++i) {
     if (!EnoughDiskSpaceIsAvailableForDBOperation(storage_->directory_path()))
-      return FILE_ERROR_NO_SPACE;
+      return FILE_ERROR_NO_LOCAL_SPACE;
 
     if (entry_map.count(children[i]) == 0) {
       if (!RemoveEntryRecursively(children[i]))