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.
5 #ifndef CONTENT_BROWSER_DOWNLOAD_DRAG_DOWNLOAD_UTIL_H_
6 #define CONTENT_BROWSER_DOWNLOAD_DRAG_DOWNLOAD_UTIL_H_
8 #include "base/basictypes.h"
9 #include "base/files/file.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/strings/string16.h"
12 #include "content/browser/download/drag_download_file.h"
13 #include "ui/base/dragdrop/download_file_interface.h"
23 // Parse the download metadata set in DataTransfer.setData. The metadata
24 // consists of a set of the following values separated by ":"
28 // If the file name contains special characters, they need to be escaped
30 // For example, we can have
31 // text/plain:example.txt:http://example.com/example.txt
32 bool ParseDownloadMetadata(const base::string16
& metadata
,
33 base::string16
* mime_type
,
34 base::FilePath
* file_name
,
37 // 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 // Return a File if successful.
40 CONTENT_EXPORT
base::File
CreateFileForDrop(base::FilePath
* file_path
);
42 // Implementation of DownloadFileObserver to finalize the download process.
43 class PromiseFileFinalizer
: public ui::DownloadFileObserver
{
45 explicit PromiseFileFinalizer(DragDownloadFile
* drag_file_downloader
);
47 // DownloadFileObserver methods.
48 virtual void OnDownloadCompleted(const base::FilePath
& file_path
) OVERRIDE
;
49 virtual void OnDownloadAborted() OVERRIDE
;
52 virtual ~PromiseFileFinalizer();
57 scoped_refptr
<DragDownloadFile
> drag_file_downloader_
;
59 DISALLOW_COPY_AND_ASSIGN(PromiseFileFinalizer
);
62 } // namespace content
64 #endif // CONTENT_BROWSER_DOWNLOAD_DRAG_DOWNLOAD_UTIL_H_