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

Side by Side Diff: chrome/browser/chromeos/drive/drive_integration_service.cc

Issue 23548025: Introduce State to DriveIntegrationService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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
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/chromeos/drive/drive_integration_service.h" 5 #include "chrome/browser/chromeos/drive/drive_integration_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 } 132 }
133 133
134 } // namespace 134 } // namespace
135 135
136 DriveIntegrationService::DriveIntegrationService( 136 DriveIntegrationService::DriveIntegrationService(
137 Profile* profile, 137 Profile* profile,
138 DriveServiceInterface* test_drive_service, 138 DriveServiceInterface* test_drive_service,
139 const base::FilePath& test_cache_root, 139 const base::FilePath& test_cache_root,
140 FileSystemInterface* test_file_system) 140 FileSystemInterface* test_file_system)
141 : profile_(profile), 141 : profile_(profile),
142 is_initialized_(false), 142 state_(NOT_INITIALIZED),
143 cache_root_directory_(!test_cache_root.empty() ? 143 cache_root_directory_(!test_cache_root.empty() ?
144 test_cache_root : util::GetCacheRootPath(profile)), 144 test_cache_root : util::GetCacheRootPath(profile)),
145 weak_ptr_factory_(this) { 145 weak_ptr_factory_(this) {
146 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 146 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
147 147
148 base::SequencedWorkerPool* blocking_pool = BrowserThread::GetBlockingPool(); 148 base::SequencedWorkerPool* blocking_pool = BrowserThread::GetBlockingPool();
149 blocking_task_runner_ = blocking_pool->GetSequencedTaskRunner( 149 blocking_task_runner_ = blocking_pool->GetSequencedTaskRunner(
150 blocking_pool->GetSequenceToken()); 150 blocking_pool->GetSequenceToken());
151 151
152 OAuth2TokenService* oauth_service = 152 OAuth2TokenService* oauth_service =
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 debug_info_collector_.reset( 202 debug_info_collector_.reset(
203 new DebugInfoCollector(file_system(), cache_.get())); 203 new DebugInfoCollector(file_system(), cache_.get()));
204 } 204 }
205 205
206 DriveIntegrationService::~DriveIntegrationService() { 206 DriveIntegrationService::~DriveIntegrationService() {
207 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 207 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
208 } 208 }
209 209
210 void DriveIntegrationService::Initialize() { 210 void DriveIntegrationService::Initialize() {
211 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 211 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
212 DCHECK_EQ(NOT_INITIALIZED, state_);
213
214 state_ = INITIALIZING;
212 drive_service_->Initialize(); 215 drive_service_->Initialize();
213 file_system_->Initialize(); 216 file_system_->Initialize();
214 217
215 base::PostTaskAndReplyWithResult( 218 base::PostTaskAndReplyWithResult(
216 blocking_task_runner_.get(), 219 blocking_task_runner_.get(),
217 FROM_HERE, 220 FROM_HERE,
218 base::Bind(&InitializeMetadata, 221 base::Bind(&InitializeMetadata,
219 cache_root_directory_, 222 cache_root_directory_,
220 metadata_storage_.get(), 223 metadata_storage_.get(),
221 cache_.get(), 224 cache_.get(),
222 resource_metadata_.get()), 225 resource_metadata_.get()),
223 base::Bind(&DriveIntegrationService::InitializeAfterMetadataInitialized, 226 base::Bind(&DriveIntegrationService::InitializeAfterMetadataInitialized,
224 weak_ptr_factory_.GetWeakPtr())); 227 weak_ptr_factory_.GetWeakPtr()));
225 } 228 }
226 229
227 void DriveIntegrationService::Shutdown() { 230 void DriveIntegrationService::Shutdown() {
228 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 231 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
229 232
233 weak_ptr_factory_.InvalidateWeakPtrs();
234
230 DriveNotificationManager* drive_notification_manager = 235 DriveNotificationManager* drive_notification_manager =
231 DriveNotificationManagerFactory::GetForBrowserContext(profile_); 236 DriveNotificationManagerFactory::GetForBrowserContext(profile_);
232 if (drive_notification_manager) 237 if (drive_notification_manager)
233 drive_notification_manager->RemoveObserver(this); 238 drive_notification_manager->RemoveObserver(this);
234 239
235 RemoveDriveMountPoint(); 240 RemoveDriveMountPoint();
236 debug_info_collector_.reset(); 241 debug_info_collector_.reset();
237 download_handler_.reset(); 242 download_handler_.reset();
238 file_system_.reset(); 243 file_system_.reset();
239 drive_app_registry_.reset(); 244 drive_app_registry_.reset();
(...skipping 25 matching lines...) Expand all
265 const char* status = (enabled ? "enabled" : "disabled"); 270 const char* status = (enabled ? "enabled" : "disabled");
266 util::Log(logging::LOG_INFO, "Push notification is %s", status); 271 util::Log(logging::LOG_INFO, "Push notification is %s", status);
267 } 272 }
268 273
269 bool DriveIntegrationService::IsDriveEnabled() { 274 bool DriveIntegrationService::IsDriveEnabled() {
270 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 275 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
271 276
272 if (!util::IsDriveEnabledForProfile(profile_)) 277 if (!util::IsDriveEnabledForProfile(profile_))
273 return false; 278 return false;
274 279
275 return is_initialized_; 280 // For backword compatibility, REMOUNTING also means enabled.
281 return state_ == INITIALIZED || state_ == REMOUNTING;
276 } 282 }
277 283
278 void DriveIntegrationService::ClearCacheAndRemountFileSystem( 284 void DriveIntegrationService::ClearCacheAndRemountFileSystem(
279 const base::Callback<void(bool)>& callback) { 285 const base::Callback<void(bool)>& callback) {
280 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 286 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
281 DCHECK(!callback.is_null()); 287 DCHECK(!callback.is_null());
282 288
289 if (state_ != INITIALIZED) {
290 callback.Run(false);
291 return;
292 }
293
294 state_ = REMOUNTING;
295
283 RemoveDriveMountPoint(); 296 RemoveDriveMountPoint();
284 // Reloading the file system will clear the resource metadata. 297 // Reloading the file system will clear the resource metadata.
285 file_system_->Reload(); 298 file_system_->Reload();
286 // Reload the Drive app registry too. 299 // Reload the Drive app registry too.
287 drive_app_registry_->Update(); 300 drive_app_registry_->Update();
288 301
289 cache_->ClearAllOnUIThread(base::Bind( 302 cache_->ClearAllOnUIThread(base::Bind(
290 &DriveIntegrationService::AddBackDriveMountPoint, 303 &DriveIntegrationService::AddBackDriveMountPoint,
291 weak_ptr_factory_.GetWeakPtr(), 304 weak_ptr_factory_.GetWeakPtr(),
292 callback)); 305 callback));
(...skipping 24 matching lines...) Expand all
317 fileapi::ExternalMountPoints* mount_points = 330 fileapi::ExternalMountPoints* mount_points =
318 BrowserContext::GetMountPoints(profile_); 331 BrowserContext::GetMountPoints(profile_);
319 DCHECK(mount_points); 332 DCHECK(mount_points);
320 333
321 bool success = mount_points->RegisterFileSystem( 334 bool success = mount_points->RegisterFileSystem(
322 drive_mount_point.BaseName().AsUTF8Unsafe(), 335 drive_mount_point.BaseName().AsUTF8Unsafe(),
323 fileapi::kFileSystemTypeDrive, 336 fileapi::kFileSystemTypeDrive,
324 drive_mount_point); 337 drive_mount_point);
325 338
326 if (success) { 339 if (success) {
340 state_ = INITIALIZED;
327 util::Log(logging::LOG_INFO, "Drive mount point is added"); 341 util::Log(logging::LOG_INFO, "Drive mount point is added");
328 FOR_EACH_OBSERVER(DriveIntegrationServiceObserver, observers_, 342 FOR_EACH_OBSERVER(DriveIntegrationServiceObserver, observers_,
329 OnFileSystemMounted()); 343 OnFileSystemMounted());
344 } else {
345 state_ = NOT_INITIALIZED;
330 } 346 }
331 } 347 }
332 348
333 void DriveIntegrationService::RemoveDriveMountPoint() { 349 void DriveIntegrationService::RemoveDriveMountPoint() {
334 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 350 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
335 351
336 job_list()->CancelAllJobs(); 352 job_list()->CancelAllJobs();
337 353
338 FOR_EACH_OBSERVER(DriveIntegrationServiceObserver, observers_, 354 FOR_EACH_OBSERVER(DriveIntegrationServiceObserver, observers_,
339 OnFileSystemBeingUnmounted()); 355 OnFileSystemBeingUnmounted());
(...skipping 15 matching lines...) Expand all
355 LOG(WARNING) << "Failed to initialize: " << FileErrorToString(error); 371 LOG(WARNING) << "Failed to initialize: " << FileErrorToString(error);
356 372
357 // Change the download directory to the default value if the download 373 // Change the download directory to the default value if the download
358 // destination is set to under Drive mount point. 374 // destination is set to under Drive mount point.
359 PrefService* pref_service = profile_->GetPrefs(); 375 PrefService* pref_service = profile_->GetPrefs();
360 if (util::IsUnderDriveMountPoint( 376 if (util::IsUnderDriveMountPoint(
361 pref_service->GetFilePath(prefs::kDownloadDefaultDirectory))) { 377 pref_service->GetFilePath(prefs::kDownloadDefaultDirectory))) {
362 pref_service->SetFilePath(prefs::kDownloadDefaultDirectory, 378 pref_service->SetFilePath(prefs::kDownloadDefaultDirectory,
363 DownloadPrefs::GetDefaultDownloadDirectory()); 379 DownloadPrefs::GetDefaultDownloadDirectory());
364 } 380 }
381
382 // Back to NOT_INITIALIZED state. Then, re-running Initialize() should
383 // work if the error is recovarable manually (such as out of disk space).
384 state_ = NOT_INITIALIZED;
365 return; 385 return;
366 } 386 }
367 is_initialized_ = true;
368 387
369 content::DownloadManager* download_manager = 388 content::DownloadManager* download_manager =
370 g_browser_process->download_status_updater() ? 389 g_browser_process->download_status_updater() ?
371 BrowserContext::GetDownloadManager(profile_) : NULL; 390 BrowserContext::GetDownloadManager(profile_) : NULL;
372 download_handler_->Initialize( 391 download_handler_->Initialize(
373 download_manager, 392 download_manager,
374 cache_root_directory_.Append(kTemporaryFileDirectory)); 393 cache_root_directory_.Append(kTemporaryFileDirectory));
375 394
376 // Register for Google Drive invalidation notifications. 395 // Register for Google Drive invalidation notifications.
377 DriveNotificationManager* drive_notification_manager = 396 DriveNotificationManager* drive_notification_manager =
378 DriveNotificationManagerFactory::GetForBrowserContext(profile_); 397 DriveNotificationManagerFactory::GetForBrowserContext(profile_);
379 if (drive_notification_manager) { 398 if (drive_notification_manager) {
380 drive_notification_manager->AddObserver(this); 399 drive_notification_manager->AddObserver(this);
381 const bool registered = 400 const bool registered =
382 drive_notification_manager->push_notification_registered(); 401 drive_notification_manager->push_notification_registered();
383 const char* status = (registered ? "registered" : "not registered"); 402 const char* status = (registered ? "registered" : "not registered");
384 util::Log(logging::LOG_INFO, "Push notification is %s", status); 403 util::Log(logging::LOG_INFO, "Push notification is %s", status);
385 404
386 if (drive_notification_manager->push_notification_enabled()) 405 if (drive_notification_manager->push_notification_enabled())
387 drive_app_registry_->Update(); 406 drive_app_registry_->Update();
388 } 407 }
389 408
390 AddDriveMountPoint(); 409 AddDriveMountPoint();
410 state_ = INITIALIZED;
391 } 411 }
392 412
393 //===================== DriveIntegrationServiceFactory ======================= 413 //===================== DriveIntegrationServiceFactory =======================
394 414
395 // static 415 // static
396 DriveIntegrationService* DriveIntegrationServiceFactory::GetForProfile( 416 DriveIntegrationService* DriveIntegrationServiceFactory::GetForProfile(
397 Profile* profile) { 417 Profile* profile) {
398 DriveIntegrationService* service = GetForProfileRegardlessOfStates(profile); 418 DriveIntegrationService* service = GetForProfileRegardlessOfStates(profile);
399 if (service && !service->IsDriveEnabled()) 419 if (service && !service->IsDriveEnabled())
400 return NULL; 420 return NULL;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 profile, NULL, base::FilePath(), NULL); 482 profile, NULL, base::FilePath(), NULL);
463 } else { 483 } else {
464 service = factory_for_test_.Run(profile); 484 service = factory_for_test_.Run(profile);
465 } 485 }
466 486
467 service->Initialize(); 487 service->Initialize();
468 return service; 488 return service;
469 } 489 }
470 490
471 } // namespace drive 491 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/drive_integration_service.h ('k') | chrome/browser/chromeos/drive/file_system.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698