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

Side by Side 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, 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 // 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
55 // returned." Decide if 10000 is reasonable or not.
56 const char kGetContactsURL[] =
57 "https://www.google.com/m8/feeds/contacts/default/full"
58 "?alt=json&showdeleted=true&max-results=10000";
59
60 // Query parameter optionally appended to |kGetContactsURL| to return only
61 // recently-updated contacts.
62 const char kGetContactsUpdatedMinParam[] = "updated-min";
63
51 const char kUploadContentRange[] = "Content-Range: bytes "; 64 const char kUploadContentRange[] = "Content-Range: bytes ";
52 const char kUploadContentType[] = "X-Upload-Content-Type: "; 65 const char kUploadContentType[] = "X-Upload-Content-Type: ";
53 const char kUploadContentLength[] = "X-Upload-Content-Length: "; 66 const char kUploadContentLength[] = "X-Upload-Content-Length: ";
54 67
55 #ifndef NDEBUG 68 #ifndef NDEBUG
56 // Use smaller 'page' size while debugging to ensure we hit feed reload 69 // 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 70 // 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. 71 // have many items because server side 503 error might kick in.
59 const int kMaxDocumentsPerFeed = 1000; 72 const int kMaxDocumentsPerFeed = 1000;
60 #else 73 #else
(...skipping 807 matching lines...) Expand 10 before | Expand all | Expand 10 after
868 params_.end_range - params_.start_range + 1); 881 params_.end_range - params_.start_range + 1);
869 return true; 882 return true;
870 } 883 }
871 884
872 void ResumeUploadOperation::OnURLFetchUploadProgress( 885 void ResumeUploadOperation::OnURLFetchUploadProgress(
873 const URLFetcher* source, int64 current, int64 total) { 886 const URLFetcher* source, int64 current, int64 total) {
874 // Adjust the progress values according to the range currently uploaded. 887 // Adjust the progress values according to the range currently uploaded.
875 NotifyProgress(params_.start_range + current, params_.content_length); 888 NotifyProgress(params_.start_range + current, params_.content_length);
876 } 889 }
877 890
891 //============================ GetContactsOperation ============================
892
893 GetContactsOperation::GetContactsOperation(GDataOperationRegistry* registry,
894 Profile* profile,
895 const base::Time& min_update_time,
896 const GetDataCallback& callback)
897 : GetDataOperation(registry, profile, callback),
898 min_update_time_(min_update_time) {
899 }
900
901 GetContactsOperation::~GetContactsOperation() {}
902
903 GURL GetContactsOperation::GetURL() const {
904 if (!feed_url_for_testing_.is_empty())
905 return GURL(feed_url_for_testing_);
906
907 GURL url(kGetContactsURL);
908 if (!min_update_time_.is_null()) {
909 std::string time_rfc3339 = util::FormatTimeAsString(min_update_time_);
910 url = chrome_common_net::AppendQueryParameter(
911 url, kGetContactsUpdatedMinParam, time_rfc3339);
912 }
913 return url;
914 }
915
916 //========================== GetContactPhotoOperation ==========================
917
918 GetContactPhotoOperation::GetContactPhotoOperation(
919 GDataOperationRegistry* registry,
920 Profile* profile,
921 const GURL& photo_url,
922 const GetDownloadDataCallback& callback)
923 : UrlFetchOperationBase(registry, profile),
924 photo_url_(photo_url),
925 callback_(callback) {
926 }
927
928 GetContactPhotoOperation::~GetContactPhotoOperation() {}
929
930 GURL GetContactPhotoOperation::GetURL() const {
931 return photo_url_;
932 }
933
934 bool GetContactPhotoOperation::ProcessURLFetchResults(
935 const net::URLFetcher* source) {
936 GDataErrorCode code = static_cast<GDataErrorCode>(source->GetResponseCode());
937 scoped_ptr<std::string> data(new std::string);
938 source->GetResponseAsString(data.get());
939 callback_.Run(code, data.Pass());
940 return code == HTTP_SUCCESS;
941 }
942
943 void GetContactPhotoOperation::RunCallbackOnPrematureFailure(
944 GDataErrorCode code) {
945 scoped_ptr<std::string> data(new std::string);
946 callback_.Run(code, data.Pass());
947 }
948
878 } // namespace gdata 949 } // namespace gdata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698