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