This source file includes following definitions.
- LaunchSoon
- Observe
- ShowFirstRunDefaultBrowserPrompt
#include "chrome/browser/ui/startup/default_browser_prompt.h"
#include "base/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/shell_integration.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/webui/set_as_default_browser_ui.h"
#include "chrome/common/pref_names.h"
#include "components/startup_metric_utils/startup_metric_utils.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_types.h"
using content::BrowserThread;
namespace {
class SetMetroBrowserFlowLauncher : public content::NotificationObserver {
public:
static void LaunchSoon(Profile* profile) {
new SetMetroBrowserFlowLauncher(profile);
}
private:
explicit SetMetroBrowserFlowLauncher(Profile* profile)
: profile_(profile) {
registrar_.Add(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
content::NotificationService::AllSources());
}
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
content::NotificationRegistrar registrar_;
Profile* profile_;
DISALLOW_COPY_AND_ASSIGN(SetMetroBrowserFlowLauncher);
};
void SetMetroBrowserFlowLauncher::Observe(
int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
DCHECK_EQ(type, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME);
Browser* browser = chrome::FindBrowserWithWebContents(
content::Source<content::WebContents>(source).ptr());
if (!browser || !browser->is_type_tabbed())
return;
registrar_.RemoveAll();
SetAsDefaultBrowserUI::Show(profile_, browser);
delete this;
}
}
namespace chrome {
bool ShowFirstRunDefaultBrowserPrompt(Profile* profile) {
bool show_status =
(ShellIntegration::CanSetAsDefaultBrowser() ==
ShellIntegration::SET_DEFAULT_INTERACTIVE) &&
(ShellIntegration::GetDefaultBrowser() == ShellIntegration::NOT_DEFAULT);
if (show_status) {
startup_metric_utils::SetNonBrowserUIDisplayed();
SetMetroBrowserFlowLauncher::LaunchSoon(profile);
}
return show_status;
}
}