<commit_before>// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "webkit/fileapi/media/device_media_async_file_util.h"

#include "base/callback.h"
#include "base/file_util.h"
#include "base/single_thread_task_runner.h"
#include "webkit/fileapi/file_system_context.h"
#include "webkit/fileapi/file_system_operation_context.h"
#include "webkit/fileapi/file_system_task_runners.h"
#include "webkit/fileapi/file_system_url.h"
#include "webkit/fileapi/isolated_context.h"
#include "webkit/fileapi/media/filtering_file_enumerator.h"
#include "webkit/fileapi/media/media_path_filter.h"
#include "webkit/fileapi/media/mtp_device_async_delegate.h"
#include "webkit/fileapi/media/mtp_device_map_service.h"

namespace fileapi {

namespace {

const base::FilePath::CharType kDeviceMediaAsyncFileUtilTempDir[] =
    FILE_PATH_LITERAL("DeviceMediaFileSystem");

// Returns true if the current thread is IO thread.
bool IsOnIOThread(FileSystemOperationContext* context) {
  return context->file_system_context()->task_runners()->
      io_task_runner()->RunsTasksOnCurrentThread();
}

// Called on the IO thread.
MTPDeviceAsyncDelegate* GetMTPDeviceDelegate(
    FileSystemOperationContext* context) {
  DCHECK(IsOnIOThread(context));
  return MTPDeviceMapService::GetInstance()->GetMTPDeviceAsyncDelegate(
      context->mtp_device_delegate_url());
}

// Called on the blocking pool thread to create a snapshot file to hold the
// contents of |device_file_path|. The snapshot file is created in
// "profile_path/kDeviceMediaAsyncFileUtilTempDir" directory. If the snapshot
// file is created successfully, |snapshot_file_path| will be a non-empty file
// path. In case of failure, the |snapshot_file_path| will be an empty file
// path.
void CreateSnapshotFileOnBlockingPool(
    const base::FilePath& device_file_path,
    const base::FilePath& profile_path,
    base::FilePath* snapshot_file_path) {
  DCHECK(snapshot_file_path);
  base::FilePath isolated_media_file_system_dir_path =
      profile_path.Append(kDeviceMediaAsyncFileUtilTempDir);
  if (!file_util::CreateDirectory(isolated_media_file_system_dir_path) ||
      !file_util::CreateTemporaryFileInDir(isolated_media_file_system_dir_path,
                                           snapshot_file_path)) {
    LOG(WARNING) << "Could not create media snapshot file "
                 << isolated_media_file_system_dir_path.value();
    *snapshot_file_path = base::FilePath();
  }
}

}  // namespace

DeviceMediaAsyncFileUtil::~DeviceMediaAsyncFileUtil() {
}

// static
DeviceMediaAsyncFileUtil* DeviceMediaAsyncFileUtil::Create(
    const base::FilePath& profile_path) {
  NOTIMPLEMENTED();
  return NULL;
}

bool DeviceMediaAsyncFileUtil::CreateOrOpen(
    FileSystemOperationContext* context,
    const FileSystemURL& url,
    int file_flags,
    const CreateOrOpenCallback& callback) {
  DCHECK(IsOnIOThread(context));
  NOTIMPLEMENTED();
  if (!callback.is_null()) {
    base::PlatformFile invalid_file = base::kInvalidPlatformFileValue;
    callback.Run(base::PLATFORM_FILE_ERROR_SECURITY,
                 base::PassPlatformFile(&invalid_file),
                 false);
  }
  return true;
}

bool DeviceMediaAsyncFileUtil::EnsureFileExists(
    FileSystemOperationContext* context,
    const FileSystemURL& url,
    const EnsureFileExistsCallback& callback) {
  DCHECK(IsOnIOThread(context));
  NOTIMPLEMENTED();
  if (!callback.is_null())
    callback.Run(base::PLATFORM_FILE_ERROR_SECURITY, false);
  return true;<commit_msg>Remove NOTIMPLEMENTED() from DeviceMediaAsyncFileUtil::Create().<commit_after>// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "webkit/fileapi/media/device_media_async_file_util.h"

#include "base/callback.h"
#include "base/file_util.h"
#include "base/single_thread_task_runner.h"
#include "webkit/fileapi/file_system_context.h"
#include "webkit/fileapi/file_system_operation_context.h"
#include "webkit/fileapi/file_system_task_runners.h"
#include "webkit/fileapi/file_system_url.h"
#include "webkit/fileapi/isolated_context.h"
#include "webkit/fileapi/media/filtering_file_enumerator.h"
#include "webkit/fileapi/media/media_path_filter.h"
#include "webkit/fileapi/media/mtp_device_async_delegate.h"
#include "webkit/fileapi/media/mtp_device_map_service.h"

namespace fileapi {

namespace {

const base::FilePath::CharType kDeviceMediaAsyncFileUtilTempDir[] =
    FILE_PATH_LITERAL("DeviceMediaFileSystem");

// Returns true if the current thread is IO thread.
bool IsOnIOThread(FileSystemOperationContext* context) {
  return context->file_system_context()->task_runners()->
      io_task_runner()->RunsTasksOnCurrentThread();
}

// Called on the IO thread.
MTPDeviceAsyncDelegate* GetMTPDeviceDelegate(
    FileSystemOperationContext* context) {
  DCHECK(IsOnIOThread(context));
  return MTPDeviceMapService::GetInstance()->GetMTPDeviceAsyncDelegate(
      context->mtp_device_delegate_url());
}

// Called on the blocking pool thread to create a snapshot file to hold the
// contents of |device_file_path|. The snapshot file is created in
// "profile_path/kDeviceMediaAsyncFileUtilTempDir" directory. If the snapshot
// file is created successfully, |snapshot_file_path| will be a non-empty file
// path. In case of failure, the |snapshot_file_path| will be an empty file
// path.
void CreateSnapshotFileOnBlockingPool(
    const base::FilePath& device_file_path,
    const base::FilePath& profile_path,
    base::FilePath* snapshot_file_path) {
  DCHECK(snapshot_file_path);
  base::FilePath isolated_media_file_system_dir_path =
      profile_path.Append(kDeviceMediaAsyncFileUtilTempDir);
  if (!file_util::CreateDirectory(isolated_media_file_system_dir_path) ||
      !file_util::CreateTemporaryFileInDir(isolated_media_file_system_dir_path,
                                           snapshot_file_path)) {
    LOG(WARNING) << "Could not create media snapshot file "
                 << isolated_media_file_system_dir_path.value();
    *snapshot_file_path = base::FilePath();
  }
}

}  // namespace

DeviceMediaAsyncFileUtil::~DeviceMediaAsyncFileUtil() {
}

// static
DeviceMediaAsyncFileUtil* DeviceMediaAsyncFileUtil::Create(
    const base::FilePath& profile_path) {
  return NULL;
}

bool DeviceMediaAsyncFileUtil::CreateOrOpen(
    FileSystemOperationContext* context,
    const FileSystemURL& url,
    int file_flags,
    const CreateOrOpenCallback& callback) {
  DCHECK(IsOnIOThread(context));
  NOTIMPLEMENTED();
  if (!callback.is_null()) {
    base::PlatformFile invalid_file = base::kInvalidPlatformFileValue;
    callback.Run(base::PLATFORM_FILE_ERROR_SECURITY,
                 base::PassPlatformFile(&invalid_file),
                 false);
  }
  return true;
}

bool DeviceMediaAsyncFileUtil::EnsureFileExists(
    FileSystemOperationContext* context,
    const FileSystemURL& url,
    const EnsureFileExistsCallback& callback) {
  DCHECK(IsOnIOThread(context));
  NOTIMPLEMENTED();
  if (!callback.is_null())
    callback.Run(base::PLATFORM_FILE_ERROR_SECURITY, false);
  return true;
{'fraction_non_alphanumeric': 0.09877224444751, 'fraction_numerical': 0.0011036004966202234, 'mean_word_length': 5.112984822934233, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4887556', 'n_tokens_mistral': 2208, 'n_tokens_neox': 2202, 'n_words': 445}