| 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_FILE_H_ | 5 #ifndef CONTENT_BROWSER_DOWNLOAD_DRAG_DOWNLOAD_FILE_H_ |
| 6 #define CONTENT_BROWSER_DOWNLOAD_DRAG_DOWNLOAD_FILE_H_ | 6 #define CONTENT_BROWSER_DOWNLOAD_DRAG_DOWNLOAD_FILE_H_ |
| 7 | 7 |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 // This class implements downloading a file via dragging virtual files out of | 33 // This class implements downloading a file via dragging virtual files out of |
| 34 // the browser: | 34 // the browser: |
| 35 // http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2009-August/022118.html | 35 // http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2009-August/022118.html |
| 36 // http://www.html5rocks.com/en/tutorials/casestudies/box_dnd_download/ | 36 // http://www.html5rocks.com/en/tutorials/casestudies/box_dnd_download/ |
| 37 class CONTENT_EXPORT DragDownloadFile : public ui::DownloadFileProvider { | 37 class CONTENT_EXPORT DragDownloadFile : public ui::DownloadFileProvider { |
| 38 public: | 38 public: |
| 39 // On Windows, we need to download into a temporary file. On posix, we need to | 39 // On Windows, we need to download into a temporary file. On posix, we need to |
| 40 // download into a file stream that has already been created, so only the UI | 40 // download into a file stream that has already been created, so only the UI |
| 41 // thread is involved. |file_stream| must be null on windows but non-null on | 41 // thread is involved. |file_stream| must be null on windows but non-null on |
| 42 // posix systems. |file_path| is an absolute path on all systems. | 42 // posix systems. |file_path| is an absolute path on all systems. |
| 43 DragDownloadFile(const FilePath& file_path, | 43 DragDownloadFile(const base::FilePath& file_path, |
| 44 scoped_ptr<net::FileStream> file_stream, | 44 scoped_ptr<net::FileStream> file_stream, |
| 45 const GURL& url, | 45 const GURL& url, |
| 46 const Referrer& referrer, | 46 const Referrer& referrer, |
| 47 const std::string& referrer_encoding, | 47 const std::string& referrer_encoding, |
| 48 WebContents* web_contents); | 48 WebContents* web_contents); |
| 49 | 49 |
| 50 // DownloadFileProvider methods. | 50 // DownloadFileProvider methods. |
| 51 virtual void Start(ui::DownloadFileObserver* observer) OVERRIDE; | 51 virtual void Start(ui::DownloadFileObserver* observer) OVERRIDE; |
| 52 virtual bool Wait() OVERRIDE; | 52 virtual bool Wait() OVERRIDE; |
| 53 virtual void Stop() OVERRIDE; | 53 virtual void Stop() OVERRIDE; |
| 54 | 54 |
| 55 private: | 55 private: |
| 56 class DragDownloadFileUI; | 56 class DragDownloadFileUI; |
| 57 enum State {INITIALIZED, STARTED, SUCCESS, FAILURE}; | 57 enum State {INITIALIZED, STARTED, SUCCESS, FAILURE}; |
| 58 | 58 |
| 59 virtual ~DragDownloadFile(); | 59 virtual ~DragDownloadFile(); |
| 60 | 60 |
| 61 void DownloadCompleted(bool is_successful); | 61 void DownloadCompleted(bool is_successful); |
| 62 void CheckThread(); | 62 void CheckThread(); |
| 63 | 63 |
| 64 FilePath file_path_; | 64 base::FilePath file_path_; |
| 65 scoped_ptr<net::FileStream> file_stream_; | 65 scoped_ptr<net::FileStream> file_stream_; |
| 66 MessageLoop* drag_message_loop_; | 66 MessageLoop* drag_message_loop_; |
| 67 State state_; | 67 State state_; |
| 68 scoped_refptr<ui::DownloadFileObserver> observer_; | 68 scoped_refptr<ui::DownloadFileObserver> observer_; |
| 69 base::RunLoop nested_loop_; | 69 base::RunLoop nested_loop_; |
| 70 DragDownloadFileUI* drag_ui_; | 70 DragDownloadFileUI* drag_ui_; |
| 71 base::WeakPtrFactory<DragDownloadFile> weak_ptr_factory_; | 71 base::WeakPtrFactory<DragDownloadFile> weak_ptr_factory_; |
| 72 | 72 |
| 73 DISALLOW_COPY_AND_ASSIGN(DragDownloadFile); | 73 DISALLOW_COPY_AND_ASSIGN(DragDownloadFile); |
| 74 }; | 74 }; |
| 75 | 75 |
| 76 } // namespace content | 76 } // namespace content |
| 77 | 77 |
| 78 #endif // CONTENT_BROWSER_DOWNLOAD_DRAG_DOWNLOAD_FILE_H_ | 78 #endif // CONTENT_BROWSER_DOWNLOAD_DRAG_DOWNLOAD_FILE_H_ |
| OLD | NEW |