1 // Copyright (c) 2012 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 #ifndef CONTENT_BROWSER_DOWNLOAD_DRAG_DOWNLOAD_UTIL_H_ 6 #define CONTENT_BROWSER_DOWNLOAD_DRAG_DOWNLOAD_UTIL_H_ 7 8 #include "base/basictypes.h" 9 #include "base/memory/ref_counted.h" 10 #include "base/strings/string16.h" 11 #include "content/browser/download/drag_download_file.h" 12 #include "ui/base/dragdrop/download_file_interface.h" 13 14 class GURL; 15 16 namespace base { 17 class FilePath; 18 } 19 20 namespace net { 21 class FileStream; 22 } 23 24 namespace content { 25 26 // Parse the download metadata set in DataTransfer.setData. The metadata 27 // consists of a set of the following values separated by ":" 28 // * MIME type 29 // * File name 30 // * URL 31 // If the file name contains special characters, they need to be escaped 32 // appropriately. 33 // For example, we can have 34 // text/plain:example.txt:http://example.com/example.txt 35 bool ParseDownloadMetadata(const base::string16& metadata, 36 base::string16* mime_type, 37 base::FilePath* file_name, 38 GURL* url); 39 40 // Create a new file at the specified path. If the file already exists, try to 41 // insert the sequential unifier to produce a new file, like foo-01.txt. 42 // Return a FileStream if successful. 43 // |net_log| is a NetLog for the stream. 44 CONTENT_EXPORT net::FileStream* CreateFileStreamForDrop( 45 base::FilePath* file_path, net::NetLog* net_log); 46 47 // Implementation of DownloadFileObserver to finalize the download process. 48 class PromiseFileFinalizer : public ui::DownloadFileObserver { 49 public: 50 explicit PromiseFileFinalizer(DragDownloadFile* drag_file_downloader); 51 52 // DownloadFileObserver methods. 53 virtual void OnDownloadCompleted(const base::FilePath& file_path) OVERRIDE; 54 virtual void OnDownloadAborted() OVERRIDE; 55 56 protected: 57 virtual ~PromiseFileFinalizer(); 58 59 private: 60 void Cleanup(); 61 62 scoped_refptr<DragDownloadFile> drag_file_downloader_; 63 64 DISALLOW_COPY_AND_ASSIGN(PromiseFileFinalizer); 65 }; 66 67 } // namespace content 68 69 #endif // CONTENT_BROWSER_DOWNLOAD_DRAG_DOWNLOAD_UTIL_H_ 70