| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 | 66 |
| 67 DriveFileSyncClient::DriveFileSyncClient(Profile* profile) | 67 DriveFileSyncClient::DriveFileSyncClient(Profile* profile) |
| 68 : url_generator_(GURL( | 68 : url_generator_(GURL( |
| 69 google_apis::GDataWapiUrlGenerator::kBaseUrlForProduction)) { | 69 google_apis::GDataWapiUrlGenerator::kBaseUrlForProduction)) { |
| 70 drive_service_.reset(new google_apis::GDataWapiService( | 70 drive_service_.reset(new google_apis::GDataWapiService( |
| 71 profile->GetRequestContext(), | 71 profile->GetRequestContext(), |
| 72 GURL(google_apis::GDataWapiUrlGenerator::kBaseUrlForProduction), | 72 GURL(google_apis::GDataWapiUrlGenerator::kBaseUrlForProduction), |
| 73 "" /* custom_user_agent */)); | 73 "" /* custom_user_agent */)); |
| 74 drive_service_->Initialize(profile); | 74 drive_service_->Initialize(profile); |
| 75 drive_service_->AddObserver(this); | 75 drive_service_->AddObserver(this); |
| 76 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); | 76 net::NetworkChangeNotifier::AddNetworkChangeObserver(this); |
| 77 | 77 |
| 78 drive_uploader_.reset(new google_apis::DriveUploader(drive_service_.get())); | 78 drive_uploader_.reset(new google_apis::DriveUploader(drive_service_.get())); |
| 79 } | 79 } |
| 80 | 80 |
| 81 scoped_ptr<DriveFileSyncClient> DriveFileSyncClient::CreateForTesting( | 81 scoped_ptr<DriveFileSyncClient> DriveFileSyncClient::CreateForTesting( |
| 82 Profile* profile, | 82 Profile* profile, |
| 83 const GURL& base_url, | 83 const GURL& base_url, |
| 84 scoped_ptr<google_apis::DriveServiceInterface> drive_service, | 84 scoped_ptr<google_apis::DriveServiceInterface> drive_service, |
| 85 scoped_ptr<google_apis::DriveUploaderInterface> drive_uploader) { | 85 scoped_ptr<google_apis::DriveUploaderInterface> drive_uploader) { |
| 86 return make_scoped_ptr(new DriveFileSyncClient( | 86 return make_scoped_ptr(new DriveFileSyncClient( |
| 87 profile, base_url, drive_service.Pass(), drive_uploader.Pass())); | 87 profile, base_url, drive_service.Pass(), drive_uploader.Pass())); |
| 88 } | 88 } |
| 89 | 89 |
| 90 DriveFileSyncClient::DriveFileSyncClient( | 90 DriveFileSyncClient::DriveFileSyncClient( |
| 91 Profile* profile, | 91 Profile* profile, |
| 92 const GURL& base_url, | 92 const GURL& base_url, |
| 93 scoped_ptr<google_apis::DriveServiceInterface> drive_service, | 93 scoped_ptr<google_apis::DriveServiceInterface> drive_service, |
| 94 scoped_ptr<google_apis::DriveUploaderInterface> drive_uploader) | 94 scoped_ptr<google_apis::DriveUploaderInterface> drive_uploader) |
| 95 : url_generator_(base_url) { | 95 : url_generator_(base_url) { |
| 96 drive_service_ = drive_service.Pass(); | 96 drive_service_ = drive_service.Pass(); |
| 97 drive_service_->Initialize(profile); | 97 drive_service_->Initialize(profile); |
| 98 drive_service_->AddObserver(this); | 98 drive_service_->AddObserver(this); |
| 99 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); | 99 net::NetworkChangeNotifier::AddNetworkChangeObserver(this); |
| 100 | 100 |
| 101 drive_uploader_ = drive_uploader.Pass(); | 101 drive_uploader_ = drive_uploader.Pass(); |
| 102 } | 102 } |
| 103 | 103 |
| 104 DriveFileSyncClient::~DriveFileSyncClient() { | 104 DriveFileSyncClient::~DriveFileSyncClient() { |
| 105 DCHECK(CalledOnValidThread()); | 105 DCHECK(CalledOnValidThread()); |
| 106 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); | 106 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this); |
| 107 drive_service_->RemoveObserver(this); | 107 drive_service_->RemoveObserver(this); |
| 108 drive_service_->CancelAll(); | 108 drive_service_->CancelAll(); |
| 109 } | 109 } |
| 110 | 110 |
| 111 void DriveFileSyncClient::AddObserver(DriveFileSyncClientObserver* observer) { | 111 void DriveFileSyncClient::AddObserver(DriveFileSyncClientObserver* observer) { |
| 112 DCHECK(CalledOnValidThread()); | 112 DCHECK(CalledOnValidThread()); |
| 113 observers_.AddObserver(observer); | 113 observers_.AddObserver(observer); |
| 114 } | 114 } |
| 115 | 115 |
| 116 void DriveFileSyncClient::RemoveObserver( | 116 void DriveFileSyncClient::RemoveObserver( |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 GURL DriveFileSyncClient::ResourceIdToResourceLink( | 384 GURL DriveFileSyncClient::ResourceIdToResourceLink( |
| 385 const std::string& resource_id) const { | 385 const std::string& resource_id) const { |
| 386 return url_generator_.GenerateResourceEntryUrl(resource_id); | 386 return url_generator_.GenerateResourceEntryUrl(resource_id); |
| 387 } | 387 } |
| 388 | 388 |
| 389 void DriveFileSyncClient::OnReadyToPerformOperations() { | 389 void DriveFileSyncClient::OnReadyToPerformOperations() { |
| 390 DCHECK(CalledOnValidThread()); | 390 DCHECK(CalledOnValidThread()); |
| 391 FOR_EACH_OBSERVER(DriveFileSyncClientObserver, observers_, OnAuthenticated()); | 391 FOR_EACH_OBSERVER(DriveFileSyncClientObserver, observers_, OnAuthenticated()); |
| 392 } | 392 } |
| 393 | 393 |
| 394 void DriveFileSyncClient::OnConnectionTypeChanged( | 394 void DriveFileSyncClient::OnNetworkChanged( |
| 395 net::NetworkChangeNotifier::ConnectionType type) { | 395 net::NetworkChangeNotifier::ConnectionType type) { |
| 396 DCHECK(CalledOnValidThread()); | 396 DCHECK(CalledOnValidThread()); |
| 397 if (type != net::NetworkChangeNotifier::CONNECTION_NONE) | 397 if (type != net::NetworkChangeNotifier::CONNECTION_NONE) |
| 398 FOR_EACH_OBSERVER(DriveFileSyncClientObserver, | 398 FOR_EACH_OBSERVER(DriveFileSyncClientObserver, |
| 399 observers_, OnNetworkConnected()); | 399 observers_, OnNetworkConnected()); |
| 400 } | 400 } |
| 401 | 401 |
| 402 void DriveFileSyncClient::DidGetResourceList( | 402 void DriveFileSyncClient::DidGetResourceList( |
| 403 const ResourceListCallback& callback, | 403 const ResourceListCallback& callback, |
| 404 google_apis::GDataErrorCode error, | 404 google_apis::GDataErrorCode error, |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 } | 630 } |
| 631 | 631 |
| 632 void DriveFileSyncClient::DidDeleteFile( | 632 void DriveFileSyncClient::DidDeleteFile( |
| 633 const GDataErrorCallback& callback, | 633 const GDataErrorCallback& callback, |
| 634 google_apis::GDataErrorCode error) { | 634 google_apis::GDataErrorCode error) { |
| 635 DCHECK(CalledOnValidThread()); | 635 DCHECK(CalledOnValidThread()); |
| 636 callback.Run(error); | 636 callback.Run(error); |
| 637 } | 637 } |
| 638 | 638 |
| 639 } // namespace sync_file_system | 639 } // namespace sync_file_system |
| OLD | NEW |