diff options
author | bartfab@chromium.org <bartfab@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-26 11:52:08 +0000 |
---|---|---|
committer | bartfab@chromium.org <bartfab@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-26 11:52:08 +0000 |
commit | 0045b0f431a65956e1207fbab1999b97f44f7bb9 (patch) | |
tree | cfc679a87490e4b25593710cb0a76d90f8f4c00f | |
parent | f4bd4cb2957cc174db7104123be51ea3467518e1 (diff) | |
download | chromium_src-0045b0f431a65956e1207fbab1999b97f44f7bb9.zip chromium_src-0045b0f431a65956e1207fbab1999b97f44f7bb9.tar.gz chromium_src-0045b0f431a65956e1207fbab1999b97f44f7bb9.tar.bz2 |
Move printing.* prefs from local state to profile
This CL moves the printing.* prefs to the profile where they arguably
should have resided in the first place. Unit tests are simplified by
this change as the prefs can now be checked without verifying that local
state exists. There is no user-visible change as the prefs are not
exposed via the UI.
BUG=137814
TEST=all unit_tests pass, all printing browser_tests pass
Review URL: https://chromiumcodereview.appspot.com/10808006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@148531 0039d316-1c4b-4281-b951-d872f2087c98
24 files changed, 90 insertions, 185 deletions
diff --git a/chrome/browser/browser_process_impl.cc b/chrome/browser/browser_process_impl.cc index d0161c7..9526a72 100644 --- a/chrome/browser/browser_process_impl.cc +++ b/chrome/browser/browser_process_impl.cc @@ -708,10 +708,6 @@ void BrowserProcessImpl::CreateLocalState() { pref_change_registrar_.Init(local_state_.get()); -#if defined(ENABLE_PRINTING) - print_job_manager_->InitOnUIThread(local_state_.get()); -#endif - // Initialize the notification for the default browser setting policy. local_state_->RegisterBooleanPref(prefs::kDefaultBrowserSettingEnabled, false); diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc index 01fb71b..658cbe4 100644 --- a/chrome/browser/chrome_content_browser_client.cc +++ b/chrome/browser/chrome_content_browser_client.cc @@ -449,7 +449,7 @@ void ChromeContentBrowserClient::RenderProcessHostCreated( id, profile, profile->GetRequestContextForRenderProcess(id))); host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile)); #if defined(ENABLE_PRINTING) - host->GetChannel()->AddFilter(new PrintingMessageFilter(id)); + host->GetChannel()->AddFilter(new PrintingMessageFilter(id, profile)); #endif host->GetChannel()->AddFilter( new SearchProviderInstallStateMessageFilter(id, profile)); @@ -793,13 +793,9 @@ void ChromeContentBrowserClient::AppendExtraCommandLineSwitches( command_line->AppendSwitch( switches::kDisableClientSidePhishingDetection); } - } - { - PrefService* local_state = g_browser_process->local_state(); - if (local_state && - !local_state->GetBoolean(prefs::kPrintPreviewDisabled)) { + + if (!prefs->GetBoolean(prefs::kPrintPreviewDisabled)) command_line->AppendSwitch(switches::kRendererPrintPreview); - } } // Please keep this in alphabetical order. diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc index 647de33..e9d979d 100644 --- a/chrome/browser/prefs/browser_prefs.cc +++ b/chrome/browser/prefs/browser_prefs.cc @@ -45,7 +45,6 @@ #include "chrome/browser/prefs/incognito_mode_prefs.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/prefs/session_startup_pref.h" -#include "chrome/browser/printing/print_job_manager.h" #include "chrome/browser/profiles/chrome_version_service.h" #include "chrome/browser/profiles/gaia_info_update_service.h" #include "chrome/browser/profiles/profile_impl.h" @@ -170,10 +169,6 @@ void RegisterLocalState(PrefService* local_state) { UpgradeDetector::RegisterPrefs(local_state); #endif -#if defined(ENABLE_PRINTING) - printing::PrintJobManager::RegisterPrefs(local_state); -#endif - #if defined(OS_CHROMEOS) chromeos::AudioHandler::RegisterPrefs(local_state); chromeos::language_prefs::RegisterPrefs(local_state); diff --git a/chrome/browser/printing/print_job_manager.cc b/chrome/browser/printing/print_job_manager.cc index e3abfd1..154f735 100644 --- a/chrome/browser/printing/print_job_manager.cc +++ b/chrome/browser/printing/print_job_manager.cc @@ -4,18 +4,13 @@ #include "chrome/browser/printing/print_job_manager.h" -#include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/printing/print_job.h" #include "chrome/browser/printing/printer_query.h" #include "chrome/common/chrome_notification_types.h" -#include "chrome/common/pref_names.h" -#include "content/public/browser/browser_thread.h" #include "content/public/browser/notification_service.h" #include "printing/printed_document.h" #include "printing/printed_page.h" -using content::BrowserThread; - namespace printing { PrintJobManager::PrintJobManager() { @@ -28,12 +23,6 @@ PrintJobManager::~PrintJobManager() { queued_queries_.clear(); } -void PrintJobManager::InitOnUIThread(PrefService* prefs) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - printing_enabled_.Init(prefs::kPrintingEnabled, prefs, NULL); - printing_enabled_.MoveToThread(BrowserThread::IO); -} - void PrintJobManager::OnQuit() { StopJobs(true); registrar_.RemoveAll(); @@ -88,11 +77,6 @@ void PrintJobManager::PopPrinterQuery(int document_cookie, } } -// static -void PrintJobManager::RegisterPrefs(PrefService* prefs) { - prefs->RegisterBooleanPref(prefs::kPrintingEnabled, true); -} - void PrintJobManager::Observe(int type, const content::NotificationSource& source, const content::NotificationDetails& details) { @@ -164,8 +148,4 @@ void PrintJobManager::OnPrintJobEvent( } } -bool PrintJobManager::printing_enabled() const { - return *printing_enabled_; -} - } // namespace printing diff --git a/chrome/browser/printing/print_job_manager.h b/chrome/browser/printing/print_job_manager.h index b73f972..f25764e 100644 --- a/chrome/browser/printing/print_job_manager.h +++ b/chrome/browser/printing/print_job_manager.h @@ -9,13 +9,10 @@ #include "base/memory/ref_counted.h" #include "base/synchronization/lock.h" -#include "chrome/browser/prefs/pref_member.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" #include "printing/print_destination_interface.h" -class PrefService; - namespace printing { class JobEventDetails; @@ -27,10 +24,6 @@ class PrintJobManager : public content::NotificationObserver { PrintJobManager(); virtual ~PrintJobManager(); - // Registers for changes to the printing enabled preference in |prefs|. - // This method should be called on the UI thread. - void InitOnUIThread(PrefService* prefs); - // On browser quit, we should wait to have the print job finished. void OnQuit(); @@ -50,17 +43,11 @@ class PrintJobManager : public content::NotificationObserver { // called from any thread. Current use case is poping from the browser thread. void PopPrinterQuery(int document_cookie, scoped_refptr<PrinterQuery>* job); - static void RegisterPrefs(PrefService* prefs); - // content::NotificationObserver virtual void Observe(int type, const content::NotificationSource& source, const content::NotificationDetails& details) OVERRIDE; - // Only accessed on the IO thread. UI thread can query - // prefs::kPrintingEnabled via g_browser_process->local_state() directly. - bool printing_enabled() const; - // May return NULL when no destination was set. PrintDestinationInterface* destination() const { return destination_.get(); } @@ -74,16 +61,6 @@ class PrintJobManager : public content::NotificationObserver { content::NotificationRegistrar registrar_; - // Printing is enabled/disabled. For printing with the native print dialog, - // this variable is checked at only one place, by - // PrintingMessageFilter::OnGetDefaultPrintSettings. If its value is true - // at that point, then the initiated print flow will complete itself, - // even if the value of this variable changes afterwards. - // In the print preview workflow, this variable is checked in - // PrintingMessageFilter::OnUpdatePrintSettings, which gets called multiple - // times in the print preview workflow. - BooleanPrefMember printing_enabled_; - // Used to serialize access to queued_workers_. base::Lock lock_; diff --git a/chrome/browser/printing/print_preview_tab_controller_unittest.cc b/chrome/browser/printing/print_preview_tab_controller_unittest.cc index fe84d1c..5d0d9d5 100644 --- a/chrome/browser/printing/print_preview_tab_controller_unittest.cc +++ b/chrome/browser/printing/print_preview_tab_controller_unittest.cc @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/printing/print_preview_tab_controller.h" -#include "chrome/browser/printing/print_preview_unit_test_base.h" #include "chrome/browser/printing/print_view_manager.h" #include "chrome/browser/ui/browser_commands.h" #include "chrome/browser/ui/browser_list.h" @@ -11,6 +11,8 @@ #include "chrome/browser/ui/tab_contents/tab_contents.h" #include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" +#include "chrome/common/pref_names.h" +#include "chrome/test/base/browser_with_test_window_test.h" #include "content/public/browser/navigation_details.h" #include "content/public/browser/notification_service.h" #include "content/public/browser/notification_types.h" @@ -28,10 +30,17 @@ #define MAYBE_ClearInitiatorTabDetails ClearInitiatorTabDetails #endif -class PrintPreviewTabControllerUnitTest : public PrintPreviewUnitTestBase { +class PrintPreviewTabControllerUnitTest : public BrowserWithTestWindowTest { public: PrintPreviewTabControllerUnitTest() {} virtual ~PrintPreviewTabControllerUnitTest() {} + + protected: + virtual void SetUp() OVERRIDE { + BrowserWithTestWindowTest::SetUp(); + + profile()->GetPrefs()->SetBoolean(prefs::kPrintPreviewDisabled, false); + } }; // Create/Get a preview tab for initiator tab. diff --git a/chrome/browser/printing/print_preview_unit_test_base.cc b/chrome/browser/printing/print_preview_unit_test_base.cc deleted file mode 100644 index 0fb0e33..0000000 --- a/chrome/browser/printing/print_preview_unit_test_base.cc +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/printing/print_preview_unit_test_base.h" - -#include "chrome/browser/prefs/browser_prefs.h" -#include "chrome/common/pref_names.h" -#include "chrome/test/base/testing_browser_process.h" -#include "chrome/test/base/testing_pref_service.h" - -PrintPreviewUnitTestBase::PrintPreviewUnitTestBase() { -} - -PrintPreviewUnitTestBase::~PrintPreviewUnitTestBase() { -} - -void PrintPreviewUnitTestBase::SetUp() { - BrowserWithTestWindowTest::SetUp(); - - testing_local_state_.reset(new TestingPrefService); - testing_local_state_->SetUserPref(prefs::kPrintPreviewDisabled, - Value::CreateBooleanValue(false)); - - chrome::RegisterLocalState(testing_local_state_.get()); - TestingBrowserProcess* testing_browser_process = - static_cast<TestingBrowserProcess*>(g_browser_process); - EXPECT_FALSE(testing_browser_process->local_state()); - testing_browser_process->SetLocalState(testing_local_state_.get()); -} - -void PrintPreviewUnitTestBase::TearDown() { - EXPECT_EQ(testing_local_state_.get(), g_browser_process->local_state()); - TestingBrowserProcess* testing_browser_process = - static_cast<TestingBrowserProcess*>(g_browser_process); - testing_browser_process->SetLocalState(NULL); - BrowserWithTestWindowTest::TearDown(); -} diff --git a/chrome/browser/printing/print_preview_unit_test_base.h b/chrome/browser/printing/print_preview_unit_test_base.h deleted file mode 100644 index 90e840e..0000000 --- a/chrome/browser/printing/print_preview_unit_test_base.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_PRINTING_PRINT_PREVIEW_UNIT_TEST_BASE_H_ -#define CHROME_BROWSER_PRINTING_PRINT_PREVIEW_UNIT_TEST_BASE_H_ - -#include "base/memory/scoped_ptr.h" -#include "chrome/test/base/browser_with_test_window_test.h" - -class TestingPrefService; - -class PrintPreviewUnitTestBase : public BrowserWithTestWindowTest { - public: - PrintPreviewUnitTestBase(); - virtual ~PrintPreviewUnitTestBase(); - - protected: - virtual void SetUp() OVERRIDE; - virtual void TearDown() OVERRIDE; - - private: - scoped_ptr<TestingPrefService> testing_local_state_; -}; - -#endif // CHROME_BROWSER_PRINTING_PRINT_PREVIEW_UNIT_TEST_BASE_H_ diff --git a/chrome/browser/printing/print_view_manager.cc b/chrome/browser/printing/print_view_manager.cc index d602d8d..0cf3e1d 100644 --- a/chrome/browser/printing/print_view_manager.cc +++ b/chrome/browser/printing/print_view_manager.cc @@ -22,6 +22,7 @@ #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" #include "chrome/common/chrome_notification_types.h" #include "chrome/common/print_messages.h" +#include "content/public/browser/browser_thread.h" #include "content/public/browser/notification_details.h" #include "content/public/browser/notification_service.h" #include "content/public/browser/notification_source.h" diff --git a/chrome/browser/printing/printing_message_filter.cc b/chrome/browser/printing/printing_message_filter.cc index 2ba8a02..c525080 100644 --- a/chrome/browser/printing/printing_message_filter.cc +++ b/chrome/browser/printing/printing_message_filter.cc @@ -11,8 +11,11 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/printing/printer_query.h" #include "chrome/browser/printing/print_job_manager.h" +#include "chrome/browser/profiles/profile.h" +#include "chrome/browser/profiles/profile_io_data.h" #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" #include "chrome/common/print_messages.h" +#include "content/public/browser/browser_thread.h" #include "content/public/browser/render_view_host.h" #include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents_view.h" @@ -79,8 +82,11 @@ void RenderParamsFromPrintSettings(const printing::PrintSettings& settings, } // namespace -PrintingMessageFilter::PrintingMessageFilter(int render_process_id) +PrintingMessageFilter::PrintingMessageFilter(int render_process_id, + Profile* profile) : print_job_manager_(g_browser_process->print_job_manager()), + profile_io_data_(ProfileIOData::FromResourceContext( + profile->GetResourceContext())), render_process_id_(render_process_id) { } @@ -226,7 +232,7 @@ void PrintingMessageFilter::GetPrintSettingsForRenderView( void PrintingMessageFilter::OnGetDefaultPrintSettings(IPC::Message* reply_msg) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); scoped_refptr<printing::PrinterQuery> printer_query; - if (!print_job_manager_->printing_enabled()) { + if (!profile_io_data_->printing_enabled()->GetValue()) { // Reply with NULL query. OnGetDefaultPrintSettingsReply(printer_query, reply_msg); return; @@ -327,7 +333,7 @@ void PrintingMessageFilter::OnUpdatePrintSettings( int document_cookie, const DictionaryValue& job_settings, IPC::Message* reply_msg) { scoped_refptr<printing::PrinterQuery> printer_query; - if (!print_job_manager_->printing_enabled()) { + if (!profile_io_data_->printing_enabled()->GetValue()) { // Reply with NULL query. OnUpdatePrintSettingsReply(printer_query, reply_msg); return; diff --git a/chrome/browser/printing/printing_message_filter.h b/chrome/browser/printing/printing_message_filter.h index 5eac9fd..a7e95dd 100644 --- a/chrome/browser/printing/printing_message_filter.h +++ b/chrome/browser/printing/printing_message_filter.h @@ -16,6 +16,8 @@ class FilePath; struct PrintHostMsg_ScriptedPrint_Params; +class Profile; +class ProfileIOData; namespace base { class DictionaryValue; @@ -34,7 +36,7 @@ class PrintJobManager; // renderer process on the IPC thread. class PrintingMessageFilter : public content::BrowserMessageFilter { public: - explicit PrintingMessageFilter(int render_process_id); + PrintingMessageFilter(int render_process_id, Profile* profile); // content::BrowserMessageFilter methods. virtual void OverrideThreadForMessage( @@ -111,6 +113,8 @@ class PrintingMessageFilter : public content::BrowserMessageFilter { printing::PrintJobManager* print_job_manager_; + ProfileIOData* profile_io_data_; + int render_process_id_; DISALLOW_COPY_AND_ASSIGN(PrintingMessageFilter); diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc index 7a5199b..0da0aea 100644 --- a/chrome/browser/profiles/profile_impl.cc +++ b/chrome/browser/profiles/profile_impl.cc @@ -222,6 +222,18 @@ void ProfileImpl::RegisterUserPrefs(PrefService* prefs) { prefs->RegisterStringPref(prefs::kHomePage, std::string(), PrefService::SYNCABLE_PREF); +#if defined(ENABLE_PRINTING) + prefs->RegisterBooleanPref(prefs::kPrintingEnabled, + true, + PrefService::UNSYNCABLE_PREF); +#endif + prefs->RegisterBooleanPref(prefs::kPrintPreviewDisabled, +#if defined(GOOGLE_CHROME_BUILD) + false, +#else + true, +#endif + PrefService::UNSYNCABLE_PREF); // Initialize the cache prefs. prefs->RegisterFilePathPref(prefs::kDiskCacheDir, diff --git a/chrome/browser/profiles/profile_io_data.cc b/chrome/browser/profiles/profile_io_data.cc index 4a92298..67d9d5d 100644 --- a/chrome/browser/profiles/profile_io_data.cc +++ b/chrome/browser/profiles/profile_io_data.cc @@ -197,6 +197,10 @@ void ProfileIOData::InitializeOnUIThread(Profile* profile) { proxy_config_service); params->profile = profile; profile_params_.reset(params.release()); +#if defined(ENABLE_PRINTING) + printing_enabled_.Init(prefs::kPrintingEnabled, pref_service, NULL); + printing_enabled_.MoveToThread(BrowserThread::IO); +#endif // The URLBlacklistManager has to be created on the UI thread to register // observers of |pref_service|, and it also has to clean up on @@ -567,6 +571,7 @@ void ProfileIOData::ShutdownOnUIThread() { enable_metrics_.Destroy(); #endif safe_browsing_enabled_.Destroy(); + printing_enabled_.Destroy(); session_startup_pref_.Destroy(); #if defined(ENABLE_CONFIGURATION_POLICY) if (url_blacklist_manager_.get()) diff --git a/chrome/browser/profiles/profile_io_data.h b/chrome/browser/profiles/profile_io_data.h index b4ebf01..6a900a3 100644 --- a/chrome/browser/profiles/profile_io_data.h +++ b/chrome/browser/profiles/profile_io_data.h @@ -104,6 +104,10 @@ class ProfileIOData { return &safe_browsing_enabled_; } + BooleanPrefMember* printing_enabled() const { + return &printing_enabled_; + } + net::TransportSecurityState* transport_security_state() const { return transport_security_state_.get(); } @@ -310,6 +314,7 @@ class ProfileIOData { // Member variables which are pointed to by the various context objects. mutable BooleanPrefMember enable_referrers_; mutable BooleanPrefMember safe_browsing_enabled_; + mutable BooleanPrefMember printing_enabled_; // TODO(marja): Remove session_startup_pref_ if no longer needed. mutable IntegerPrefMember session_startup_pref_; diff --git a/chrome/browser/tab_contents/render_view_context_menu.cc b/chrome/browser/tab_contents/render_view_context_menu.cc index bd8bf56..d668e7a 100644 --- a/chrome/browser/tab_contents/render_view_context_menu.cc +++ b/chrome/browser/tab_contents/render_view_context_menu.cc @@ -1334,13 +1334,9 @@ bool RenderViewContextMenu::IsCommandIdEnabled(int id) const { incognito_avail != IncognitoModePrefs::DISABLED; case IDC_PRINT: - if (g_browser_process->local_state() && - !g_browser_process->local_state()->GetBoolean( - prefs::kPrintingEnabled)) { - return false; - } - return params_.media_type == WebContextMenuData::MediaTypeNone || - params_.media_flags & WebContextMenuData::MediaCanPrint; + return profile_->GetPrefs()->GetBoolean(prefs::kPrintingEnabled) && + (params_.media_type == WebContextMenuData::MediaTypeNone || + params_.media_flags & WebContextMenuData::MediaCanPrint); case IDC_CONTENT_CONTEXT_SEARCHWEBFOR: case IDC_CONTENT_CONTEXT_GOTOURL: @@ -1703,8 +1699,7 @@ void RenderViewContextMenu::ExecuteCommand(int id, int event_flags) { TabContents::FromWebContents(source_web_contents_); if (!tab_contents) break; - if (g_browser_process->local_state()->GetBoolean( - prefs::kPrintPreviewDisabled)) { + if (profile_->GetPrefs()->GetBoolean(prefs::kPrintPreviewDisabled)) { tab_contents->print_view_manager()->PrintNow(); } else { tab_contents->print_view_manager()->PrintPreviewNow(); diff --git a/chrome/browser/ui/browser_command_controller.cc b/chrome/browser/ui/browser_command_controller.cc index 96dc1ba..fac52ea 100644 --- a/chrome/browser/ui/browser_command_controller.cc +++ b/chrome/browser/ui/browser_command_controller.cc @@ -85,7 +85,6 @@ BrowserCommandController::BrowserCommandController(Browser* browser) PrefService* local_state = g_browser_process->local_state(); if (local_state) { local_pref_registrar_.Init(local_state); - local_pref_registrar_.Add(prefs::kPrintingEnabled, this); local_pref_registrar_.Add(prefs::kAllowFileSelectionDialogs, this); local_pref_registrar_.Add(prefs::kInManagedMode, this); } @@ -95,6 +94,7 @@ BrowserCommandController::BrowserCommandController(Browser* browser) profile_pref_registrar_.Add(prefs::kEditBookmarksEnabled, this); profile_pref_registrar_.Add(prefs::kShowBookmarkBar, this); profile_pref_registrar_.Add(prefs::kIncognitoModeAvailability, this); + profile_pref_registrar_.Add(prefs::kPrintingEnabled, this); InitCommandState(); diff --git a/chrome/browser/ui/browser_commands.cc b/chrome/browser/ui/browser_commands.cc index 21e90cd..40cefff 100644 --- a/chrome/browser/ui/browser_commands.cc +++ b/chrome/browser/ui/browser_commands.cc @@ -664,8 +664,8 @@ void ShowChromeToMobileBubble(Browser* browser) { } void Print(Browser* browser) { - if (g_browser_process->local_state()->GetBoolean( - prefs::kPrintPreviewDisabled)) { + if (browser->profile()->GetPrefs()->GetBoolean( + prefs::kPrintPreviewDisabled)) { GetActiveTabContents(browser)->print_view_manager()->PrintNow(); } else { GetActiveTabContents(browser)->print_view_manager()-> @@ -674,15 +674,11 @@ void Print(Browser* browser) { } bool CanPrint(const Browser* browser) { - // LocalState can be NULL in tests. - if (g_browser_process->local_state() && - !g_browser_process->local_state()->GetBoolean(prefs::kPrintingEnabled)) { - return false; - } - + // Do not print when printing is disabled via pref or policy. // Do not print when a constrained window is showing. It's confusing. // Do not print if instant extended API is enabled and mode is NTP. - return !(HasConstrainedWindow(browser) || + return browser->profile()->GetPrefs()->GetBoolean(prefs::kPrintingEnabled) && + !(HasConstrainedWindow(browser) || GetContentRestrictions(browser) & content::CONTENT_RESTRICTION_PRINT || IsNTPModeForInstantExtendedAPI(browser)); } @@ -693,14 +689,10 @@ void AdvancedPrint(Browser* browser) { } bool CanAdvancedPrint(const Browser* browser) { - // LocalState can be NULL in tests. - if (g_browser_process->local_state() && - !g_browser_process->local_state()->GetBoolean(prefs::kPrintingEnabled)) { - return false; - } - - // It is always possible to advanced print when print preview is visible. - return PrintPreviewShowing(browser) || CanPrint(browser); + // If printing is not disabled via pref or policy, it is always possible to + // advanced print when the print preview is visible. + return browser->profile()->GetPrefs()->GetBoolean(prefs::kPrintingEnabled) && + (PrintPreviewShowing(browser) || CanPrint(browser)); } void PrintToDestination(Browser* browser) { diff --git a/chrome/browser/ui/browser_ui_prefs.cc b/chrome/browser/ui/browser_ui_prefs.cc index 502bb18..1d4d8e5 100644 --- a/chrome/browser/ui/browser_ui_prefs.cc +++ b/chrome/browser/ui/browser_ui_prefs.cc @@ -30,13 +30,6 @@ void RegisterBrowserPrefs(PrefService* prefs) { prefs->RegisterIntegerPref(prefs::kOptionsWindowLastTabIndex, 0); prefs->RegisterBooleanPref(prefs::kAllowFileSelectionDialogs, true); prefs->RegisterBooleanPref(prefs::kShouldShowFirstRunBubble, false); - prefs->RegisterBooleanPref(prefs::kPrintPreviewDisabled, -#if defined(GOOGLE_CHROME_BUILD) - false -#else - true -#endif - ); } void RegisterBrowserUserPrefs(PrefService* prefs) { diff --git a/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc b/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc index e204233..6b965f77 100644 --- a/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc +++ b/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc @@ -6,7 +6,6 @@ #include "base/command_line.h" #include "chrome/browser/about_flags.h" -#include "chrome/browser/browser_process.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_web_ui.h" #include "chrome/browser/history/history_types.h" @@ -256,10 +255,8 @@ WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui, #endif #if defined(ENABLE_PRINTING) if (url.host() == chrome::kChromeUIPrintHost && - !g_browser_process->local_state()->GetBoolean( - prefs::kPrintPreviewDisabled)) { + !profile->GetPrefs()->GetBoolean(prefs::kPrintPreviewDisabled)) return &NewWebUI<PrintPreviewUI>; - } #endif #if defined(OS_WIN) if (url.host() == chrome::kChromeUIConflictsHost) diff --git a/chrome/browser/ui/webui/print_preview/print_preview_handler_unittest.cc b/chrome/browser/ui/webui/print_preview/print_preview_handler_unittest.cc index 07938e2..1432760 100644 --- a/chrome/browser/ui/webui/print_preview/print_preview_handler_unittest.cc +++ b/chrome/browser/ui/webui/print_preview/print_preview_handler_unittest.cc @@ -5,9 +5,9 @@ #include "base/json/json_writer.h" #include "base/values.h" #include "chrome/browser/browser_process.h" +#include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/printing/background_printing_manager.h" #include "chrome/browser/printing/print_preview_tab_controller.h" -#include "chrome/browser/printing/print_preview_unit_test_base.h" #include "chrome/browser/printing/print_view_manager.h" #include "chrome/browser/ui/browser_commands.h" #include "chrome/browser/ui/browser_tabstrip.h" @@ -15,6 +15,8 @@ #include "chrome/browser/ui/webui/print_preview/print_preview_handler.h" #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" #include "chrome/browser/ui/webui/print_preview/sticky_settings.h" +#include "chrome/common/pref_names.h" +#include "chrome/test/base/browser_with_test_window_test.h" #include "content/public/browser/web_contents.h" #include "printing/page_size_margins.h" #include "printing/print_job_constants.h" @@ -34,7 +36,7 @@ DictionaryValue* GetCustomMarginsDictionary( } // namespace -class PrintPreviewHandlerTest : public PrintPreviewUnitTestBase { +class PrintPreviewHandlerTest : public BrowserWithTestWindowTest { public: PrintPreviewHandlerTest() : preview_ui_(NULL), @@ -44,7 +46,9 @@ class PrintPreviewHandlerTest : public PrintPreviewUnitTestBase { protected: virtual void SetUp() OVERRIDE { - PrintPreviewUnitTestBase::SetUp(); + BrowserWithTestWindowTest::SetUp(); + + profile()->GetPrefs()->SetBoolean(prefs::kPrintPreviewDisabled, false); chrome::NewTab(browser()); EXPECT_EQ(1, browser()->tab_count()); @@ -55,7 +59,7 @@ class PrintPreviewHandlerTest : public PrintPreviewUnitTestBase { DeletePrintPreviewTab(); ClearStickySettings(); - PrintPreviewUnitTestBase::TearDown(); + BrowserWithTestWindowTest::TearDown(); } void OpenPrintPreviewTab() { diff --git a/chrome/browser/ui/webui/print_preview/print_preview_ui_unittest.cc b/chrome/browser/ui/webui/print_preview/print_preview_ui_unittest.cc index eb75655..106c7bc 100644 --- a/chrome/browser/ui/webui/print_preview/print_preview_ui_unittest.cc +++ b/chrome/browser/ui/webui/print_preview/print_preview_ui_unittest.cc @@ -5,14 +5,16 @@ #include <vector> #include "base/memory/ref_counted_memory.h" +#include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/printing/print_preview_tab_controller.h" -#include "chrome/browser/printing/print_preview_unit_test_base.h" #include "chrome/browser/printing/print_view_manager.h" #include "chrome/browser/ui/browser_commands.h" #include "chrome/browser/ui/browser_tabstrip.h" #include "chrome/browser/ui/constrained_window_tab_helper.h" #include "chrome/browser/ui/tab_contents/tab_contents.h" #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" +#include "chrome/common/pref_names.h" +#include "chrome/test/base/browser_with_test_window_test.h" #include "content/public/browser/site_instance.h" #include "content/public/browser/web_contents.h" #include "content/public/test/web_contents_tester.h" @@ -32,14 +34,16 @@ size_t GetConstrainedWindowCount(TabContents* tab) { } // namespace -class PrintPreviewUIUnitTest : public PrintPreviewUnitTestBase { +class PrintPreviewUIUnitTest : public BrowserWithTestWindowTest { public: PrintPreviewUIUnitTest() {} virtual ~PrintPreviewUIUnitTest() {} protected: virtual void SetUp() OVERRIDE { - PrintPreviewUnitTestBase::SetUp(); + BrowserWithTestWindowTest::SetUp(); + + profile()->GetPrefs()->SetBoolean(prefs::kPrintPreviewDisabled, false); chrome::NewTab(browser()); } diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 1d6021a..79d4030 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -1470,8 +1470,6 @@ 'browser/printing/print_dialog_cloud_unittest.cc', 'browser/printing/print_job_unittest.cc', 'browser/printing/print_preview_tab_controller_unittest.cc', - 'browser/printing/print_preview_unit_test_base.cc', - 'browser/printing/print_preview_unit_test_base.h', 'browser/process_info_snapshot_mac_unittest.cc', 'browser/process_singleton_linux_unittest.cc', 'browser/process_singleton_mac_unittest.cc', diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc index a44dcb4..9a99dd8 100644 --- a/chrome/common/pref_names.cc +++ b/chrome/common/pref_names.cc @@ -1020,6 +1020,12 @@ const char kProfileName[] = "profile.name"; // mode is on, recommending high-contrast extensions and themes. const char kInvertNotificationShown[] = "invert_notification_version_2_shown"; +// Boolean controlling whether printing is enabled. +const char kPrintingEnabled[] = "printing.enabled"; + +// Boolean controlling whether print preview is disabled. +const char kPrintPreviewDisabled[] = "printing.print_preview_disabled"; + // *************** LOCAL STATE *************** // These are attached to the machine/installation @@ -1679,16 +1685,10 @@ const char kGeolocationAccessToken[] = "geolocation.access_token"; const char kRemoteAccessHostFirewallTraversal[] = "remote_access.host_firewall_traversal"; -// Boolean controlling whether printing is enabled. -const char kPrintingEnabled[] = "printing.enabled"; - -// Boolean controlling whether print preview is disabled. -const char kPrintPreviewDisabled[] = "printing.print_preview_disabled"; // The last used printer and its settings. const char kPrintPreviewStickySettings[] = "printing.print_preview_sticky_settings"; - // The root URL of the cloud print service. const char kCloudPrintServiceURL[] = "cloud_print.service_url"; diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h index edc071a..c8a6045 100644 --- a/chrome/common/pref_names.h +++ b/chrome/common/pref_names.h @@ -363,6 +363,9 @@ extern const char kProfileName[]; extern const char kInvertNotificationShown[]; +extern const char kPrintingEnabled[]; +extern const char kPrintPreviewDisabled[]; + // Local state prefs. Please add Profile prefs above instead. extern const char kCertRevocationCheckingEnabled[]; extern const char kSSLVersionMin[]; @@ -612,10 +615,7 @@ extern const char kGeolocationEnabled[]; extern const char kRemoteAccessHostFirewallTraversal[]; -extern const char kPrintingEnabled[]; -extern const char kPrintPreviewDisabled[]; extern const char kPrintPreviewStickySettings[]; - extern const char kCloudPrintServiceURL[]; extern const char kCloudPrintSigninURL[]; extern const char kCloudPrintDialogWidth[]; |