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 CHROME_BROWSER_DOWNLOAD_DOWNLOAD_PREFS_H_
6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_PREFS_H_
10 #include "base/files/file_path.h"
11 #include "base/prefs/pref_member.h"
18 class DownloadManager;
21 namespace user_prefs {
22 class PrefRegistrySyncable;
25 // Stores all download-related preferences.
28 explicit DownloadPrefs(Profile* profile);
31 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
33 // Returns the default download directory.
34 static const base::FilePath& GetDefaultDownloadDirectory();
36 // Returns the DownloadPrefs corresponding to the given DownloadManager
38 static DownloadPrefs* FromDownloadManager(
39 content::DownloadManager* download_manager);
40 static DownloadPrefs* FromBrowserContext(
41 content::BrowserContext* browser_context);
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);
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;
55 // Returns true if the download path preference is managed.
56 bool IsDownloadPathManaged() const;
58 // Returns true if there is at least one file extension registered
60 bool IsAutoOpenUsed() const;
62 // Returns true if |path| should be opened automatically based on
63 // |path.Extension()|.
64 bool IsAutoOpenEnabledBasedOnExtension(const base::FilePath& path) const;
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);
70 // Disables auto-open based on file extension.
71 void DisableAutoOpenBasedOnExtension(const base::FilePath& file_name);
76 void SaveAutoOpenState();
80 BooleanPrefMember prompt_for_download_;
81 FilePathPrefMember download_path_;
82 FilePathPrefMember save_file_path_;
83 IntegerPrefMember save_file_type_;
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;
90 typedef std::set<base::FilePath::StringType,
91 AutoOpenCompareFunctor> AutoOpenSet;
92 AutoOpenSet auto_open_;
94 DISALLOW_COPY_AND_ASSIGN(DownloadPrefs);
97 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_PREFS_H_