Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: chrome/browser/download/download_prefs.cc

Issue 7192016: chrome.experimental.downloads (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: merged db_handle, id; onCreated, onErased Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/download/download_prefs.h ('k') | chrome/browser/download/download_query.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/download/download_prefs.h" 5 #include "chrome/browser/download/download_prefs.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/string_split.h" 9 #include "base/string_split.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 #include "base/sys_string_conversions.h" 11 #include "base/sys_string_conversions.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "chrome/browser/download/download_extensions.h" 13 #include "chrome/browser/download/download_extensions.h"
14 #include "chrome/browser/download/download_util.h" 14 #include "chrome/browser/download/download_util.h"
15 #include "chrome/browser/download/save_package.h" 15 #include "chrome/browser/download/save_package.h"
16 #include "chrome/browser/prefs/pref_service.h" 16 #include "chrome/browser/prefs/pref_service.h"
17 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
18 #include "content/browser/browser_thread.h" 18 #include "content/browser/browser_thread.h"
19 19
20 DownloadPrefs::DownloadPrefs(PrefService* prefs) : prefs_(prefs) { 20 DownloadPrefs::DownloadPrefs(PrefService* prefs) : prefs_(prefs) {
21 next_download_id_.Init(prefs::kNextDownloadId, prefs, NULL);
21 prompt_for_download_.Init(prefs::kPromptForDownload, prefs, NULL); 22 prompt_for_download_.Init(prefs::kPromptForDownload, prefs, NULL);
22 download_path_.Init(prefs::kDownloadDefaultDirectory, prefs, NULL); 23 download_path_.Init(prefs::kDownloadDefaultDirectory, prefs, NULL);
23 save_file_type_.Init(prefs::kSaveFileType, prefs, NULL); 24 save_file_type_.Init(prefs::kSaveFileType, prefs, NULL);
24 25
25 // We store any file extension that should be opened automatically at 26 // We store any file extension that should be opened automatically at
26 // download completion in this pref. 27 // download completion in this pref.
27 std::string extensions_to_open = 28 std::string extensions_to_open =
28 prefs->GetString(prefs::kDownloadExtensionsToOpen); 29 prefs->GetString(prefs::kDownloadExtensionsToOpen);
29 std::vector<std::string> extensions; 30 std::vector<std::string> extensions;
30 base::SplitString(extensions_to_open, ':', &extensions); 31 base::SplitString(extensions_to_open, ':', &extensions);
31 32
32 for (size_t i = 0; i < extensions.size(); ++i) { 33 for (size_t i = 0; i < extensions.size(); ++i) {
33 #if defined(OS_POSIX) 34 #if defined(OS_POSIX)
34 FilePath path(extensions[i]); 35 FilePath path(extensions[i]);
35 #elif defined(OS_WIN) 36 #elif defined(OS_WIN)
36 FilePath path(UTF8ToWide(extensions[i])); 37 FilePath path(UTF8ToWide(extensions[i]));
37 #endif 38 #endif
38 if (!extensions[i].empty() && 39 if (!extensions[i].empty() &&
39 download_util::GetFileDangerLevel(path) == download_util::NotDangerous) 40 download_util::GetFileDangerLevel(path) == download_util::NotDangerous)
40 auto_open_.insert(path.value()); 41 auto_open_.insert(path.value());
41 } 42 }
42 } 43 }
43 44
44 DownloadPrefs::~DownloadPrefs() { 45 DownloadPrefs::~DownloadPrefs() {
45 SaveAutoOpenState(); 46 SaveAutoOpenState();
46 } 47 }
47 48
48 // static 49 // static
49 void DownloadPrefs::RegisterUserPrefs(PrefService* prefs) { 50 void DownloadPrefs::RegisterUserPrefs(PrefService* prefs) {
51 prefs->RegisterIntegerPref(prefs::kNextDownloadId,
52 0,
53 PrefService::UNSYNCABLE_PREF);
50 prefs->RegisterBooleanPref(prefs::kPromptForDownload, 54 prefs->RegisterBooleanPref(prefs::kPromptForDownload,
51 false, 55 false,
52 PrefService::SYNCABLE_PREF); 56 PrefService::SYNCABLE_PREF);
53 prefs->RegisterStringPref(prefs::kDownloadExtensionsToOpen, 57 prefs->RegisterStringPref(prefs::kDownloadExtensionsToOpen,
54 "", 58 "",
55 PrefService::UNSYNCABLE_PREF); 59 PrefService::UNSYNCABLE_PREF);
56 prefs->RegisterBooleanPref(prefs::kDownloadDirUpgraded, 60 prefs->RegisterBooleanPref(prefs::kDownloadDirUpgraded,
57 false, 61 false,
58 PrefService::UNSYNCABLE_PREF); 62 PrefService::UNSYNCABLE_PREF);
59 prefs->RegisterIntegerPref(prefs::kSaveFileType, 63 prefs->RegisterIntegerPref(prefs::kSaveFileType,
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 extension.erase(0, 1); 132 extension.erase(0, 1);
129 auto_open_.erase(extension); 133 auto_open_.erase(extension);
130 SaveAutoOpenState(); 134 SaveAutoOpenState();
131 } 135 }
132 136
133 void DownloadPrefs::ResetAutoOpen() { 137 void DownloadPrefs::ResetAutoOpen() {
134 auto_open_.clear(); 138 auto_open_.clear();
135 SaveAutoOpenState(); 139 SaveAutoOpenState();
136 } 140 }
137 141
142 int DownloadPrefs::GetNextId() {
143 int next_id = *next_download_id_;
144 prefs_->SetInteger(prefs::kNextDownloadId, next_id + 1);
145 return next_id;
146 }
147
138 void DownloadPrefs::SaveAutoOpenState() { 148 void DownloadPrefs::SaveAutoOpenState() {
139 std::string extensions; 149 std::string extensions;
140 for (AutoOpenSet::iterator it = auto_open_.begin(); 150 for (AutoOpenSet::iterator it = auto_open_.begin();
141 it != auto_open_.end(); ++it) { 151 it != auto_open_.end(); ++it) {
142 #if defined(OS_POSIX) 152 #if defined(OS_POSIX)
143 std::string this_extension = *it; 153 std::string this_extension = *it;
144 #elif defined(OS_WIN) 154 #elif defined(OS_WIN)
145 // TODO(phajdan.jr): Why we're using Sys conversion here, but not in ctor? 155 // TODO(phajdan.jr): Why we're using Sys conversion here, but not in ctor?
146 std::string this_extension = base::SysWideToUTF8(*it); 156 std::string this_extension = base::SysWideToUTF8(*it);
147 #endif 157 #endif
148 extensions += this_extension + ":"; 158 extensions += this_extension + ":";
149 } 159 }
150 if (!extensions.empty()) 160 if (!extensions.empty())
151 extensions.erase(extensions.size() - 1); 161 extensions.erase(extensions.size() - 1);
152 162
153 prefs_->SetString(prefs::kDownloadExtensionsToOpen, extensions); 163 prefs_->SetString(prefs::kDownloadExtensionsToOpen, extensions);
154 } 164 }
155 165
156 bool DownloadPrefs::AutoOpenCompareFunctor::operator()( 166 bool DownloadPrefs::AutoOpenCompareFunctor::operator()(
157 const FilePath::StringType& a, 167 const FilePath::StringType& a,
158 const FilePath::StringType& b) const { 168 const FilePath::StringType& b) const {
159 return FilePath::CompareLessIgnoreCase(a, b); 169 return FilePath::CompareLessIgnoreCase(a, b);
160 } 170 }
OLDNEW
« no previous file with comments | « chrome/browser/download/download_prefs.h ('k') | chrome/browser/download/download_query.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698