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

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

Issue 11419281: DriveFileSyncService listens to OnNetworkConnected event to restart synchronization (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 drive_service_->AddObserver(this);
72 net::NetworkChangeNotifier::AddConnectionTypeObserver(this);
72 73
73 drive_uploader_.reset(new google_apis::DriveUploader(drive_service_.get())); 74 drive_uploader_.reset(new google_apis::DriveUploader(drive_service_.get()));
74 } 75 }
75 76
76 scoped_ptr<DriveFileSyncClient> DriveFileSyncClient::CreateForTesting( 77 scoped_ptr<DriveFileSyncClient> DriveFileSyncClient::CreateForTesting(
77 Profile* profile, 78 Profile* profile,
78 scoped_ptr<google_apis::DriveServiceInterface> drive_service, 79 scoped_ptr<google_apis::DriveServiceInterface> drive_service,
79 scoped_ptr<google_apis::DriveUploaderInterface> drive_uploader) { 80 scoped_ptr<google_apis::DriveUploaderInterface> drive_uploader) {
80 return make_scoped_ptr(new DriveFileSyncClient( 81 return make_scoped_ptr(new DriveFileSyncClient(
81 profile, drive_service.Pass(), drive_uploader.Pass())); 82 profile, drive_service.Pass(), drive_uploader.Pass()));
82 } 83 }
83 84
84 DriveFileSyncClient::DriveFileSyncClient( 85 DriveFileSyncClient::DriveFileSyncClient(
85 Profile* profile, 86 Profile* profile,
86 scoped_ptr<google_apis::DriveServiceInterface> drive_service, 87 scoped_ptr<google_apis::DriveServiceInterface> drive_service,
87 scoped_ptr<google_apis::DriveUploaderInterface> drive_uploader) { 88 scoped_ptr<google_apis::DriveUploaderInterface> drive_uploader) {
88 drive_service_ = drive_service.Pass(); 89 drive_service_ = drive_service.Pass();
89 drive_service_->Initialize(profile); 90 drive_service_->Initialize(profile);
90 drive_service_->AddObserver(this); 91 drive_service_->AddObserver(this);
92 net::NetworkChangeNotifier::AddConnectionTypeObserver(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 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this);
97 drive_service_->RemoveObserver(this); 100 drive_service_->RemoveObserver(this);
98 drive_service_->CancelAll(); 101 drive_service_->CancelAll();
99 } 102 }
100 103
101 void DriveFileSyncClient::AddObserver(DriveFileSyncClientObserver* observer) { 104 void DriveFileSyncClient::AddObserver(DriveFileSyncClientObserver* observer) {
102 DCHECK(CalledOnValidThread()); 105 DCHECK(CalledOnValidThread());
103 observers_.AddObserver(observer); 106 observers_.AddObserver(observer);
104 } 107 }
105 108
106 void DriveFileSyncClient::RemoveObserver( 109 void DriveFileSyncClient::RemoveObserver(
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 AsWeakPtr(), 371 AsWeakPtr(),
369 base::Bind(&DriveFileSyncClient::DeleteFileInternal, 372 base::Bind(&DriveFileSyncClient::DeleteFileInternal,
370 AsWeakPtr(), remote_file_md5, callback))); 373 AsWeakPtr(), remote_file_md5, callback)));
371 } 374 }
372 375
373 void DriveFileSyncClient::OnReadyToPerformOperations() { 376 void DriveFileSyncClient::OnReadyToPerformOperations() {
374 DCHECK(CalledOnValidThread()); 377 DCHECK(CalledOnValidThread());
375 FOR_EACH_OBSERVER(DriveFileSyncClientObserver, observers_, OnAuthenticated()); 378 FOR_EACH_OBSERVER(DriveFileSyncClientObserver, observers_, OnAuthenticated());
376 } 379 }
377 380
381 void DriveFileSyncClient::OnConnectionTypeChanged(
382 net::NetworkChangeNotifier::ConnectionType type) {
383 DCHECK(CalledOnValidThread());
384 if (type != net::NetworkChangeNotifier::CONNECTION_NONE)
385 FOR_EACH_OBSERVER(DriveFileSyncClientObserver,
386 observers_, OnNetworkConnected());
387 }
388
378 void DriveFileSyncClient::DidGetDocumentFeedData( 389 void DriveFileSyncClient::DidGetDocumentFeedData(
379 const DocumentFeedCallback& callback, 390 const DocumentFeedCallback& callback,
380 google_apis::GDataErrorCode error, 391 google_apis::GDataErrorCode error,
381 scoped_ptr<base::Value> data) { 392 scoped_ptr<base::Value> data) {
382 DCHECK(CalledOnValidThread()); 393 DCHECK(CalledOnValidThread());
383 394
384 if (error != google_apis::HTTP_SUCCESS) { 395 if (error != google_apis::HTTP_SUCCESS) {
385 callback.Run(error, scoped_ptr<google_apis::DocumentFeed>()); 396 callback.Run(error, scoped_ptr<google_apis::DocumentFeed>());
386 return; 397 return;
387 } 398 }
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 } 628 }
618 629
619 void DriveFileSyncClient::DidDeleteFile( 630 void DriveFileSyncClient::DidDeleteFile(
620 const GDataErrorCallback& callback, 631 const GDataErrorCallback& callback,
621 google_apis::GDataErrorCode error) { 632 google_apis::GDataErrorCode error) {
622 DCHECK(CalledOnValidThread()); 633 DCHECK(CalledOnValidThread());
623 callback.Run(error); 634 callback.Run(error);
624 } 635 }
625 636
626 } // namespace sync_file_system 637 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698