OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/file_system_provider/operations/open_file.h" | 5 #include "chrome/browser/chromeos/file_system_provider/operations/open_file.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "chrome/common/extensions/api/file_system_provider.h" | 9 #include "chrome/common/extensions/api/file_system_provider.h" |
10 #include "chrome/common/extensions/api/file_system_provider_internal.h" | 10 #include "chrome/common/extensions/api/file_system_provider_internal.h" |
11 | 11 |
12 namespace chromeos { | 12 namespace chromeos { |
13 namespace file_system_provider { | 13 namespace file_system_provider { |
14 namespace operations { | 14 namespace operations { |
15 | 15 |
16 OpenFile::OpenFile( | 16 template <int source> |
17 extensions::EventRouter* event_router, | 17 OpenFile<source>::OpenFile( |
| 18 typename Operation<source>::EventRouterType* event_router, |
18 const ProvidedFileSystemInfo& file_system_info, | 19 const ProvidedFileSystemInfo& file_system_info, |
19 const base::FilePath& file_path, | 20 const base::FilePath& file_path, |
20 OpenFileMode mode, | 21 OpenFileMode mode, |
21 const ProvidedFileSystemInterface::OpenFileCallback& callback) | 22 const ProvidedFileSystemInterface::OpenFileCallback& callback) |
22 : Operation(event_router, file_system_info), | 23 : Operation<source>(event_router, file_system_info), |
23 file_path_(file_path), | 24 file_path_(file_path), |
24 mode_(mode), | 25 mode_(mode), |
25 callback_(callback) { | 26 callback_(callback) { |
26 } | 27 } |
27 | 28 |
28 OpenFile::~OpenFile() { | 29 template <int source> |
| 30 OpenFile<source>::~OpenFile() { |
29 } | 31 } |
30 | 32 |
31 bool OpenFile::Execute(int request_id) { | 33 template <int source> |
| 34 bool OpenFile<source>::Execute(int request_id) { |
32 using extensions::api::file_system_provider::OpenFileRequestedOptions; | 35 using extensions::api::file_system_provider::OpenFileRequestedOptions; |
33 | 36 |
34 if (!file_system_info_.writable() && mode_ == OPEN_FILE_MODE_WRITE) { | 37 if (!this->file_system_info_.writable() && mode_ == OPEN_FILE_MODE_WRITE) { |
35 return false; | 38 return false; |
36 } | 39 } |
37 | 40 |
38 OpenFileRequestedOptions options; | 41 OpenFileRequestedOptions options; |
39 options.file_system_id = file_system_info_.file_system_id(); | 42 options.file_system_id = this->file_system_info_.file_system_id(); |
40 options.request_id = request_id; | 43 options.request_id = request_id; |
41 options.file_path = file_path_.AsUTF8Unsafe(); | 44 options.file_path = file_path_.AsUTF8Unsafe(); |
42 | 45 |
43 switch (mode_) { | 46 switch (mode_) { |
44 case OPEN_FILE_MODE_READ: | 47 case OPEN_FILE_MODE_READ: |
45 options.mode = extensions::api::file_system_provider::OPEN_FILE_MODE_READ; | 48 options.mode = extensions::api::file_system_provider::OPEN_FILE_MODE_READ; |
46 break; | 49 break; |
47 case OPEN_FILE_MODE_WRITE: | 50 case OPEN_FILE_MODE_WRITE: |
48 options.mode = | 51 options.mode = |
49 extensions::api::file_system_provider::OPEN_FILE_MODE_WRITE; | 52 extensions::api::file_system_provider::OPEN_FILE_MODE_WRITE; |
50 break; | 53 break; |
51 } | 54 } |
52 | 55 |
53 return SendEvent( | 56 return this->SendEvent( |
54 request_id, | 57 request_id, |
55 extensions::api::file_system_provider::OnOpenFileRequested::kEventName, | 58 extensions::api::file_system_provider::OnOpenFileRequested::kEventName, |
56 extensions::api::file_system_provider::OnOpenFileRequested::Create( | 59 extensions::api::file_system_provider::OnOpenFileRequested::Create( |
57 options)); | 60 options)); |
58 } | 61 } |
59 | 62 |
60 void OpenFile::OnSuccess(int request_id, | 63 template <int source> |
61 scoped_ptr<RequestValue> result, | 64 void OpenFile<source>::OnSuccess(int request_id, |
62 bool has_more) { | 65 scoped_ptr<RequestValue> result, |
| 66 bool has_more) { |
63 // File handle is the same as request id of the OpenFile operation. | 67 // File handle is the same as request id of the OpenFile operation. |
64 callback_.Run(request_id, base::File::FILE_OK); | 68 callback_.Run(request_id, base::File::FILE_OK); |
65 } | 69 } |
66 | 70 |
67 void OpenFile::OnError(int /* request_id */, | 71 template <int source> |
68 scoped_ptr<RequestValue> /* result */, | 72 void OpenFile<source>::OnError(int /* request_id */, |
69 base::File::Error error) { | 73 scoped_ptr<RequestValue> /* result */, |
| 74 base::File::Error error) { |
70 callback_.Run(0 /* file_handle */, error); | 75 callback_.Run(0 /* file_handle */, error); |
71 } | 76 } |
72 | 77 |
| 78 template class OpenFile<Source_Type::extension>; |
| 79 template class OpenFile<Source_Type::plugin>; |
| 80 |
73 } // namespace operations | 81 } // namespace operations |
74 } // namespace file_system_provider | 82 } // namespace file_system_provider |
75 } // namespace chromeos | 83 } // namespace chromeos |
OLD | NEW |