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

Unified Diff: chrome/browser/chromeos/gdata/gdata_wapi_feed_loader.cc

Issue 10823226: Get AboutResource as account metadata for Drive V2. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/gdata/gdata_wapi_feed_loader.cc
diff --git a/chrome/browser/chromeos/gdata/gdata_wapi_feed_loader.cc b/chrome/browser/chromeos/gdata/gdata_wapi_feed_loader.cc
index b5eb7cdcbf426b286711427ae47800547a1b2982..416f3357e2de215d17375911da9268e8734d268b 100644
--- a/chrome/browser/chromeos/gdata/gdata_wapi_feed_loader.cc
+++ b/chrome/browser/chromeos/gdata/gdata_wapi_feed_loader.cc
@@ -13,6 +13,7 @@
#include "base/stringprintf.h"
#include "base/threading/sequenced_worker_pool.h"
#include "chrome/browser/chromeos/gdata/drive_webapps_registry.h"
+#include "chrome/browser/chromeos/gdata/drive_api_parser.h"
#include "chrome/browser/chromeos/gdata/gdata_cache.h"
#include "chrome/browser/chromeos/gdata/gdata_documents_service.h"
#include "chrome/browser/chromeos/gdata/gdata_util.h"
@@ -136,8 +137,8 @@ bool UseLevelDB() {
} // namespace
GetDocumentsParams::GetDocumentsParams(
- int start_changestamp,
- int root_feed_changestamp,
+ int64 start_changestamp,
+ int64 root_feed_changestamp,
std::vector<DocumentFeed*>* feed_list,
bool should_fetch_multiple_feeds,
const FilePath& search_file_path,
@@ -219,7 +220,7 @@ void GDataWapiFeedLoader::RemoveObserver(Observer* observer) {
void GDataWapiFeedLoader::ReloadFromServerIfNeeded(
ContentOrigin initial_origin,
- int local_changestamp,
+ int64 local_changestamp,
const FilePath& search_file_path,
const FindEntryCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
@@ -229,6 +230,17 @@ void GDataWapiFeedLoader::ReloadFromServerIfNeeded(
// First fetch the latest changestamp to see if there were any new changes
// there at all.
+ if (gdata::util::IsDriveV2ApiEnabled()) {
satorux1 2012/08/08 13:18:51 I named the file "gdata_wapi_feed_loader.cc", assu
kochi 2012/08/08 16:53:27 I could have a separate file but it turned out tha
+ documents_service_->GetAboutResource(
+ base::Bind(&GDataWapiFeedLoader::OnGetAboutResource,
+ weak_ptr_factory_.GetWeakPtr(),
+ initial_origin,
+ local_changestamp,
+ search_file_path,
+ callback));
+ return;
+ }
+
documents_service_->GetAccountMetadata(
base::Bind(&GDataWapiFeedLoader::OnGetAccountMetadata,
weak_ptr_factory_.GetWeakPtr(),
@@ -240,7 +252,7 @@ void GDataWapiFeedLoader::ReloadFromServerIfNeeded(
void GDataWapiFeedLoader::OnGetAccountMetadata(
ContentOrigin initial_origin,
- int local_changestamp,
+ int64 local_changestamp,
const FilePath& search_file_path,
const FindEntryCallback& callback,
GDataErrorCode status,
@@ -333,10 +345,94 @@ void GDataWapiFeedLoader::OnGetAccountMetadata(
weak_ptr_factory_.GetWeakPtr()));
}
+void GDataWapiFeedLoader::OnGetAboutResource(
+ ContentOrigin initial_origin,
+ int64 local_changestamp,
+ const FilePath& search_file_path,
+ const FindEntryCallback& callback,
+ GDataErrorCode status,
+ scoped_ptr<base::Value> feed_data) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
+ GDataFileError error = util::GDataToGDataFileError(status);
+ if (error != GDATA_FILE_OK) {
+ // Get changes starting from the next changestamp from what we have locally.
+ LoadFromServer(initial_origin,
satorux1 2012/08/08 13:18:51 LoadFromServer has too many parameters. Could you
kochi 2012/08/08 16:53:27 Will work on a separate CL.
+ local_changestamp + 1, 0,
+ true, /* should_fetch_multiple_feeds */
+ search_file_path,
+ std::string() /* no search query */,
+ GURL(), /* feed not explicitly set */
+ std::string() /* no directory resource ID */,
+ callback,
+ base::Bind(&GDataWapiFeedLoader::OnFeedFromServerLoaded,
+ weak_ptr_factory_.GetWeakPtr()));
+ return;
+ }
+
+ scoped_ptr<AboutResource> about_resource;
+ if (feed_data.get())
+ about_resource = AboutResource::CreateFrom(*feed_data);
+
+ if (!about_resource.get()) {
+ LoadFromServer(initial_origin,
+ local_changestamp + 1, 0,
+ true, /* should_fetch_multiple_feeds */
+ search_file_path,
+ std::string() /* no search query */,
+ GURL(), /* feed not explicitly set */
+ std::string() /* no directory resource ID */,
+ callback,
+ base::Bind(&GDataWapiFeedLoader::OnFeedFromServerLoaded,
+ weak_ptr_factory_.GetWeakPtr()));
+ return;
+ }
+
+ bool changes_detected = true;
+ int64 largest_changestamp = about_resource->largest_change_id();
+ directory_service_->SetRootResourceId(about_resource->root_folder_id());
+
+ if (local_changestamp >= largest_changestamp) {
+ if (local_changestamp > largest_changestamp) {
+ LOG(WARNING) << "Cached client feed is fresher than server, client = "
+ << local_changestamp
+ << ", server = "
+ << largest_changestamp;
+ }
+ // If our cache holds the latest state from the server, change the
+ // state to FROM_SERVER.
+ directory_service_->set_origin(
+ initial_origin == FROM_CACHE ? FROM_SERVER : initial_origin);
+ changes_detected = false;
+ }
+
+ // No changes detected, continue with search as planned.
+ if (!changes_detected) {
+ if (!callback.is_null()) {
+ directory_service_->FindEntryByPathAndRunSync(search_file_path,
+ callback);
+ }
+ return;
+ }
+
+ // Load changes from the server.
+ LoadFromServer(initial_origin,
+ local_changestamp > 0 ? local_changestamp + 1 : 0,
+ largest_changestamp,
+ true, /* should_fetch_multiple_feeds */
+ search_file_path,
+ std::string() /* no search query */,
+ GURL(), /* feed not explicitly set */
+ std::string() /* no directory resource ID */,
+ callback,
+ base::Bind(&GDataWapiFeedLoader::OnFeedFromServerLoaded,
+ weak_ptr_factory_.GetWeakPtr()));
+}
+
void GDataWapiFeedLoader::LoadFromServer(
ContentOrigin initial_origin,
- int start_changestamp,
- int root_feed_changestamp,
+ int64 start_changestamp,
+ int64 root_feed_changestamp,
bool should_fetch_multiple_feeds,
const FilePath& search_file_path,
const std::string& search_query,
@@ -449,7 +545,7 @@ void GDataWapiFeedLoader::OnGetDocuments(
#ifndef NDEBUG
// Save initial root feed for analysis.
std::string file_name =
- base::StringPrintf("DEBUG_feed_%d.json",
+ base::StringPrintf("DEBUG_feed_%ld.json",
params->start_changestamp);
util::PostBlockingPoolSequencedTask(
FROM_HERE,
@@ -686,8 +782,8 @@ void GDataWapiFeedLoader::SaveFileSystem() {
GDataFileError GDataWapiFeedLoader::UpdateFromFeed(
const std::vector<DocumentFeed*>& feed_list,
- int start_changestamp,
- int root_feed_changestamp) {
+ int64 start_changestamp,
+ int64 root_feed_changestamp) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DVLOG(1) << "Updating directory with a feed";

Powered by Google App Engine
This is Rietveld 408576698