OLD | NEW |
(Empty) | |
| 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/open_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 |
| 12 namespace chromeos { |
| 13 namespace file_system_provider { |
| 14 namespace operations { |
| 15 |
| 16 OpenFile::OpenFile(extensions::EventRouter* event_router, |
| 17 const ProvidedFileSystemInfo& file_system_info, |
| 18 const base::FilePath& file_path, |
| 19 ProvidedFileSystemInterface::OpenFileMode mode, |
| 20 bool create, |
| 21 const fileapi::AsyncFileUtil::StatusCallback& callback) |
| 22 : Operation(event_router, file_system_info), |
| 23 file_path_(file_path), |
| 24 mode_(mode), |
| 25 create_(create), |
| 26 callback_(callback) { |
| 27 } |
| 28 |
| 29 OpenFile::~OpenFile() { |
| 30 } |
| 31 |
| 32 bool OpenFile::Execute(int request_id) { |
| 33 scoped_ptr<base::ListValue> values(new base::ListValue); |
| 34 values->AppendString(file_path_.AsUTF8Unsafe()); |
| 35 |
| 36 switch (mode_) { |
| 37 case ProvidedFileSystemInterface::OPEN_FILE_MODE_READ: |
| 38 values->AppendString(extensions::api::file_system_provider::ToString( |
| 39 extensions::api::file_system_provider::OPEN_FILE_MODE_READ)); |
| 40 break; |
| 41 case ProvidedFileSystemInterface::OPEN_FILE_MODE_WRITE: |
| 42 values->AppendString(extensions::api::file_system_provider::ToString( |
| 43 extensions::api::file_system_provider::OPEN_FILE_MODE_WRITE)); |
| 44 break; |
| 45 } |
| 46 |
| 47 values->AppendBoolean(create_); |
| 48 |
| 49 return SendEvent( |
| 50 request_id, |
| 51 extensions::api::file_system_provider::OnOpenFileRequested::kEventName, |
| 52 values.Pass()); |
| 53 } |
| 54 |
| 55 void OpenFile::OnSuccess(int /* request_id */, |
| 56 scoped_ptr<RequestValue> result, |
| 57 bool has_next) { |
| 58 callback_.Run(base::File::FILE_OK); |
| 59 } |
| 60 |
| 61 void OpenFile::OnError(int /* request_id */, base::File::Error error) { |
| 62 callback_.Run(error); |
| 63 } |
| 64 |
| 65 } // namespace operations |
| 66 } // namespace file_system_provider |
| 67 } // namespace chromeos |
OLD | NEW |