| 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/contacts/gdata_contacts_service.h" | 5 #include "chrome/browser/chromeos/contacts/gdata_contacts_service.h" |
| 6 | 6 |
| 7 #include <cstring> | 7 #include <cstring> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 const char kAddressRelMobileValue[] = "http://schemas.google.com/g/2005#mobile"; | 139 const char kAddressRelMobileValue[] = "http://schemas.google.com/g/2005#mobile"; |
| 140 const char kAddressLabelField[] = "label"; | 140 const char kAddressLabelField[] = "label"; |
| 141 | 141 |
| 142 // Fields in entries in the |kLinkField| list. | 142 // Fields in entries in the |kLinkField| list. |
| 143 const char kLinkHrefField[] = "href"; | 143 const char kLinkHrefField[] = "href"; |
| 144 const char kLinkRelField[] = "rel"; | 144 const char kLinkRelField[] = "rel"; |
| 145 const char kLinkETagField[] = "gd$etag"; | 145 const char kLinkETagField[] = "gd$etag"; |
| 146 const char kLinkRelPhotoValue[] = | 146 const char kLinkRelPhotoValue[] = |
| 147 "http://schemas.google.com/contacts/2008/rel#photo"; | 147 "http://schemas.google.com/contacts/2008/rel#photo"; |
| 148 | 148 |
| 149 // OAuth2 scope for the Contacts API. | |
| 150 const char kContactsScope[] = "https://www.google.com/m8/feeds/"; | |
| 151 | |
| 152 // Returns a string containing a pretty-printed JSON representation of |value|. | 149 // Returns a string containing a pretty-printed JSON representation of |value|. |
| 153 std::string PrettyPrintValue(const base::Value& value) { | 150 std::string PrettyPrintValue(const base::Value& value) { |
| 154 std::string out; | 151 std::string out; |
| 155 base::JSONWriter::WriteWithOptions( | 152 base::JSONWriter::WriteWithOptions( |
| 156 &value, base::JSONWriter::OPTIONS_PRETTY_PRINT, &out); | 153 &value, base::JSONWriter::OPTIONS_PRETTY_PRINT, &out); |
| 157 return out; | 154 return out; |
| 158 } | 155 } |
| 159 | 156 |
| 160 // Assigns the value at |path| within |dict| to |out|, returning false if the | 157 // Assigns the value at |path| within |dict| to |out|, returning false if the |
| 161 // path wasn't present. Unicode byte order marks are removed from the string. | 158 // path wasn't present. Unicode byte order marks are removed from the string. |
| (...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 844 | 841 |
| 845 // Note: This should remain the last member so it'll be destroyed and | 842 // Note: This should remain the last member so it'll be destroyed and |
| 846 // invalidate its weak pointers before any other members are destroyed. | 843 // invalidate its weak pointers before any other members are destroyed. |
| 847 base::WeakPtrFactory<DownloadContactsRequest> weak_ptr_factory_; | 844 base::WeakPtrFactory<DownloadContactsRequest> weak_ptr_factory_; |
| 848 | 845 |
| 849 DISALLOW_COPY_AND_ASSIGN(DownloadContactsRequest); | 846 DISALLOW_COPY_AND_ASSIGN(DownloadContactsRequest); |
| 850 }; | 847 }; |
| 851 | 848 |
| 852 GDataContactsService::GDataContactsService( | 849 GDataContactsService::GDataContactsService( |
| 853 net::URLRequestContextGetter* url_request_context_getter, | 850 net::URLRequestContextGetter* url_request_context_getter, |
| 854 Profile* profile) | 851 google_apis::AuthServiceInterface* auth_service) |
| 855 : max_photo_downloads_per_second_(kMaxPhotoDownloadsPerSecond), | 852 : max_photo_downloads_per_second_(kMaxPhotoDownloadsPerSecond), |
| 856 photo_download_timer_interval_(base::TimeDelta::FromSeconds(1)) { | 853 photo_download_timer_interval_(base::TimeDelta::FromSeconds(1)) { |
| 857 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 854 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 858 std::vector<std::string> scopes; | |
| 859 scopes.push_back(kContactsScope); | |
| 860 sender_.reset(new google_apis::RequestSender( | 855 sender_.reset(new google_apis::RequestSender( |
| 861 profile, | 856 auth_service, |
| 862 url_request_context_getter, | 857 url_request_context_getter, |
| 863 content::BrowserThread::GetBlockingPool(), | 858 content::BrowserThread::GetBlockingPool(), |
| 864 scopes, | |
| 865 "" /* custom_user_agent */)); | 859 "" /* custom_user_agent */)); |
| 866 } | 860 } |
| 867 | 861 |
| 868 GDataContactsService::~GDataContactsService() { | 862 GDataContactsService::~GDataContactsService() { |
| 869 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 863 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 870 STLDeleteContainerPointers(requests_.begin(), requests_.end()); | 864 STLDeleteContainerPointers(requests_.begin(), requests_.end()); |
| 871 requests_.clear(); | 865 requests_.clear(); |
| 872 } | 866 } |
| 873 | 867 |
| 874 google_apis::AuthService* GDataContactsService::auth_service_for_testing() { | |
| 875 return sender_->auth_service(); | |
| 876 } | |
| 877 | |
| 878 void GDataContactsService::Initialize() { | |
| 879 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 880 sender_->Initialize(); | |
| 881 } | |
| 882 | |
| 883 void GDataContactsService::DownloadContacts(SuccessCallback success_callback, | 868 void GDataContactsService::DownloadContacts(SuccessCallback success_callback, |
| 884 FailureCallback failure_callback, | 869 FailureCallback failure_callback, |
| 885 const base::Time& min_update_time) { | 870 const base::Time& min_update_time) { |
| 886 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 871 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 887 DownloadContactsRequest* request = | 872 DownloadContactsRequest* request = |
| 888 new DownloadContactsRequest(this, | 873 new DownloadContactsRequest(this, |
| 889 sender_.get(), | 874 sender_.get(), |
| 890 success_callback, | 875 success_callback, |
| 891 failure_callback, | 876 failure_callback, |
| 892 min_update_time); | 877 min_update_time); |
| 893 VLOG(1) << "Starting contacts download with request " << request; | 878 VLOG(1) << "Starting contacts download with request " << request; |
| 894 requests_.insert(request); | 879 requests_.insert(request); |
| 895 request->Run(); | 880 request->Run(); |
| 896 } | 881 } |
| 897 | 882 |
| 898 void GDataContactsService::OnRequestComplete(DownloadContactsRequest* request) { | 883 void GDataContactsService::OnRequestComplete(DownloadContactsRequest* request) { |
| 899 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 884 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 900 DCHECK(request); | 885 DCHECK(request); |
| 901 VLOG(1) << "Download request " << request << " complete"; | 886 VLOG(1) << "Download request " << request << " complete"; |
| 902 if (!request->my_contacts_group_id().empty()) | 887 if (!request->my_contacts_group_id().empty()) |
| 903 cached_my_contacts_group_id_ = request->my_contacts_group_id(); | 888 cached_my_contacts_group_id_ = request->my_contacts_group_id(); |
| 904 requests_.erase(request); | 889 requests_.erase(request); |
| 905 delete request; | 890 delete request; |
| 906 } | 891 } |
| 907 | 892 |
| 908 } // namespace contacts | 893 } // namespace contacts |
| OLD | NEW |