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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 return NULL; | 63 return NULL; |
64 } | 64 } |
65 | 65 |
66 } // namespace | 66 } // namespace |
67 | 67 |
68 DriveFileSyncClient::DriveFileSyncClient(Profile* profile) { | 68 DriveFileSyncClient::DriveFileSyncClient(Profile* profile) { |
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 | 74 |
74 drive_uploader_.reset(new google_apis::DriveUploader(drive_service_.get())); | 75 drive_uploader_.reset(new google_apis::DriveUploader(drive_service_.get())); |
75 } | 76 } |
76 | 77 |
77 scoped_ptr<DriveFileSyncClient> DriveFileSyncClient::CreateForTesting( | 78 scoped_ptr<DriveFileSyncClient> DriveFileSyncClient::CreateForTesting( |
78 Profile* profile, | 79 Profile* profile, |
79 scoped_ptr<google_apis::DriveServiceInterface> drive_service, | 80 scoped_ptr<google_apis::DriveServiceInterface> drive_service, |
80 scoped_ptr<google_apis::DriveUploaderInterface> drive_uploader) { | 81 scoped_ptr<google_apis::DriveUploaderInterface> drive_uploader) { |
81 return make_scoped_ptr(new DriveFileSyncClient( | 82 return make_scoped_ptr(new DriveFileSyncClient( |
82 profile, drive_service.Pass(), drive_uploader.Pass())); | 83 profile, drive_service.Pass(), drive_uploader.Pass())); |
83 } | 84 } |
84 | 85 |
85 DriveFileSyncClient::DriveFileSyncClient( | 86 DriveFileSyncClient::DriveFileSyncClient( |
86 Profile* profile, | 87 Profile* profile, |
87 scoped_ptr<google_apis::DriveServiceInterface> drive_service, | 88 scoped_ptr<google_apis::DriveServiceInterface> drive_service, |
88 scoped_ptr<google_apis::DriveUploaderInterface> drive_uploader) { | 89 scoped_ptr<google_apis::DriveUploaderInterface> drive_uploader) { |
89 drive_service_ = drive_service.Pass(); | 90 drive_service_ = drive_service.Pass(); |
90 drive_service_->Initialize(profile); | 91 drive_service_->Initialize(profile); |
| 92 drive_service_->AddObserver(this); |
91 | 93 |
92 drive_uploader_ = drive_uploader.Pass(); | 94 drive_uploader_ = drive_uploader.Pass(); |
93 } | 95 } |
94 | 96 |
95 DriveFileSyncClient::~DriveFileSyncClient() { | 97 DriveFileSyncClient::~DriveFileSyncClient() { |
96 DCHECK(CalledOnValidThread()); | 98 DCHECK(CalledOnValidThread()); |
| 99 drive_service_->RemoveObserver(this); |
97 drive_service_->CancelAll(); | 100 drive_service_->CancelAll(); |
98 } | 101 } |
99 | 102 |
| 103 void DriveFileSyncClient::AddObserver(DriveFileSyncClientObserver* observer) { |
| 104 DCHECK(CalledOnValidThread()); |
| 105 observers_.AddObserver(observer); |
| 106 } |
| 107 |
| 108 void DriveFileSyncClient::RemoveObserver( |
| 109 DriveFileSyncClientObserver* observer) { |
| 110 DCHECK(CalledOnValidThread()); |
| 111 observers_.RemoveObserver(observer); |
| 112 } |
| 113 |
100 void DriveFileSyncClient::GetDriveDirectoryForSyncRoot( | 114 void DriveFileSyncClient::GetDriveDirectoryForSyncRoot( |
101 const ResourceIdCallback& callback) { | 115 const ResourceIdCallback& callback) { |
102 DCHECK(CalledOnValidThread()); | 116 DCHECK(CalledOnValidThread()); |
103 | 117 |
104 std::string directory_name(kSyncRootDirectoryName); | 118 std::string directory_name(kSyncRootDirectoryName); |
105 SearchFilesInDirectory( | 119 SearchFilesInDirectory( |
106 kRootResourceId, | 120 kRootResourceId, |
107 FormatTitleQuery(directory_name), | 121 FormatTitleQuery(directory_name), |
108 base::Bind(&DriveFileSyncClient::DidGetDirectory, AsWeakPtr(), | 122 base::Bind(&DriveFileSyncClient::DidGetDirectory, AsWeakPtr(), |
109 kRootResourceId, directory_name, callback)); | 123 kRootResourceId, directory_name, callback)); |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 std::string DriveFileSyncClient::OriginToDirectoryTitle(const GURL& origin) { | 376 std::string DriveFileSyncClient::OriginToDirectoryTitle(const GURL& origin) { |
363 DCHECK(origin.SchemeIs(extensions::kExtensionScheme)); | 377 DCHECK(origin.SchemeIs(extensions::kExtensionScheme)); |
364 return origin.host(); | 378 return origin.host(); |
365 } | 379 } |
366 | 380 |
367 // static | 381 // static |
368 GURL DriveFileSyncClient::DirectoryTitleToOrigin(const std::string& title) { | 382 GURL DriveFileSyncClient::DirectoryTitleToOrigin(const std::string& title) { |
369 return extensions::Extension::GetBaseURLFromExtensionId(title); | 383 return extensions::Extension::GetBaseURLFromExtensionId(title); |
370 } | 384 } |
371 | 385 |
| 386 void DriveFileSyncClient::OnReadyToPerformOperations() { |
| 387 DCHECK(CalledOnValidThread()); |
| 388 FOR_EACH_OBSERVER(DriveFileSyncClientObserver, observers_, OnAuthenticated()); |
| 389 } |
| 390 |
372 void DriveFileSyncClient::DidGetDocumentFeedData( | 391 void DriveFileSyncClient::DidGetDocumentFeedData( |
373 const DocumentFeedCallback& callback, | 392 const DocumentFeedCallback& callback, |
374 google_apis::GDataErrorCode error, | 393 google_apis::GDataErrorCode error, |
375 scoped_ptr<base::Value> data) { | 394 scoped_ptr<base::Value> data) { |
376 DCHECK(CalledOnValidThread()); | 395 DCHECK(CalledOnValidThread()); |
377 | 396 |
378 if (error != google_apis::HTTP_SUCCESS) { | 397 if (error != google_apis::HTTP_SUCCESS) { |
379 callback.Run(error, scoped_ptr<google_apis::DocumentFeed>()); | 398 callback.Run(error, scoped_ptr<google_apis::DocumentFeed>()); |
380 return; | 399 return; |
381 } | 400 } |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 } | 630 } |
612 | 631 |
613 void DriveFileSyncClient::DidDeleteFile( | 632 void DriveFileSyncClient::DidDeleteFile( |
614 const GDataErrorCallback& callback, | 633 const GDataErrorCallback& callback, |
615 google_apis::GDataErrorCode error) { | 634 google_apis::GDataErrorCode error) { |
616 DCHECK(CalledOnValidThread()); | 635 DCHECK(CalledOnValidThread()); |
617 callback.Run(error); | 636 callback.Run(error); |
618 } | 637 } |
619 | 638 |
620 } // namespace sync_file_system | 639 } // namespace sync_file_system |
OLD | NEW |