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/write_file.h" | 5 #include "chrome/browser/chromeos/file_system_provider/operations/write_file.h" |
6 | 6 |
7 #include "base/debug/trace_event.h" | 7 #include "base/debug/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" |
(...skipping 15 matching lines...) Expand all Loading... |
26 offset_(offset), | 26 offset_(offset), |
27 length_(length), | 27 length_(length), |
28 callback_(callback) { | 28 callback_(callback) { |
29 } | 29 } |
30 | 30 |
31 WriteFile::~WriteFile() { | 31 WriteFile::~WriteFile() { |
32 } | 32 } |
33 | 33 |
34 bool WriteFile::Execute(int request_id) { | 34 bool WriteFile::Execute(int request_id) { |
35 TRACE_EVENT0("file_system_provider", "WriteFile::Execute"); | 35 TRACE_EVENT0("file_system_provider", "WriteFile::Execute"); |
| 36 using extensions::api::file_system_provider::WriteFileRequestedOptions; |
36 | 37 |
37 if (!file_system_info_.writable()) | 38 if (!file_system_info_.writable()) |
38 return false; | 39 return false; |
39 | 40 |
40 scoped_ptr<base::DictionaryValue> values(new base::DictionaryValue); | 41 WriteFileRequestedOptions options; |
41 values->SetInteger("openRequestId", file_handle_); | 42 options.file_system_id = file_system_info_.file_system_id(); |
42 values->SetDouble("offset", offset_); | 43 options.request_id = request_id; |
| 44 options.open_request_id = file_handle_; |
| 45 options.offset = offset_; |
43 // Length is not passed directly since it can be accessed via data.byteLength. | 46 // Length is not passed directly since it can be accessed via data.byteLength. |
44 | 47 |
| 48 // Set the data directly on base::Value() to avoid an extra string copy. |
45 DCHECK(buffer_.get()); | 49 DCHECK(buffer_.get()); |
46 values->Set( | 50 scoped_ptr<base::DictionaryValue> options_as_value = options.ToValue(); |
| 51 options_as_value->Set( |
47 "data", | 52 "data", |
48 base::BinaryValue::CreateWithCopiedBuffer(buffer_->data(), length_)); | 53 base::BinaryValue::CreateWithCopiedBuffer(buffer_->data(), length_)); |
49 | 54 |
| 55 scoped_ptr<base::ListValue> event_args(new base::ListValue); |
| 56 event_args->Append(options_as_value.release()); |
| 57 |
50 return SendEvent( | 58 return SendEvent( |
51 request_id, | 59 request_id, |
52 extensions::api::file_system_provider::OnWriteFileRequested::kEventName, | 60 extensions::api::file_system_provider::OnWriteFileRequested::kEventName, |
53 values.Pass()); | 61 event_args.Pass()); |
54 } | 62 } |
55 | 63 |
56 void WriteFile::OnSuccess(int /* request_id */, | 64 void WriteFile::OnSuccess(int /* request_id */, |
57 scoped_ptr<RequestValue> /* result */, | 65 scoped_ptr<RequestValue> /* result */, |
58 bool /* has_more */) { | 66 bool /* has_more */) { |
59 TRACE_EVENT0("file_system_provider", "WriteFile::OnSuccess"); | 67 TRACE_EVENT0("file_system_provider", "WriteFile::OnSuccess"); |
60 callback_.Run(base::File::FILE_OK); | 68 callback_.Run(base::File::FILE_OK); |
61 } | 69 } |
62 | 70 |
63 void WriteFile::OnError(int /* request_id */, | 71 void WriteFile::OnError(int /* request_id */, |
64 scoped_ptr<RequestValue> /* result */, | 72 scoped_ptr<RequestValue> /* result */, |
65 base::File::Error error) { | 73 base::File::Error error) { |
66 TRACE_EVENT0("file_system_provider", "WriteFile::OnError"); | 74 TRACE_EVENT0("file_system_provider", "WriteFile::OnError"); |
67 callback_.Run(error); | 75 callback_.Run(error); |
68 } | 76 } |
69 | 77 |
70 } // namespace operations | 78 } // namespace operations |
71 } // namespace file_system_provider | 79 } // namespace file_system_provider |
72 } // namespace chromeos | 80 } // namespace chromeos |
OLD | NEW |