blob: f2d2c8fe6ea59917437f376193c751a06cf35029 [file] [log] [blame]
[email protected]9fe42042013-10-29 21:13:331// Copyright 2013 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/extensions/chrome_extensions_browser_client.h"
6
[email protected]7f474212013-11-05 04:26:167#include "base/command_line.h"
[email protected]9fe42042013-10-29 21:13:338#include "chrome/browser/browser_process.h"
9#include "chrome/browser/profiles/profile.h"
[email protected]7f474212013-11-05 04:26:1610#include "chrome/browser/profiles/profile_manager.h"
11#include "chrome/browser/ui/browser_finder.h"
12#include "chrome/common/chrome_switches.h"
[email protected]9fe42042013-10-29 21:13:3313
14namespace extensions {
15
16namespace {
17
18static base::LazyInstance<ChromeExtensionsBrowserClient> g_client =
19 LAZY_INSTANCE_INITIALIZER;
20
21} // namespace
22
23ChromeExtensionsBrowserClient::ChromeExtensionsBrowserClient() {}
24
25ChromeExtensionsBrowserClient::~ChromeExtensionsBrowserClient() {}
26
27bool ChromeExtensionsBrowserClient::IsShuttingDown() {
28 return g_browser_process->IsShuttingDown();
29}
30
31bool ChromeExtensionsBrowserClient::IsSameContext(
32 content::BrowserContext* first,
33 content::BrowserContext* second) {
34 return static_cast<Profile*>(first)->IsSameProfile(
35 static_cast<Profile*>(second));
36}
37
38bool ChromeExtensionsBrowserClient::HasOffTheRecordContext(
39 content::BrowserContext* context) {
40 return static_cast<Profile*>(context)->HasOffTheRecordProfile();
41}
42
43content::BrowserContext* ChromeExtensionsBrowserClient::GetOffTheRecordContext(
44 content::BrowserContext* context) {
45 return static_cast<Profile*>(context)->GetOffTheRecordProfile();
46}
47
[email protected]7f474212013-11-05 04:26:1648content::BrowserContext* ChromeExtensionsBrowserClient::GetOriginalContext(
49 content::BrowserContext* context) {
50 return static_cast<Profile*>(context)->GetOriginalProfile();
51}
52
53bool ChromeExtensionsBrowserClient::DeferLoadingBackgroundHosts(
54 content::BrowserContext* context) const {
55 Profile* profile = static_cast<Profile*>(context);
56
57 // The profile may not be valid yet if it is still being initialized.
58 // In that case, defer loading, since it depends on an initialized profile.
59 // http://crbug.com/222473
60 if (!g_browser_process->profile_manager()->IsValidProfile(profile))
61 return true;
62
63#if defined(OS_ANDROID)
64 return false;
65#else
66 // There are no browser windows open and the browser process was
67 // started to show the app launcher.
68 return chrome::GetTotalBrowserCountForProfile(profile) == 0 &&
69 CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowAppList);
70#endif
71}
72
[email protected]9fe42042013-10-29 21:13:3373// static
74ChromeExtensionsBrowserClient* ChromeExtensionsBrowserClient::GetInstance() {
75 return g_client.Pointer();
76}
77
78} // namespace extensions