| 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/sync_file_system/drive_file_sync_client.h" | 5 #include "chrome/browser/sync_file_system/drive_file_sync_client.h" |
| 6 | 6 |
| 7 #include <sstream> | 7 #include <sstream> |
| 8 | 8 |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 } // namespace | 64 } // namespace |
| 65 | 65 |
| 66 DriveFileSyncClient::DriveFileSyncClient(Profile* profile) | 66 DriveFileSyncClient::DriveFileSyncClient(Profile* profile) |
| 67 : url_generator_(GURL( | 67 : url_generator_(GURL( |
| 68 google_apis::GDataWapiUrlGenerator::kBaseUrlForProduction)) { | 68 google_apis::GDataWapiUrlGenerator::kBaseUrlForProduction)) { |
| 69 drive_service_.reset(new google_apis::GDataWapiService( | 69 drive_service_.reset(new google_apis::GDataWapiService( |
| 70 GURL(google_apis::GDataWapiUrlGenerator::kBaseUrlForProduction), | 70 GURL(google_apis::GDataWapiUrlGenerator::kBaseUrlForProduction), |
| 71 "" /* custom_user_agent */)); | 71 "" /* custom_user_agent */)); |
| 72 drive_service_->Initialize(profile); | 72 drive_service_->Initialize(profile); |
| 73 drive_service_->AddObserver(this); | 73 drive_service_->AddObserver(this); |
| 74 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); |
| 74 | 75 |
| 75 drive_uploader_.reset(new google_apis::DriveUploader(drive_service_.get())); | 76 drive_uploader_.reset(new google_apis::DriveUploader(drive_service_.get())); |
| 76 } | 77 } |
| 77 | 78 |
| 78 scoped_ptr<DriveFileSyncClient> DriveFileSyncClient::CreateForTesting( | 79 scoped_ptr<DriveFileSyncClient> DriveFileSyncClient::CreateForTesting( |
| 79 Profile* profile, | 80 Profile* profile, |
| 80 const GURL& base_url, | 81 const GURL& base_url, |
| 81 scoped_ptr<google_apis::DriveServiceInterface> drive_service, | 82 scoped_ptr<google_apis::DriveServiceInterface> drive_service, |
| 82 scoped_ptr<google_apis::DriveUploaderInterface> drive_uploader) { | 83 scoped_ptr<google_apis::DriveUploaderInterface> drive_uploader) { |
| 83 return make_scoped_ptr(new DriveFileSyncClient( | 84 return make_scoped_ptr(new DriveFileSyncClient( |
| 84 profile, base_url, drive_service.Pass(), drive_uploader.Pass())); | 85 profile, base_url, drive_service.Pass(), drive_uploader.Pass())); |
| 85 } | 86 } |
| 86 | 87 |
| 87 DriveFileSyncClient::DriveFileSyncClient( | 88 DriveFileSyncClient::DriveFileSyncClient( |
| 88 Profile* profile, | 89 Profile* profile, |
| 89 const GURL& base_url, | 90 const GURL& base_url, |
| 90 scoped_ptr<google_apis::DriveServiceInterface> drive_service, | 91 scoped_ptr<google_apis::DriveServiceInterface> drive_service, |
| 91 scoped_ptr<google_apis::DriveUploaderInterface> drive_uploader) | 92 scoped_ptr<google_apis::DriveUploaderInterface> drive_uploader) |
| 92 : url_generator_(base_url) { | 93 : url_generator_(base_url) { |
| 93 drive_service_ = drive_service.Pass(); | 94 drive_service_ = drive_service.Pass(); |
| 94 drive_service_->Initialize(profile); | 95 drive_service_->Initialize(profile); |
| 95 drive_service_->AddObserver(this); | 96 drive_service_->AddObserver(this); |
| 97 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); |
| 96 | 98 |
| 97 drive_uploader_ = drive_uploader.Pass(); | 99 drive_uploader_ = drive_uploader.Pass(); |
| 98 } | 100 } |
| 99 | 101 |
| 100 DriveFileSyncClient::~DriveFileSyncClient() { | 102 DriveFileSyncClient::~DriveFileSyncClient() { |
| 101 DCHECK(CalledOnValidThread()); | 103 DCHECK(CalledOnValidThread()); |
| 104 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); |
| 102 drive_service_->RemoveObserver(this); | 105 drive_service_->RemoveObserver(this); |
| 103 drive_service_->CancelAll(); | 106 drive_service_->CancelAll(); |
| 104 } | 107 } |
| 105 | 108 |
| 106 void DriveFileSyncClient::AddObserver(DriveFileSyncClientObserver* observer) { | 109 void DriveFileSyncClient::AddObserver(DriveFileSyncClientObserver* observer) { |
| 107 DCHECK(CalledOnValidThread()); | 110 DCHECK(CalledOnValidThread()); |
| 108 observers_.AddObserver(observer); | 111 observers_.AddObserver(observer); |
| 109 } | 112 } |
| 110 | 113 |
| 111 void DriveFileSyncClient::RemoveObserver( | 114 void DriveFileSyncClient::RemoveObserver( |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 GURL DriveFileSyncClient::ResourceIdToResourceLink( | 395 GURL DriveFileSyncClient::ResourceIdToResourceLink( |
| 393 const std::string& resource_id) const { | 396 const std::string& resource_id) const { |
| 394 return url_generator_.GenerateDocumentEntryUrl(resource_id); | 397 return url_generator_.GenerateDocumentEntryUrl(resource_id); |
| 395 } | 398 } |
| 396 | 399 |
| 397 void DriveFileSyncClient::OnReadyToPerformOperations() { | 400 void DriveFileSyncClient::OnReadyToPerformOperations() { |
| 398 DCHECK(CalledOnValidThread()); | 401 DCHECK(CalledOnValidThread()); |
| 399 FOR_EACH_OBSERVER(DriveFileSyncClientObserver, observers_, OnAuthenticated()); | 402 FOR_EACH_OBSERVER(DriveFileSyncClientObserver, observers_, OnAuthenticated()); |
| 400 } | 403 } |
| 401 | 404 |
| 405 void DriveFileSyncClient::OnConnectionTypeChanged( |
| 406 net::NetworkChangeNotifier::ConnectionType type) { |
| 407 DCHECK(CalledOnValidThread()); |
| 408 if (type != net::NetworkChangeNotifier::CONNECTION_NONE) |
| 409 FOR_EACH_OBSERVER(DriveFileSyncClientObserver, |
| 410 observers_, OnNetworkConnected()); |
| 411 } |
| 412 |
| 402 void DriveFileSyncClient::DidGetDocumentFeedData( | 413 void DriveFileSyncClient::DidGetDocumentFeedData( |
| 403 const DocumentFeedCallback& callback, | 414 const DocumentFeedCallback& callback, |
| 404 google_apis::GDataErrorCode error, | 415 google_apis::GDataErrorCode error, |
| 405 scoped_ptr<base::Value> data) { | 416 scoped_ptr<base::Value> data) { |
| 406 DCHECK(CalledOnValidThread()); | 417 DCHECK(CalledOnValidThread()); |
| 407 | 418 |
| 408 if (error != google_apis::HTTP_SUCCESS) { | 419 if (error != google_apis::HTTP_SUCCESS) { |
| 409 callback.Run(error, scoped_ptr<google_apis::DocumentFeed>()); | 420 callback.Run(error, scoped_ptr<google_apis::DocumentFeed>()); |
| 410 return; | 421 return; |
| 411 } | 422 } |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 641 } | 652 } |
| 642 | 653 |
| 643 void DriveFileSyncClient::DidDeleteFile( | 654 void DriveFileSyncClient::DidDeleteFile( |
| 644 const GDataErrorCallback& callback, | 655 const GDataErrorCallback& callback, |
| 645 google_apis::GDataErrorCode error) { | 656 google_apis::GDataErrorCode error) { |
| 646 DCHECK(CalledOnValidThread()); | 657 DCHECK(CalledOnValidThread()); |
| 647 callback.Run(error); | 658 callback.Run(error); |
| 648 } | 659 } |
| 649 | 660 |
| 650 } // namespace sync_file_system | 661 } // namespace sync_file_system |
| OLD | NEW |