Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / chromeos / file_system_provider / operations / open_file.cc
blobecd626f8b533d0273697480d1bfec982c532d706
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"
7 #include <string>
9 #include "chrome/common/extensions/api/file_system_provider.h"
10 #include "chrome/common/extensions/api/file_system_provider_internal.h"
12 namespace chromeos {
13 namespace file_system_provider {
14 namespace operations {
16 OpenFile::OpenFile(
17 extensions::EventRouter* event_router,
18 const ProvidedFileSystemInfo& file_system_info,
19 const base::FilePath& file_path,
20 OpenFileMode mode,
21 const ProvidedFileSystemInterface::OpenFileCallback& callback)
22 : Operation(event_router, file_system_info),
23 file_path_(file_path),
24 mode_(mode),
25 callback_(callback) {
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) {
35 return false;
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();
43 switch (mode_) {
44 case OPEN_FILE_MODE_READ:
45 options.mode = extensions::api::file_system_provider::OPEN_FILE_MODE_READ;
46 break;
47 case OPEN_FILE_MODE_WRITE:
48 options.mode =
49 extensions::api::file_system_provider::OPEN_FILE_MODE_WRITE;
50 break;
53 return SendEvent(
54 request_id,
55 extensions::api::file_system_provider::OnOpenFileRequested::kEventName,
56 extensions::api::file_system_provider::OnOpenFileRequested::Create(
57 options));
60 void OpenFile::OnSuccess(int request_id,
61 scoped_ptr<RequestValue> result,
62 bool has_more) {
63 // File handle is the same as request id of the OpenFile operation.
64 callback_.Run(request_id, base::File::FILE_OK);
67 void OpenFile::OnError(int /* request_id */,
68 scoped_ptr<RequestValue> /* result */,
69 base::File::Error error) {
70 callback_.Run(0 /* file_handle */, error);
73 } // namespace operations
74 } // namespace file_system_provider
75 } // namespace chromeos