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