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

Side by Side Diff: chrome/browser/chromeos/file_system_provider/operations/read_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/read_file.h" 5 #include "chrome/browser/chromeos/file_system_provider/operations/read_file.h"
6 6
7 #include <limits> 7 #include <limits>
8 #include <string> 8 #include <string>
9 9
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 26 matching lines...) Expand all
37 return -1; 37 return -1;
38 38
39 memcpy(buffer->data() + buffer_offset, vector_as_array(&params->data), 39 memcpy(buffer->data() + buffer_offset, vector_as_array(&params->data),
40 chunk_size); 40 chunk_size);
41 41
42 return chunk_size; 42 return chunk_size;
43 } 43 }
44 44
45 } // namespace 45 } // namespace
46 46
47 ReadFile::ReadFile( 47 template <class DestinationPolicy>
48 extensions::EventRouter* event_router, 48 ReadFile<DestinationPolicy>::ReadFile(
49 typename DestinationPolicy::EventRouterType* event_router,
49 const ProvidedFileSystemInfo& file_system_info, 50 const ProvidedFileSystemInfo& file_system_info,
50 int file_handle, 51 int file_handle,
51 scoped_refptr<net::IOBuffer> buffer, 52 scoped_refptr<net::IOBuffer> buffer,
52 int64 offset, 53 int64 offset,
53 int length, 54 int length,
54 const ProvidedFileSystemInterface::ReadChunkReceivedCallback& callback) 55 const ProvidedFileSystemInterface::ReadChunkReceivedCallback& callback)
55 : Operation(event_router, file_system_info), 56 : Operation<DestinationPolicy>(event_router, file_system_info),
56 file_handle_(file_handle), 57 file_handle_(file_handle),
57 buffer_(buffer), 58 buffer_(buffer),
58 offset_(offset), 59 offset_(offset),
59 length_(length), 60 length_(length),
60 current_offset_(0), 61 current_offset_(0),
61 callback_(callback) { 62 callback_(callback) {
62 } 63 }
63 64
64 ReadFile::~ReadFile() { 65 template <class DestinationPolicy>
66 ReadFile<DestinationPolicy>::~ReadFile() {
65 } 67 }
66 68
67 bool ReadFile::Execute(int request_id) { 69 template <class DestinationPolicy>
70 bool ReadFile<DestinationPolicy>::Execute(int request_id) {
68 using extensions::api::file_system_provider::ReadFileRequestedOptions; 71 using extensions::api::file_system_provider::ReadFileRequestedOptions;
69 TRACE_EVENT0("file_system_provider", "ReadFile::Execute"); 72 TRACE_EVENT0("file_system_provider", "ReadFile::Execute");
70 73
71 ReadFileRequestedOptions options; 74 ReadFileRequestedOptions options;
72 options.file_system_id = file_system_info_.file_system_id(); 75 options.file_system_id = this->file_system_info_.file_system_id();
73 options.request_id = request_id; 76 options.request_id = request_id;
74 options.open_request_id = file_handle_; 77 options.open_request_id = file_handle_;
75 options.offset = offset_; 78 options.offset = offset_;
76 options.length = length_; 79 options.length = length_;
77 80
78 return SendEvent( 81 return this->SendEvent(
79 request_id, 82 request_id,
80 extensions::api::file_system_provider::OnReadFileRequested::kEventName, 83 extensions::api::file_system_provider::OnReadFileRequested::kEventName,
81 extensions::api::file_system_provider::OnReadFileRequested::Create( 84 extensions::api::file_system_provider::OnReadFileRequested::Create(
82 options)); 85 options));
83 } 86 }
84 87
85 void ReadFile::OnSuccess(int /* request_id */, 88 template <class DestinationPolicy>
86 scoped_ptr<RequestValue> result, 89 void ReadFile<DestinationPolicy>::OnSuccess(int /* request_id */,
87 bool has_more) { 90 scoped_ptr<RequestValue> result,
91 bool has_more) {
88 TRACE_EVENT0("file_system_provider", "ReadFile::OnSuccess"); 92 TRACE_EVENT0("file_system_provider", "ReadFile::OnSuccess");
89 const int copy_result = CopyRequestValueToBuffer( 93 const int copy_result = CopyRequestValueToBuffer(
90 result.Pass(), buffer_, current_offset_, length_); 94 result.Pass(), buffer_, current_offset_, length_);
91 95
92 if (copy_result < 0) { 96 if (copy_result < 0) {
93 LOG(ERROR) << "Failed to parse a response for the read file operation."; 97 LOG(ERROR) << "Failed to parse a response for the read file operation.";
94 callback_.Run( 98 callback_.Run(
95 0 /* chunk_length */, false /* has_more */, base::File::FILE_ERROR_IO); 99 0 /* chunk_length */, false /* has_more */, base::File::FILE_ERROR_IO);
96 return; 100 return;
97 } 101 }
98 102
99 if (copy_result > 0) 103 if (copy_result > 0)
100 current_offset_ += copy_result; 104 current_offset_ += copy_result;
101 callback_.Run(copy_result, has_more, base::File::FILE_OK); 105 callback_.Run(copy_result, has_more, base::File::FILE_OK);
102 } 106 }
103 107
104 void ReadFile::OnError(int /* request_id */, 108 template <class DestinationPolicy>
105 scoped_ptr<RequestValue> /* result */, 109 void ReadFile<DestinationPolicy>::OnError(int /* request_id */,
106 base::File::Error error) { 110 scoped_ptr<RequestValue> /* result */,
111 base::File::Error error) {
107 TRACE_EVENT0("file_system_provider", "ReadFile::OnError"); 112 TRACE_EVENT0("file_system_provider", "ReadFile::OnError");
108 callback_.Run(0 /* chunk_length */, false /* has_more */, error); 113 callback_.Run(0 /* chunk_length */, false /* has_more */, error);
109 } 114 }
110 115
116 FOR_EACH_DESTINATION_SPECIALIZE(ReadFile)
117
111 } // namespace operations 118 } // namespace operations
112 } // namespace file_system_provider 119 } // namespace file_system_provider
113 } // namespace chromeos 120 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698