blob: eaca74626bee6683a57cd65e06f0af225f26a66b [file] [log] [blame]
[email protected]5a20b192012-03-01 06:01:571// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]4a0765a2009-05-08 23:12:255#include "chrome/browser/shell_integration.h"
6
[email protected]c5efb952011-11-01 01:28:367#include "base/bind.h"
[email protected]28375ae2010-02-05 04:45:508#include "base/command_line.h"
thestig18dfb7a52014-08-26 10:44:049#include "base/files/file_util.h"
pmonettef89ac7c72015-10-06 03:22:0110#include "base/metrics/histogram_macros.h"
[email protected]24a555b62013-06-10 22:01:1711#include "base/strings/string_util.h"
pmonette9c1457f2015-11-19 20:29:3112#include "base/strings/stringprintf.h"
[email protected]e309f312013-06-07 21:50:0813#include "base/strings/utf_string_conversions.h"
[email protected]124901f52013-03-27 14:42:1014#include "base/threading/thread_restrictions.h"
pmonettef89ac7c72015-10-06 03:22:0115#include "base/timer/timer.h"
avi664c07b2015-12-26 02:18:3116#include "build/build_config.h"
[email protected]ba26a442013-02-20 15:32:5517#include "chrome/browser/policy/policy_path_parser.h"
[email protected]b96aa932009-08-12 21:34:4918#include "chrome/common/chrome_paths.h"
[email protected]28375ae2010-02-05 04:45:5019#include "chrome/common/chrome_switches.h"
brettwb1fc1b82016-02-02 00:19:0820#include "components/prefs/pref_service.h"
sdefresne9fb67692015-08-03 18:48:2221#include "components/version_info/version_info.h"
[email protected]c38831a12011-10-28 12:44:4922#include "content/public/browser/browser_thread.h"
initial.commit09911bf2008-07-26 23:55:2923
[email protected]931d1042013-04-05 17:50:4424#if defined(OS_CHROMEOS)
25#include "chromeos/chromeos_switches.h"
26#endif
27
[email protected]2f5bc322013-12-04 08:58:1528#if !defined(OS_WIN)
sdefresne9fb67692015-08-03 18:48:2229#include "chrome/common/channel_info.h"
[email protected]af39f002014-08-22 10:18:1830#include "chrome/grit/chromium_strings.h"
[email protected]2f5bc322013-12-04 08:58:1531#include "ui/base/l10n/l10n_util.h"
32#endif
33
[email protected]631bb742011-11-02 11:29:3934using content::BrowserThread;
35
pmonette9fa59e882016-02-10 00:12:1936namespace shell_integration {
37
pmonette034a03d92015-10-02 21:04:2738namespace {
39
pmonette9fa59e882016-02-10 00:12:1940const struct AppModeInfo* gAppModeInfo = nullptr;
pmonette034a03d92015-10-02 21:04:2741
42} // namespace
43
44#if !defined(OS_WIN)
pmonette9fa59e882016-02-10 00:12:1945bool SetAsDefaultBrowserInteractive() {
pmonette034a03d92015-10-02 21:04:2746 return false;
47}
48
pmonette9fa59e882016-02-10 00:12:1949bool IsSetAsDefaultAsynchronous() {
pmonettef89ac7c72015-10-06 03:22:0150 return false;
51}
52
pmonette9fa59e882016-02-10 00:12:1953bool SetAsDefaultProtocolClientInteractive(const std::string& protocol) {
pmonette034a03d92015-10-02 21:04:2754 return false;
55}
56#endif // !defined(OS_WIN)
57
pmonette9fa59e882016-02-10 00:12:1958DefaultWebClientSetPermission CanSetAsDefaultProtocolClient() {
[email protected]a01481b2011-07-15 04:30:0259 // Allowed as long as the browser can become the operating system default
60 // browser.
pmonettef89ac7c72015-10-06 03:22:0161 DefaultWebClientSetPermission permission = CanSetAsDefaultBrowser();
62
63 // Set as default asynchronous is only supported for default web browser.
64 return (permission == SET_DEFAULT_ASYNCHRONOUS) ? SET_DEFAULT_INTERACTIVE
65 : permission;
[email protected]a01481b2011-07-15 04:30:0266}
67
pmonette034a03d92015-10-02 21:04:2768#if !defined(OS_WIN)
pmonette9fa59e882016-02-10 00:12:1969bool IsElevationNeededForSettingDefaultProtocolClient() {
pmonette034a03d92015-10-02 21:04:2770 return false;
71}
72#endif // !defined(OS_WIN)
[email protected]9561bc912012-03-07 02:41:1673
pmonette9fa59e882016-02-10 00:12:1974void SetAppModeInfo(const struct AppModeInfo* info) {
[email protected]9561bc912012-03-07 02:41:1675 gAppModeInfo = info;
76}
77
pmonette9fa59e882016-02-10 00:12:1978const struct AppModeInfo* AppModeInfo() {
[email protected]9561bc912012-03-07 02:41:1679 return gAppModeInfo;
80}
81
pmonette9fa59e882016-02-10 00:12:1982bool IsRunningInAppMode() {
[email protected]9561bc912012-03-07 02:41:1683 return gAppModeInfo != NULL;
84}
85
pmonette9fa59e882016-02-10 00:12:1986base::CommandLine CommandLineArgsForLauncher(
[email protected]2f1c09d2011-01-14 14:58:1487 const GURL& url,
[email protected]5c93a0c12012-05-02 19:45:2488 const std::string& extension_app_id,
[email protected]650b2d52013-02-10 03:41:4589 const base::FilePath& profile_path) {
[email protected]124901f52013-03-27 14:42:1090 base::ThreadRestrictions::AssertIOAllowed();
avi556c05022014-12-22 23:31:4391 base::CommandLine new_cmd_line(base::CommandLine::NO_PROGRAM);
[email protected]28375ae2010-02-05 04:45:5092
[email protected]fb06aea82014-02-26 15:48:4793 AppendProfileArgs(
94 extension_app_id.empty() ? base::FilePath() : profile_path,
95 &new_cmd_line);
[email protected]28375ae2010-02-05 04:45:5096
97 // If |extension_app_id| is present, we use the kAppId switch rather than
98 // the kApp switch (the launch url will be read from the extension app
99 // during launch.
[email protected]ec5b50d2010-10-09 16:35:18100 if (!extension_app_id.empty()) {
[email protected]b10392932011-03-08 21:28:14101 new_cmd_line.AppendSwitchASCII(switches::kAppId, extension_app_id);
[email protected]64048bd2010-03-08 23:28:58102 } else {
[email protected]28375ae2010-02-05 04:45:50103 // Use '--app=url' instead of just 'url' to launch the browser with minimal
104 // chrome.
105 // Note: Do not change this flag! Old Gears shortcuts will break if you do!
[email protected]b10392932011-03-08 21:28:14106 new_cmd_line.AppendSwitchASCII(switches::kApp, url.spec());
[email protected]28375ae2010-02-05 04:45:50107 }
[email protected]b10392932011-03-08 21:28:14108 return new_cmd_line;
[email protected]28375ae2010-02-05 04:45:50109}
110
pmonette9fa59e882016-02-10 00:12:19111void AppendProfileArgs(const base::FilePath& profile_path,
112 base::CommandLine* command_line) {
[email protected]fb06aea82014-02-26 15:48:47113 DCHECK(command_line);
avi556c05022014-12-22 23:31:43114 const base::CommandLine& cmd_line = *base::CommandLine::ForCurrentProcess();
[email protected]fb06aea82014-02-26 15:48:47115
116 // Use the same UserDataDir for new launches that we currently have set.
117 base::FilePath user_data_dir =
118 cmd_line.GetSwitchValuePath(switches::kUserDataDir);
119#if defined(OS_MACOSX) || defined(OS_WIN)
120 policy::path_parser::CheckUserDataDirPolicy(&user_data_dir);
121#endif
122 if (!user_data_dir.empty()) {
123 // Make sure user_data_dir is an absolute path.
124 user_data_dir = base::MakeAbsoluteFilePath(user_data_dir);
125 if (!user_data_dir.empty() && base::PathExists(user_data_dir))
126 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
127 }
128
129#if defined(OS_CHROMEOS)
130 base::FilePath profile = cmd_line.GetSwitchValuePath(
131 chromeos::switches::kLoginProfile);
132 if (!profile.empty())
133 command_line->AppendSwitchPath(chromeos::switches::kLoginProfile, profile);
134#else
135 if (!profile_path.empty())
136 command_line->AppendSwitchPath(switches::kProfileDirectory,
137 profile_path.BaseName());
138#endif
139}
140
[email protected]bd046bd42012-06-08 05:07:32141#if !defined(OS_WIN)
pmonette9fa59e882016-02-10 00:12:19142base::string16 GetAppShortcutsSubdirName() {
sdefresne9fb67692015-08-03 18:48:22143 if (chrome::GetChannel() == version_info::Channel::CANARY)
[email protected]2f5bc322013-12-04 08:58:15144 return l10n_util::GetStringUTF16(IDS_APP_SHORTCUTS_SUBDIR_NAME_CANARY);
145 return l10n_util::GetStringUTF16(IDS_APP_SHORTCUTS_SUBDIR_NAME);
146}
pmonette868ca642015-09-02 14:34:02147#endif // !defined(OS_WIN)
[email protected]bd046bd42012-06-08 05:07:32148
pmonette034a03d92015-10-02 21:04:27149///////////////////////////////////////////////////////////////////////////////
pmonette9fa59e882016-02-10 00:12:19150// DefaultWebClientWorker
[email protected]d24c4012009-07-28 01:57:31151//
initial.commit09911bf2008-07-26 23:55:29152
pmonette9fa59e882016-02-10 00:12:19153DefaultWebClientWorker::DefaultWebClientWorker(
pmonette8db6a8be2016-02-11 01:50:31154 DefaultWebClientObserver* observer,
155 bool delete_observer)
156 : observer_(observer), delete_observer_(delete_observer) {}
initial.commit09911bf2008-07-26 23:55:29157
pmonette9fa59e882016-02-10 00:12:19158void DefaultWebClientWorker::StartCheckIsDefault() {
pmonette9c1457f2015-11-19 20:29:31159 if (observer_)
[email protected]4468a5b2011-05-26 07:48:02160 observer_->SetDefaultWebClientUIState(STATE_PROCESSING);
pmonette9c1457f2015-11-19 20:29:31161
162 BrowserThread::PostTask(
163 BrowserThread::FILE, FROM_HERE,
164 base::Bind(&DefaultWebClientWorker::CheckIsDefault, this));
[email protected]4468a5b2011-05-26 07:48:02165}
166
pmonette9fa59e882016-02-10 00:12:19167void DefaultWebClientWorker::StartSetAsDefault() {
pmonettef89ac7c72015-10-06 03:22:01168 // Cancel the already running process if another start is requested.
169 if (set_as_default_in_progress_) {
170 if (set_as_default_initialized_) {
171 FinalizeSetAsDefault();
172 set_as_default_initialized_ = false;
173 }
174
175 ReportAttemptResult(AttemptResult::RETRY);
176 }
177
178 set_as_default_in_progress_ = true;
pmonette8db6a8be2016-02-11 01:50:31179 if (observer_)
[email protected]4468a5b2011-05-26 07:48:02180 observer_->SetDefaultWebClientUIState(STATE_PROCESSING);
pmonettef89ac7c72015-10-06 03:22:01181
pmonette9c1457f2015-11-19 20:29:31182 set_as_default_initialized_ = InitializeSetAsDefault();
183
pmonettef89ac7c72015-10-06 03:22:01184 // Remember the start time.
185 start_time_ = base::TimeTicks::Now();
186
pmonette8db6a8be2016-02-11 01:50:31187 BrowserThread::PostTask(
188 BrowserThread::FILE, FROM_HERE,
189 base::Bind(&DefaultWebClientWorker::SetAsDefault, this));
initial.commit09911bf2008-07-26 23:55:29190}
191
pmonette9fa59e882016-02-10 00:12:19192void DefaultWebClientWorker::ObserverDestroyed() {
[email protected]d24c4012009-07-28 01:57:31193 // Our associated view has gone away, so we shouldn't call back to it if
194 // our worker thread returns after the view is dead.
thestig00844cea2015-09-08 21:44:52195 DCHECK_CURRENTLY_ON(BrowserThread::UI);
pmonettef89ac7c72015-10-06 03:22:01196 observer_ = nullptr;
197
198 if (set_as_default_initialized_) {
199 FinalizeSetAsDefault();
200 set_as_default_initialized_ = false;
201 }
202
203 if (set_as_default_in_progress_)
204 ReportAttemptResult(AttemptResult::ABANDONED);
[email protected]d24c4012009-07-28 01:57:31205}
206
207///////////////////////////////////////////////////////////////////////////////
[email protected]4468a5b2011-05-26 07:48:02208// DefaultWebClientWorker, private:
[email protected]d24c4012009-07-28 01:57:31209
pmonette9fa59e882016-02-10 00:12:19210DefaultWebClientWorker::~DefaultWebClientWorker() {}
[email protected]d24c4012009-07-28 01:57:31211
pmonette9fa59e882016-02-10 00:12:19212void DefaultWebClientWorker::OnCheckIsDefaultComplete(
[email protected]4468a5b2011-05-26 07:48:02213 DefaultWebClientState state) {
thestig00844cea2015-09-08 21:44:52214 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]264f74d12009-09-04 23:39:58215 UpdateUI(state);
pmonette9c1457f2015-11-19 20:29:31216
217 if (check_default_should_report_success_) {
218 check_default_should_report_success_ = false;
219
220 ReportAttemptResult(state == DefaultWebClientState::IS_DEFAULT
221 ? AttemptResult::SUCCESS
222 : AttemptResult::NO_ERRORS_NOT_DEFAULT);
223 }
224
[email protected]97e2e3f2011-07-22 10:21:25225 // The worker has finished everything it needs to do, so free the observer
226 // if we own it.
pmonette8db6a8be2016-02-11 01:50:31227 if (observer_ && delete_observer_) {
[email protected]97e2e3f2011-07-22 10:21:25228 delete observer_;
pmonettef89ac7c72015-10-06 03:22:01229 observer_ = nullptr;
[email protected]97e2e3f2011-07-22 10:21:25230 }
[email protected]d24c4012009-07-28 01:57:31231}
232
pmonette9fa59e882016-02-10 00:12:19233void DefaultWebClientWorker::OnSetAsDefaultAttemptComplete(
pmonettef89ac7c72015-10-06 03:22:01234 AttemptResult result) {
thestig00844cea2015-09-08 21:44:52235 DCHECK_CURRENTLY_ON(BrowserThread::UI);
pmonettef89ac7c72015-10-06 03:22:01236 // Hold on to a reference because if this was called via the default browser
237 // callback in StartupBrowserCreator, clearing the callback in
pmonette9c1457f2015-11-19 20:29:31238 // FinalizeSetAsDefault() would otherwise remove the last reference and delete
pmonettef89ac7c72015-10-06 03:22:01239 // us in the middle of this function.
240 scoped_refptr<DefaultWebClientWorker> scoped_ref(this);
241
242 if (set_as_default_in_progress_) {
243 set_as_default_in_progress_ = false;
244
245 if (set_as_default_initialized_) {
246 FinalizeSetAsDefault();
247 set_as_default_initialized_ = false;
248 }
249 if (observer_) {
250 bool succeeded = result == AttemptResult::SUCCESS ||
251 result == AttemptResult::ALREADY_DEFAULT;
252 observer_->OnSetAsDefaultConcluded(succeeded);
253 }
254
pmonette9c1457f2015-11-19 20:29:31255 // Report failures here. Successes are reported in
256 // OnCheckIsDefaultComplete() after checking that the change is verified.
257 check_default_should_report_success_ = result == AttemptResult::SUCCESS;
258 if (!check_default_should_report_success_)
259 ReportAttemptResult(result);
pmonettef89ac7c72015-10-06 03:22:01260
261 // Start the default browser check which will notify the observer as to
262 // whether Chrome is really the default browser. This is needed because
263 // detecting that the process was successful is not 100% sure.
264 // For example, on Windows 10+, the user might have unchecked the "Always
265 // use this app" checkbox which can't be detected.
266 StartCheckIsDefault();
267 }
[email protected]d24c4012009-07-28 01:57:31268}
269
pmonette9fa59e882016-02-10 00:12:19270void DefaultWebClientWorker::ReportAttemptResult(AttemptResult result) {
pmonette9c1457f2015-11-19 20:29:31271 const char* histogram_prefix = GetHistogramPrefix();
pmonettef89ac7c72015-10-06 03:22:01272
pmonette9c1457f2015-11-19 20:29:31273 // Report result.
274 base::LinearHistogram::FactoryGet(
275 base::StringPrintf("%s.SetDefaultResult", histogram_prefix), 1,
276 AttemptResult::NUM_ATTEMPT_RESULT_TYPES,
277 AttemptResult::NUM_ATTEMPT_RESULT_TYPES + 1,
278 base::HistogramBase::kUmaTargetedHistogramFlag)
279 ->Add(result);
pmonettef89ac7c72015-10-06 03:22:01280
pmonette9c1457f2015-11-19 20:29:31281 // Report asynchronous duration.
282 if (IsSetAsDefaultAsynchronous() && ShouldReportDurationForResult(result)) {
283 base::Histogram::FactoryTimeGet(
284 base::StringPrintf("%s.SetDefaultAsyncDuration_%s", histogram_prefix,
285 AttemptResultToString(result)),
286 base::TimeDelta::FromMilliseconds(10), base::TimeDelta::FromMinutes(3),
287 50, base::HistogramBase::kUmaTargetedHistogramFlag)
288 ->AddTime(base::TimeTicks::Now() - start_time_);
pmonettef89ac7c72015-10-06 03:22:01289 }
290}
291
pmonette9fa59e882016-02-10 00:12:19292bool DefaultWebClientWorker::InitializeSetAsDefault() {
pmonettef89ac7c72015-10-06 03:22:01293 return true;
294}
295
pmonette9fa59e882016-02-10 00:12:19296void DefaultWebClientWorker::FinalizeSetAsDefault() {}
pmonettef89ac7c72015-10-06 03:22:01297
pmonette9fa59e882016-02-10 00:12:19298void DefaultWebClientWorker::UpdateUI(DefaultWebClientState state) {
[email protected]d24c4012009-07-28 01:57:31299 if (observer_) {
[email protected]264f74d12009-09-04 23:39:58300 switch (state) {
[email protected]89886652012-12-11 18:09:07301 case NOT_DEFAULT:
[email protected]4468a5b2011-05-26 07:48:02302 observer_->SetDefaultWebClientUIState(STATE_NOT_DEFAULT);
[email protected]264f74d12009-09-04 23:39:58303 break;
[email protected]89886652012-12-11 18:09:07304 case IS_DEFAULT:
[email protected]4468a5b2011-05-26 07:48:02305 observer_->SetDefaultWebClientUIState(STATE_IS_DEFAULT);
[email protected]264f74d12009-09-04 23:39:58306 break;
[email protected]89886652012-12-11 18:09:07307 case UNKNOWN_DEFAULT:
[email protected]4468a5b2011-05-26 07:48:02308 observer_->SetDefaultWebClientUIState(STATE_UNKNOWN);
[email protected]264f74d12009-09-04 23:39:58309 break;
310 default:
311 break;
312 }
[email protected]d24c4012009-07-28 01:57:31313 }
initial.commit09911bf2008-07-26 23:55:29314}
[email protected]4468a5b2011-05-26 07:48:02315
pmonette9fa59e882016-02-10 00:12:19316bool DefaultWebClientWorker::ShouldReportDurationForResult(
pmonette9c1457f2015-11-19 20:29:31317 AttemptResult result) {
318 return result == SUCCESS || result == FAILURE || result == ABANDONED ||
319 result == RETRY;
320}
321
pmonette9fa59e882016-02-10 00:12:19322const char* DefaultWebClientWorker::AttemptResultToString(
pmonette9c1457f2015-11-19 20:29:31323 AttemptResult result) {
324 switch (result) {
325 case SUCCESS:
326 return "Success";
327 case ALREADY_DEFAULT:
328 return "AlreadyDefault";
329 case FAILURE:
330 return "Failure";
331 case ABANDONED:
332 return "Abandoned";
333 case LAUNCH_FAILURE:
334 return "LaunchFailure";
335 case OTHER_WORKER:
336 return "OtherWorker";
337 case RETRY:
338 return "Retry";
339 case NO_ERRORS_NOT_DEFAULT:
340 return "NoErrorsNotDefault";
341 case NUM_ATTEMPT_RESULT_TYPES:
342 break;
343 }
344 NOTREACHED();
345 return "";
346}
347
[email protected]4468a5b2011-05-26 07:48:02348///////////////////////////////////////////////////////////////////////////////
pmonette9fa59e882016-02-10 00:12:19349// DefaultBrowserWorker
[email protected]4468a5b2011-05-26 07:48:02350//
351
pmonette8db6a8be2016-02-11 01:50:31352DefaultBrowserWorker::DefaultBrowserWorker(DefaultWebClientObserver* observer,
353 bool delete_observer)
354 : DefaultWebClientWorker(observer, delete_observer) {}
[email protected]4468a5b2011-05-26 07:48:02355
pmonette9fa59e882016-02-10 00:12:19356DefaultBrowserWorker::~DefaultBrowserWorker() {}
pmonettef89ac7c72015-10-06 03:22:01357
[email protected]4468a5b2011-05-26 07:48:02358///////////////////////////////////////////////////////////////////////////////
359// DefaultBrowserWorker, private:
360
pmonette9fa59e882016-02-10 00:12:19361void DefaultBrowserWorker::CheckIsDefault() {
pmonettef89ac7c72015-10-06 03:22:01362 DefaultWebClientState state = GetDefaultBrowser();
363 BrowserThread::PostTask(
364 BrowserThread::UI, FROM_HERE,
365 base::Bind(&DefaultBrowserWorker::OnCheckIsDefaultComplete, this, state));
[email protected]4468a5b2011-05-26 07:48:02366}
367
pmonette8db6a8be2016-02-11 01:50:31368void DefaultBrowserWorker::SetAsDefault() {
pmonettef89ac7c72015-10-06 03:22:01369 AttemptResult result = AttemptResult::FAILURE;
370 switch (CanSetAsDefaultBrowser()) {
371 case SET_DEFAULT_NOT_ALLOWED:
[email protected]bd046bd42012-06-08 05:07:32372 NOTREACHED();
pmonettef89ac7c72015-10-06 03:22:01373 break;
374 case SET_DEFAULT_UNATTENDED:
375 if (SetAsDefaultBrowser())
376 result = AttemptResult::SUCCESS;
377 break;
378 case SET_DEFAULT_INTERACTIVE:
pmonette8db6a8be2016-02-11 01:50:31379 if (interactive_permitted_ && SetAsDefaultBrowserInteractive())
pmonettef89ac7c72015-10-06 03:22:01380 result = AttemptResult::SUCCESS;
381 break;
382 case SET_DEFAULT_ASYNCHRONOUS:
383#if defined(OS_WIN)
pmonette8db6a8be2016-02-11 01:50:31384 if (!interactive_permitted_)
pmonettef89ac7c72015-10-06 03:22:01385 break;
386 if (GetDefaultBrowser() == IS_DEFAULT) {
387 // Don't start the asynchronous operation since it could result in
388 // losing the default browser status.
389 result = AttemptResult::ALREADY_DEFAULT;
390 break;
391 }
392 // This function will cause OnSetAsDefaultAttemptComplete() to be called
393 // asynchronously via a filter established in InitializeSetAsDefault().
394 if (!SetAsDefaultBrowserAsynchronous()) {
395 result = AttemptResult::LAUNCH_FAILURE;
396 break;
397 }
398 return;
399#else
400 NOTREACHED();
401 break;
402#endif
[email protected]bd046bd42012-06-08 05:07:32403 }
pmonettef89ac7c72015-10-06 03:22:01404 BrowserThread::PostTask(
405 BrowserThread::UI, FROM_HERE,
406 base::Bind(&DefaultBrowserWorker::OnSetAsDefaultAttemptComplete, this,
407 result));
[email protected]4468a5b2011-05-26 07:48:02408}
409
pmonette9fa59e882016-02-10 00:12:19410const char* DefaultBrowserWorker::GetHistogramPrefix() {
pmonette9c1457f2015-11-19 20:29:31411 return "DefaultBrowser";
412}
413
[email protected]4468a5b2011-05-26 07:48:02414///////////////////////////////////////////////////////////////////////////////
pmonette9fa59e882016-02-10 00:12:19415// DefaultProtocolClientWorker
[email protected]4468a5b2011-05-26 07:48:02416//
417
pmonette9fa59e882016-02-10 00:12:19418DefaultProtocolClientWorker::DefaultProtocolClientWorker(
419 DefaultWebClientObserver* observer,
pmonette8db6a8be2016-02-11 01:50:31420 const std::string& protocol,
421 bool delete_observer)
422 : DefaultWebClientWorker(observer, delete_observer), protocol_(protocol) {}
[email protected]4468a5b2011-05-26 07:48:02423
424///////////////////////////////////////////////////////////////////////////////
425// DefaultProtocolClientWorker, private:
426
pmonette9fa59e882016-02-10 00:12:19427DefaultProtocolClientWorker::~DefaultProtocolClientWorker() {}
pmonettef89ac7c72015-10-06 03:22:01428
pmonette9fa59e882016-02-10 00:12:19429void DefaultProtocolClientWorker::CheckIsDefault() {
pmonettef89ac7c72015-10-06 03:22:01430 DefaultWebClientState state = IsDefaultProtocolClient(protocol_);
431 BrowserThread::PostTask(
432 BrowserThread::UI, FROM_HERE,
433 base::Bind(&DefaultProtocolClientWorker::OnCheckIsDefaultComplete, this,
434 state));
[email protected]4468a5b2011-05-26 07:48:02435}
436
pmonette8db6a8be2016-02-11 01:50:31437void DefaultProtocolClientWorker::SetAsDefault() {
pmonettef89ac7c72015-10-06 03:22:01438 AttemptResult result = AttemptResult::FAILURE;
439 switch (CanSetAsDefaultProtocolClient()) {
440 case SET_DEFAULT_NOT_ALLOWED:
441 // Not allowed, do nothing.
[email protected]e7f79872013-09-13 01:39:31442 break;
pmonettef89ac7c72015-10-06 03:22:01443 case SET_DEFAULT_UNATTENDED:
444 if (SetAsDefaultProtocolClient(protocol_))
445 result = AttemptResult::SUCCESS;
[email protected]ee9d89d2012-09-25 18:21:03446 break;
pmonettef89ac7c72015-10-06 03:22:01447 case SET_DEFAULT_INTERACTIVE:
pmonette8db6a8be2016-02-11 01:50:31448 if (interactive_permitted_ &&
pmonettef89ac7c72015-10-06 03:22:01449 SetAsDefaultProtocolClientInteractive(protocol_)) {
450 result = AttemptResult::SUCCESS;
[email protected]ee9d89d2012-09-25 18:21:03451 }
452 break;
pmonettef89ac7c72015-10-06 03:22:01453 case SET_DEFAULT_ASYNCHRONOUS:
454 NOTREACHED();
455 break;
[email protected]ee9d89d2012-09-25 18:21:03456 }
pmonettef89ac7c72015-10-06 03:22:01457 BrowserThread::PostTask(
458 BrowserThread::UI, FROM_HERE,
459 base::Bind(&DefaultProtocolClientWorker::OnSetAsDefaultAttemptComplete,
460 this, result));
[email protected]4468a5b2011-05-26 07:48:02461}
pmonette9c1457f2015-11-19 20:29:31462
pmonette9fa59e882016-02-10 00:12:19463const char* DefaultProtocolClientWorker::GetHistogramPrefix() {
pmonette9c1457f2015-11-19 20:29:31464 return "DefaultProtocolClient";
465}
pmonette9fa59e882016-02-10 00:12:19466
467} // namespace shell_integration