Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / xwalk / runtime / browser / runtime_download_manager_delegate.h
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Copyright (c) 2013 Intel Corporation. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5
6 #ifndef XWALK_RUNTIME_BROWSER_RUNTIME_DOWNLOAD_MANAGER_DELEGATE_H_
7 #define XWALK_RUNTIME_BROWSER_RUNTIME_DOWNLOAD_MANAGER_DELEGATE_H_
8
9 #include "base/compiler_specific.h"
10 #include "base/memory/ref_counted.h"
11 #include "content/public/browser/download_manager_delegate.h"
12
13 namespace xwalk {
14
15 class RuntimeDownloadManagerDelegate
16     : public content::DownloadManagerDelegate,
17       public base::RefCountedThreadSafe<RuntimeDownloadManagerDelegate> {
18  public:
19   RuntimeDownloadManagerDelegate();
20
21   void SetDownloadManager(content::DownloadManager* manager);
22
23   void Shutdown() override;
24   bool DetermineDownloadTarget(
25       content::DownloadItem* download,
26       const content::DownloadTargetCallback& callback) override;
27   bool ShouldOpenDownload(
28       content::DownloadItem* item,
29       const content::DownloadOpenDelayedCallback& callback) override;
30   void GetNextId(const content::DownloadIdCallback& callback) override;
31
32   // Inhibits prompting and sets the default download path.
33   void SetDownloadBehaviorForTesting(
34       const base::FilePath& default_download_path);
35
36  protected:
37   // To allow subclasses for testing.
38   virtual ~RuntimeDownloadManagerDelegate();
39
40  private:
41   friend class base::RefCountedThreadSafe<RuntimeDownloadManagerDelegate>;
42
43   void GenerateFilename(uint32 download_id,
44                         const content::DownloadTargetCallback& callback,
45                         const base::FilePath& generated_name,
46                         const base::FilePath& suggested_directory);
47   void OnDownloadPathGenerated(uint32 download_id,
48                                const content::DownloadTargetCallback& callback,
49                                const base::FilePath& suggested_path);
50   void ChooseDownloadPath(uint32 download_id,
51                           const content::DownloadTargetCallback& callback,
52                           const base::FilePath& suggested_path);
53
54   content::DownloadManager* download_manager_;
55   base::FilePath default_download_path_;
56   bool suppress_prompting_;
57
58   DISALLOW_COPY_AND_ASSIGN(RuntimeDownloadManagerDelegate);
59 };
60
61 }  // namespace xwalk
62
63 #endif  // XWALK_RUNTIME_BROWSER_RUNTIME_DOWNLOAD_MANAGER_DELEGATE_H_