Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(447)

Side by Side Diff: chrome/browser/sync_file_system/drive_file_sync_client.cc

Issue 11414253: DriveFileSyncService listens to OnAuthenticated event to recover from unavailable state (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 return NULL; 61 return NULL;
62 } 62 }
63 63
64 } // namespace 64 } // namespace
65 65
66 DriveFileSyncClient::DriveFileSyncClient(Profile* profile) { 66 DriveFileSyncClient::DriveFileSyncClient(Profile* profile) {
67 drive_service_.reset(new google_apis::GDataWapiService( 67 drive_service_.reset(new google_apis::GDataWapiService(
68 GURL(google_apis::GDataWapiUrlGenerator::kBaseUrlForProduction), 68 GURL(google_apis::GDataWapiUrlGenerator::kBaseUrlForProduction),
69 "" /* custom_user_agent */)); 69 "" /* custom_user_agent */));
70 drive_service_->Initialize(profile); 70 drive_service_->Initialize(profile);
71 drive_service_->AddObserver(this);
71 72
72 drive_uploader_.reset(new google_apis::DriveUploader(drive_service_.get())); 73 drive_uploader_.reset(new google_apis::DriveUploader(drive_service_.get()));
73 } 74 }
74 75
75 scoped_ptr<DriveFileSyncClient> DriveFileSyncClient::CreateForTesting( 76 scoped_ptr<DriveFileSyncClient> DriveFileSyncClient::CreateForTesting(
76 Profile* profile, 77 Profile* profile,
77 scoped_ptr<google_apis::DriveServiceInterface> drive_service, 78 scoped_ptr<google_apis::DriveServiceInterface> drive_service,
78 scoped_ptr<google_apis::DriveUploaderInterface> drive_uploader) { 79 scoped_ptr<google_apis::DriveUploaderInterface> drive_uploader) {
79 return make_scoped_ptr(new DriveFileSyncClient( 80 return make_scoped_ptr(new DriveFileSyncClient(
80 profile, drive_service.Pass(), drive_uploader.Pass())); 81 profile, drive_service.Pass(), drive_uploader.Pass()));
81 } 82 }
82 83
83 DriveFileSyncClient::DriveFileSyncClient( 84 DriveFileSyncClient::DriveFileSyncClient(
84 Profile* profile, 85 Profile* profile,
85 scoped_ptr<google_apis::DriveServiceInterface> drive_service, 86 scoped_ptr<google_apis::DriveServiceInterface> drive_service,
86 scoped_ptr<google_apis::DriveUploaderInterface> drive_uploader) { 87 scoped_ptr<google_apis::DriveUploaderInterface> drive_uploader) {
87 drive_service_ = drive_service.Pass(); 88 drive_service_ = drive_service.Pass();
88 drive_service_->Initialize(profile); 89 drive_service_->Initialize(profile);
90 drive_service_->AddObserver(this);
89 91
90 drive_uploader_ = drive_uploader.Pass(); 92 drive_uploader_ = drive_uploader.Pass();
91 } 93 }
92 94
93 DriveFileSyncClient::~DriveFileSyncClient() { 95 DriveFileSyncClient::~DriveFileSyncClient() {
94 DCHECK(CalledOnValidThread()); 96 DCHECK(CalledOnValidThread());
97 drive_service_->RemoveObserver(this);
95 drive_service_->CancelAll(); 98 drive_service_->CancelAll();
96 } 99 }
97 100
101 void DriveFileSyncClient::AddObserver(DriveFileSyncClientObserver* observer) {
102 DCHECK(CalledOnValidThread());
103 observers_.AddObserver(observer);
104 }
105
106 void DriveFileSyncClient::RemoveObserver(
107 DriveFileSyncClientObserver* observer) {
108 DCHECK(CalledOnValidThread());
109 observers_.RemoveObserver(observer);
110 }
111
98 void DriveFileSyncClient::GetDriveDirectoryForSyncRoot( 112 void DriveFileSyncClient::GetDriveDirectoryForSyncRoot(
99 const ResourceIdCallback& callback) { 113 const ResourceIdCallback& callback) {
100 DCHECK(CalledOnValidThread()); 114 DCHECK(CalledOnValidThread());
101 115
102 std::string directory_name(kSyncRootDirectoryName); 116 std::string directory_name(kSyncRootDirectoryName);
103 SearchFilesInDirectory( 117 SearchFilesInDirectory(
104 kRootResourceId, 118 kRootResourceId,
105 FormatTitleQuery(directory_name), 119 FormatTitleQuery(directory_name),
106 base::Bind(&DriveFileSyncClient::DidGetDirectory, AsWeakPtr(), 120 base::Bind(&DriveFileSyncClient::DidGetDirectory, AsWeakPtr(),
107 kRootResourceId, directory_name, callback)); 121 kRootResourceId, directory_name, callback));
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 const GDataErrorCallback& callback) { 363 const GDataErrorCallback& callback) {
350 DCHECK(CalledOnValidThread()); 364 DCHECK(CalledOnValidThread());
351 drive_service_->GetDocumentEntry( 365 drive_service_->GetDocumentEntry(
352 resource_id, 366 resource_id,
353 base::Bind(&DriveFileSyncClient::DidGetDocumentEntryData, 367 base::Bind(&DriveFileSyncClient::DidGetDocumentEntryData,
354 AsWeakPtr(), 368 AsWeakPtr(),
355 base::Bind(&DriveFileSyncClient::DeleteFileInternal, 369 base::Bind(&DriveFileSyncClient::DeleteFileInternal,
356 AsWeakPtr(), remote_file_md5, callback))); 370 AsWeakPtr(), remote_file_md5, callback)));
357 } 371 }
358 372
373 void DriveFileSyncClient::OnReadyToPerformOperations() {
374 DCHECK(CalledOnValidThread());
375 FOR_EACH_OBSERVER(DriveFileSyncClientObserver, observers_, OnAuthenticated());
376 }
377
359 void DriveFileSyncClient::DidGetDocumentFeedData( 378 void DriveFileSyncClient::DidGetDocumentFeedData(
360 const DocumentFeedCallback& callback, 379 const DocumentFeedCallback& callback,
361 google_apis::GDataErrorCode error, 380 google_apis::GDataErrorCode error,
362 scoped_ptr<base::Value> data) { 381 scoped_ptr<base::Value> data) {
363 DCHECK(CalledOnValidThread()); 382 DCHECK(CalledOnValidThread());
364 383
365 if (error != google_apis::HTTP_SUCCESS) { 384 if (error != google_apis::HTTP_SUCCESS) {
366 callback.Run(error, scoped_ptr<google_apis::DocumentFeed>()); 385 callback.Run(error, scoped_ptr<google_apis::DocumentFeed>());
367 return; 386 return;
368 } 387 }
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 } 617 }
599 618
600 void DriveFileSyncClient::DidDeleteFile( 619 void DriveFileSyncClient::DidDeleteFile(
601 const GDataErrorCallback& callback, 620 const GDataErrorCallback& callback,
602 google_apis::GDataErrorCode error) { 621 google_apis::GDataErrorCode error) {
603 DCHECK(CalledOnValidThread()); 622 DCHECK(CalledOnValidThread());
604 callback.Run(error); 623 callback.Run(error);
605 } 624 }
606 625
607 } // namespace sync_file_system 626 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698