1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
// Copyright (c) 2009 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/shell_integration.h"
#include "base/message_loop.h"
#include "base/thread.h"
#include "chrome/browser/browser_process.h"
///////////////////////////////////////////////////////////////////////////////
// ShellIntegration::DefaultBrowserWorker
//
ShellIntegration::DefaultBrowserWorker::DefaultBrowserWorker(
DefaultBrowserObserver* observer)
: observer_(observer),
ui_loop_(MessageLoop::current()),
file_loop_(g_browser_process->file_thread()->message_loop()) {
}
void ShellIntegration::DefaultBrowserWorker::StartCheckDefaultBrowser() {
observer_->SetDefaultBrowserUIState(STATE_PROCESSING);
file_loop_->PostTask(FROM_HERE, NewRunnableMethod(this,
&DefaultBrowserWorker::ExecuteCheckDefaultBrowser));
}
void ShellIntegration::DefaultBrowserWorker::StartSetAsDefaultBrowser() {
observer_->SetDefaultBrowserUIState(STATE_PROCESSING);
file_loop_->PostTask(FROM_HERE, NewRunnableMethod(this,
&DefaultBrowserWorker::ExecuteSetAsDefaultBrowser));
}
void ShellIntegration::DefaultBrowserWorker::ObserverDestroyed() {
// Our associated view has gone away, so we shouldn't call back to it if
// our worker thread returns after the view is dead.
observer_ = NULL;
}
///////////////////////////////////////////////////////////////////////////////
// DefaultBrowserWorker, private:
void ShellIntegration::DefaultBrowserWorker::ExecuteCheckDefaultBrowser() {
DCHECK(MessageLoop::current() == file_loop_);
bool is_default = ShellIntegration::IsDefaultBrowser();
ui_loop_->PostTask(FROM_HERE, NewRunnableMethod(this,
&DefaultBrowserWorker::CompleteCheckDefaultBrowser, is_default));
}
void ShellIntegration::DefaultBrowserWorker::CompleteCheckDefaultBrowser(
bool is_default) {
DCHECK(MessageLoop::current() == ui_loop_);
UpdateUI(is_default);
}
void ShellIntegration::DefaultBrowserWorker::ExecuteSetAsDefaultBrowser() {
DCHECK(MessageLoop::current() == file_loop_);
ShellIntegration::SetAsDefaultBrowser();
ui_loop_->PostTask(FROM_HERE, NewRunnableMethod(this,
&DefaultBrowserWorker::CompleteSetAsDefaultBrowser));
}
void ShellIntegration::DefaultBrowserWorker::CompleteSetAsDefaultBrowser() {
DCHECK(MessageLoop::current() == ui_loop_);
if (observer_) {
// Set as default completed, check again to make sure it stuck...
StartCheckDefaultBrowser();
}
}
void ShellIntegration::DefaultBrowserWorker::UpdateUI(bool is_default) {
if (observer_) {
DefaultBrowserUIState state =
is_default ? STATE_DEFAULT : STATE_NOT_DEFAULT;
observer_->SetDefaultBrowserUIState(state);
}
}
|