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
3// found in the LICENSE file.
4
5#include "chrome/browser/chromeos/file_system_provider/operations/create_file.h"
6
7#include <string>
8
9#include "chrome/common/extensions/api/file_system_provider.h"
10#include "chrome/common/extensions/api/file_system_provider_internal.h"
11
12namespace chromeos {
13namespace file_system_provider {
14namespace operations {
15
16CreateFile::CreateFile(extensions::EventRouter* event_router,
17                       const ProvidedFileSystemInfo& file_system_info,
18                       const base::FilePath& file_path,
19                       const storage::AsyncFileUtil::StatusCallback& callback)
20    : Operation(event_router, file_system_info),
21      file_path_(file_path),
22      callback_(callback) {
23}
24
25CreateFile::~CreateFile() {
26}
27
28bool CreateFile::Execute(int request_id) {
29  using extensions::api::file_system_provider::CreateFileRequestedOptions;
30
31  if (!file_system_info_.writable())
32    return false;
33
34  CreateFileRequestedOptions options;
35  options.file_system_id = file_system_info_.file_system_id();
36  options.request_id = request_id;
37  options.file_path = file_path_.AsUTF8Unsafe();
38
39  return SendEvent(
40      request_id,
41      extensions::api::file_system_provider::OnCreateFileRequested::kEventName,
42      extensions::api::file_system_provider::OnCreateFileRequested::Create(
43          options));
44}
45
46void CreateFile::OnSuccess(int /* request_id */,
47                           scoped_ptr<RequestValue> /* result */,
48                           bool has_more) {
49  callback_.Run(base::File::FILE_OK);
50}
51
52void CreateFile::OnError(int /* request_id */,
53                         scoped_ptr<RequestValue> /* result */,
54                         base::File::Error error) {
55  callback_.Run(error);
56}
57
58}  // namespace operations
59}  // namespace file_system_provider
60}  // namespace chromeos
61