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_wapi_parser.h" | 11 #include "chrome/browser/chromeos/gdata/gdata_wapi_parser.h" |
11 #include "chrome/common/net/url_util.h" | 12 #include "chrome/common/net/url_util.h" |
12 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
13 #include "net/base/escape.h" | 14 #include "net/base/escape.h" |
14 #include "net/http/http_util.h" | 15 #include "net/http/http_util.h" |
15 #include "third_party/libxml/chromium/libxml_utils.h" | 16 #include "third_party/libxml/chromium/libxml_utils.h" |
16 | 17 |
17 using net::URLFetcher; | 18 using net::URLFetcher; |
18 | 19 |
19 namespace { | 20 namespace { |
(...skipping 21 matching lines...) Expand all Loading... |
41 "https://docs.google.com/feeds/default/private/full"; | 42 "https://docs.google.com/feeds/default/private/full"; |
42 | 43 |
43 // 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". |
44 const char kGetDocumentEntryURLFormat[] = | 45 const char kGetDocumentEntryURLFormat[] = |
45 "https://docs.google.com/feeds/default/private/full/%s"; | 46 "https://docs.google.com/feeds/default/private/full/%s"; |
46 | 47 |
47 // Metadata feed with things like user quota. | 48 // Metadata feed with things like user quota. |
48 const char kAccountMetadataURL[] = | 49 const char kAccountMetadataURL[] = |
49 "https://docs.google.com/feeds/metadata/default"; | 50 "https://docs.google.com/feeds/metadata/default"; |
50 | 51 |
| 52 // URL requesting all contacts. |
| 53 const char kGetContactsURL[] = |
| 54 "https://www.google.com/m8/feeds/contacts/default/full" |
| 55 "?alt=json&max-results=1000&showdeleted=true"; |
| 56 |
| 57 // Query parameter optionally appended to kGetContactsURL to return only |
| 58 // recently-updated contacts. |
| 59 const char kGetContactsUpdatedMinParam[] = "updated-min"; |
| 60 |
51 const char kUploadContentRange[] = "Content-Range: bytes "; | 61 const char kUploadContentRange[] = "Content-Range: bytes "; |
52 const char kUploadContentType[] = "X-Upload-Content-Type: "; | 62 const char kUploadContentType[] = "X-Upload-Content-Type: "; |
53 const char kUploadContentLength[] = "X-Upload-Content-Length: "; | 63 const char kUploadContentLength[] = "X-Upload-Content-Length: "; |
54 | 64 |
55 #ifndef NDEBUG | 65 #ifndef NDEBUG |
56 // Use smaller 'page' size while debugging to ensure we hit feed reload | 66 // Use smaller 'page' size while debugging to ensure we hit feed reload |
57 // almost always. Be careful not to use something too small on account that | 67 // almost always. Be careful not to use something too small on account that |
58 // have many items because server side 503 error might kick in. | 68 // have many items because server side 503 error might kick in. |
59 const int kMaxDocumentsPerFeed = 1000; | 69 const int kMaxDocumentsPerFeed = 1000; |
60 #else | 70 #else |
(...skipping 807 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
868 params_.end_range - params_.start_range + 1); | 878 params_.end_range - params_.start_range + 1); |
869 return true; | 879 return true; |
870 } | 880 } |
871 | 881 |
872 void ResumeUploadOperation::OnURLFetchUploadProgress( | 882 void ResumeUploadOperation::OnURLFetchUploadProgress( |
873 const URLFetcher* source, int64 current, int64 total) { | 883 const URLFetcher* source, int64 current, int64 total) { |
874 // Adjust the progress values according to the range currently uploaded. | 884 // Adjust the progress values according to the range currently uploaded. |
875 NotifyProgress(params_.start_range + current, params_.content_length); | 885 NotifyProgress(params_.start_range + current, params_.content_length); |
876 } | 886 } |
877 | 887 |
| 888 //============================ GetContactsOperation ============================ |
| 889 |
| 890 GetContactsOperation::GetContactsOperation(GDataOperationRegistry* registry, |
| 891 Profile* profile, |
| 892 const base::Time& min_update_time, |
| 893 const GetDataCallback& callback) |
| 894 : GetDataOperation(registry, profile, callback), |
| 895 min_update_time_(min_update_time) { |
| 896 } |
| 897 |
| 898 GetContactsOperation::~GetContactsOperation() {} |
| 899 |
| 900 GURL GetContactsOperation::GetURL() const { |
| 901 GURL url = !feed_url_for_testing_.is_empty() ? |
| 902 GURL(feed_url_for_testing_) : |
| 903 GURL(kGetContactsURL); |
| 904 if (!min_update_time_.is_null()) { |
| 905 std::string time_rfc3339 = util::FormatTimeAsString(min_update_time_); |
| 906 url = chrome_common_net::AppendQueryParameter( |
| 907 url, kGetContactsUpdatedMinParam, time_rfc3339); |
| 908 } |
| 909 return url; |
| 910 } |
| 911 |
| 912 //========================== GetContactPhotoOperation ========================== |
| 913 |
| 914 GetContactPhotoOperation::GetContactPhotoOperation( |
| 915 GDataOperationRegistry* registry, |
| 916 Profile* profile, |
| 917 const GURL& photo_url, |
| 918 const GetDownloadDataCallback& callback) |
| 919 : UrlFetchOperationBase(registry, profile), |
| 920 photo_url_(photo_url), |
| 921 callback_(callback) { |
| 922 } |
| 923 |
| 924 GetContactPhotoOperation::~GetContactPhotoOperation() {} |
| 925 |
| 926 GURL GetContactPhotoOperation::GetURL() const { |
| 927 return photo_url_; |
| 928 } |
| 929 |
| 930 bool GetContactPhotoOperation::ProcessURLFetchResults( |
| 931 const net::URLFetcher* source) { |
| 932 GDataErrorCode code = static_cast<GDataErrorCode>(source->GetResponseCode()); |
| 933 scoped_ptr<std::string> data(new std::string); |
| 934 source->GetResponseAsString(data.get()); |
| 935 callback_.Run(code, data.Pass()); |
| 936 return code == HTTP_SUCCESS; |
| 937 } |
| 938 |
| 939 void GetContactPhotoOperation::RunCallbackOnPrematureFailure( |
| 940 GDataErrorCode code) { |
| 941 scoped_ptr<std::string> data(new std::string); |
| 942 callback_.Run(code, data.Pass()); |
| 943 } |
| 944 |
878 } // namespace gdata | 945 } // namespace gdata |
OLD | NEW |