summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views/options
diff options
context:
space:
mode:
authormattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-28 01:57:31 +0000
committermattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-28 01:57:31 +0000
commitd24c4015c3976d20001f6de03a09a7d0ef99ffb4 (patch)
treeb15c6d9840e215a37dccdd66cda07f074f2d2734 /chrome/browser/views/options
parent55eeaa5bce8adec47150cd32b764a3fdead0c9d5 (diff)
downloadchromium_src-d24c4015c3976d20001f6de03a09a7d0ef99ffb4.zip
chromium_src-d24c4015c3976d20001f6de03a09a7d0ef99ffb4.tar.gz
chromium_src-d24c4015c3976d20001f6de03a09a7d0ef99ffb4.tar.bz2
Fix running default browser check/setting in UI thread on Linux.
Rename shell_integration.cc to shell_integration_win.cc, so shell_integration.cc can be used for cross-platform stuff. Move DefaultBrowserWorker from GeneralPageView to ShellIntegration. BUG=17179 Review URL: http://codereview.chromium.org/160218 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21794 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views/options')
-rw-r--r--chrome/browser/views/options/general_page_view.cc129
-rw-r--r--chrome/browser/views/options/general_page_view.h17
2 files changed, 14 insertions, 132 deletions
diff --git a/chrome/browser/views/options/general_page_view.cc b/chrome/browser/views/options/general_page_view.cc
index dcf579f..e99444d 100644
--- a/chrome/browser/views/options/general_page_view.cc
+++ b/chrome/browser/views/options/general_page_view.cc
@@ -9,10 +9,8 @@
#include "base/gfx/png_decoder.h"
#include "base/message_loop.h"
#include "base/string_util.h"
-#include "base/thread.h"
#include "chrome/browser/browser.h"
#include "chrome/browser/browser_list.h"
-#include "chrome/browser/browser_process.h"
#include "chrome/browser/dom_ui/new_tab_ui.h"
#include "chrome/browser/history/history.h"
#include "chrome/browser/net/url_fixer_upper.h"
@@ -20,7 +18,6 @@
#include "chrome/browser/session_startup_pref.h"
#include "chrome/browser/search_engines/template_url.h"
#include "chrome/browser/search_engines/template_url_model.h"
-#include "chrome/browser/shell_integration.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/views/keyword_editor_view.h"
#include "chrome/browser/views/options/options_group_view.h"
@@ -54,118 +51,6 @@ std::wstring GetNewTabUIURLString() {
}
///////////////////////////////////////////////////////////////////////////////
-// GeneralPageView::DefaultBrowserWorker
-//
-// A helper object that handles checking if Chrome is the default browser on
-// Windows and also setting it as the default browser. These operations are
-// performed asynchronously on the file thread since registry access is
-// involved and this can be slow.
-//
-class GeneralPageView::DefaultBrowserWorker
- : public base::RefCountedThreadSafe<GeneralPageView::DefaultBrowserWorker> {
- public:
- explicit DefaultBrowserWorker(GeneralPageView* general_page_view);
-
- // Checks if Chrome is the default browser.
- void StartCheckDefaultBrowser();
-
- // Sets Chrome as the default browser.
- void StartSetAsDefaultBrowser();
-
- // Called to notify the worker that the view is gone.
- void ViewDestroyed();
-
- private:
- // Functions that track the process of checking if Chrome is the default
- // browser.
- // |ExecuteCheckDefaultBrowser| checks the registry on the file thread.
- // |CompleteCheckDefaultBrowser| notifies the view to update on the UI thread.
- void ExecuteCheckDefaultBrowser();
- void CompleteCheckDefaultBrowser(bool is_default);
-
- // Functions that track the process of setting Chrome as the default browser.
- // |ExecuteSetAsDefaultBrowser| updates the registry on the file thread.
- // |CompleteSetAsDefaultBrowser| notifies the view to update on the UI thread.
- void ExecuteSetAsDefaultBrowser();
- void CompleteSetAsDefaultBrowser();
-
- // Updates the UI in our associated view with the current default browser
- // state.
- void UpdateUI(bool is_default);
-
- GeneralPageView* general_page_view_;
-
- MessageLoop* ui_loop_;
- MessageLoop* file_loop_;
-
- DISALLOW_COPY_AND_ASSIGN(GeneralPageView::DefaultBrowserWorker);
-};
-
-GeneralPageView::DefaultBrowserWorker::DefaultBrowserWorker(
- GeneralPageView* general_page_view)
- : general_page_view_(general_page_view),
- ui_loop_(MessageLoop::current()),
- file_loop_(g_browser_process->file_thread()->message_loop()) {
-}
-
-void GeneralPageView::DefaultBrowserWorker::StartCheckDefaultBrowser() {
- general_page_view_->SetDefaultBrowserUIState(STATE_PROCESSING);
- file_loop_->PostTask(FROM_HERE, NewRunnableMethod(this,
- &DefaultBrowserWorker::ExecuteCheckDefaultBrowser));
-}
-
-void GeneralPageView::DefaultBrowserWorker::StartSetAsDefaultBrowser() {
- general_page_view_->SetDefaultBrowserUIState(STATE_PROCESSING);
- file_loop_->PostTask(FROM_HERE, NewRunnableMethod(this,
- &DefaultBrowserWorker::ExecuteSetAsDefaultBrowser));
-}
-
-void GeneralPageView::DefaultBrowserWorker::ViewDestroyed() {
- // Our associated view has gone away, so we shouldn't call back to it if
- // our worker thread returns after the view is dead.
- general_page_view_ = NULL;
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// DefaultBrowserWorker, private:
-
-void GeneralPageView::DefaultBrowserWorker::ExecuteCheckDefaultBrowser() {
- DCHECK(MessageLoop::current() == file_loop_);
- bool is_default = ShellIntegration::IsDefaultBrowser();
- ui_loop_->PostTask(FROM_HERE, NewRunnableMethod(this,
- &DefaultBrowserWorker::CompleteCheckDefaultBrowser, is_default));
-}
-
-void GeneralPageView::DefaultBrowserWorker::CompleteCheckDefaultBrowser(
- bool is_default) {
- DCHECK(MessageLoop::current() == ui_loop_);
- UpdateUI(is_default);
-}
-
-void GeneralPageView::DefaultBrowserWorker::ExecuteSetAsDefaultBrowser() {
- DCHECK(MessageLoop::current() == file_loop_);
- bool result = ShellIntegration::SetAsDefaultBrowser();
- ui_loop_->PostTask(FROM_HERE, NewRunnableMethod(this,
- &DefaultBrowserWorker::CompleteSetAsDefaultBrowser));
-}
-
-void GeneralPageView::DefaultBrowserWorker::CompleteSetAsDefaultBrowser() {
- DCHECK(MessageLoop::current() == ui_loop_);
- if (general_page_view_) {
- // Set as default completed, check again to make sure it stuck...
- StartCheckDefaultBrowser();
- }
-}
-
-void GeneralPageView::DefaultBrowserWorker::UpdateUI(bool is_default) {
- if (general_page_view_) {
- DefaultBrowserUIState state =
- is_default ? STATE_DEFAULT : STATE_NOT_DEFAULT;
- general_page_view_->SetDefaultBrowserUIState(state);
- }
-}
-
-///////////////////////////////////////////////////////////////////////////////
// CustomHomePagesTableModel
// CustomHomePagesTableModel is the model for the TableView showing the list
@@ -525,7 +410,8 @@ GeneralPageView::GeneralPageView(Profile* profile)
default_browser_status_label_(NULL),
default_browser_use_as_default_button_(NULL),
ALLOW_THIS_IN_INITIALIZER_LIST(
- default_browser_worker_(new DefaultBrowserWorker(this))),
+ default_browser_worker_(
+ new ShellIntegration::DefaultBrowserWorker(this))),
OptionsPageView(profile) {
}
@@ -535,7 +421,7 @@ GeneralPageView::~GeneralPageView() {
prefs::kURLsToRestoreOnStartup, this);
if (startup_custom_pages_table_)
startup_custom_pages_table_->SetModel(NULL);
- default_browser_worker_->ViewDestroyed();
+ default_browser_worker_->ObserverDestroyed();
}
///////////////////////////////////////////////////////////////////////////////
@@ -755,16 +641,17 @@ void GeneralPageView::Layout() {
///////////////////////////////////////////////////////////////////////////////
// GeneralPageView, private:
-void GeneralPageView::SetDefaultBrowserUIState(DefaultBrowserUIState state) {
- bool button_enabled = state == STATE_NOT_DEFAULT;
+void GeneralPageView::SetDefaultBrowserUIState(
+ ShellIntegration::DefaultBrowserUIState state) {
+ bool button_enabled = state == ShellIntegration::STATE_NOT_DEFAULT;
default_browser_use_as_default_button_->SetEnabled(button_enabled);
- if (state == STATE_DEFAULT) {
+ if (state == ShellIntegration::STATE_DEFAULT) {
default_browser_status_label_->SetText(
l10n_util::GetStringF(IDS_OPTIONS_DEFAULTBROWSER_DEFAULT,
l10n_util::GetString(IDS_PRODUCT_NAME)));
default_browser_status_label_->SetColor(kDefaultBrowserLabelColor);
Layout();
- } else if (state == STATE_NOT_DEFAULT) {
+ } else if (state == ShellIntegration::STATE_NOT_DEFAULT) {
default_browser_status_label_->SetText(
l10n_util::GetStringF(IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT,
l10n_util::GetString(IDS_PRODUCT_NAME)));
diff --git a/chrome/browser/views/options/general_page_view.h b/chrome/browser/views/options/general_page_view.h
index 3faa421..27827be 100644
--- a/chrome/browser/views/options/general_page_view.h
+++ b/chrome/browser/views/options/general_page_view.h
@@ -5,6 +5,7 @@
#ifndef CHROME_BROWSER_VIEWS_OPTIONS_GENERAL_PAGE_VIEW_H_
#define CHROME_BROWSER_VIEWS_OPTIONS_GENERAL_PAGE_VIEW_H_
+#include "chrome/browser/shell_integration.h"
#include "chrome/browser/views/options/options_page_view.h"
#include "chrome/browser/views/shelf_item_dialog.h"
#include "chrome/common/pref_member.h"
@@ -35,7 +36,8 @@ class GeneralPageView : public OptionsPageView,
public views::ButtonListener,
public views::Textfield::Controller,
public ShelfItemDialogDelegate,
- public views::TableViewObserver {
+ public views::TableViewObserver,
+ public ShellIntegration::DefaultBrowserObserver {
public:
explicit GeneralPageView(Profile* profile);
virtual ~GeneralPageView();
@@ -64,14 +66,9 @@ class GeneralPageView : public OptionsPageView,
virtual void Layout();
private:
- // The current default browser UI state
- enum DefaultBrowserUIState {
- STATE_PROCESSING,
- STATE_DEFAULT,
- STATE_NOT_DEFAULT
- };
+ // ShellIntegration::DefaultBrowserObserver implementation:
// Updates the UI state to reflect the current default browser state.
- void SetDefaultBrowserUIState(DefaultBrowserUIState state);
+ virtual void SetDefaultBrowserUIState(ShellIntegration::DefaultBrowserUIState state);
// Init all the dialog controls
void InitStartupGroup();
@@ -151,9 +148,7 @@ class GeneralPageView : public OptionsPageView,
views::NativeButton* default_browser_use_as_default_button_;
// The helper object that performs default browser set/check tasks.
- class DefaultBrowserWorker;
- friend DefaultBrowserWorker;
- scoped_refptr<DefaultBrowserWorker> default_browser_worker_;
+ scoped_refptr<ShellIntegration::DefaultBrowserWorker> default_browser_worker_;
DISALLOW_COPY_AND_ASSIGN(GeneralPageView);
};