Remove unused script android_webview/build/install_binary.
[chromium-blink-merge.git] / google_apis / drive / gdata_contacts_requests.cc
blob11419af449b3dd411daa98e58f3cf6a0cf1f285c
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "google_apis/drive/gdata_contacts_requests.h"
7 #include "google_apis/drive/time_util.h"
8 #include "net/base/url_util.h"
9 #include "url/gurl.h"
11 namespace google_apis {
13 namespace {
15 // URL requesting all contact groups.
16 const char kGetContactGroupsURL[] =
17 "https://www.google.com/m8/feeds/groups/default/full?alt=json";
19 // URL requesting all contacts.
20 // TODO(derat): Per https://goo.gl/AufHP, "The feed may not contain all of the
21 // user's contacts, because there's a default limit on the number of results
22 // returned." Decide if 10000 is reasonable or not.
23 const char kGetContactsURL[] =
24 "https://www.google.com/m8/feeds/contacts/default/full"
25 "?alt=json&showdeleted=true&max-results=10000";
27 // Query parameter optionally appended to |kGetContactsURL| to return contacts
28 // from a specific group (as opposed to all contacts).
29 const char kGetContactsGroupParam[] = "group";
31 // Query parameter optionally appended to |kGetContactsURL| to return only
32 // recently-updated contacts.
33 const char kGetContactsUpdatedMinParam[] = "updated-min";
35 } // namespace
37 //========================== GetContactGroupsRequest =========================
39 GetContactGroupsRequest::GetContactGroupsRequest(
40 RequestSender* runner,
41 const GetDataCallback& callback)
42 : GetDataRequest(runner, callback) {
45 GetContactGroupsRequest::~GetContactGroupsRequest() {}
47 GURL GetContactGroupsRequest::GetURL() const {
48 return !feed_url_for_testing_.is_empty() ?
49 feed_url_for_testing_ :
50 GURL(kGetContactGroupsURL);
53 //============================ GetContactsRequest ============================
55 GetContactsRequest::GetContactsRequest(
56 RequestSender* runner,
57 const std::string& group_id,
58 const base::Time& min_update_time,
59 const GetDataCallback& callback)
60 : GetDataRequest(runner, callback),
61 group_id_(group_id),
62 min_update_time_(min_update_time) {
65 GetContactsRequest::~GetContactsRequest() {}
67 GURL GetContactsRequest::GetURL() const {
68 if (!feed_url_for_testing_.is_empty())
69 return GURL(feed_url_for_testing_);
71 GURL url(kGetContactsURL);
73 if (!group_id_.empty()) {
74 url = net::AppendQueryParameter(url, kGetContactsGroupParam, group_id_);
76 if (!min_update_time_.is_null()) {
77 std::string time_rfc3339 = util::FormatTimeAsString(min_update_time_);
78 url = net::AppendQueryParameter(
79 url, kGetContactsUpdatedMinParam, time_rfc3339);
81 return url;
84 //========================== GetContactPhotoRequest ==========================
86 GetContactPhotoRequest::GetContactPhotoRequest(
87 RequestSender* runner,
88 const GURL& photo_url,
89 const GetContentCallback& callback)
90 : UrlFetchRequestBase(runner),
91 photo_url_(photo_url),
92 callback_(callback) {
95 GetContactPhotoRequest::~GetContactPhotoRequest() {}
97 GURL GetContactPhotoRequest::GetURL() const {
98 return photo_url_;
101 void GetContactPhotoRequest::ProcessURLFetchResults(
102 const net::URLFetcher* source) {
103 GDataErrorCode code = GetErrorCode();
104 scoped_ptr<std::string> data(new std::string(response_writer()->data()));
105 callback_.Run(code, data.Pass());
106 OnProcessURLFetchResultsComplete();
109 void GetContactPhotoRequest::RunCallbackOnPrematureFailure(
110 GDataErrorCode code) {
111 scoped_ptr<std::string> data(new std::string);
112 callback_.Run(code, data.Pass());
115 } // namespace google_apis