Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Issue 23684012: Use GData WAPI for FastFetch even if Drive API v2 is enabled. (Closed)

Created:
7 years, 3 months ago by hidehiko
Modified:
7 years, 3 months ago
Reviewers:
kinaba
CC:
chromium-reviews, tfarina, stevenjb+watch_chromium.org, davemoore+watch_chromium.org, oshima+watch_chromium.org, nkostylev+watch_chromium.org
Visibility:
Public.

Description

Use GData WAPI for FastFetch even if Drive API v2 is enabled. Due to performance reason, we need to keep using GData WAPI for FastFetch even if Drive API v2 is enabled. BUG=283622 TEST=Ran unit_tests and tested manually. R=kinaba@chromium.org Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=221196

Patch Set 1 #

Total comments: 2

Patch Set 2 : Rebase #

Patch Set 3 : #

Unified diffs Side-by-side diffs Delta from patch set Stats (+116 lines, -22 lines) Patch
M chrome/browser/chromeos/drive/change_list_loader.h View 1 chunk +3 lines, -0 lines 0 comments Download
M chrome/browser/chromeos/drive/change_list_loader.cc View 1 2 7 chunks +89 lines, -7 lines 0 comments Download
M chrome/browser/drive/drive_api_util.h View 1 chunk +4 lines, -0 lines 0 comments Download
M chrome/browser/drive/drive_api_util.cc View 1 chunk +2 lines, -0 lines 0 comments Download
M chrome/browser/drive/fake_drive_service.cc View 1 6 chunks +16 lines, -9 lines 0 comments Download
M chrome/browser/drive/gdata_wapi_service.cc View 1 3 chunks +2 lines, -6 lines 0 comments Download

Messages

Total messages: 6 (0 generated)
hidehiko
Thank you for your review in advance, - hidehiko
7 years, 3 months ago (2013-09-03 14:04:12 UTC) #1
kinaba
lgtm https://codereview.chromium.org/23684012/diff/1/chrome/browser/chromeos/drive/change_list_loader.cc File chrome/browser/chromeos/drive/change_list_loader.cc (right): https://codereview.chromium.org/23684012/diff/1/chrome/browser/chromeos/drive/change_list_loader.cc#newcode291 chrome/browser/chromeos/drive/change_list_loader.cc:291: // Currently parent local id is the parent's ...
7 years, 3 months ago (2013-09-04 03:44:01 UTC) #2
hidehiko
Thank you for your review! Sending to CQ. https://codereview.chromium.org/23684012/diff/1/chrome/browser/chromeos/drive/change_list_loader.cc File chrome/browser/chromeos/drive/change_list_loader.cc (right): https://codereview.chromium.org/23684012/diff/1/chrome/browser/chromeos/drive/change_list_loader.cc#newcode291 chrome/browser/chromeos/drive/change_list_loader.cc:291: // ...
7 years, 3 months ago (2013-09-04 12:55:28 UTC) #3
hidehiko
Committed patchset #3 manually as r221196 (presubmit successful).
7 years, 3 months ago (2013-09-04 16:31:51 UTC) #4
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/hidehiko@chromium.org/23684012/9001
7 years, 3 months ago (2013-09-04 16:37:25 UTC) #5
commit-bot: I haz the power
7 years, 3 months ago (2013-09-04 16:37:34 UTC) #6
Message was sent while issue was closed.
Failed to apply patch for chrome/browser/chromeos/drive/change_list_loader.cc:
While running patch -p1 --forward --force --no-backup-if-mismatch;
  patching file chrome/browser/chromeos/drive/change_list_loader.cc
  Hunk #1 FAILED at 178.
  Hunk #2 FAILED at 188.
  Hunk #3 succeeded at 149 with fuzz 2 (offset -61 lines).
  Hunk #4 FAILED at 231.
  Hunk #5 FAILED at 484.
  Hunk #6 FAILED at 610.
  Hunk #7 FAILED at 691.
  6 out of 7 hunks FAILED -- saving rejects to file
