Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / drive / drive_integration_service.cc
index df3b6a7..9099799 100644 (file)
@@ -17,7 +17,6 @@
 #include "chrome/browser/chromeos/drive/file_system.h"
 #include "chrome/browser/chromeos/drive/file_system_util.h"
 #include "chrome/browser/chromeos/drive/job_scheduler.h"
-#include "chrome/browser/chromeos/drive/logging.h"
 #include "chrome/browser/chromeos/drive/resource_metadata.h"
 #include "chrome/browser/chromeos/drive/resource_metadata_storage.h"
 #include "chrome/browser/chromeos/file_manager/path_util.h"
@@ -30,6 +29,7 @@
 #include "chrome/browser/drive/drive_app_registry.h"
 #include "chrome/browser/drive/drive_notification_manager.h"
 #include "chrome/browser/drive/drive_notification_manager_factory.h"
+#include "chrome/browser/drive/event_logger.h"
 #include "chrome/browser/drive/gdata_wapi_service.h"
 #include "chrome/browser/profiles/profile.h"
 #include "chrome/browser/signin/profile_oauth2_token_service.h"
@@ -151,8 +151,9 @@ FileError InitializeMetadata(
     metadata_storage->RecoverCacheInfoFromTrashedResourceMap(
         &recovered_cache_info);
 
-    LOG(WARNING) << "DB could not be opened for some reasons. "
-                 << "Recovering cache files to " << dest_directory.value();
+    LOG_IF(WARNING, !recovered_cache_info.empty())
+        << "DB could not be opened for some reasons. "
+        << "Recovering cache files to " << dest_directory.value();
     if (!cache->RecoverFilesFromCacheDirectory(dest_directory,
                                                recovered_cache_info)) {
       LOG(WARNING) << "Failed to recover cache files.";
@@ -206,16 +207,19 @@ DriveIntegrationService::DriveIntegrationService(
     Profile* profile,
     PreferenceWatcher* preference_watcher,
     DriveServiceInterface* test_drive_service,
+    const std::string& test_mount_point_name,
     const base::FilePath& test_cache_root,
     FileSystemInterface* test_file_system)
     : profile_(profile),
       state_(NOT_INITIALIZED),
       enabled_(false),
+      mount_point_name_(test_mount_point_name),
       cache_root_directory_(!test_cache_root.empty() ?
                             test_cache_root : util::GetCacheRootPath(profile)),
       weak_ptr_factory_(this) {
   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
 
+  logger_.reset(new EventLogger);
   base::SequencedWorkerPool* blocking_pool = BrowserThread::GetBlockingPool();
   blocking_task_runner_ = blocking_pool->GetSequencedTaskRunner(
       blocking_pool->GetSequenceToken());
@@ -245,6 +249,7 @@ DriveIntegrationService::DriveIntegrationService(
   }
   scheduler_.reset(new JobScheduler(
       profile_->GetPrefs(),
+      logger_.get(),
       drive_service_.get(),
       blocking_task_runner_.get()));
   metadata_storage_.reset(new internal::ResourceMetadataStorage(
@@ -263,6 +268,7 @@ DriveIntegrationService::DriveIntegrationService(
   file_system_.reset(
       test_file_system ? test_file_system : new FileSystem(
           profile_->GetPrefs(),
+          logger_.get(),
           cache_.get(),
           drive_service_.get(),
           scheduler_.get(),
@@ -270,9 +276,9 @@ DriveIntegrationService::DriveIntegrationService(
           blocking_task_runner_.get(),
           cache_root_directory_.Append(kTemporaryFileDirectory)));
   download_handler_.reset(new DownloadHandler(file_system()));
-  debug_info_collector_.reset(
-      new DebugInfoCollector(file_system(), cache_.get(),
-                             blocking_task_runner_.get()));
+  debug_info_collector_.reset(new DebugInfoCollector(
+      cache_.get(), resource_metadata_.get(), file_system(),
+      blocking_task_runner_.get()));
 
   if (preference_watcher) {
     preference_watcher_.reset(preference_watcher);
@@ -345,12 +351,16 @@ void DriveIntegrationService::SetEnabled(bool enabled) {
 }
 
 bool DriveIntegrationService::IsMounted() const {
+  if (mount_point_name_.empty())
+    return false;
+
   // Look up the registered path, and just discard it.
   // GetRegisteredPath() returns true if the path is available.
-  const base::FilePath& drive_mount_point = util::GetDriveMountPointPath();
   base::FilePath unused;
-  return BrowserContext::GetMountPoints(profile_)->GetRegisteredPath(
-      drive_mount_point.BaseName().AsUTF8Unsafe(), &unused);
+  fileapi::ExternalMountPoints* const mount_points =
+      fileapi::ExternalMountPoints::GetSystemInstance();
+  DCHECK(mount_points);
+  return mount_points->GetRegisteredPath(mount_point_name_, &unused);
 }
 
 void DriveIntegrationService::AddObserver(
@@ -375,7 +385,7 @@ void DriveIntegrationService::OnPushNotificationEnabled(bool enabled) {
     drive_app_registry_->Update();
 
   const char* status = (enabled ? "enabled" : "disabled");
-  util::Log(logging::LOG_INFO, "Push notification is %s", status);
+  logger_->Log(logging::LOG_INFO, "Push notification is %s", status);
 }
 
 void DriveIntegrationService::ClearCacheAndRemountFileSystem(
@@ -423,19 +433,22 @@ void DriveIntegrationService::AddDriveMountPoint() {
   DCHECK_EQ(INITIALIZED, state_);
   DCHECK(enabled_);
 
-  const base::FilePath drive_mount_point = util::GetDriveMountPointPath();
-  fileapi::ExternalMountPoints* mount_points =
-      BrowserContext::GetMountPoints(profile_);
+  const base::FilePath& drive_mount_point =
+      util::GetDriveMountPointPath(profile_);
+  if (mount_point_name_.empty())
+    mount_point_name_ = drive_mount_point.BaseName().AsUTF8Unsafe();
+  fileapi::ExternalMountPoints* const mount_points =
+      fileapi::ExternalMountPoints::GetSystemInstance();
   DCHECK(mount_points);
 
   bool success = mount_points->RegisterFileSystem(
-      drive_mount_point.BaseName().AsUTF8Unsafe(),
+      mount_point_name_,
       fileapi::kFileSystemTypeDrive,
       fileapi::FileSystemMountOption(),
       drive_mount_point);
 
   if (success) {
-    util::Log(logging::LOG_INFO, "Drive mount point is added");
+    logger_->Log(logging::LOG_INFO, "Drive mount point is added");
     FOR_EACH_OBSERVER(DriveIntegrationServiceObserver, observers_,
                       OnFileSystemMounted());
   }
@@ -444,18 +457,19 @@ void DriveIntegrationService::AddDriveMountPoint() {
 void DriveIntegrationService::RemoveDriveMountPoint() {
   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
 
-  job_list()->CancelAllJobs();
+  if (!mount_point_name_.empty()) {
+    job_list()->CancelAllJobs();
 
-  FOR_EACH_OBSERVER(DriveIntegrationServiceObserver, observers_,
-                    OnFileSystemBeingUnmounted());
+    FOR_EACH_OBSERVER(DriveIntegrationServiceObserver, observers_,
+                      OnFileSystemBeingUnmounted());
 
-  fileapi::ExternalMountPoints* mount_points =
-      BrowserContext::GetMountPoints(profile_);
-  DCHECK(mount_points);
+    fileapi::ExternalMountPoints* const mount_points =
+        fileapi::ExternalMountPoints::GetSystemInstance();
+    DCHECK(mount_points);
 
-  mount_points->RevokeFileSystem(
-      util::GetDriveMountPointPath().BaseName().AsUTF8Unsafe());
-  util::Log(logging::LOG_INFO, "Drive mount point is removed");
+    mount_points->RevokeFileSystem(mount_point_name_);
+    logger_->Log(logging::LOG_INFO, "Drive mount point is removed");
+  }
 }
 
 void DriveIntegrationService::Initialize() {
@@ -515,7 +529,7 @@ void DriveIntegrationService::InitializeAfterMetadataInitialized(
     const bool registered =
         drive_notification_manager->push_notification_registered();
     const char* status = (registered ? "registered" : "not registered");
-    util::Log(logging::LOG_INFO, "Push notification is %s", status);
+    logger_->Log(logging::LOG_INFO, "Push notification is %s", status);
 
     if (drive_notification_manager->push_notification_enabled())
       drive_app_registry_->Update();
@@ -613,8 +627,9 @@ DriveIntegrationServiceFactory::BuildServiceInstanceFor(
           new DriveIntegrationService::PreferenceWatcher(profile->GetPrefs());
     }
 
-    service = new DriveIntegrationService(profile, preference_watcher,
-                                          NULL, base::FilePath(), NULL);
+    service = new DriveIntegrationService(
+        profile, preference_watcher,
+        NULL, std::string(), base::FilePath(), NULL);
   } else {
     service = factory_for_test_->Run(profile);
   }