1 // Copyright (c) 2011 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 #pragma once 8 9 #include <set> 10 11 #include "base/file_path.h" 12 #include "chrome/browser/prefs/pref_member.h" 13 14 class PrefService; 15 16 // Stores all download-related preferences. 17 class DownloadPrefs { 18 public: 19 explicit DownloadPrefs(PrefService* prefs); 20 ~DownloadPrefs(); 21 22 static void RegisterUserPrefs(PrefService* prefs); 23 download_path()24 FilePath download_path() const { return *download_path_; } save_file_type()25 int save_file_type() const { return *save_file_type_; } 26 27 // Returns true if the prompt_for_download preference has been set and the 28 // download location is not managed (which means the user shouldn't be able 29 // to choose another download location). 30 bool PromptForDownload() const; 31 32 // Returns true if the download path preference is managed. 33 bool IsDownloadPathManaged() const; 34 35 // Returns true if there is at least one file extension registered 36 // for auto-open. 37 bool IsAutoOpenUsed() const; 38 39 bool IsAutoOpenEnabledForExtension( 40 const FilePath::StringType& extension) const; 41 42 // Enables auto-open based on file extension. Returns true on success. 43 // TODO(phajdan.jr): Add WARN_UNUSED_RESULT here. 44 bool EnableAutoOpenBasedOnExtension(const FilePath& file_name); 45 46 // Disables auto-open based on file extension. 47 void DisableAutoOpenBasedOnExtension(const FilePath& file_name); 48 49 void ResetToDefaults(); 50 void ResetAutoOpen(); 51 52 private: 53 void SaveAutoOpenState(); 54 55 PrefService* prefs_; 56 57 BooleanPrefMember prompt_for_download_; 58 FilePathPrefMember download_path_; 59 IntegerPrefMember save_file_type_; 60 61 // Set of file extensions to open at download completion. 62 struct AutoOpenCompareFunctor { 63 bool operator()(const FilePath::StringType& a, 64 const FilePath::StringType& b) const; 65 }; 66 typedef std::set<FilePath::StringType, AutoOpenCompareFunctor> AutoOpenSet; 67 AutoOpenSet auto_open_; 68 69 DISALLOW_COPY_AND_ASSIGN(DownloadPrefs); 70 }; 71 72 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_PREFS_H_ 73