OLD | NEW |
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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/ui/webui/settings/downloads_handler.h" | 5 #include "chrome/browser/ui/webui/settings/downloads_handler.h" |
6 | 6 |
| 7 #include "base/metrics/user_metrics.h" |
7 #include "base/values.h" | 8 #include "base/values.h" |
8 #include "chrome/browser/download/download_prefs.h" | 9 #include "chrome/browser/download/download_prefs.h" |
9 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/ui/chrome_select_file_policy.h" | 11 #include "chrome/browser/ui/chrome_select_file_policy.h" |
11 #include "chrome/common/pref_names.h" | 12 #include "chrome/common/pref_names.h" |
12 #include "chrome/grit/generated_resources.h" | 13 #include "chrome/grit/generated_resources.h" |
13 #include "components/prefs/pref_service.h" | 14 #include "components/prefs/pref_service.h" |
14 #include "components/prefs/scoped_user_pref_update.h" | 15 #include "components/prefs/scoped_user_pref_update.h" |
15 #include "content/public/browser/download_manager.h" | 16 #include "content/public/browser/download_manager.h" |
16 #include "content/public/browser/user_metrics.h" | |
17 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
18 #include "content/public/browser/web_ui.h" | 18 #include "content/public/browser/web_ui.h" |
19 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
20 | 20 |
21 using base::UserMetricsAction; | 21 using base::UserMetricsAction; |
22 | 22 |
23 namespace settings { | 23 namespace settings { |
24 | 24 |
25 DownloadsHandler::DownloadsHandler(Profile* profile) : profile_(profile) {} | 25 DownloadsHandler::DownloadsHandler(Profile* profile) : profile_(profile) {} |
26 | 26 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 content::BrowserContext::GetDownloadManager(profile_); | 67 content::BrowserContext::GetDownloadManager(profile_); |
68 bool auto_open_downloads = | 68 bool auto_open_downloads = |
69 manager && DownloadPrefs::FromDownloadManager(manager)->IsAutoOpenUsed(); | 69 manager && DownloadPrefs::FromDownloadManager(manager)->IsAutoOpenUsed(); |
70 CallJavascriptFunction("cr.webUIListenerCallback", | 70 CallJavascriptFunction("cr.webUIListenerCallback", |
71 base::Value("auto-open-downloads-changed"), | 71 base::Value("auto-open-downloads-changed"), |
72 base::Value(auto_open_downloads)); | 72 base::Value(auto_open_downloads)); |
73 } | 73 } |
74 | 74 |
75 void DownloadsHandler::HandleResetAutoOpenFileTypes( | 75 void DownloadsHandler::HandleResetAutoOpenFileTypes( |
76 const base::ListValue* args) { | 76 const base::ListValue* args) { |
77 content::RecordAction(UserMetricsAction("Options_ResetAutoOpenFiles")); | 77 base::RecordAction(UserMetricsAction("Options_ResetAutoOpenFiles")); |
78 content::DownloadManager* manager = | 78 content::DownloadManager* manager = |
79 content::BrowserContext::GetDownloadManager(profile_); | 79 content::BrowserContext::GetDownloadManager(profile_); |
80 if (manager) | 80 if (manager) |
81 DownloadPrefs::FromDownloadManager(manager)->ResetAutoOpen(); | 81 DownloadPrefs::FromDownloadManager(manager)->ResetAutoOpen(); |
82 } | 82 } |
83 | 83 |
84 void DownloadsHandler::HandleSelectDownloadLocation( | 84 void DownloadsHandler::HandleSelectDownloadLocation( |
85 const base::ListValue* args) { | 85 const base::ListValue* args) { |
86 PrefService* pref_service = profile_->GetPrefs(); | 86 PrefService* pref_service = profile_->GetPrefs(); |
87 select_folder_dialog_ = ui::SelectFileDialog::Create( | 87 select_folder_dialog_ = ui::SelectFileDialog::Create( |
88 this, new ChromeSelectFilePolicy(web_ui()->GetWebContents())); | 88 this, new ChromeSelectFilePolicy(web_ui()->GetWebContents())); |
89 ui::SelectFileDialog::FileTypeInfo info; | 89 ui::SelectFileDialog::FileTypeInfo info; |
90 info.allowed_paths = ui::SelectFileDialog::FileTypeInfo::NATIVE_OR_DRIVE_PATH; | 90 info.allowed_paths = ui::SelectFileDialog::FileTypeInfo::NATIVE_OR_DRIVE_PATH; |
91 select_folder_dialog_->SelectFile( | 91 select_folder_dialog_->SelectFile( |
92 ui::SelectFileDialog::SELECT_FOLDER, | 92 ui::SelectFileDialog::SELECT_FOLDER, |
93 l10n_util::GetStringUTF16(IDS_SETTINGS_DOWNLOAD_LOCATION), | 93 l10n_util::GetStringUTF16(IDS_SETTINGS_DOWNLOAD_LOCATION), |
94 pref_service->GetFilePath(prefs::kDownloadDefaultDirectory), &info, 0, | 94 pref_service->GetFilePath(prefs::kDownloadDefaultDirectory), &info, 0, |
95 base::FilePath::StringType(), | 95 base::FilePath::StringType(), |
96 web_ui()->GetWebContents()->GetTopLevelNativeWindow(), NULL); | 96 web_ui()->GetWebContents()->GetTopLevelNativeWindow(), NULL); |
97 } | 97 } |
98 | 98 |
99 void DownloadsHandler::FileSelected(const base::FilePath& path, | 99 void DownloadsHandler::FileSelected(const base::FilePath& path, |
100 int index, | 100 int index, |
101 void* params) { | 101 void* params) { |
102 content::RecordAction(UserMetricsAction("Options_SetDownloadDirectory")); | 102 base::RecordAction(UserMetricsAction("Options_SetDownloadDirectory")); |
103 PrefService* pref_service = profile_->GetPrefs(); | 103 PrefService* pref_service = profile_->GetPrefs(); |
104 pref_service->SetFilePath(prefs::kDownloadDefaultDirectory, path); | 104 pref_service->SetFilePath(prefs::kDownloadDefaultDirectory, path); |
105 pref_service->SetFilePath(prefs::kSaveFileDefaultDirectory, path); | 105 pref_service->SetFilePath(prefs::kSaveFileDefaultDirectory, path); |
106 } | 106 } |
107 | 107 |
108 } // namespace settings | 108 } // namespace settings |
OLD | NEW |