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/drive_errorcode.h" | |
22 #include "chrome/browser/chromeos/gdata/gdata_operations.h" | 23 #include "chrome/browser/chromeos/gdata/gdata_operations.h" |
23 #include "chrome/browser/chromeos/gdata/gdata_util.h" | 24 #include "chrome/browser/chromeos/gdata/gdata_util.h" |
24 #include "chrome/browser/chromeos/gdata/operation_registry.h" | 25 #include "chrome/browser/chromeos/gdata/operation_registry.h" |
25 #include "chrome/browser/chromeos/gdata/operation_runner.h" | 26 #include "chrome/browser/chromeos/gdata/operation_runner.h" |
26 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
27 | 28 |
28 using content::BrowserThread; | 29 using content::BrowserThread; |
29 | 30 |
30 namespace gdata { | 31 namespace gdata { |
31 | 32 |
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
472 // Invokes the failure callback and notifies GDataContactsService that the | 473 // Invokes the failure callback and notifies GDataContactsService that the |
473 // request is done. | 474 // request is done. |
474 void ReportFailure() { | 475 void ReportFailure() { |
475 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 476 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
476 failure_callback_.Run(); | 477 failure_callback_.Run(); |
477 service_->OnRequestComplete(this); | 478 service_->OnRequestComplete(this); |
478 } | 479 } |
479 | 480 |
480 // Callback for GetContactGroupsOperation calls. Starts downloading the | 481 // Callback for GetContactGroupsOperation calls. Starts downloading the |
481 // actual contacts after finding the "My Contacts" group ID. | 482 // actual contacts after finding the "My Contacts" group ID. |
482 void HandleGroupsFeedData(GDataErrorCode error, | 483 void HandleGroupsFeedData(DriveErrorCode error, |
satorux1
2012/08/22 20:12:21
Hmm... This does not look correct.
Contacts is no
Daniel Erat
2012/08/22 20:18:41
Yeah, I think so too. :-(
| |
483 scoped_ptr<base::Value> feed_data) { | 484 scoped_ptr<base::Value> feed_data) { |
484 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 485 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
485 if (error != HTTP_SUCCESS) { | 486 if (error != HTTP_SUCCESS) { |
486 LOG(WARNING) << "Got error " << error << " while downloading groups"; | 487 LOG(WARNING) << "Got error " << error << " while downloading groups"; |
487 ReportFailure(); | 488 ReportFailure(); |
488 return; | 489 return; |
489 } | 490 } |
490 | 491 |
491 VLOG(2) << "Got groups feed data:\n" | 492 VLOG(2) << "Got groups feed data:\n" |
492 << PrettyPrintValue(*(feed_data.get())); | 493 << PrettyPrintValue(*(feed_data.get())); |
(...skipping 26 matching lines...) Expand all Loading... | |
519 base::Bind(&DownloadContactsRequest::HandleContactsFeedData, | 520 base::Bind(&DownloadContactsRequest::HandleContactsFeedData, |
520 weak_ptr_factory_.GetWeakPtr())); | 521 weak_ptr_factory_.GetWeakPtr())); |
521 if (!service_->contacts_feed_url_for_testing_.is_empty()) { | 522 if (!service_->contacts_feed_url_for_testing_.is_empty()) { |
522 operation->set_feed_url_for_testing( | 523 operation->set_feed_url_for_testing( |
523 service_->contacts_feed_url_for_testing_); | 524 service_->contacts_feed_url_for_testing_); |
524 } | 525 } |
525 runner_->StartOperationWithRetry(operation); | 526 runner_->StartOperationWithRetry(operation); |
526 } | 527 } |
527 | 528 |
528 // Callback for GetContactsOperation calls. | 529 // Callback for GetContactsOperation calls. |
529 void HandleContactsFeedData(GDataErrorCode error, | 530 void HandleContactsFeedData(DriveErrorCode error, |
530 scoped_ptr<base::Value> feed_data) { | 531 scoped_ptr<base::Value> feed_data) { |
531 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 532 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
532 if (error != HTTP_SUCCESS) { | 533 if (error != HTTP_SUCCESS) { |
533 LOG(WARNING) << "Got error " << error << " while downloading contacts"; | 534 LOG(WARNING) << "Got error " << error << " while downloading contacts"; |
534 ReportFailure(); | 535 ReportFailure(); |
535 return; | 536 return; |
536 } | 537 } |
537 | 538 |
538 VLOG(2) << "Got contacts feed data:\n" | 539 VLOG(2) << "Got contacts feed data:\n" |
539 << PrettyPrintValue(*(feed_data.get())); | 540 << PrettyPrintValue(*(feed_data.get())); |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
673 base::Bind(&DownloadContactsRequest::HandlePhotoData, | 674 base::Bind(&DownloadContactsRequest::HandlePhotoData, |
674 weak_ptr_factory_.GetWeakPtr(), | 675 weak_ptr_factory_.GetWeakPtr(), |
675 contact))); | 676 contact))); |
676 num_in_progress_photo_downloads_++; | 677 num_in_progress_photo_downloads_++; |
677 } | 678 } |
678 } | 679 } |
679 | 680 |
680 // Callback for GetContactPhotoOperation calls. Updates the associated | 681 // Callback for GetContactPhotoOperation calls. Updates the associated |
681 // Contact and checks for completion. | 682 // Contact and checks for completion. |
682 void HandlePhotoData(contacts::Contact* contact, | 683 void HandlePhotoData(contacts::Contact* contact, |
683 GDataErrorCode error, | 684 DriveErrorCode error, |
684 scoped_ptr<std::string> download_data) { | 685 scoped_ptr<std::string> download_data) { |
685 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 686 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
686 VLOG(1) << "Got photo data for " << contact->contact_id() | 687 VLOG(1) << "Got photo data for " << contact->contact_id() |
687 << " (error=" << error << " size=" << download_data->size() << ")"; | 688 << " (error=" << error << " size=" << download_data->size() << ")"; |
688 num_in_progress_photo_downloads_--; | 689 num_in_progress_photo_downloads_--; |
689 | 690 |
690 if (error == HTTP_INTERNAL_SERVER_ERROR || | 691 if (error == HTTP_INTERNAL_SERVER_ERROR || |
691 error == HTTP_SERVICE_UNAVAILABLE) { | 692 error == HTTP_SERVICE_UNAVAILABLE) { |
692 int num_errors = ++transient_photo_download_errors_per_contact_[contact]; | 693 int num_errors = ++transient_photo_download_errors_per_contact_[contact]; |
693 if (num_errors <= kMaxTransientPhotoDownloadErrorsPerContact) { | 694 if (num_errors <= kMaxTransientPhotoDownloadErrorsPerContact) { |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
806 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 807 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
807 DCHECK(request); | 808 DCHECK(request); |
808 VLOG(1) << "Download request " << request << " complete"; | 809 VLOG(1) << "Download request " << request << " complete"; |
809 if (!request->my_contacts_group_id().empty()) | 810 if (!request->my_contacts_group_id().empty()) |
810 cached_my_contacts_group_id_ = request->my_contacts_group_id(); | 811 cached_my_contacts_group_id_ = request->my_contacts_group_id(); |
811 requests_.erase(request); | 812 requests_.erase(request); |
812 delete request; | 813 delete request; |
813 } | 814 } |
814 | 815 |
815 } // namespace contacts | 816 } // namespace contacts |
OLD | NEW |