[email protected] | 9fe4204 | 2013-10-29 21:13:33 | [diff] [blame] | 1 | // 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] | 7f47421 | 2013-11-05 04:26:16 | [diff] [blame^] | 7 | #include "base/command_line.h" |
[email protected] | 9fe4204 | 2013-10-29 21:13:33 | [diff] [blame] | 8 | #include "chrome/browser/browser_process.h" |
| 9 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 7f47421 | 2013-11-05 04:26:16 | [diff] [blame^] | 10 | #include "chrome/browser/profiles/profile_manager.h" |
| 11 | #include "chrome/browser/ui/browser_finder.h" |
| 12 | #include "chrome/common/chrome_switches.h" |
[email protected] | 9fe4204 | 2013-10-29 21:13:33 | [diff] [blame] | 13 | |
| 14 | namespace extensions { |
| 15 | |
| 16 | namespace { |
| 17 | |
| 18 | static base::LazyInstance<ChromeExtensionsBrowserClient> g_client = |
| 19 | LAZY_INSTANCE_INITIALIZER; |
| 20 | |
| 21 | } // namespace |
| 22 | |
| 23 | ChromeExtensionsBrowserClient::ChromeExtensionsBrowserClient() {} |
| 24 | |
| 25 | ChromeExtensionsBrowserClient::~ChromeExtensionsBrowserClient() {} |
| 26 | |
| 27 | bool ChromeExtensionsBrowserClient::IsShuttingDown() { |
| 28 | return g_browser_process->IsShuttingDown(); |
| 29 | } |
| 30 | |
| 31 | bool ChromeExtensionsBrowserClient::IsSameContext( |
| 32 | content::BrowserContext* first, |
| 33 | content::BrowserContext* second) { |
| 34 | return static_cast<Profile*>(first)->IsSameProfile( |
| 35 | static_cast<Profile*>(second)); |
| 36 | } |
| 37 | |
| 38 | bool ChromeExtensionsBrowserClient::HasOffTheRecordContext( |
| 39 | content::BrowserContext* context) { |
| 40 | return static_cast<Profile*>(context)->HasOffTheRecordProfile(); |
| 41 | } |
| 42 | |
| 43 | content::BrowserContext* ChromeExtensionsBrowserClient::GetOffTheRecordContext( |
| 44 | content::BrowserContext* context) { |
| 45 | return static_cast<Profile*>(context)->GetOffTheRecordProfile(); |
| 46 | } |
| 47 | |
[email protected] | 7f47421 | 2013-11-05 04:26:16 | [diff] [blame^] | 48 | content::BrowserContext* ChromeExtensionsBrowserClient::GetOriginalContext( |
| 49 | content::BrowserContext* context) { |
| 50 | return static_cast<Profile*>(context)->GetOriginalProfile(); |
| 51 | } |
| 52 | |
| 53 | bool 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] | 9fe4204 | 2013-10-29 21:13:33 | [diff] [blame] | 73 | // static |
| 74 | ChromeExtensionsBrowserClient* ChromeExtensionsBrowserClient::GetInstance() { |
| 75 | return g_client.Pointer(); |
| 76 | } |
| 77 | |
| 78 | } // namespace extensions |