Commit b695df63 authored by nhiroki@chromium.org's avatar nhiroki@chromium.org

DriveFileSyncService listens to OnNetworkConnected event to restart synchronization

BUG=161436
TEST=manual (Launch test app -> Disconnect network -> Connect network -> Receive notification)

Review URL: https://codereview.chromium.org/11419281

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@170931 0039d316-1c4b-4281-b951-d872f2087c98
parent 8ab0b01d
......@@ -71,6 +71,7 @@ DriveFileSyncClient::DriveFileSyncClient(Profile* profile)
"" /* custom_user_agent */));
drive_service_->Initialize(profile);
drive_service_->AddObserver(this);
net::NetworkChangeNotifier::AddConnectionTypeObserver(this);
drive_uploader_.reset(new google_apis::DriveUploader(drive_service_.get()));
}
......@@ -93,12 +94,14 @@ DriveFileSyncClient::DriveFileSyncClient(
drive_service_ = drive_service.Pass();
drive_service_->Initialize(profile);
drive_service_->AddObserver(this);
net::NetworkChangeNotifier::AddConnectionTypeObserver(this);
drive_uploader_ = drive_uploader.Pass();
}
DriveFileSyncClient::~DriveFileSyncClient() {
DCHECK(CalledOnValidThread());
net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this);
drive_service_->RemoveObserver(this);
drive_service_->CancelAll();
}
......@@ -399,6 +402,14 @@ void DriveFileSyncClient::OnReadyToPerformOperations() {
FOR_EACH_OBSERVER(DriveFileSyncClientObserver, observers_, OnAuthenticated());
}
void DriveFileSyncClient::OnConnectionTypeChanged(
net::NetworkChangeNotifier::ConnectionType type) {
DCHECK(CalledOnValidThread());
if (type != net::NetworkChangeNotifier::CONNECTION_NONE)
FOR_EACH_OBSERVER(DriveFileSyncClientObserver,
observers_, OnNetworkConnected());
}
void DriveFileSyncClient::DidGetDocumentFeedData(
const DocumentFeedCallback& callback,
google_apis::GDataErrorCode error,
......
......@@ -17,6 +17,7 @@
#include "chrome/browser/google_apis/gdata_errorcode.h"
#include "chrome/browser/google_apis/gdata_wapi_parser.h"
#include "chrome/browser/google_apis/gdata_wapi_url_generator.h"
#include "net/base/network_change_notifier.h"
class GURL;
class Profile;
......@@ -32,6 +33,7 @@ class DriveFileSyncClientObserver {
DriveFileSyncClientObserver() {}
virtual ~DriveFileSyncClientObserver() {}
virtual void OnAuthenticated() = 0;
virtual void OnNetworkConnected() = 0;
private:
DISALLOW_COPY_AND_ASSIGN(DriveFileSyncClientObserver);
......@@ -40,9 +42,11 @@ class DriveFileSyncClientObserver {
// This class is responsible for talking to the Drive service to get and put
// Drive directories, files and metadata.
// This class is owned by DriveFileSyncService.
class DriveFileSyncClient : public google_apis::DriveServiceObserver,
public base::NonThreadSafe,
public base::SupportsWeakPtr<DriveFileSyncClient> {
class DriveFileSyncClient
: public google_apis::DriveServiceObserver,
public net::NetworkChangeNotifier::ConnectionTypeObserver,
public base::NonThreadSafe,
public base::SupportsWeakPtr<DriveFileSyncClient> {
public:
typedef base::Callback<void(google_apis::GDataErrorCode error)>
GDataErrorCallback;
......@@ -176,6 +180,10 @@ class DriveFileSyncClient : public google_apis::DriveServiceObserver,
// DriveServiceObserver overrides.
virtual void OnReadyToPerformOperations() OVERRIDE;
// ConnectionTypeObserver overrides.
virtual void OnConnectionTypeChanged(
net::NetworkChangeNotifier::ConnectionType type) OVERRIDE;
private:
friend class DriveFileSyncClientTest;
friend class DriveFileSyncServiceTest;
......
......@@ -540,6 +540,17 @@ void DriveFileSyncService::OnAuthenticated() {
}
}
void DriveFileSyncService::OnNetworkConnected() {
DVLOG(1) << "OnNetworkConnected";
if (state_ == REMOTE_SERVICE_AUTHENTICATION_REQUIRED ||
state_ == REMOTE_SERVICE_TEMPORARY_UNAVAILABLE) {
state_ = REMOTE_SERVICE_OK;
FOR_EACH_OBSERVER(
Observer, observers_,
OnRemoteServiceStateUpdated(state_, "Network connected"));
}
}
// Called by CreateForTesting.
DriveFileSyncService::DriveFileSyncService(
const FilePath& base_dir,
......
......@@ -88,6 +88,7 @@ class DriveFileSyncService
// DriveFileSyncClientObserver overrides.
virtual void OnAuthenticated() OVERRIDE;
virtual void OnNetworkConnected() OVERRIDE;
private:
friend class DriveFileSyncServiceTest;
......@@ -178,7 +179,6 @@ class DriveFileSyncService
void UpdateServiceState();
base::WeakPtr<DriveFileSyncService> AsWeakPtr();
void DidGetRemoteFileMetadata(
const fileapi::SyncFileMetadataCallback& callback,
google_apis::GDataErrorCode error,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment