| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/gdata/gdata_operations.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_operations.h" |
| 6 | 6 |
| 7 #include "base/string_number_conversions.h" | 7 #include "base/string_number_conversions.h" |
| 8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/browser/chromeos/gdata/gdata_util.h" | 10 #include "chrome/browser/chromeos/gdata/gdata_util.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 "https://docs.google.com/feeds/default/private/full"; | 42 "https://docs.google.com/feeds/default/private/full"; |
| 43 | 43 |
| 44 // URL requesting single document entry whose resource id is specified by "%s". | 44 // URL requesting single document entry whose resource id is specified by "%s". |
| 45 const char kGetDocumentEntryURLFormat[] = | 45 const char kGetDocumentEntryURLFormat[] = |
| 46 "https://docs.google.com/feeds/default/private/full/%s"; | 46 "https://docs.google.com/feeds/default/private/full/%s"; |
| 47 | 47 |
| 48 // Metadata feed with things like user quota. | 48 // Metadata feed with things like user quota. |
| 49 const char kAccountMetadataURL[] = | 49 const char kAccountMetadataURL[] = |
| 50 "https://docs.google.com/feeds/metadata/default"; | 50 "https://docs.google.com/feeds/metadata/default"; |
| 51 | 51 |
| 52 // URL requesting all contact groups. |
| 53 const char kGetContactGroupsURL[] = |
| 54 "https://www.google.com/m8/feeds/groups/default/full?alt=json"; |
| 55 |
| 52 // URL requesting all contacts. | 56 // URL requesting all contacts. |
| 53 // TODO(derat): Per https://goo.gl/AufHP, "The feed may not contain all of the | 57 // TODO(derat): Per https://goo.gl/AufHP, "The feed may not contain all of the |
| 54 // user's contacts, because there's a default limit on the number of results | 58 // user's contacts, because there's a default limit on the number of results |
| 55 // returned." Decide if 10000 is reasonable or not. | 59 // returned." Decide if 10000 is reasonable or not. |
| 56 const char kGetContactsURL[] = | 60 const char kGetContactsURL[] = |
| 57 "https://www.google.com/m8/feeds/contacts/default/full" | 61 "https://www.google.com/m8/feeds/contacts/default/full" |
| 58 "?alt=json&showdeleted=true&max-results=10000"; | 62 "?alt=json&showdeleted=true&max-results=10000"; |
| 59 | 63 |
| 64 // Query parameter optionally appended to |kGetContactsURL| to return contacts |
| 65 // from a specific group (as opposed to all contacts). |
| 66 const char kGetContactsGroupParam[] = "group"; |
| 67 |
| 60 // Query parameter optionally appended to |kGetContactsURL| to return only | 68 // Query parameter optionally appended to |kGetContactsURL| to return only |
| 61 // recently-updated contacts. | 69 // recently-updated contacts. |
| 62 const char kGetContactsUpdatedMinParam[] = "updated-min"; | 70 const char kGetContactsUpdatedMinParam[] = "updated-min"; |
| 63 | 71 |
| 64 const char kUploadContentRange[] = "Content-Range: bytes "; | 72 const char kUploadContentRange[] = "Content-Range: bytes "; |
| 65 const char kUploadContentType[] = "X-Upload-Content-Type: "; | 73 const char kUploadContentType[] = "X-Upload-Content-Type: "; |
| 66 const char kUploadContentLength[] = "X-Upload-Content-Length: "; | 74 const char kUploadContentLength[] = "X-Upload-Content-Length: "; |
| 67 | 75 |
| 68 #ifndef NDEBUG | 76 #ifndef NDEBUG |
| 69 // Use smaller 'page' size while debugging to ensure we hit feed reload | 77 // Use smaller 'page' size while debugging to ensure we hit feed reload |
| (...skipping 798 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 868 params_.end_range - params_.start_range + 1); | 876 params_.end_range - params_.start_range + 1); |
| 869 return true; | 877 return true; |
| 870 } | 878 } |
| 871 | 879 |
| 872 void ResumeUploadOperation::OnURLFetchUploadProgress( | 880 void ResumeUploadOperation::OnURLFetchUploadProgress( |
| 873 const URLFetcher* source, int64 current, int64 total) { | 881 const URLFetcher* source, int64 current, int64 total) { |
| 874 // Adjust the progress values according to the range currently uploaded. | 882 // Adjust the progress values according to the range currently uploaded. |
| 875 NotifyProgress(params_.start_range + current, params_.content_length); | 883 NotifyProgress(params_.start_range + current, params_.content_length); |
| 876 } | 884 } |
| 877 | 885 |
| 886 //========================== GetContactGroupsOperation ========================= |
| 887 |
| 888 GetContactGroupsOperation::GetContactGroupsOperation( |
| 889 GDataOperationRegistry* registry, |
| 890 const GetDataCallback& callback) |
| 891 : GetDataOperation(registry, callback) { |
| 892 } |
| 893 |
| 894 GetContactGroupsOperation::~GetContactGroupsOperation() {} |
| 895 |
| 896 GURL GetContactGroupsOperation::GetURL() const { |
| 897 return !feed_url_for_testing_.is_empty() ? |
| 898 feed_url_for_testing_ : |
| 899 GURL(kGetContactGroupsURL); |
| 900 } |
| 901 |
| 878 //============================ GetContactsOperation ============================ | 902 //============================ GetContactsOperation ============================ |
| 879 | 903 |
| 880 GetContactsOperation::GetContactsOperation(GDataOperationRegistry* registry, | 904 GetContactsOperation::GetContactsOperation(GDataOperationRegistry* registry, |
| 905 const std::string& group_id, |
| 881 const base::Time& min_update_time, | 906 const base::Time& min_update_time, |
| 882 const GetDataCallback& callback) | 907 const GetDataCallback& callback) |
| 883 : GetDataOperation(registry, callback), | 908 : GetDataOperation(registry, callback), |
| 909 group_id_(group_id), |
| 884 min_update_time_(min_update_time) { | 910 min_update_time_(min_update_time) { |
| 885 } | 911 } |
| 886 | 912 |
| 887 GetContactsOperation::~GetContactsOperation() {} | 913 GetContactsOperation::~GetContactsOperation() {} |
| 888 | 914 |
| 889 GURL GetContactsOperation::GetURL() const { | 915 GURL GetContactsOperation::GetURL() const { |
| 890 if (!feed_url_for_testing_.is_empty()) | 916 if (!feed_url_for_testing_.is_empty()) |
| 891 return GURL(feed_url_for_testing_); | 917 return GURL(feed_url_for_testing_); |
| 892 | 918 |
| 893 GURL url(kGetContactsURL); | 919 GURL url(kGetContactsURL); |
| 920 |
| 921 if (!group_id_.empty()) { |
| 922 url = chrome_common_net::AppendQueryParameter( |
| 923 url, kGetContactsGroupParam, group_id_); |
| 924 } |
| 894 if (!min_update_time_.is_null()) { | 925 if (!min_update_time_.is_null()) { |
| 895 std::string time_rfc3339 = util::FormatTimeAsString(min_update_time_); | 926 std::string time_rfc3339 = util::FormatTimeAsString(min_update_time_); |
| 896 url = chrome_common_net::AppendQueryParameter( | 927 url = chrome_common_net::AppendQueryParameter( |
| 897 url, kGetContactsUpdatedMinParam, time_rfc3339); | 928 url, kGetContactsUpdatedMinParam, time_rfc3339); |
| 898 } | 929 } |
| 899 return url; | 930 return url; |
| 900 } | 931 } |
| 901 | 932 |
| 902 //========================== GetContactPhotoOperation ========================== | 933 //========================== GetContactPhotoOperation ========================== |
| 903 | 934 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 925 OnProcessURLFetchResultsComplete(code == HTTP_SUCCESS); | 956 OnProcessURLFetchResultsComplete(code == HTTP_SUCCESS); |
| 926 } | 957 } |
| 927 | 958 |
| 928 void GetContactPhotoOperation::RunCallbackOnPrematureFailure( | 959 void GetContactPhotoOperation::RunCallbackOnPrematureFailure( |
| 929 GDataErrorCode code) { | 960 GDataErrorCode code) { |
| 930 scoped_ptr<std::string> data(new std::string); | 961 scoped_ptr<std::string> data(new std::string); |
| 931 callback_.Run(code, data.Pass()); | 962 callback_.Run(code, data.Pass()); |
| 932 } | 963 } |
| 933 | 964 |
| 934 } // namespace gdata | 965 } // namespace gdata |
| OLD | NEW |