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.
5 #include "chrome/browser/chromeos/file_system_provider/operations/open_file.h"
9 #include "chrome/common/extensions/api/file_system_provider.h"
10 #include "chrome/common/extensions/api/file_system_provider_internal.h"
13 namespace file_system_provider
{
14 namespace operations
{
17 extensions::EventRouter
* event_router
,
18 const ProvidedFileSystemInfo
& file_system_info
,
19 const base::FilePath
& file_path
,
21 const ProvidedFileSystemInterface::OpenFileCallback
& callback
)
22 : Operation(event_router
, file_system_info
),
23 file_path_(file_path
),
28 OpenFile::~OpenFile() {
31 bool OpenFile::Execute(int request_id
) {
32 using extensions::api::file_system_provider::OpenFileRequestedOptions
;
34 if (!file_system_info_
.writable() && mode_
== OPEN_FILE_MODE_WRITE
) {
38 OpenFileRequestedOptions options
;
39 options
.file_system_id
= file_system_info_
.file_system_id();
40 options
.request_id
= request_id
;
41 options
.file_path
= file_path_
.AsUTF8Unsafe();
44 case OPEN_FILE_MODE_READ
:
45 options
.mode
= extensions::api::file_system_provider::OPEN_FILE_MODE_READ
;
47 case OPEN_FILE_MODE_WRITE
:
49 extensions::api::file_system_provider::OPEN_FILE_MODE_WRITE
;
55 extensions::events::FILE_SYSTEM_PROVIDER_ON_OPEN_FILE_REQUESTED
,
56 extensions::api::file_system_provider::OnOpenFileRequested::kEventName
,
57 extensions::api::file_system_provider::OnOpenFileRequested::Create(
61 void OpenFile::OnSuccess(int request_id
,
62 scoped_ptr
<RequestValue
> result
,
64 // File handle is the same as request id of the OpenFile operation.
65 callback_
.Run(request_id
, base::File::FILE_OK
);
68 void OpenFile::OnError(int /* request_id */,
69 scoped_ptr
<RequestValue
> /* result */,
70 base::File::Error error
) {
71 callback_
.Run(0 /* file_handle */, error
);
74 } // namespace operations
75 } // namespace file_system_provider
76 } // namespace chromeos