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

Side by Side Diff: chrome/browser/sync_file_system/drive_backend/sync_worker.cc

Issue 309253002: [SyncFS] SyncWorker cache refresh token status (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rename again Created 6 years, 6 months 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
« no previous file with comments | « chrome/browser/sync_file_system/drive_backend/sync_worker.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_backend/sync_worker.h" 5 #include "chrome/browser/sync_file_system/drive_backend/sync_worker.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 service_state_(REMOTE_SERVICE_TEMPORARY_UNAVAILABLE), 95 service_state_(REMOTE_SERVICE_TEMPORARY_UNAVAILABLE),
96 should_check_conflict_(true), 96 should_check_conflict_(true),
97 should_check_remote_change_(true), 97 should_check_remote_change_(true),
98 listing_remote_changes_(false), 98 listing_remote_changes_(false),
99 sync_enabled_(false), 99 sync_enabled_(false),
100 default_conflict_resolution_policy_( 100 default_conflict_resolution_policy_(
101 CONFLICT_RESOLUTION_POLICY_LAST_WRITE_WIN), 101 CONFLICT_RESOLUTION_POLICY_LAST_WRITE_WIN),
102 network_available_(false), 102 network_available_(false),
103 extension_service_(extension_service), 103 extension_service_(extension_service),
104 context_(sync_engine_context.Pass()), 104 context_(sync_engine_context.Pass()),
105 has_refresh_token_(false),
105 weak_ptr_factory_(this) {} 106 weak_ptr_factory_(this) {}
106 107
107 SyncWorker::~SyncWorker() {} 108 SyncWorker::~SyncWorker() {}
108 109
109 void SyncWorker::Initialize() { 110 void SyncWorker::Initialize() {
110 DCHECK(!task_manager_); 111 DCHECK(!task_manager_);
111 112
112 task_manager_.reset(new SyncTaskManager( 113 task_manager_.reset(new SyncTaskManager(
113 weak_ptr_factory_.GetWeakPtr(), 0 /* maximum_background_task */)); 114 weak_ptr_factory_.GetWeakPtr(), 0 /* maximum_background_task */));
114 task_manager_->Initialize(SYNC_STATUS_OK); 115 task_manager_->Initialize(SYNC_STATUS_OK);
115 116
116 PostInitializeTask(); 117 PostInitializeTask();
117 118
118 net::NetworkChangeNotifier::ConnectionType type = 119 net::NetworkChangeNotifier::ConnectionType type =
119 net::NetworkChangeNotifier::GetConnectionType(); 120 net::NetworkChangeNotifier::GetConnectionType();
120 network_available_ = 121 network_available_ =
121 type != net::NetworkChangeNotifier::CONNECTION_NONE; 122 type != net::NetworkChangeNotifier::CONNECTION_NONE;
122 } 123 }
123 124
124 void SyncWorker::RegisterOrigin( 125 void SyncWorker::RegisterOrigin(
125 const GURL& origin, 126 const GURL& origin,
126 const SyncStatusCallback& callback) { 127 const SyncStatusCallback& callback) {
127 if (!GetMetadataDatabase() && GetDriveService()->HasRefreshToken()) 128 if (!GetMetadataDatabase() && has_refresh_token_)
128 PostInitializeTask(); 129 PostInitializeTask();
129 130
130 scoped_ptr<RegisterAppTask> task( 131 scoped_ptr<RegisterAppTask> task(
131 new RegisterAppTask(context_.get(), origin.host())); 132 new RegisterAppTask(context_.get(), origin.host()));
132 if (task->CanFinishImmediately()) { 133 if (task->CanFinishImmediately()) {
133 context_->GetUITaskRunner()->PostTask( 134 context_->GetUITaskRunner()->PostTask(
134 FROM_HERE, base::Bind(callback, SYNC_STATUS_OK)); 135 FROM_HERE, base::Bind(callback, SYNC_STATUS_OK));
135 return; 136 return;
136 } 137 }
137 138
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 340
340 void SyncWorker::OnNotificationReceived() { 341 void SyncWorker::OnNotificationReceived() {
341 if (service_state_ == REMOTE_SERVICE_TEMPORARY_UNAVAILABLE) 342 if (service_state_ == REMOTE_SERVICE_TEMPORARY_UNAVAILABLE)
342 UpdateServiceState(REMOTE_SERVICE_OK, "Got push notification for Drive."); 343 UpdateServiceState(REMOTE_SERVICE_OK, "Got push notification for Drive.");
343 344
344 should_check_remote_change_ = true; 345 should_check_remote_change_ = true;
345 MaybeScheduleNextTask(); 346 MaybeScheduleNextTask();
346 } 347 }
347 348
348 void SyncWorker::OnReadyToSendRequests(const std::string& account_id) { 349 void SyncWorker::OnReadyToSendRequests(const std::string& account_id) {
350 has_refresh_token_ = true;
349 if (service_state_ == REMOTE_SERVICE_OK) 351 if (service_state_ == REMOTE_SERVICE_OK)
350 return; 352 return;
351 UpdateServiceState(REMOTE_SERVICE_OK, "Authenticated"); 353 UpdateServiceState(REMOTE_SERVICE_OK, "Authenticated");
352 354
353 if (!GetMetadataDatabase() && !account_id.empty()) { 355 if (!GetMetadataDatabase() && !account_id.empty()) {
354 GetDriveService()->Initialize(account_id); 356 GetDriveService()->Initialize(account_id);
355 PostInitializeTask(); 357 PostInitializeTask();
356 return; 358 return;
357 } 359 }
358 360
359 should_check_remote_change_ = true; 361 should_check_remote_change_ = true;
360 MaybeScheduleNextTask(); 362 MaybeScheduleNextTask();
361 } 363 }
362 364
363 void SyncWorker::OnRefreshTokenInvalid() { 365 void SyncWorker::OnRefreshTokenInvalid() {
366 has_refresh_token_ = false;
367
364 UpdateServiceState( 368 UpdateServiceState(
365 REMOTE_SERVICE_AUTHENTICATION_REQUIRED, 369 REMOTE_SERVICE_AUTHENTICATION_REQUIRED,
366 "Found invalid refresh token."); 370 "Found invalid refresh token.");
367 } 371 }
368 372
369 void SyncWorker::OnNetworkChanged( 373 void SyncWorker::OnNetworkChanged(
370 net::NetworkChangeNotifier::ConnectionType type) { 374 net::NetworkChangeNotifier::ConnectionType type) {
371 bool new_network_availability = 375 bool new_network_availability =
372 type != net::NetworkChangeNotifier::CONNECTION_NONE; 376 type != net::NetworkChangeNotifier::CONNECTION_NONE;
373 377
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 scoped_ptr<SyncTask>(initializer), 439 scoped_ptr<SyncTask>(initializer),
436 SyncTaskManager::PRIORITY_HIGH, 440 SyncTaskManager::PRIORITY_HIGH,
437 base::Bind(&SyncWorker::DidInitialize, 441 base::Bind(&SyncWorker::DidInitialize,
438 weak_ptr_factory_.GetWeakPtr(), 442 weak_ptr_factory_.GetWeakPtr(),
439 initializer)); 443 initializer));
440 } 444 }
441 445
442 void SyncWorker::DidInitialize(SyncEngineInitializer* initializer, 446 void SyncWorker::DidInitialize(SyncEngineInitializer* initializer,
443 SyncStatusCode status) { 447 SyncStatusCode status) {
444 if (status != SYNC_STATUS_OK) { 448 if (status != SYNC_STATUS_OK) {
445 if (GetDriveService()->HasRefreshToken()) { 449 if (has_refresh_token_) {
446 UpdateServiceState(REMOTE_SERVICE_TEMPORARY_UNAVAILABLE, 450 UpdateServiceState(REMOTE_SERVICE_TEMPORARY_UNAVAILABLE,
447 "Could not initialize remote service"); 451 "Could not initialize remote service");
448 } else { 452 } else {
449 UpdateServiceState(REMOTE_SERVICE_AUTHENTICATION_REQUIRED, 453 UpdateServiceState(REMOTE_SERVICE_AUTHENTICATION_REQUIRED,
450 "Authentication required."); 454 "Authentication required.");
451 } 455 }
452 return; 456 return;
453 } 457 }
454 458
455 scoped_ptr<MetadataDatabase> metadata_database = 459 scoped_ptr<MetadataDatabase> metadata_database =
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 case SYNC_STATUS_ACCESS_FORBIDDEN: 668 case SYNC_STATUS_ACCESS_FORBIDDEN:
665 UpdateServiceState(REMOTE_SERVICE_AUTHENTICATION_REQUIRED, 669 UpdateServiceState(REMOTE_SERVICE_AUTHENTICATION_REQUIRED,
666 "Access forbidden"); 670 "Access forbidden");
667 break; 671 break;
668 672
669 // Errors which could make the service temporarily unavailable. 673 // Errors which could make the service temporarily unavailable.
670 case SYNC_STATUS_SERVICE_TEMPORARILY_UNAVAILABLE: 674 case SYNC_STATUS_SERVICE_TEMPORARILY_UNAVAILABLE:
671 case SYNC_STATUS_NETWORK_ERROR: 675 case SYNC_STATUS_NETWORK_ERROR:
672 case SYNC_STATUS_ABORT: 676 case SYNC_STATUS_ABORT:
673 case SYNC_STATUS_FAILED: 677 case SYNC_STATUS_FAILED:
674 if (GetDriveService()->HasRefreshToken()) { 678 if (has_refresh_token_) {
675 UpdateServiceState(REMOTE_SERVICE_TEMPORARY_UNAVAILABLE, 679 UpdateServiceState(REMOTE_SERVICE_TEMPORARY_UNAVAILABLE,
676 "Network or temporary service error."); 680 "Network or temporary service error.");
677 } else { 681 } else {
678 UpdateServiceState(REMOTE_SERVICE_AUTHENTICATION_REQUIRED, 682 UpdateServiceState(REMOTE_SERVICE_AUTHENTICATION_REQUIRED,
679 "Authentication required"); 683 "Authentication required");
680 } 684 }
681 break; 685 break;
682 686
683 // Errors which would require manual user intervention to resolve. 687 // Errors which would require manual user intervention to resolve.
684 case SYNC_DATABASE_ERROR_CORRUPTION: 688 case SYNC_DATABASE_ERROR_CORRUPTION:
(...skipping 21 matching lines...) Expand all
706 "Service state changed: %d->%d: %s", 710 "Service state changed: %d->%d: %s",
707 old_state, GetCurrentState(), description.c_str()); 711 old_state, GetCurrentState(), description.c_str());
708 712
709 FOR_EACH_OBSERVER( 713 FOR_EACH_OBSERVER(
710 Observer, observers_, 714 Observer, observers_,
711 UpdateServiceState(GetCurrentState(), description)); 715 UpdateServiceState(GetCurrentState(), description));
712 } 716 }
713 717
714 } // namespace drive_backend 718 } // namespace drive_backend
715 } // namespace sync_file_system 719 } // namespace sync_file_system
OLDNEW
« no previous file with comments | « chrome/browser/sync_file_system/drive_backend/sync_worker.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698