Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / drive / fake_file_system.cc
index 1497ad8..c2cf36d 100644 (file)
@@ -7,8 +7,8 @@
 #include "base/bind.h"
 #include "base/bind_helpers.h"
 #include "base/callback.h"
-#include "base/file_util.h"
 #include "base/files/file_path.h"
+#include "base/files/file_util.h"
 #include "base/logging.h"
 #include "chrome/browser/chromeos/drive/drive.pb.h"
 #include "chrome/browser/chromeos/drive/file_errors.h"
@@ -17,8 +17,6 @@
 #include "chrome/browser/drive/drive_service_interface.h"
 #include "content/public/browser/browser_thread.h"
 #include "google_apis/drive/drive_api_parser.h"
-#include "google_apis/drive/gdata_wapi_parser.h"
-#include "testing/gtest/include/gtest/gtest.h"
 
 namespace drive {
 namespace test_util {
@@ -148,9 +146,6 @@ void FakeFileSystem::GetResourceEntry(
     const GetResourceEntryCallback& callback) {
   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
 
-  // Now, we only support files under my drive.
-  DCHECK(!util::IsUnderDriveMountPoint(file_path));
-
   if (file_path == util::GetDriveMyDriveRootPath()) {
     // Specialized for the root entry.
     drive_service_->GetAboutResource(
@@ -160,6 +155,8 @@ void FakeFileSystem::GetResourceEntry(
     return;
   }
 
+  // Now, we only support files under my drive.
+  DCHECK(util::GetDriveMyDriveRootPath().IsParent(file_path));
   GetResourceEntry(
       file_path.DirName(),
       base::Bind(
@@ -217,12 +214,6 @@ void FakeFileSystem::MarkCacheFileAsUnmounted(
   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
 }
 
-void FakeFileSystem::GetCacheEntry(
-    const base::FilePath& drive_file_path,
-    const GetCacheEntryCallback& callback) {
-  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
-}
-
 void FakeFileSystem::AddPermission(const base::FilePath& drive_file_path,
                                    const std::string& email,
                                    google_apis::drive::PermissionRole role,
@@ -260,23 +251,23 @@ void FakeFileSystem::GetFileContentAfterGetResourceEntry(
     return;
   }
 
-  // Fetch google_apis::ResourceEntry for its |download_url|.
-  drive_service_->GetResourceEntry(
+  // Fetch google_apis::FileResource for its |download_url|.
+  drive_service_->GetFileResource(
       entry->resource_id(),
       base::Bind(
-          &FakeFileSystem::GetFileContentAfterGetWapiResourceEntry,
+          &FakeFileSystem::GetFileContentAfterGetFileResource,
           weak_ptr_factory_.GetWeakPtr(),
           initialized_callback,
           get_content_callback,
           completion_callback));
 }
 
-void FakeFileSystem::GetFileContentAfterGetWapiResourceEntry(
+void FakeFileSystem::GetFileContentAfterGetFileResource(
     const GetFileContentInitializedCallback& initialized_callback,
     const google_apis::GetContentCallback& get_content_callback,
     const FileOperationCallback& completion_callback,
     google_apis::GDataErrorCode gdata_error,
-    scoped_ptr<google_apis::ResourceEntry> gdata_entry) {
+    scoped_ptr<google_apis::FileResource> gdata_entry) {
   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
 
   FileError error = GDataToFileError(gdata_error);
@@ -288,13 +279,18 @@ void FakeFileSystem::GetFileContentAfterGetWapiResourceEntry(
 
   scoped_ptr<ResourceEntry> entry(new ResourceEntry);
   std::string parent_resource_id;
-  bool converted =
-      ConvertToResourceEntry(*gdata_entry, entry.get(), &parent_resource_id);
+  bool converted = ConvertFileResourceToResourceEntry(
+      *gdata_entry, entry.get(), &parent_resource_id);
   DCHECK(converted);
   entry->set_parent_local_id(parent_resource_id);
 
   base::FilePath cache_path =
       cache_dir_.path().AppendASCII(entry->resource_id());
+  if (entry->file_specific_info().is_hosted_document()) {
+    // For hosted documents return a dummy cache without server request.
+    int result = base::WriteFile(cache_path, "", 0);
+    DCHECK_EQ(0, result);
+  }
   if (base::PathExists(cache_path)) {
     // Cache file is found.
     initialized_callback.Run(FILE_ERROR_OK, cache_path, entry.Pass());
@@ -305,7 +301,7 @@ void FakeFileSystem::GetFileContentAfterGetWapiResourceEntry(
   initialized_callback.Run(FILE_ERROR_OK, base::FilePath(), entry.Pass());
   drive_service_->DownloadFile(
       cache_path,
-      gdata_entry->resource_id(),
+      gdata_entry->file_id(),
       base::Bind(&FakeFileSystem::GetFileContentAfterDownloadFile,
                  weak_ptr_factory_.GetWeakPtr(),
                  completion_callback),
@@ -355,18 +351,18 @@ void FakeFileSystem::GetResourceEntryAfterGetParentEntryInfo(
   }
 
   DCHECK(parent_entry);
-  drive_service_->GetResourceListInDirectory(
+  drive_service_->GetFileListInDirectory(
       parent_entry->resource_id(),
       base::Bind(
-          &FakeFileSystem::GetResourceEntryAfterGetResourceList,
+          &FakeFileSystem::GetResourceEntryAfterGetFileList,
           weak_ptr_factory_.GetWeakPtr(), base_name, callback));
 }
 
-void FakeFileSystem::GetResourceEntryAfterGetResourceList(
+void FakeFileSystem::GetResourceEntryAfterGetFileList(
     const base::FilePath& base_name,
     const GetResourceEntryCallback& callback,
     google_apis::GDataErrorCode gdata_error,
-    scoped_ptr<google_apis::ResourceList> resource_list) {
+    scoped_ptr<google_apis::FileList> file_list) {
   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
 
   FileError error = GDataToFileError(gdata_error);
@@ -375,14 +371,13 @@ void FakeFileSystem::GetResourceEntryAfterGetResourceList(
     return;
   }
 
-  DCHECK(resource_list);
-  const ScopedVector<google_apis::ResourceEntry>& entries =
-      resource_list->entries();
+  DCHECK(file_list);
+  const ScopedVector<google_apis::FileResource>& entries = file_list->items();
   for (size_t i = 0; i < entries.size(); ++i) {
     scoped_ptr<ResourceEntry> entry(new ResourceEntry);
     std::string parent_resource_id;
-    bool converted =
-        ConvertToResourceEntry(*entries[i], entry.get(), &parent_resource_id);
+    bool converted = ConvertFileResourceToResourceEntry(
+        *entries[i], entry.get(), &parent_resource_id);
     DCHECK(converted);
     entry->set_parent_local_id(parent_resource_id);