- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / download / download_prefs.h
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.
4
5 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_PREFS_H_
6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_PREFS_H_
7
8 #include <set>
9
10 #include "base/files/file_path.h"
11 #include "base/prefs/pref_member.h"
12
13 class PrefService;
14 class Profile;
15
16 namespace content {
17 class BrowserContext;
18 class DownloadManager;
19 }
20
21 namespace user_prefs {
22 class PrefRegistrySyncable;
23 }
24
25 // Stores all download-related preferences.
26 class DownloadPrefs {
27  public:
28   explicit DownloadPrefs(Profile* profile);
29   ~DownloadPrefs();
30
31   static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
32
33   // Returns the default download directory.
34   static const base::FilePath& GetDefaultDownloadDirectory();
35
36   // Returns the DownloadPrefs corresponding to the given DownloadManager
37   // or BrowserContext.
38   static DownloadPrefs* FromDownloadManager(
39       content::DownloadManager* download_manager);
40   static DownloadPrefs* FromBrowserContext(
41       content::BrowserContext* browser_context);
42
43   base::FilePath DownloadPath() const;
44   void SetDownloadPath(const base::FilePath& path);
45   base::FilePath SaveFilePath() const;
46   void SetSaveFilePath(const base::FilePath& path);
47   int save_file_type() const { return *save_file_type_; }
48   void SetSaveFileType(int type);
49
50   // Returns true if the prompt_for_download preference has been set and the
51   // download location is not managed (which means the user shouldn't be able
52   // to choose another download location).
53   bool PromptForDownload() const;
54
55   // Returns true if the download path preference is managed.
56   bool IsDownloadPathManaged() const;
57
58   // Returns true if there is at least one file extension registered
59   // for auto-open.
60   bool IsAutoOpenUsed() const;
61
62   // Returns true if |path| should be opened automatically based on
63   // |path.Extension()|.
64   bool IsAutoOpenEnabledBasedOnExtension(const base::FilePath& path) const;
65
66   // Enables auto-open based on file extension. Returns true on success.
67   // TODO(phajdan.jr): Add WARN_UNUSED_RESULT here.
68   bool EnableAutoOpenBasedOnExtension(const base::FilePath& file_name);
69
70   // Disables auto-open based on file extension.
71   void DisableAutoOpenBasedOnExtension(const base::FilePath& file_name);
72
73   void ResetAutoOpen();
74
75  private:
76   void SaveAutoOpenState();
77
78   Profile* profile_;
79
80   BooleanPrefMember prompt_for_download_;
81   FilePathPrefMember download_path_;
82   FilePathPrefMember save_file_path_;
83   IntegerPrefMember save_file_type_;
84
85   // Set of file extensions to open at download completion.
86   struct AutoOpenCompareFunctor {
87     bool operator()(const base::FilePath::StringType& a,
88                     const base::FilePath::StringType& b) const;
89   };
90   typedef std::set<base::FilePath::StringType,
91                    AutoOpenCompareFunctor> AutoOpenSet;
92   AutoOpenSet auto_open_;
93
94   DISALLOW_COPY_AND_ASSIGN(DownloadPrefs);
95 };
96
97 #endif  // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_PREFS_H_