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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
// 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/path_service.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/browser/chrome_thread.h"
///////////////////////////////////////////////////////////////////////////////
// ShellIntegration::DefaultBrowserWorker
//
ShellIntegration::DefaultBrowserWorker::DefaultBrowserWorker(
DefaultBrowserObserver* observer)
: observer_(observer) {
}
void ShellIntegration::DefaultBrowserWorker::StartCheckDefaultBrowser() {
observer_->SetDefaultBrowserUIState(STATE_PROCESSING);
ChromeThread::PostTask(
ChromeThread::FILE, FROM_HERE,
NewRunnableMethod(
this, &DefaultBrowserWorker::ExecuteCheckDefaultBrowser));
}
void ShellIntegration::DefaultBrowserWorker::StartSetAsDefaultBrowser() {
observer_->SetDefaultBrowserUIState(STATE_PROCESSING);
ChromeThread::PostTask(
ChromeThread::FILE, 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(ChromeThread::CurrentlyOn(ChromeThread::FILE));
DefaultBrowserState state = ShellIntegration::IsDefaultBrowser();
ChromeThread::PostTask(
ChromeThread::UI, FROM_HERE,
NewRunnableMethod(
this, &DefaultBrowserWorker::CompleteCheckDefaultBrowser, state));
}
void ShellIntegration::DefaultBrowserWorker::CompleteCheckDefaultBrowser(
DefaultBrowserState state) {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
UpdateUI(state);
}
void ShellIntegration::DefaultBrowserWorker::ExecuteSetAsDefaultBrowser() {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE));
ShellIntegration::SetAsDefaultBrowser();
ChromeThread::PostTask(
ChromeThread::UI, FROM_HERE,
NewRunnableMethod(
this, &DefaultBrowserWorker::CompleteSetAsDefaultBrowser));
}
void ShellIntegration::DefaultBrowserWorker::CompleteSetAsDefaultBrowser() {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
if (observer_) {
// Set as default completed, check again to make sure it stuck...
StartCheckDefaultBrowser();
}
}
void ShellIntegration::DefaultBrowserWorker::UpdateUI(
DefaultBrowserState state) {
if (observer_) {
switch (state) {
case NOT_DEFAULT_BROWSER:
observer_->SetDefaultBrowserUIState(STATE_NOT_DEFAULT);
break;
case IS_DEFAULT_BROWSER:
observer_->SetDefaultBrowserUIState(STATE_IS_DEFAULT);
break;
case UNKNOWN_DEFAULT_BROWSER:
observer_->SetDefaultBrowserUIState(STATE_UNKNOWN);
break;
default:
break;
}
}
}
|