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 3// found in the LICENSE file. 4 5#include "chrome/browser/chromeos/file_system_provider/operations/truncate.h" 6 7#include <string> 8 9#include "chrome/common/extensions/api/file_system_provider.h" 10#include "chrome/common/extensions/api/file_system_provider_internal.h" 11 12namespace chromeos { 13namespace file_system_provider { 14namespace operations { 15 16Truncate::Truncate(extensions::EventRouter* event_router, 17 const ProvidedFileSystemInfo& file_system_info, 18 const base::FilePath& file_path, 19 int64 length, 20 const storage::AsyncFileUtil::StatusCallback& callback) 21 : Operation(event_router, file_system_info), 22 file_path_(file_path), 23 length_(length), 24 callback_(callback) { 25} 26 27Truncate::~Truncate() { 28} 29 30bool Truncate::Execute(int request_id) { 31 using extensions::api::file_system_provider::TruncateRequestedOptions; 32 33 if (!file_system_info_.writable()) 34 return false; 35 36 TruncateRequestedOptions options; 37 options.file_system_id = file_system_info_.file_system_id(); 38 options.request_id = request_id; 39 options.file_path = file_path_.AsUTF8Unsafe(); 40 options.length = length_; 41 42 return SendEvent( 43 request_id, 44 extensions::api::file_system_provider::OnTruncateRequested::kEventName, 45 extensions::api::file_system_provider::OnTruncateRequested::Create( 46 options)); 47} 48 49void Truncate::OnSuccess(int /* request_id */, 50 scoped_ptr<RequestValue> /* result */, 51 bool has_more) { 52 callback_.Run(base::File::FILE_OK); 53} 54 55void Truncate::OnError(int /* request_id */, 56 scoped_ptr<RequestValue> /* result */, 57 base::File::Error error) { 58 callback_.Run(error); 59} 60 61} // namespace operations 62} // namespace file_system_provider 63} // namespace chromeos 64