Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(529)

Side by Side Diff: chrome/browser/chromeos/file_system_provider/operations/open_file.cc

Issue 1093383002: [WIP] Provided file system from NACL. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moved several modules to chromeos folder. Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <class DestinationPolicy>
17 extensions::EventRouter* event_router, 17 OpenFile<DestinationPolicy>::OpenFile(
18 typename DestinationPolicy::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<DestinationPolicy>(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 <class DestinationPolicy>
30 OpenFile<DestinationPolicy>::~OpenFile() {
29 } 31 }
30 32
31 bool OpenFile::Execute(int request_id) { 33 template <class DestinationPolicy>
34 bool OpenFile<DestinationPolicy>::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 <class DestinationPolicy>
61 scoped_ptr<RequestValue> result, 64 void OpenFile<DestinationPolicy>::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 <class DestinationPolicy>
68 scoped_ptr<RequestValue> /* result */, 72 void OpenFile<DestinationPolicy>::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 FOR_EACH_DESTINATION_SPECIALIZE(OpenFile)
79
73 } // namespace operations 80 } // namespace operations
74 } // namespace file_system_provider 81 } // namespace file_system_provider
75 } // namespace chromeos 82 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698