chrome/browser/chromeos/drive/change_list_loader.cc.rej

Patch:       chrome/browser/chromeos/drive/change_list_loader.cc
Index: chrome/browser/chromeos/drive/change_list_loader.cc
diff --git a/chrome/browser/chromeos/drive/change_list_loader.cc
b/chrome/browser/chromeos/drive/change_list_loader.cc
index
0ba027de81b532b6572ed9637690cdfa1c399877..43ccbc9858c34ab0e5d7fe3568fc01217c960794
100644
--- a/chrome/browser/chromeos/drive/change_list_loader.cc
+++ b/chrome/browser/chromeos/drive/change_list_loader.cc
@@ -178,9 +178,11 @@ class DeltaFeedFetcher : public
ChangeListLoader::FeedFetcher {
 class FastFetchFeedFetcher : public ChangeListLoader::FeedFetcher {
  public:
   FastFetchFeedFetcher(JobScheduler* scheduler,
-                       const std::string& directory_resource_id)
+                       const std::string& directory_resource_id,
+                       const std::string& root_folder_id)
       : scheduler_(scheduler),
         directory_resource_id_(directory_resource_id),
+        root_folder_id_(root_folder_id),
         weak_ptr_factory_(this) {
   }
 
@@ -188,13 +190,59 @@ class FastFetchFeedFetcher : public
ChangeListLoader::FeedFetcher {
   }
 
   virtual void Run(const FeedFetcherCallback& callback) OVERRIDE {
-    scheduler_->GetResourceListInDirectory(
-        directory_resource_id_,
+    if (util::IsDriveV2ApiEnabled() && root_folder_id_.empty()) {
+      // The root folder id is not available yet. Fetch from the server.
+      scheduler_->GetAboutResource(
+          base::Bind(&FastFetchFeedFetcher::RunAfterGetAboutResource,
+                     weak_ptr_factory_.GetWeakPtr(), callback));
+      return;
+    }
+
+    StartGetResourceListInDirectory(callback);
+  }
+
+ private:
+  void RunAfterGetAboutResource(
+      const FeedFetcherCallback& callback,
+      google_apis::GDataErrorCode status,
+      scoped_ptr<google_apis::AboutResource> about_resource) {
+    DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+    DCHECK(!callback.is_null());
+
+    FileError error = GDataToFileError(status);
+    if (error != FILE_ERROR_OK) {
+      callback.Run(error, ScopedVector<ChangeList>());
+      return;
+    }
+
+    root_folder_id_ = about_resource->root_folder_id();
+    StartGetResourceListInDirectory(callback);
+  }
+
+  void StartGetResourceListInDirectory(const FeedFetcherCallback& callback) {
+    DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+    DCHECK(!callback.is_null());
+    DCHECK(!directory_resource_id_.empty());
+    DCHECK(!util::IsDriveV2ApiEnabled() || !root_folder_id_.empty());
+
+    // We use WAPI's GetResourceListInDirectory even if Drive API v2 is
+    // enabled. This is the short term work around of the performance
+    // regression.
+
+    std::string resource_id = directory_resource_id_;
+    if (util::IsDriveV2ApiEnabled() &&
+        directory_resource_id_ == root_folder_id_) {
+      // GData WAPI doesn't accept the root directory id which is used in Drive
+      // API v2. So it is necessary to translate it here.
+      resource_id = util::kWapiRootDirectoryResourceId;
+    }
+
+    scheduler_->GetResourceListInDirectoryByWapi(
+        resource_id,
         base::Bind(&FastFetchFeedFetcher::OnFileListFetched,
                    weak_ptr_factory_.GetWeakPtr(), callback));
   }
 
- private:
   void OnFileListFetched(
       const FeedFetcherCallback& callback,
       google_apis::GDataErrorCode status,
@@ -210,7 +258,10 @@ class FastFetchFeedFetcher : public
ChangeListLoader::FeedFetcher {
 
     // Add the current change list to the list of collected lists.
     DCHECK(resource_list);
-    change_lists_.push_back(new ChangeList(*resource_list));
+    ChangeList* change_list = new ChangeList(*resource_list);
+    if (util::IsDriveV2ApiEnabled())
+      FixResourceIdInChangeList(change_list);
+    change_lists_.push_back(change_list);
 
     GURL next_url;
     if (resource_list->GetNextFeedURL(&next_url) && !next_url.is_empty()) {
@@ -228,8 +279,34 @@ class FastFetchFeedFetcher : public
ChangeListLoader::FeedFetcher {
     callback.Run(FILE_ERROR_OK, change_lists_.Pass());
   }
 
+  void FixResourceIdInChangeList(ChangeList* change_list) {
+    std::vector<ResourceEntry>* entries = change_list->mutable_entries();
+    for (size_t i = 0; i < entries->size(); ++i) {
+      ResourceEntry* entry = &(*entries)[i];
+      if (entry->has_resource_id()) {
+        entry->set_resource_id(UpgradeResourceIdFromGDataWapiToDriveApiV2(
+            entry->resource_id()));
+      }
+
+      // Currently parent local id is the parent's resource id.
+      // It will be replaced by actual local id. (crbug.com/260514).
+      if (entry->has_parent_local_id()) {
+        entry->set_parent_local_id(UpgradeResourceIdFromGDataWapiToDriveApiV2(
+            entry->parent_local_id()));
+      }
+    }
+  }
+
+  std::string UpgradeResourceIdFromGDataWapiToDriveApiV2(
+      const std::string& resource_id) {
+    if (resource_id == util::kWapiRootDirectoryResourceId)
+      return root_folder_id_;
+    return drive::util::CanonicalizeResourceId(resource_id);
+  }
+
   JobScheduler* scheduler_;
   std::string directory_resource_id_;
+  std::string root_folder_id_;
   ScopedVector<ChangeList> change_lists_;
   base::WeakPtrFactory<FastFetchFeedFetcher> weak_ptr_factory_;
   DISALLOW_COPY_AND_ASSIGN(FastFetchFeedFetcher);
@@ -481,6 +558,7 @@ void ChangeListLoader::LoadFromServerIfNeededAfterGetAbout(
   if (GDataToFileError(status) == FILE_ERROR_OK) {
     DCHECK(about_resource);
     last_known_remote_changestamp_ = about_resource->largest_change_id();
+    root_folder_id_ = about_resource->root_folder_id();
   }
 
   int64 remote_changestamp =
@@ -607,8 +685,11 @@ void
ChangeListLoader::LoadDirectoryFromServerAfterGetAbout(
   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
   DCHECK(!callback.is_null());
 
-  if (GDataToFileError(status) == FILE_ERROR_OK)
+  if (GDataToFileError(status) == FILE_ERROR_OK) {
+    DCHECK(about_resource);
     last_known_remote_changestamp_ = about_resource->largest_change_id();
+    root_folder_id_ = about_resource->root_folder_id();
+  }
 
   DoLoadDirectoryFromServer(
       DirectoryFetchInfo(directory_resource_id,
last_known_remote_changestamp_),
@@ -688,7 +769,8 @@ void ChangeListLoader::DoLoadDirectoryFromServer(
 
   FastFetchFeedFetcher* fetcher = new FastFetchFeedFetcher(
       scheduler_,
-      directory_fetch_info.resource_id());
+      directory_fetch_info.resource_id(),
+      root_folder_id_);
   fast_fetch_feed_fetcher_set_.insert(fetcher);
   fetcher->Run(
       base::Bind(&ChangeListLoader::DoLoadDirectoryFromServerAfterLoad,

Powered by Google App Engine
This is Rietveld 408576698