13551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 23551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 33551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// found in the LICENSE file. 43551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 53551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#ifndef CHROME_BROWSER_CHROMEOS_DRIVE_WRITE_ON_CACHE_FILE_H_ 63551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#define CHROME_BROWSER_CHROMEOS_DRIVE_WRITE_ON_CACHE_FILE_H_ 73551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 83551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "base/callback_forward.h" 93551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "chrome/browser/chromeos/drive/file_errors.h" 103551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 113551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)namespace base { 123551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)class FilePath; 133551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)} 143551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 153551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)namespace drive { 163551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 173551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)class FileSystemInterface; 183551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 193551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// Callback type for WriteOnCacheFile. 203551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)typedef base::Callback<void (FileError, const base::FilePath& path)> 213551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) WriteOnCacheFileCallback; 223551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 233551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// Creates (if needed) a file at |path|, brings it to the local cache, 243551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// and invokes |callback| on blocking thread pool with the cache file path. 253551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// The |callback| can write to the file at the path by normal local file I/O 263551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// operations. After it returns, the written content is synced to the server. 273551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// 283551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// If non-empty |mime_type| is set and the file is created by this function 293551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// call, the mime type for the entry is set to |mime_type|. Otherwise the type 303551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// is automatically determined from |path|. 313551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// 323551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// Must be called from UI thread. 333551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)void WriteOnCacheFile(FileSystemInterface* file_system, 343551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) const base::FilePath& path, 353551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) const std::string& mime_type, 363551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) const WriteOnCacheFileCallback& callback); 373551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 38a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// Does the same thing as WriteOnCacheFile() and runs |reply| on the UI thread 39a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// after the completion. 40a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)void WriteOnCacheFileAndReply(FileSystemInterface* file_system, 41a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const base::FilePath& path, 42a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const std::string& mime_type, 43a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const WriteOnCacheFileCallback& callback, 44a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const FileOperationCallback& reply); 45a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 463551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)} // namespace drive 473551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 483551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#endif // CHROME_BROWSER_CHROMEOS_DRIVE_WRITE_ON_CACHE_FILE_H_ 49