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

Side by Side Diff: chrome/browser/ui/webui/options/advanced_options_handler.cc

Issue 6973052: When the download folder does not exist, change the download folder to a user's "Downloads" (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Added URLRequestMockHTTPJob.test_dir_ and URLRequestMockHTTPJob.temp_dir_ Created 9 years, 4 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
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/ui/webui/options/advanced_options_handler.h" 5 #include "chrome/browser/ui/webui/options/advanced_options_handler.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/file_util.h"
13 #include "base/path_service.h"
12 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
13 #include "base/values.h" 15 #include "base/values.h"
14 #include "chrome/browser/browser_process.h" 16 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/download/download_manager.h" 17 #include "chrome/browser/download/download_manager.h"
16 #include "chrome/browser/download/download_prefs.h" 18 #include "chrome/browser/download/download_prefs.h"
17 #include "chrome/browser/google/google_util.h" 19 #include "chrome/browser/google/google_util.h"
18 #include "chrome/browser/prefs/pref_service.h" 20 #include "chrome/browser/prefs/pref_service.h"
19 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" 21 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h"
20 #include "chrome/browser/printing/cloud_print/cloud_print_setup_flow.h" 22 #include "chrome/browser/printing/cloud_print/cloud_print_setup_flow.h"
21 #include "chrome/browser/printing/cloud_print/cloud_print_url.h" 23 #include "chrome/browser/printing/cloud_print/cloud_print_url.h"
22 #include "chrome/browser/profiles/profile.h" 24 #include "chrome/browser/profiles/profile.h"
23 #include "chrome/browser/service/service_process_control.h" 25 #include "chrome/browser/service/service_process_control.h"
24 #include "chrome/browser/ui/options/options_util.h" 26 #include "chrome/browser/ui/options/options_util.h"
25 #include "chrome/common/chrome_notification_types.h" 27 #include "chrome/common/chrome_notification_types.h"
28 #include "chrome/common/chrome_paths.h"
26 #include "chrome/common/chrome_switches.h" 29 #include "chrome/common/chrome_switches.h"
27 #include "chrome/common/pref_names.h" 30 #include "chrome/common/pref_names.h"
28 #include "chrome/common/url_constants.h" 31 #include "chrome/common/url_constants.h"
29 #include "content/browser/tab_contents/tab_contents.h" 32 #include "content/browser/tab_contents/tab_contents.h"
30 #include "content/browser/tab_contents/tab_contents_view.h" 33 #include "content/browser/tab_contents/tab_contents_view.h"
31 #include "content/browser/user_metrics.h" 34 #include "content/browser/user_metrics.h"
32 #include "content/common/content_notification_types.h" 35 #include "content/common/content_notification_types.h"
33 #include "content/common/notification_details.h" 36 #include "content/common/notification_details.h"
34 #include "grit/chromium_strings.h" 37 #include "grit/chromium_strings.h"
35 #include "grit/generated_resources.h" 38 #include "grit/generated_resources.h"
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 GURL(chrome::kCloudPrintLearnMoreURL)).spec()); 196 GURL(chrome::kCloudPrintLearnMoreURL)).spec());
194 #endif 197 #endif
195 } 198 }
196 199
197 void AdvancedOptionsHandler::Initialize() { 200 void AdvancedOptionsHandler::Initialize() {
198 DCHECK(web_ui_); 201 DCHECK(web_ui_);
199 SetupMetricsReportingCheckbox(); 202 SetupMetricsReportingCheckbox();
200 SetupMetricsReportingSettingVisibility(); 203 SetupMetricsReportingSettingVisibility();
201 SetupFontSizeLabel(); 204 SetupFontSizeLabel();
202 SetupDownloadLocationPath(); 205 SetupDownloadLocationPath();
206 download_path_checker_ = new DownloadPathChecker(this);
207 download_path_checker_->CheckIfDownloadPathExists(
208 default_download_location_.GetValue());
203 SetupPromptForDownload(); 209 SetupPromptForDownload();
204 SetupAutoOpenFileTypesDisabledAttribute(); 210 SetupAutoOpenFileTypesDisabledAttribute();
205 SetupProxySettingsSection(); 211 SetupProxySettingsSection();
206 SetupSSLConfigSettings(); 212 SetupSSLConfigSettings();
207 #if !defined(OS_CHROMEOS) 213 #if !defined(OS_CHROMEOS)
208 if (cloud_print_proxy_ui_enabled_) { 214 if (cloud_print_proxy_ui_enabled_) {
209 SetupCloudPrintProxySection(); 215 SetupCloudPrintProxySection();
210 RefreshCloudPrintStatusFromService(); 216 RefreshCloudPrintStatusFromService();
211 } else { 217 } else {
212 RemoveCloudPrintProxySection(); 218 RemoveCloudPrintProxySection();
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 web_ui_->CallJavascriptFunction( 651 web_ui_->CallJavascriptFunction(
646 "options.AdvancedOptions.SetUseSSL3CheckboxState", checked, disabled); 652 "options.AdvancedOptions.SetUseSSL3CheckboxState", checked, disabled);
647 } 653 }
648 { 654 {
649 FundamentalValue checked(tls1_enabled_.GetValue()); 655 FundamentalValue checked(tls1_enabled_.GetValue());
650 FundamentalValue disabled(tls1_enabled_.IsManaged()); 656 FundamentalValue disabled(tls1_enabled_.IsManaged());
651 web_ui_->CallJavascriptFunction( 657 web_ui_->CallJavascriptFunction(
652 "options.AdvancedOptions.SetUseTLS1CheckboxState", checked, disabled); 658 "options.AdvancedOptions.SetUseTLS1CheckboxState", checked, disabled);
653 } 659 }
654 } 660 }
661
662 AdvancedOptionsHandler::DownloadPathChecker::DownloadPathChecker(
663 AdvancedOptionsHandler* handler)
664 : handler_(handler) {
665 }
666
667 AdvancedOptionsHandler::DownloadPathChecker::~DownloadPathChecker() {
668 }
669
670 void AdvancedOptionsHandler::DownloadPathChecker::
671 CheckIfDownloadPathExists(const FilePath& path) {
672 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
673 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
674 NewRunnableMethod(this,
675 &DownloadPathChecker::CheckIfDownloadPathExistsOnFileThread, path));
676 }
677
678 void AdvancedOptionsHandler::DownloadPathChecker::
679 CheckIfDownloadPathExistsOnFileThread(
680 const FilePath& path) {
681 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
682 if (!file_util::PathExists(path)) {
683 FilePath new_path;
684 if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, &new_path)) {
685 // Create the |path| folder if we cannot get DIR_DEFAULT_DOWNLOADS
686 // (This will be a rare case).
687 new_path = path;
688 }
689 // Make sure that the folder does exist.
690 if (!file_util::CreateDirectory(new_path))
691 LOG(ERROR) << "Failed to create " << new_path.value();
692
693 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
694 NewRunnableMethod(this,
695 &DownloadPathChecker::OnDownloadPathChanged, new_path));
696 }
697 }
698
699 void AdvancedOptionsHandler::DownloadPathChecker::
700 OnDownloadPathChanged(const FilePath path) {
701 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
702 if (handler_) {
703 handler_->default_download_location_.SetValue(path);
704 handler_->SetupDownloadLocationPath();
705 }
706 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698