No dual_mode on Win10+ shortcuts.
[chromium-blink-merge.git] / chrome / browser / download / download_prefs.h
blobb3e70467877d60f88f4907e4f46b378d63ce713e
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_
8 #include <set>
10 #include "base/files/file_path.h"
11 #include "base/prefs/pref_member.h"
13 class PrefService;
14 class Profile;
16 namespace content {
17 class BrowserContext;
18 class DownloadManager;
21 namespace user_prefs {
22 class PrefRegistrySyncable;
25 // Stores all download-related preferences.
26 class DownloadPrefs {
27 public:
28 explicit DownloadPrefs(Profile* profile);
29 ~DownloadPrefs();
31 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
33 // Returns the default download directory.
34 static const base::FilePath& GetDefaultDownloadDirectory();
36 // Returns the default download directory for the current profile.
37 base::FilePath GetDefaultDownloadDirectoryForProfile() const;
39 // Returns the DownloadPrefs corresponding to the given DownloadManager
40 // or BrowserContext.
41 static DownloadPrefs* FromDownloadManager(
42 content::DownloadManager* download_manager);
43 static DownloadPrefs* FromBrowserContext(
44 content::BrowserContext* browser_context);
46 base::FilePath DownloadPath() const;
47 void SetDownloadPath(const base::FilePath& path);
48 base::FilePath SaveFilePath() const;
49 void SetSaveFilePath(const base::FilePath& path);
50 int save_file_type() const { return *save_file_type_; }
51 void SetSaveFileType(int type);
53 // Returns true if the prompt_for_download preference has been set and the
54 // download location is not managed (which means the user shouldn't be able
55 // to choose another download location).
56 bool PromptForDownload() const;
58 // Returns true if the download path preference is managed.
59 bool IsDownloadPathManaged() const;
61 // Returns true if there is at least one file extension registered
62 // for auto-open.
63 bool IsAutoOpenUsed() const;
65 // Returns true if |path| should be opened automatically based on
66 // |path.Extension()|.
67 bool IsAutoOpenEnabledBasedOnExtension(const base::FilePath& path) const;
69 // Enables automatically opening all downloads with the same file type as
70 // |file_name|. Returns true on success. The call may fail if |file_name|
71 // either doesn't have an extension (hence the file type cannot be
72 // determined), or if the file type is one that is disallowed from being
73 // opened automatically. See IsAllowedToOpenAutomatically() for details on the
74 // latter.
75 bool EnableAutoOpenBasedOnExtension(const base::FilePath& file_name);
77 // Disables auto-open based on file extension.
78 void DisableAutoOpenBasedOnExtension(const base::FilePath& file_name);
80 #if defined(OS_WIN) || defined(OS_LINUX) || \
81 (defined(OS_MACOSX) && !defined(OS_IOS))
82 // Store the user preference to disk. If |should_open| is true, also disable
83 // the built-in PDF plugin. If |should_open| is false, enable the PDF plugin.
84 void SetShouldOpenPdfInSystemReader(bool should_open);
86 // Return whether the user prefers to open PDF downloads in the platform's
87 // default reader.
88 bool ShouldOpenPdfInSystemReader() const;
89 #endif
91 void ResetAutoOpen();
93 private:
94 void SaveAutoOpenState();
96 Profile* profile_;
98 BooleanPrefMember prompt_for_download_;
99 FilePathPrefMember download_path_;
100 FilePathPrefMember save_file_path_;
101 IntegerPrefMember save_file_type_;
103 // Set of file extensions to open at download completion.
104 struct AutoOpenCompareFunctor {
105 bool operator()(const base::FilePath::StringType& a,
106 const base::FilePath::StringType& b) const;
108 typedef std::set<base::FilePath::StringType,
109 AutoOpenCompareFunctor> AutoOpenSet;
110 AutoOpenSet auto_open_;
112 #if defined(OS_WIN) || defined(OS_LINUX) || \
113 (defined(OS_MACOSX) && !defined(OS_IOS))
114 bool should_open_pdf_in_system_reader_;
115 #endif
117 DISALLOW_COPY_AND_ASSIGN(DownloadPrefs);
120 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_PREFS_H_