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

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: Overrides the user's "Downloads" folder in DownloadPrefs Created 9 years, 6 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/browser/ui/webui/options/options_managed_banner_handler.h" 27 #include "chrome/browser/ui/webui/options/options_managed_banner_handler.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/notification_details.h" 35 #include "content/common/notification_details.h"
33 #include "content/common/notification_type.h" 36 #include "content/common/notification_type.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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 google_util::AppendGoogleLocaleParam( 182 google_util::AppendGoogleLocaleParam(
180 GURL(chrome::kPrivacyLearnMoreURL)).spec()); 183 GURL(chrome::kPrivacyLearnMoreURL)).spec());
181 } 184 }
182 185
183 void AdvancedOptionsHandler::Initialize() { 186 void AdvancedOptionsHandler::Initialize() {
184 DCHECK(web_ui_); 187 DCHECK(web_ui_);
185 SetupMetricsReportingCheckbox(); 188 SetupMetricsReportingCheckbox();
186 SetupMetricsReportingSettingVisibility(); 189 SetupMetricsReportingSettingVisibility();
187 SetupFontSizeLabel(); 190 SetupFontSizeLabel();
188 SetupDownloadLocationPath(); 191 SetupDownloadLocationPath();
192 download_path_checker_ = new DownloadPathChecker(this);
193 download_path_checker_->CheckIfDownloadPathExists(
194 default_download_location_.GetValue());
189 SetupPromptForDownload(); 195 SetupPromptForDownload();
190 SetupAutoOpenFileTypesDisabledAttribute(); 196 SetupAutoOpenFileTypesDisabledAttribute();
191 SetupProxySettingsSection(); 197 SetupProxySettingsSection();
192 SetupSSLConfigSettings(); 198 SetupSSLConfigSettings();
193 #if !defined(OS_CHROMEOS) 199 #if !defined(OS_CHROMEOS)
194 if (cloud_print_proxy_ui_enabled_) { 200 if (cloud_print_proxy_ui_enabled_) {
195 SetupCloudPrintProxySection(); 201 SetupCloudPrintProxySection();
196 RefreshCloudPrintStatusFromService(); 202 RefreshCloudPrintStatusFromService();
197 } else { 203 } else {
198 RemoveCloudPrintProxySection(); 204 RemoveCloudPrintProxySection();
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 web_ui_->CallJavascriptFunction( 640 web_ui_->CallJavascriptFunction(
635 "options.AdvancedOptions.SetUseSSL3CheckboxState", checked, disabled); 641 "options.AdvancedOptions.SetUseSSL3CheckboxState", checked, disabled);
636 } 642 }
637 { 643 {
638 FundamentalValue checked(tls1_enabled_.GetValue()); 644 FundamentalValue checked(tls1_enabled_.GetValue());
639 FundamentalValue disabled(tls1_enabled_.IsManaged()); 645 FundamentalValue disabled(tls1_enabled_.IsManaged());
640 web_ui_->CallJavascriptFunction( 646 web_ui_->CallJavascriptFunction(
641 "options.AdvancedOptions.SetUseTLS1CheckboxState", checked, disabled); 647 "options.AdvancedOptions.SetUseTLS1CheckboxState", checked, disabled);
642 } 648 }
643 } 649 }
650
651 AdvancedOptionsHandler::DownloadPathChecker::DownloadPathChecker(
652 AdvancedOptionsHandler* handler)
653 : handler_(handler) {
654 }
655
656 AdvancedOptionsHandler::DownloadPathChecker::~DownloadPathChecker() {
657 }
658
659 void AdvancedOptionsHandler::DownloadPathChecker::
660 CheckIfDownloadPathExists(const FilePath& path) {
661 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
662 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
663 NewRunnableMethod(this,
664 &DownloadPathChecker::CheckIfDownloadPathExistsOnFileThread, path));
665 }
666
667 void AdvancedOptionsHandler::DownloadPathChecker::
668 CheckIfDownloadPathExistsOnFileThread(
669 const FilePath& path) {
670 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
671 if (!file_util::PathExists(path)) {
672 FilePath new_path;
673 if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, &new_path)) {
674 // Create the |path| folder if we cannot get DIR_DEFAULT_DOWNLOADS
675 // (This will be a rare case).
676 new_path = path;
677 }
678 // Make sure that the folder does exist.
679 if (!file_util::CreateDirectory(new_path))
680 LOG(ERROR) << "Failed to create " << new_path.value();
681
682 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
683 NewRunnableMethod(this,
684 &DownloadPathChecker::OnDownloadPathChanged, new_path));
685 }
686 }
687
688 void AdvancedOptionsHandler::DownloadPathChecker::
689 OnDownloadPathChanged(const FilePath path) {
690 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
691 if (handler_) {
692 handler_->default_download_location_.SetValue(path);
693 handler_->SetupDownloadLocationPath();
694 }
695 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698