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

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

Issue 10818017: contacts: Add GDataContactsService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: apply review feedback Created 8 years, 5 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_operations.cc
diff --git a/chrome/browser/chromeos/gdata/gdata_operations.cc b/chrome/browser/chromeos/gdata/gdata_operations.cc
index e0057eb392b823f9288ef945bfcda7c37497b55f..45c59fdde68a6011b98636d2f61bf4c5c23f00aa 100644
--- a/chrome/browser/chromeos/gdata/gdata_operations.cc
+++ b/chrome/browser/chromeos/gdata/gdata_operations.cc
@@ -7,6 +7,7 @@
#include "base/string_number_conversions.h"
#include "base/stringprintf.h"
#include "base/values.h"
+#include "chrome/browser/chromeos/gdata/gdata_util.h"
#include "chrome/browser/chromeos/gdata/gdata_wapi_parser.h"
#include "chrome/common/net/url_util.h"
#include "content/public/browser/browser_thread.h"
@@ -48,6 +49,18 @@ const char kGetDocumentEntryURLFormat[] =
const char kAccountMetadataURL[] =
"https://docs.google.com/feeds/metadata/default";
+// URL requesting all contacts.
+// TODO(derat): Per https://goo.gl/AufHP, "The feed may not contain all of the
+// user's contacts, because there's a default limit on the number of results
+// returned." Decide if 10000 is reasonable or not.
+const char kGetContactsURL[] =
+ "https://www.google.com/m8/feeds/contacts/default/full"
+ "?alt=json&showdeleted=true&max-results=10000";
+
+// Query parameter optionally appended to |kGetContactsURL| to return only
+// recently-updated contacts.
+const char kGetContactsUpdatedMinParam[] = "updated-min";
+
const char kUploadContentRange[] = "Content-Range: bytes ";
const char kUploadContentType[] = "X-Upload-Content-Type: ";
const char kUploadContentLength[] = "X-Upload-Content-Length: ";
@@ -875,4 +888,62 @@ void ResumeUploadOperation::OnURLFetchUploadProgress(
NotifyProgress(params_.start_range + current, params_.content_length);
}
+//============================ GetContactsOperation ============================
+
+GetContactsOperation::GetContactsOperation(GDataOperationRegistry* registry,
+ Profile* profile,
+ const base::Time& min_update_time,
+ const GetDataCallback& callback)
+ : GetDataOperation(registry, profile, callback),
+ min_update_time_(min_update_time) {
+}
+
+GetContactsOperation::~GetContactsOperation() {}
+
+GURL GetContactsOperation::GetURL() const {
+ if (!feed_url_for_testing_.is_empty())
+ return GURL(feed_url_for_testing_);
+
+ GURL url(kGetContactsURL);
+ if (!min_update_time_.is_null()) {
+ std::string time_rfc3339 = util::FormatTimeAsString(min_update_time_);
+ url = chrome_common_net::AppendQueryParameter(
+ url, kGetContactsUpdatedMinParam, time_rfc3339);
+ }
+ return url;
+}
+
+//========================== GetContactPhotoOperation ==========================
+
+GetContactPhotoOperation::GetContactPhotoOperation(
+ GDataOperationRegistry* registry,
+ Profile* profile,
+ const GURL& photo_url,
+ const GetDownloadDataCallback& callback)
+ : UrlFetchOperationBase(registry, profile),
+ photo_url_(photo_url),
+ callback_(callback) {
+}
+
+GetContactPhotoOperation::~GetContactPhotoOperation() {}
+
+GURL GetContactPhotoOperation::GetURL() const {
+ return photo_url_;
+}
+
+bool GetContactPhotoOperation::ProcessURLFetchResults(
+ const net::URLFetcher* source) {
+ GDataErrorCode code = static_cast<GDataErrorCode>(source->GetResponseCode());
+ scoped_ptr<std::string> data(new std::string);
+ source->GetResponseAsString(data.get());
+ callback_.Run(code, data.Pass());
+ return code == HTTP_SUCCESS;
+}
+
+void GetContactPhotoOperation::RunCallbackOnPrematureFailure(
+ GDataErrorCode code) {
+ scoped_ptr<std::string> data(new std::string);
+ callback_.Run(code, data.Pass());
+}
+
} // namespace gdata

Powered by Google App Engine
This is Rietveld 408576698