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_contacts_service.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_contacts_service.h" |
6 | 6 |
7 #include <cstring> | 7 #include <cstring> |
8 #include <string> | 8 #include <string> |
9 #include <map> | 9 #include <map> |
10 #include <utility> | 10 #include <utility> |
11 | 11 |
12 #include "base/json/json_value_converter.h" | 12 #include "base/json/json_value_converter.h" |
13 #include "base/json/json_writer.h" | 13 #include "base/json/json_writer.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
17 #include "base/string_util.h" | 17 #include "base/string_util.h" |
18 #include "base/time.h" | 18 #include "base/time.h" |
19 #include "base/timer.h" | 19 #include "base/timer.h" |
20 #include "base/values.h" | 20 #include "base/values.h" |
21 #include "chrome/browser/chromeos/contacts/contact.pb.h" | 21 #include "chrome/browser/chromeos/contacts/contact.pb.h" |
22 #include "chrome/browser/chromeos/gdata/gdata_operation_registry.h" | |
23 #include "chrome/browser/chromeos/gdata/gdata_operation_runner.h" | |
24 #include "chrome/browser/chromeos/gdata/gdata_operations.h" | 22 #include "chrome/browser/chromeos/gdata/gdata_operations.h" |
25 #include "chrome/browser/chromeos/gdata/gdata_util.h" | 23 #include "chrome/browser/chromeos/gdata/gdata_util.h" |
| 24 #include "chrome/browser/chromeos/gdata/operation_registry.h" |
| 25 #include "chrome/browser/chromeos/gdata/operation_runner.h" |
26 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
27 | 27 |
28 using content::BrowserThread; | 28 using content::BrowserThread; |
29 | 29 |
30 namespace gdata { | 30 namespace gdata { |
31 | 31 |
32 namespace { | 32 namespace { |
33 | 33 |
34 // Maximum number of profile photos that we'll download per second. | 34 // Maximum number of profile photos that we'll download per second. |
35 // At values above 10, Google starts returning 503 errors. | 35 // At values above 10, Google starts returning 503 errors. |
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 // Next, the contacts feed is downloaded via GetContactsOperation and parsed. | 411 // Next, the contacts feed is downloaded via GetContactsOperation and parsed. |
412 // Individual contacts::Contact objects are created using the data from the | 412 // Individual contacts::Contact objects are created using the data from the |
413 // feed. | 413 // feed. |
414 // | 414 // |
415 // Finally, GetContactPhotoOperations are created and used to start downloading | 415 // Finally, GetContactPhotoOperations are created and used to start downloading |
416 // contacts' photos in parallel. When all photos have been downloaded, the | 416 // contacts' photos in parallel. When all photos have been downloaded, the |
417 // contacts are passed to the passed-in callback. | 417 // contacts are passed to the passed-in callback. |
418 class GDataContactsService::DownloadContactsRequest { | 418 class GDataContactsService::DownloadContactsRequest { |
419 public: | 419 public: |
420 DownloadContactsRequest(GDataContactsService* service, | 420 DownloadContactsRequest(GDataContactsService* service, |
421 GDataOperationRunner* runner, | 421 OperationRunner* runner, |
422 SuccessCallback success_callback, | 422 SuccessCallback success_callback, |
423 FailureCallback failure_callback, | 423 FailureCallback failure_callback, |
424 const base::Time& min_update_time) | 424 const base::Time& min_update_time) |
425 : service_(service), | 425 : service_(service), |
426 runner_(runner), | 426 runner_(runner), |
427 success_callback_(success_callback), | 427 success_callback_(success_callback), |
428 failure_callback_(failure_callback), | 428 failure_callback_(failure_callback), |
429 min_update_time_(min_update_time), | 429 min_update_time_(min_update_time), |
430 contacts_(new ScopedVector<contacts::Contact>), | 430 contacts_(new ScopedVector<contacts::Contact>), |
431 my_contacts_group_id_(service->cached_my_contacts_group_id_), | 431 my_contacts_group_id_(service->cached_my_contacts_group_id_), |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
715 return; | 715 return; |
716 } | 716 } |
717 | 717 |
718 contact->set_raw_untrusted_photo(*download_data); | 718 contact->set_raw_untrusted_photo(*download_data); |
719 CheckCompletion(); | 719 CheckCompletion(); |
720 } | 720 } |
721 | 721 |
722 typedef std::map<contacts::Contact*, std::string> ContactPhotoUrls; | 722 typedef std::map<contacts::Contact*, std::string> ContactPhotoUrls; |
723 | 723 |
724 GDataContactsService* service_; // not owned | 724 GDataContactsService* service_; // not owned |
725 GDataOperationRunner* runner_; // not owned | 725 OperationRunner* runner_; // not owned |
726 | 726 |
727 SuccessCallback success_callback_; | 727 SuccessCallback success_callback_; |
728 FailureCallback failure_callback_; | 728 FailureCallback failure_callback_; |
729 | 729 |
730 base::Time min_update_time_; | 730 base::Time min_update_time_; |
731 | 731 |
732 scoped_ptr<ScopedVector<contacts::Contact> > contacts_; | 732 scoped_ptr<ScopedVector<contacts::Contact> > contacts_; |
733 | 733 |
734 // ID of the "My Contacts" contacts group. | 734 // ID of the "My Contacts" contacts group. |
735 std::string my_contacts_group_id_; | 735 std::string my_contacts_group_id_; |
(...skipping 22 matching lines...) Expand all Loading... |
758 bool photo_download_failed_; | 758 bool photo_download_failed_; |
759 | 759 |
760 // Note: This should remain the last member so it'll be destroyed and | 760 // Note: This should remain the last member so it'll be destroyed and |
761 // invalidate its weak pointers before any other members are destroyed. | 761 // invalidate its weak pointers before any other members are destroyed. |
762 base::WeakPtrFactory<DownloadContactsRequest> weak_ptr_factory_; | 762 base::WeakPtrFactory<DownloadContactsRequest> weak_ptr_factory_; |
763 | 763 |
764 DISALLOW_COPY_AND_ASSIGN(DownloadContactsRequest); | 764 DISALLOW_COPY_AND_ASSIGN(DownloadContactsRequest); |
765 }; | 765 }; |
766 | 766 |
767 GDataContactsService::GDataContactsService(Profile* profile) | 767 GDataContactsService::GDataContactsService(Profile* profile) |
768 : runner_(new GDataOperationRunner(profile)), | 768 : runner_(new OperationRunner(profile)), |
769 max_photo_downloads_per_second_(kMaxPhotoDownloadsPerSecond), | 769 max_photo_downloads_per_second_(kMaxPhotoDownloadsPerSecond), |
770 photo_download_timer_interval_(base::TimeDelta::FromSeconds(1)) { | 770 photo_download_timer_interval_(base::TimeDelta::FromSeconds(1)) { |
771 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 771 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
772 } | 772 } |
773 | 773 |
774 GDataContactsService::~GDataContactsService() { | 774 GDataContactsService::~GDataContactsService() { |
775 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 775 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
776 runner_->CancelAll(); | 776 runner_->CancelAll(); |
777 STLDeleteContainerPointers(requests_.begin(), requests_.end()); | 777 STLDeleteContainerPointers(requests_.begin(), requests_.end()); |
778 requests_.clear(); | 778 requests_.clear(); |
779 } | 779 } |
780 | 780 |
781 GDataAuthService* GDataContactsService::auth_service_for_testing() { | 781 AuthService* GDataContactsService::auth_service_for_testing() { |
782 return runner_->auth_service(); | 782 return runner_->auth_service(); |
783 } | 783 } |
784 | 784 |
785 void GDataContactsService::Initialize() { | 785 void GDataContactsService::Initialize() { |
786 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 786 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
787 runner_->Initialize(); | 787 runner_->Initialize(); |
788 } | 788 } |
789 | 789 |
790 void GDataContactsService::DownloadContacts(SuccessCallback success_callback, | 790 void GDataContactsService::DownloadContacts(SuccessCallback success_callback, |
791 FailureCallback failure_callback, | 791 FailureCallback failure_callback, |
(...skipping 14 matching lines...) Expand all Loading... |
806 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 806 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
807 DCHECK(request); | 807 DCHECK(request); |
808 VLOG(1) << "Download request " << request << " complete"; | 808 VLOG(1) << "Download request " << request << " complete"; |
809 if (!request->my_contacts_group_id().empty()) | 809 if (!request->my_contacts_group_id().empty()) |
810 cached_my_contacts_group_id_ = request->my_contacts_group_id(); | 810 cached_my_contacts_group_id_ = request->my_contacts_group_id(); |
811 requests_.erase(request); | 811 requests_.erase(request); |
812 delete request; | 812 delete request; |
813 } | 813 } |
814 | 814 |
815 } // namespace contacts | 815 } // namespace contacts |
OLD | NEW |