Respond with QuotaExceededError when IndexedDB has no disk space on open.
[chromium-blink-merge.git] / content / browser / download / drag_download_file.h
blob41fdf6224e2ffe8d17326787d7386448ccf3f3d0
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_FILE_H_
6 #define CONTENT_BROWSER_DOWNLOAD_DRAG_DOWNLOAD_FILE_H_
8 #include "base/compiler_specific.h"
9 #include "base/files/file_path.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "base/run_loop.h"
13 #include "content/browser/download/download_file.h"
14 #include "content/common/content_export.h"
15 #include "content/public/browser/download_item.h"
16 #include "content/public/browser/download_manager.h"
17 #include "content/public/common/referrer.h"
18 #include "net/base/file_stream.h"
19 #include "ui/base/dragdrop/download_file_interface.h"
20 #include "ui/base/ui_export.h"
21 #include "url/gurl.h"
23 namespace net {
24 class FileStream;
27 namespace content {
29 class DownloadManager;
30 class WebContents;
32 // This class implements downloading a file via dragging virtual files out of
33 // the browser:
34 // http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2009-August/022118.html
35 // http://www.html5rocks.com/en/tutorials/casestudies/box_dnd_download/
36 class CONTENT_EXPORT DragDownloadFile : public ui::DownloadFileProvider {
37 public:
38 // On Windows, we need to download into a temporary file. On posix, we need to
39 // download into a file stream that has already been created, so only the UI
40 // thread is involved. |file_stream| must be null on windows but non-null on
41 // posix systems. |file_path| is an absolute path on all systems.
42 DragDownloadFile(const base::FilePath& file_path,
43 scoped_ptr<net::FileStream> file_stream,
44 const GURL& url,
45 const Referrer& referrer,
46 const std::string& referrer_encoding,
47 WebContents* web_contents);
49 // DownloadFileProvider methods.
50 virtual void Start(ui::DownloadFileObserver* observer) OVERRIDE;
51 virtual bool Wait() OVERRIDE;
52 virtual void Stop() OVERRIDE;
54 private:
55 class DragDownloadFileUI;
56 enum State {INITIALIZED, STARTED, SUCCESS, FAILURE};
58 virtual ~DragDownloadFile();
60 void DownloadCompleted(bool is_successful);
61 void CheckThread();
63 base::FilePath file_path_;
64 scoped_ptr<net::FileStream> file_stream_;
65 base::MessageLoop* drag_message_loop_;
66 State state_;
67 scoped_refptr<ui::DownloadFileObserver> observer_;
68 base::RunLoop nested_loop_;
69 DragDownloadFileUI* drag_ui_;
70 base::WeakPtrFactory<DragDownloadFile> weak_ptr_factory_;
72 DISALLOW_COPY_AND_ASSIGN(DragDownloadFile);
75 } // namespace content
77 #endif // CONTENT_BROWSER_DOWNLOAD_DRAG_DOWNLOAD_FILE_H_