OLD | NEW |
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_proxy_service_factory.
h" | 22 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory.
h" |
21 #include "chrome/browser/printing/cloud_print/cloud_print_setup_flow.h" | 23 #include "chrome/browser/printing/cloud_print/cloud_print_setup_flow.h" |
22 #include "chrome/browser/printing/cloud_print/cloud_print_url.h" | 24 #include "chrome/browser/printing/cloud_print/cloud_print_url.h" |
23 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
24 #include "chrome/browser/service/service_process_control.h" | 26 #include "chrome/browser/service/service_process_control.h" |
25 #include "chrome/browser/ui/options/options_util.h" | 27 #include "chrome/browser/ui/options/options_util.h" |
26 #include "chrome/common/chrome_notification_types.h" | 28 #include "chrome/common/chrome_notification_types.h" |
| 29 #include "chrome/common/chrome_paths.h" |
27 #include "chrome/common/chrome_switches.h" | 30 #include "chrome/common/chrome_switches.h" |
28 #include "chrome/common/pref_names.h" | 31 #include "chrome/common/pref_names.h" |
29 #include "chrome/common/url_constants.h" | 32 #include "chrome/common/url_constants.h" |
30 #include "content/browser/tab_contents/tab_contents.h" | 33 #include "content/browser/tab_contents/tab_contents.h" |
31 #include "content/browser/tab_contents/tab_contents_view.h" | 34 #include "content/browser/tab_contents/tab_contents_view.h" |
32 #include "content/browser/user_metrics.h" | 35 #include "content/browser/user_metrics.h" |
33 #include "content/common/content_notification_types.h" | 36 #include "content/common/content_notification_types.h" |
34 #include "content/common/notification_details.h" | 37 #include "content/common/notification_details.h" |
35 #include "grit/chromium_strings.h" | 38 #include "grit/chromium_strings.h" |
36 #include "grit/generated_resources.h" | 39 #include "grit/generated_resources.h" |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 GURL(chrome::kCloudPrintLearnMoreURL)).spec()); | 197 GURL(chrome::kCloudPrintLearnMoreURL)).spec()); |
195 #endif | 198 #endif |
196 } | 199 } |
197 | 200 |
198 void AdvancedOptionsHandler::Initialize() { | 201 void AdvancedOptionsHandler::Initialize() { |
199 DCHECK(web_ui_); | 202 DCHECK(web_ui_); |
200 SetupMetricsReportingCheckbox(); | 203 SetupMetricsReportingCheckbox(); |
201 SetupMetricsReportingSettingVisibility(); | 204 SetupMetricsReportingSettingVisibility(); |
202 SetupFontSizeLabel(); | 205 SetupFontSizeLabel(); |
203 SetupDownloadLocationPath(); | 206 SetupDownloadLocationPath(); |
| 207 download_path_checker_ = new DownloadPathChecker(this); |
| 208 download_path_checker_->CheckIfDownloadPathExists( |
| 209 default_download_location_.GetValue()); |
204 SetupPromptForDownload(); | 210 SetupPromptForDownload(); |
205 SetupAutoOpenFileTypesDisabledAttribute(); | 211 SetupAutoOpenFileTypesDisabledAttribute(); |
206 SetupProxySettingsSection(); | 212 SetupProxySettingsSection(); |
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(); |
213 } | 219 } |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 label_str = l10n_util::GetStringUTF16(IDS_OPTIONS_EXTENSION_PROXIES_LABEL); | 587 label_str = l10n_util::GetStringUTF16(IDS_OPTIONS_EXTENSION_PROXIES_LABEL); |
582 } else { | 588 } else { |
583 label_str = l10n_util::GetStringFUTF16(IDS_OPTIONS_SYSTEM_PROXIES_LABEL, | 589 label_str = l10n_util::GetStringFUTF16(IDS_OPTIONS_SYSTEM_PROXIES_LABEL, |
584 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); | 590 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); |
585 } | 591 } |
586 StringValue label(label_str); | 592 StringValue label(label_str); |
587 | 593 |
588 web_ui_->CallJavascriptFunction( | 594 web_ui_->CallJavascriptFunction( |
589 "options.AdvancedOptions.SetupProxySettingsSection", disabled, label); | 595 "options.AdvancedOptions.SetupProxySettingsSection", disabled, label); |
590 } | 596 } |
| 597 |
| 598 AdvancedOptionsHandler::DownloadPathChecker::DownloadPathChecker( |
| 599 AdvancedOptionsHandler* handler) |
| 600 : handler_(handler) { |
| 601 } |
| 602 |
| 603 AdvancedOptionsHandler::DownloadPathChecker::~DownloadPathChecker() { |
| 604 } |
| 605 |
| 606 void AdvancedOptionsHandler::DownloadPathChecker:: |
| 607 CheckIfDownloadPathExists(const FilePath& path) { |
| 608 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 609 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 610 NewRunnableMethod(this, |
| 611 &DownloadPathChecker::CheckIfDownloadPathExistsOnFileThread, path)); |
| 612 } |
| 613 |
| 614 void AdvancedOptionsHandler::DownloadPathChecker:: |
| 615 CheckIfDownloadPathExistsOnFileThread( |
| 616 const FilePath& path) { |
| 617 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 618 if (!file_util::PathExists(path)) { |
| 619 FilePath new_path; |
| 620 if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, &new_path)) { |
| 621 // Create the |path| folder if we cannot get DIR_DEFAULT_DOWNLOADS |
| 622 // (This will be a rare case). |
| 623 new_path = path; |
| 624 } |
| 625 // Make sure that the folder does exist. |
| 626 if (!file_util::CreateDirectory(new_path)) |
| 627 LOG(ERROR) << "Failed to create " << new_path.value(); |
| 628 |
| 629 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 630 NewRunnableMethod(this, |
| 631 &DownloadPathChecker::OnDownloadPathChanged, new_path)); |
| 632 } |
| 633 } |
| 634 |
| 635 void AdvancedOptionsHandler::DownloadPathChecker:: |
| 636 OnDownloadPathChanged(const FilePath path) { |
| 637 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 638 if (handler_) { |
| 639 handler_->default_download_location_.SetValue(path); |
| 640 handler_->SetupDownloadLocationPath(); |
| 641 } |
| 642 } |
OLD | NEW |