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

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

Issue 1036723003: favor DCHECK_CURRENTLY_ON for better logs in chrome/browser/chromeos/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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
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/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/prefs/pref_change_registrar.h" 9 #include "base/prefs/pref_change_registrar.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 const std::string& test_mount_point_name, 212 const std::string& test_mount_point_name,
213 const base::FilePath& test_cache_root, 213 const base::FilePath& test_cache_root,
214 FileSystemInterface* test_file_system) 214 FileSystemInterface* test_file_system)
215 : profile_(profile), 215 : profile_(profile),
216 state_(NOT_INITIALIZED), 216 state_(NOT_INITIALIZED),
217 enabled_(false), 217 enabled_(false),
218 mount_point_name_(test_mount_point_name), 218 mount_point_name_(test_mount_point_name),
219 cache_root_directory_(!test_cache_root.empty() ? 219 cache_root_directory_(!test_cache_root.empty() ?
220 test_cache_root : util::GetCacheRootPath(profile)), 220 test_cache_root : util::GetCacheRootPath(profile)),
221 weak_ptr_factory_(this) { 221 weak_ptr_factory_(this) {
222 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 222 DCHECK_CURRENTLY_ON(BrowserThread::UI);
223 DCHECK(profile && !profile->IsOffTheRecord()); 223 DCHECK(profile && !profile->IsOffTheRecord());
224 224
225 logger_.reset(new EventLogger); 225 logger_.reset(new EventLogger);
226 base::SequencedWorkerPool* blocking_pool = BrowserThread::GetBlockingPool(); 226 base::SequencedWorkerPool* blocking_pool = BrowserThread::GetBlockingPool();
227 blocking_task_runner_ = blocking_pool->GetSequencedTaskRunner( 227 blocking_task_runner_ = blocking_pool->GetSequencedTaskRunner(
228 blocking_pool->GetSequenceToken()); 228 blocking_pool->GetSequenceToken());
229 229
230 ProfileOAuth2TokenService* oauth_service = 230 ProfileOAuth2TokenService* oauth_service =
231 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); 231 ProfileOAuth2TokenServiceFactory::GetForProfile(profile);
232 232
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 274
275 if (preference_watcher) { 275 if (preference_watcher) {
276 preference_watcher_.reset(preference_watcher); 276 preference_watcher_.reset(preference_watcher);
277 preference_watcher->set_integration_service(this); 277 preference_watcher->set_integration_service(this);
278 } 278 }
279 279
280 SetEnabled(drive::util::IsDriveEnabledForProfile(profile)); 280 SetEnabled(drive::util::IsDriveEnabledForProfile(profile));
281 } 281 }
282 282
283 DriveIntegrationService::~DriveIntegrationService() { 283 DriveIntegrationService::~DriveIntegrationService() {
284 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 284 DCHECK_CURRENTLY_ON(BrowserThread::UI);
285 } 285 }
286 286
287 void DriveIntegrationService::Shutdown() { 287 void DriveIntegrationService::Shutdown() {
288 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 288 DCHECK_CURRENTLY_ON(BrowserThread::UI);
289 289
290 weak_ptr_factory_.InvalidateWeakPtrs(); 290 weak_ptr_factory_.InvalidateWeakPtrs();
291 291
292 DriveNotificationManager* drive_notification_manager = 292 DriveNotificationManager* drive_notification_manager =
293 DriveNotificationManagerFactory::FindForBrowserContext(profile_); 293 DriveNotificationManagerFactory::FindForBrowserContext(profile_);
294 if (drive_notification_manager) 294 if (drive_notification_manager)
295 drive_notification_manager->RemoveObserver(this); 295 drive_notification_manager->RemoveObserver(this);
296 296
297 RemoveDriveMountPoint(); 297 RemoveDriveMountPoint();
298 debug_info_collector_.reset(); 298 debug_info_collector_.reset();
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 // GetRegisteredPath() returns true if the path is available. 350 // GetRegisteredPath() returns true if the path is available.
351 base::FilePath unused; 351 base::FilePath unused;
352 storage::ExternalMountPoints* const mount_points = 352 storage::ExternalMountPoints* const mount_points =
353 storage::ExternalMountPoints::GetSystemInstance(); 353 storage::ExternalMountPoints::GetSystemInstance();
354 DCHECK(mount_points); 354 DCHECK(mount_points);
355 return mount_points->GetRegisteredPath(mount_point_name_, &unused); 355 return mount_points->GetRegisteredPath(mount_point_name_, &unused);
356 } 356 }
357 357
358 void DriveIntegrationService::AddObserver( 358 void DriveIntegrationService::AddObserver(
359 DriveIntegrationServiceObserver* observer) { 359 DriveIntegrationServiceObserver* observer) {
360 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 360 DCHECK_CURRENTLY_ON(BrowserThread::UI);
361 observers_.AddObserver(observer); 361 observers_.AddObserver(observer);
362 } 362 }
363 363
364 void DriveIntegrationService::RemoveObserver( 364 void DriveIntegrationService::RemoveObserver(
365 DriveIntegrationServiceObserver* observer) { 365 DriveIntegrationServiceObserver* observer) {
366 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 366 DCHECK_CURRENTLY_ON(BrowserThread::UI);
367 observers_.RemoveObserver(observer); 367 observers_.RemoveObserver(observer);
368 } 368 }
369 369
370 void DriveIntegrationService::OnNotificationReceived() { 370 void DriveIntegrationService::OnNotificationReceived() {
371 file_system_->CheckForUpdates(); 371 file_system_->CheckForUpdates();
372 drive_app_registry_->Update(); 372 drive_app_registry_->Update();
373 } 373 }
374 374
375 void DriveIntegrationService::OnPushNotificationEnabled(bool enabled) { 375 void DriveIntegrationService::OnPushNotificationEnabled(bool enabled) {
376 if (enabled) 376 if (enabled)
377 drive_app_registry_->Update(); 377 drive_app_registry_->Update();
378 378
379 const char* status = (enabled ? "enabled" : "disabled"); 379 const char* status = (enabled ? "enabled" : "disabled");
380 logger_->Log(logging::LOG_INFO, "Push notification is %s", status); 380 logger_->Log(logging::LOG_INFO, "Push notification is %s", status);
381 } 381 }
382 382
383 void DriveIntegrationService::ClearCacheAndRemountFileSystem( 383 void DriveIntegrationService::ClearCacheAndRemountFileSystem(
384 const base::Callback<void(bool)>& callback) { 384 const base::Callback<void(bool)>& callback) {
385 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 385 DCHECK_CURRENTLY_ON(BrowserThread::UI);
386 DCHECK(!callback.is_null()); 386 DCHECK(!callback.is_null());
387 387
388 if (state_ != INITIALIZED) { 388 if (state_ != INITIALIZED) {
389 callback.Run(false); 389 callback.Run(false);
390 return; 390 return;
391 } 391 }
392 392
393 RemoveDriveMountPoint(); 393 RemoveDriveMountPoint();
394 394
395 state_ = REMOUNTING; 395 state_ = REMOUNTING;
396 // Reloads the Drive app registry. 396 // Reloads the Drive app registry.
397 drive_app_registry_->Update(); 397 drive_app_registry_->Update();
398 // Resetting the file system clears resource metadata and cache. 398 // Resetting the file system clears resource metadata and cache.
399 file_system_->Reset(base::Bind( 399 file_system_->Reset(base::Bind(
400 &DriveIntegrationService::AddBackDriveMountPoint, 400 &DriveIntegrationService::AddBackDriveMountPoint,
401 weak_ptr_factory_.GetWeakPtr(), 401 weak_ptr_factory_.GetWeakPtr(),
402 callback)); 402 callback));
403 } 403 }
404 404
405 void DriveIntegrationService::AddBackDriveMountPoint( 405 void DriveIntegrationService::AddBackDriveMountPoint(
406 const base::Callback<void(bool)>& callback, 406 const base::Callback<void(bool)>& callback,
407 FileError error) { 407 FileError error) {
408 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 408 DCHECK_CURRENTLY_ON(BrowserThread::UI);
409 DCHECK(!callback.is_null()); 409 DCHECK(!callback.is_null());
410 410
411 state_ = error == FILE_ERROR_OK ? INITIALIZED : NOT_INITIALIZED; 411 state_ = error == FILE_ERROR_OK ? INITIALIZED : NOT_INITIALIZED;
412 412
413 if (error != FILE_ERROR_OK || !enabled_) { 413 if (error != FILE_ERROR_OK || !enabled_) {
414 // Failed to reset, or Drive was disabled during the reset. 414 // Failed to reset, or Drive was disabled during the reset.
415 callback.Run(false); 415 callback.Run(false);
416 return; 416 return;
417 } 417 }
418 418
419 AddDriveMountPoint(); 419 AddDriveMountPoint();
420 callback.Run(true); 420 callback.Run(true);
421 } 421 }
422 422
423 void DriveIntegrationService::AddDriveMountPoint() { 423 void DriveIntegrationService::AddDriveMountPoint() {
424 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 424 DCHECK_CURRENTLY_ON(BrowserThread::UI);
425 DCHECK_EQ(INITIALIZED, state_); 425 DCHECK_EQ(INITIALIZED, state_);
426 DCHECK(enabled_); 426 DCHECK(enabled_);
427 427
428 const base::FilePath& drive_mount_point = 428 const base::FilePath& drive_mount_point =
429 util::GetDriveMountPointPath(profile_); 429 util::GetDriveMountPointPath(profile_);
430 if (mount_point_name_.empty()) 430 if (mount_point_name_.empty())
431 mount_point_name_ = drive_mount_point.BaseName().AsUTF8Unsafe(); 431 mount_point_name_ = drive_mount_point.BaseName().AsUTF8Unsafe();
432 storage::ExternalMountPoints* const mount_points = 432 storage::ExternalMountPoints* const mount_points =
433 storage::ExternalMountPoints::GetSystemInstance(); 433 storage::ExternalMountPoints::GetSystemInstance();
434 DCHECK(mount_points); 434 DCHECK(mount_points);
435 435
436 bool success = 436 bool success =
437 mount_points->RegisterFileSystem(mount_point_name_, 437 mount_points->RegisterFileSystem(mount_point_name_,
438 storage::kFileSystemTypeDrive, 438 storage::kFileSystemTypeDrive,
439 storage::FileSystemMountOption(), 439 storage::FileSystemMountOption(),
440 drive_mount_point); 440 drive_mount_point);
441 441
442 if (success) { 442 if (success) {
443 logger_->Log(logging::LOG_INFO, "Drive mount point is added"); 443 logger_->Log(logging::LOG_INFO, "Drive mount point is added");
444 FOR_EACH_OBSERVER(DriveIntegrationServiceObserver, observers_, 444 FOR_EACH_OBSERVER(DriveIntegrationServiceObserver, observers_,
445 OnFileSystemMounted()); 445 OnFileSystemMounted());
446 } 446 }
447 } 447 }
448 448
449 void DriveIntegrationService::RemoveDriveMountPoint() { 449 void DriveIntegrationService::RemoveDriveMountPoint() {
450 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 450 DCHECK_CURRENTLY_ON(BrowserThread::UI);
451 451
452 if (!mount_point_name_.empty()) { 452 if (!mount_point_name_.empty()) {
453 job_list()->CancelAllJobs(); 453 job_list()->CancelAllJobs();
454 454
455 FOR_EACH_OBSERVER(DriveIntegrationServiceObserver, observers_, 455 FOR_EACH_OBSERVER(DriveIntegrationServiceObserver, observers_,
456 OnFileSystemBeingUnmounted()); 456 OnFileSystemBeingUnmounted());
457 457
458 storage::ExternalMountPoints* const mount_points = 458 storage::ExternalMountPoints* const mount_points =
459 storage::ExternalMountPoints::GetSystemInstance(); 459 storage::ExternalMountPoints::GetSystemInstance();
460 DCHECK(mount_points); 460 DCHECK(mount_points);
461 461
462 mount_points->RevokeFileSystem(mount_point_name_); 462 mount_points->RevokeFileSystem(mount_point_name_);
463 logger_->Log(logging::LOG_INFO, "Drive mount point is removed"); 463 logger_->Log(logging::LOG_INFO, "Drive mount point is removed");
464 } 464 }
465 } 465 }
466 466
467 void DriveIntegrationService::Initialize() { 467 void DriveIntegrationService::Initialize() {
468 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 468 DCHECK_CURRENTLY_ON(BrowserThread::UI);
469 DCHECK_EQ(NOT_INITIALIZED, state_); 469 DCHECK_EQ(NOT_INITIALIZED, state_);
470 DCHECK(enabled_); 470 DCHECK(enabled_);
471 471
472 state_ = INITIALIZING; 472 state_ = INITIALIZING;
473 473
474 base::PostTaskAndReplyWithResult( 474 base::PostTaskAndReplyWithResult(
475 blocking_task_runner_.get(), 475 blocking_task_runner_.get(),
476 FROM_HERE, 476 FROM_HERE,
477 base::Bind(&InitializeMetadata, 477 base::Bind(&InitializeMetadata,
478 cache_root_directory_, 478 cache_root_directory_,
479 metadata_storage_.get(), 479 metadata_storage_.get(),
480 cache_.get(), 480 cache_.get(),
481 resource_metadata_.get(), 481 resource_metadata_.get(),
482 file_manager::util::GetDownloadsFolderForProfile(profile_)), 482 file_manager::util::GetDownloadsFolderForProfile(profile_)),
483 base::Bind(&DriveIntegrationService::InitializeAfterMetadataInitialized, 483 base::Bind(&DriveIntegrationService::InitializeAfterMetadataInitialized,
484 weak_ptr_factory_.GetWeakPtr())); 484 weak_ptr_factory_.GetWeakPtr()));
485 } 485 }
486 486
487 void DriveIntegrationService::InitializeAfterMetadataInitialized( 487 void DriveIntegrationService::InitializeAfterMetadataInitialized(
488 FileError error) { 488 FileError error) {
489 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 489 DCHECK_CURRENTLY_ON(BrowserThread::UI);
490 DCHECK_EQ(INITIALIZING, state_); 490 DCHECK_EQ(INITIALIZING, state_);
491 491
492 SigninManagerBase* signin_manager = 492 SigninManagerBase* signin_manager =
493 SigninManagerFactory::GetForProfile(profile_); 493 SigninManagerFactory::GetForProfile(profile_);
494 drive_service_->Initialize(signin_manager->GetAuthenticatedAccountId()); 494 drive_service_->Initialize(signin_manager->GetAuthenticatedAccountId());
495 495
496 if (error != FILE_ERROR_OK) { 496 if (error != FILE_ERROR_OK) {
497 LOG(WARNING) << "Failed to initialize: " << FileErrorToString(error); 497 LOG(WARNING) << "Failed to initialize: " << FileErrorToString(error);
498 498
499 // Cannot used Drive. Set the download destination preference out of Drive. 499 // Cannot used Drive. Set the download destination preference out of Drive.
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 profile, preference_watcher, 641 profile, preference_watcher,
642 NULL, std::string(), base::FilePath(), NULL); 642 NULL, std::string(), base::FilePath(), NULL);
643 } else { 643 } else {
644 service = factory_for_test_->Run(profile); 644 service = factory_for_test_->Run(profile);
645 } 645 }
646 646
647 return service; 647 return service;
648 } 648 }
649 649
650 } // namespace drive 650 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/drive_file_stream_reader.cc ('k') | chrome/browser/chromeos/drive/fake_file_system.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698