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

Side by Side Diff: chrome/browser/chromeos/file_system_provider/operations/write_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/write_file.h" 5 #include "chrome/browser/chromeos/file_system_provider/operations/write_file.h"
6 6
7 #include "base/trace_event/trace_event.h" 7 #include "base/trace_event/trace_event.h"
8 #include "base/values.h" 8 #include "base/values.h"
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 WriteFile::WriteFile(extensions::EventRouter* event_router, 16 template <class DestinationPolicy>
17 const ProvidedFileSystemInfo& file_system_info, 17 WriteFile<DestinationPolicy>::WriteFile(
18 int file_handle, 18 typename DestinationPolicy::EventRouterType* event_router,
19 scoped_refptr<net::IOBuffer> buffer, 19 const ProvidedFileSystemInfo& file_system_info,
20 int64 offset, 20 int file_handle,
21 int length, 21 scoped_refptr<net::IOBuffer> buffer,
22 const storage::AsyncFileUtil::StatusCallback& callback) 22 int64 offset,
23 : Operation(event_router, file_system_info), 23 int length,
24 const storage::AsyncFileUtil::StatusCallback& callback)
25 : Operation<DestinationPolicy>(event_router, file_system_info),
24 file_handle_(file_handle), 26 file_handle_(file_handle),
25 buffer_(buffer), 27 buffer_(buffer),
26 offset_(offset), 28 offset_(offset),
27 length_(length), 29 length_(length),
28 callback_(callback) { 30 callback_(callback) {
29 } 31 }
30 32
31 WriteFile::~WriteFile() { 33 template <class DestinationPolicy>
34 WriteFile<DestinationPolicy>::~WriteFile() {
32 } 35 }
33 36
34 bool WriteFile::Execute(int request_id) { 37 template <class DestinationPolicy>
38 bool WriteFile<DestinationPolicy>::Execute(int request_id) {
35 TRACE_EVENT0("file_system_provider", "WriteFile::Execute"); 39 TRACE_EVENT0("file_system_provider", "WriteFile::Execute");
36 using extensions::api::file_system_provider::WriteFileRequestedOptions; 40 using extensions::api::file_system_provider::WriteFileRequestedOptions;
37 41
38 if (!file_system_info_.writable()) 42 if (!this->file_system_info_.writable())
39 return false; 43 return false;
40 44
41 WriteFileRequestedOptions options; 45 WriteFileRequestedOptions options;
42 options.file_system_id = file_system_info_.file_system_id(); 46 options.file_system_id = this->file_system_info_.file_system_id();
43 options.request_id = request_id; 47 options.request_id = request_id;
44 options.open_request_id = file_handle_; 48 options.open_request_id = file_handle_;
45 options.offset = offset_; 49 options.offset = offset_;
46 // Length is not passed directly since it can be accessed via data.byteLength. 50 // Length is not passed directly since it can be accessed via data.byteLength.
47 51
48 // Set the data directly on base::Value() to avoid an extra string copy. 52 // Set the data directly on base::Value() to avoid an extra string copy.
49 DCHECK(buffer_.get()); 53 DCHECK(buffer_.get());
50 scoped_ptr<base::DictionaryValue> options_as_value = options.ToValue(); 54 scoped_ptr<base::DictionaryValue> options_as_value = options.ToValue();
51 options_as_value->Set( 55 options_as_value->Set(
52 "data", 56 "data",
53 base::BinaryValue::CreateWithCopiedBuffer(buffer_->data(), length_)); 57 base::BinaryValue::CreateWithCopiedBuffer(buffer_->data(), length_));
54 58
55 scoped_ptr<base::ListValue> event_args(new base::ListValue); 59 scoped_ptr<base::ListValue> event_args(new base::ListValue);
56 event_args->Append(options_as_value.release()); 60 event_args->Append(options_as_value.release());
57 61
58 return SendEvent( 62 return this->SendEvent(
59 request_id, 63 request_id,
60 extensions::api::file_system_provider::OnWriteFileRequested::kEventName, 64 extensions::api::file_system_provider::OnWriteFileRequested::kEventName,
61 event_args.Pass()); 65 event_args.Pass());
62 } 66 }
63 67
64 void WriteFile::OnSuccess(int /* request_id */, 68 template <class DestinationPolicy>
65 scoped_ptr<RequestValue> /* result */, 69 void WriteFile<DestinationPolicy>::OnSuccess(int /* request_id */,
66 bool /* has_more */) { 70 scoped_ptr<RequestValue> /* result */,
71 bool /* has_more */) {
67 TRACE_EVENT0("file_system_provider", "WriteFile::OnSuccess"); 72 TRACE_EVENT0("file_system_provider", "WriteFile::OnSuccess");
68 callback_.Run(base::File::FILE_OK); 73 callback_.Run(base::File::FILE_OK);
69 } 74 }
70 75
71 void WriteFile::OnError(int /* request_id */, 76 template <class DestinationPolicy>
72 scoped_ptr<RequestValue> /* result */, 77 void WriteFile<DestinationPolicy>::OnError(int /* request_id */,
73 base::File::Error error) { 78 scoped_ptr<RequestValue> /* result */,
79 base::File::Error error) {
74 TRACE_EVENT0("file_system_provider", "WriteFile::OnError"); 80 TRACE_EVENT0("file_system_provider", "WriteFile::OnError");
75 callback_.Run(error); 81 callback_.Run(error);
76 } 82 }
77 83
84 FOR_EACH_DESTINATION_SPECIALIZE(WriteFile)
85
78 } // namespace operations 86 } // namespace operations
79 } // namespace file_system_provider 87 } // namespace file_system_provider
80 } // namespace chromeos 88 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698