OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
Mark Mentovai
2011/05/23 00:23:52
I am not yet examining this file heavily as it wil
| |
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/shell_integration.h" | 5 #include "chrome/browser/shell_integration.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
54 } else { | 54 } else { |
55 // Use '--app=url' instead of just 'url' to launch the browser with minimal | 55 // Use '--app=url' instead of just 'url' to launch the browser with minimal |
56 // chrome. | 56 // chrome. |
57 // Note: Do not change this flag! Old Gears shortcuts will break if you do! | 57 // Note: Do not change this flag! Old Gears shortcuts will break if you do! |
58 new_cmd_line.AppendSwitchASCII(switches::kApp, url.spec()); | 58 new_cmd_line.AppendSwitchASCII(switches::kApp, url.spec()); |
59 } | 59 } |
60 return new_cmd_line; | 60 return new_cmd_line; |
61 } | 61 } |
62 | 62 |
63 /////////////////////////////////////////////////////////////////////////////// | 63 /////////////////////////////////////////////////////////////////////////////// |
64 // ShellIntegration::DefaultBrowserWorker | 64 // ShellIntegration::DefaultClientAppWorker |
65 // | 65 // |
66 | 66 |
67 ShellIntegration::DefaultBrowserWorker::DefaultBrowserWorker( | 67 ShellIntegration::DefaultClientAppWorker::DefaultClientAppWorker( |
68 DefaultBrowserObserver* observer) | 68 DefaultClientAppObserver* observer) |
69 : observer_(observer) { | 69 : observer_(observer), protocol_() { |
70 } | 70 } |
71 | 71 |
72 void ShellIntegration::DefaultBrowserWorker::StartCheckDefaultBrowser() { | 72 void ShellIntegration::DefaultClientAppWorker::StartCheckDefaultBrowser() { |
73 observer_->SetDefaultBrowserUIState(STATE_PROCESSING); | 73 if (observer_) { |
74 observer_->SetDefaultClientAppUIState(STATE_PROCESSING); | |
75 } | |
74 BrowserThread::PostTask( | 76 BrowserThread::PostTask( |
75 BrowserThread::FILE, FROM_HERE, | 77 BrowserThread::FILE, FROM_HERE, |
76 NewRunnableMethod( | 78 NewRunnableMethod( |
77 this, &DefaultBrowserWorker::ExecuteCheckDefaultBrowser)); | 79 this, &DefaultClientAppWorker::ExecuteCheckDefaultBrowser)); |
78 } | 80 } |
79 | 81 |
80 void ShellIntegration::DefaultBrowserWorker::StartSetAsDefaultBrowser() { | 82 void ShellIntegration::DefaultClientAppWorker::StartCheckDefaultProtocolClient( |
81 observer_->SetDefaultBrowserUIState(STATE_PROCESSING); | 83 const std::string& protocol) { |
84 if (observer_) { | |
85 observer_->SetDefaultClientAppUIState(STATE_PROCESSING); | |
86 } | |
87 protocol_.assign(protocol); | |
82 BrowserThread::PostTask( | 88 BrowserThread::PostTask( |
83 BrowserThread::FILE, FROM_HERE, | 89 BrowserThread::FILE, FROM_HERE, |
84 NewRunnableMethod( | 90 NewRunnableMethod( |
85 this, &DefaultBrowserWorker::ExecuteSetAsDefaultBrowser)); | 91 this, &DefaultClientAppWorker::ExecuteCheckDefaultProtocolClient)); |
86 } | 92 } |
87 | 93 |
88 void ShellIntegration::DefaultBrowserWorker::ObserverDestroyed() { | 94 void ShellIntegration::DefaultClientAppWorker::StartSetAsDefaultBrowser() { |
95 if (observer_) { | |
96 observer_->SetDefaultClientAppUIState(STATE_PROCESSING); | |
97 } | |
98 BrowserThread::PostTask( | |
99 BrowserThread::FILE, FROM_HERE, | |
100 NewRunnableMethod( | |
101 this, &DefaultClientAppWorker::ExecuteSetAsDefaultBrowser)); | |
102 } | |
103 | |
104 void ShellIntegration::DefaultClientAppWorker::StartSetAsDefaultProtocolClient( | |
105 const std::string& protocol) { | |
106 if (observer_) { | |
107 observer_->SetDefaultClientAppUIState(STATE_PROCESSING); | |
108 } | |
109 protocol_.assign(protocol); | |
110 BrowserThread::PostTask( | |
111 BrowserThread::FILE, FROM_HERE, | |
112 NewRunnableMethod( | |
113 this, &DefaultClientAppWorker::ExecuteSetAsDefaultProtocolClient)); | |
114 } | |
115 | |
116 void ShellIntegration::DefaultClientAppWorker::ObserverDestroyed() { | |
89 // Our associated view has gone away, so we shouldn't call back to it if | 117 // Our associated view has gone away, so we shouldn't call back to it if |
90 // our worker thread returns after the view is dead. | 118 // our worker thread returns after the view is dead. |
91 observer_ = NULL; | 119 observer_ = NULL; |
92 } | 120 } |
93 | 121 |
94 /////////////////////////////////////////////////////////////////////////////// | 122 /////////////////////////////////////////////////////////////////////////////// |
95 // DefaultBrowserWorker, private: | 123 // DefaultClientAppWorker, private: |
96 | 124 |
97 void ShellIntegration::DefaultBrowserWorker::ExecuteCheckDefaultBrowser() { | 125 void ShellIntegration::DefaultClientAppWorker::ExecuteCheckDefaultBrowser() { |
98 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 126 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
99 DefaultBrowserState state = ShellIntegration::IsDefaultBrowser(); | 127 DefaultClientAppState state = ShellIntegration::IsDefaultBrowser(); |
100 BrowserThread::PostTask( | 128 BrowserThread::PostTask( |
101 BrowserThread::UI, FROM_HERE, | 129 BrowserThread::UI, FROM_HERE, |
102 NewRunnableMethod( | 130 NewRunnableMethod( |
103 this, &DefaultBrowserWorker::CompleteCheckDefaultBrowser, state)); | 131 this, &DefaultClientAppWorker::CompleteCheckDefaultApplication, |
132 state)); | |
104 } | 133 } |
105 | 134 |
106 void ShellIntegration::DefaultBrowserWorker::CompleteCheckDefaultBrowser( | 135 void |
107 DefaultBrowserState state) { | 136 ShellIntegration::DefaultClientAppWorker::ExecuteCheckDefaultProtocolClient() { |
137 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | |
138 DefaultClientAppState state = | |
139 ShellIntegration::IsDefaultProtocolClient(protocol_); | |
140 BrowserThread::PostTask( | |
141 BrowserThread::UI, FROM_HERE, | |
142 NewRunnableMethod( | |
143 this, &DefaultClientAppWorker::CompleteCheckDefaultApplication, | |
144 state)); | |
145 } | |
146 | |
147 void ShellIntegration::DefaultClientAppWorker::CompleteCheckDefaultApplication( | |
148 DefaultClientAppState state) { | |
108 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 149 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
109 UpdateUI(state); | 150 UpdateUI(state); |
110 } | 151 } |
111 | 152 |
112 void ShellIntegration::DefaultBrowserWorker::ExecuteSetAsDefaultBrowser() { | 153 void ShellIntegration::DefaultClientAppWorker::ExecuteSetAsDefaultBrowser() { |
113 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 154 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
114 ShellIntegration::SetAsDefaultBrowser(); | 155 ShellIntegration::SetAsDefaultBrowser(); |
115 BrowserThread::PostTask( | 156 BrowserThread::PostTask( |
116 BrowserThread::UI, FROM_HERE, | 157 BrowserThread::UI, FROM_HERE, |
117 NewRunnableMethod( | 158 NewRunnableMethod( |
118 this, &DefaultBrowserWorker::CompleteSetAsDefaultBrowser)); | 159 this, &DefaultClientAppWorker::CompleteSetAsDefaultBrowser)); |
119 } | 160 } |
120 | 161 |
121 void ShellIntegration::DefaultBrowserWorker::CompleteSetAsDefaultBrowser() { | 162 void ShellIntegration::DefaultClientAppWorker::CompleteSetAsDefaultBrowser() { |
122 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 163 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
123 if (observer_) { | 164 if (observer_) { |
124 // Set as default completed, check again to make sure it stuck... | 165 // Set as default completed, check again to make sure it stuck... |
125 StartCheckDefaultBrowser(); | 166 StartCheckDefaultBrowser(); |
126 } | 167 } |
127 } | 168 } |
128 | 169 |
129 void ShellIntegration::DefaultBrowserWorker::UpdateUI( | 170 void |
130 DefaultBrowserState state) { | 171 ShellIntegration::DefaultClientAppWorker::ExecuteSetAsDefaultProtocolClient() { |
172 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | |
173 ShellIntegration::SetAsDefaultProtocolClient(protocol_); | |
174 BrowserThread::PostTask( | |
175 BrowserThread::UI, FROM_HERE, | |
176 NewRunnableMethod( | |
177 this, &DefaultClientAppWorker::CompleteSetAsDefaultProtocolClient)); | |
178 } | |
179 | |
180 void | |
181 ShellIntegration::DefaultClientAppWorker::CompleteSetAsDefaultProtocolClient() { | |
182 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
183 if (observer_) { | |
184 // Set as default completed, check again to make sure it stuck... | |
185 StartCheckDefaultProtocolClient(protocol_); | |
186 } | |
187 } | |
188 | |
189 void ShellIntegration::DefaultClientAppWorker::UpdateUI( | |
190 DefaultClientAppState state) { | |
131 if (observer_) { | 191 if (observer_) { |
132 switch (state) { | 192 switch (state) { |
133 case NOT_DEFAULT_BROWSER: | 193 case NOT_DEFAULT_CLIENT_APP: |
134 observer_->SetDefaultBrowserUIState(STATE_NOT_DEFAULT); | 194 observer_->SetDefaultClientAppUIState(STATE_NOT_DEFAULT); |
135 break; | 195 break; |
136 case IS_DEFAULT_BROWSER: | 196 case IS_DEFAULT_CLIENT_APP: |
137 observer_->SetDefaultBrowserUIState(STATE_IS_DEFAULT); | 197 observer_->SetDefaultClientAppUIState(STATE_IS_DEFAULT); |
138 break; | 198 break; |
139 case UNKNOWN_DEFAULT_BROWSER: | 199 case UNKNOWN_DEFAULT_CLIENT_APP: |
140 observer_->SetDefaultBrowserUIState(STATE_UNKNOWN); | 200 observer_->SetDefaultClientAppUIState(STATE_UNKNOWN); |
141 break; | 201 break; |
142 default: | 202 default: |
143 break; | 203 break; |
144 } | 204 } |
145 } | 205 } |
146 } | 206 } |
OLD | NEW |