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 22 matching lines...) Expand all Loading... |
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 | 36 |
37 if (!file_system_info_.writable()) | 37 if (!file_system_info_.writable()) |
38 return false; | 38 return false; |
39 | 39 |
40 scoped_ptr<base::DictionaryValue> values(new base::DictionaryValue); | 40 scoped_ptr<base::DictionaryValue> values(new base::DictionaryValue); |
41 values->SetInteger("openRequestId", file_handle_); | 41 values->SetInteger("openRequestId", file_handle_); |
42 values->SetDouble("offset", offset_); | 42 values->SetDouble("offset", offset_); |
43 values->SetInteger("length", length_); | 43 // Length is not passed directly since it can be accessed via data.byteLength. |
44 | 44 |
45 DCHECK(buffer_.get()); | 45 DCHECK(buffer_.get()); |
46 values->Set( | 46 values->Set( |
47 "data", | 47 "data", |
48 base::BinaryValue::CreateWithCopiedBuffer(buffer_->data(), length_)); | 48 base::BinaryValue::CreateWithCopiedBuffer(buffer_->data(), length_)); |
49 | 49 |
50 return SendEvent( | 50 return SendEvent( |
51 request_id, | 51 request_id, |
52 extensions::api::file_system_provider::OnWriteFileRequested::kEventName, | 52 extensions::api::file_system_provider::OnWriteFileRequested::kEventName, |
53 values.Pass()); | 53 values.Pass()); |
54 } | 54 } |
55 | 55 |
56 void WriteFile::OnSuccess(int /* request_id */, | 56 void WriteFile::OnSuccess(int /* request_id */, |
57 scoped_ptr<RequestValue> /* result */, | 57 scoped_ptr<RequestValue> /* result */, |
58 bool /* has_more */) { | 58 bool /* has_more */) { |
59 TRACE_EVENT0("file_system_provider", "WriteFile::OnSuccess"); | 59 TRACE_EVENT0("file_system_provider", "WriteFile::OnSuccess"); |
60 callback_.Run(base::File::FILE_OK); | 60 callback_.Run(base::File::FILE_OK); |
61 } | 61 } |
62 | 62 |
63 void WriteFile::OnError(int /* request_id */, | 63 void WriteFile::OnError(int /* request_id */, |
64 scoped_ptr<RequestValue> /* result */, | 64 scoped_ptr<RequestValue> /* result */, |
65 base::File::Error error) { | 65 base::File::Error error) { |
66 TRACE_EVENT0("file_system_provider", "WriteFile::OnError"); | 66 TRACE_EVENT0("file_system_provider", "WriteFile::OnError"); |
67 callback_.Run(error); | 67 callback_.Run(error); |
68 } | 68 } |
69 | 69 |
70 } // namespace operations | 70 } // namespace operations |
71 } // namespace file_system_provider | 71 } // namespace file_system_provider |
72 } // namespace chromeos | 72 } // namespace chromeos |
OLD | NEW |