1 // Copyright 2014 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.
5 #include "chromecast/browser/cast_browser_context.h"
7 #include "base/command_line.h"
8 #include "base/files/file_util.h"
9 #include "base/macros.h"
10 #include "base/path_service.h"
11 #include "chromecast/browser/cast_download_manager_delegate.h"
12 #include "chromecast/browser/url_request_context_factory.h"
13 #include "chromecast/common/cast_paths.h"
14 #include "content/public/browser/browser_thread.h"
15 #include "content/public/browser/resource_context.h"
16 #include "content/public/browser/storage_partition.h"
17 #include "content/public/common/content_switches.h"
18 #include "net/url_request/url_request_context.h"
19 #include "net/url_request/url_request_context_getter.h"
21 namespace chromecast
{
24 class CastBrowserContext::CastResourceContext
:
25 public content::ResourceContext
{
27 explicit CastResourceContext(
28 URLRequestContextFactory
* url_request_context_factory
) :
29 url_request_context_factory_(url_request_context_factory
) {}
30 virtual ~CastResourceContext() {}
32 // ResourceContext implementation:
33 virtual net::HostResolver
* GetHostResolver() override
{
34 return url_request_context_factory_
->GetMainGetter()->
35 GetURLRequestContext()->host_resolver();
38 virtual net::URLRequestContext
* GetRequestContext() override
{
39 return url_request_context_factory_
->GetMainGetter()->
40 GetURLRequestContext();
44 URLRequestContextFactory
* url_request_context_factory_
;
46 DISALLOW_COPY_AND_ASSIGN(CastResourceContext
);
49 CastBrowserContext::CastBrowserContext(
50 URLRequestContextFactory
* url_request_context_factory
)
51 : url_request_context_factory_(url_request_context_factory
),
52 resource_context_(new CastResourceContext(url_request_context_factory
)),
53 download_manager_delegate_(new CastDownloadManagerDelegate()) {
57 CastBrowserContext::~CastBrowserContext() {
58 content::BrowserThread::DeleteSoon(
59 content::BrowserThread::IO
,
61 resource_context_
.release());
64 void CastBrowserContext::InitWhileIOAllowed() {
65 #if defined(OS_ANDROID)
66 CHECK(PathService::Get(base::DIR_ANDROID_APP_DATA
, &path_
));
67 path_
= path_
.Append(FILE_PATH_LITERAL("cast_shell"));
69 if (!base::PathExists(path_
))
70 base::CreateDirectory(path_
);
72 // Chromecast doesn't support user profiles nor does it have
73 // incognito mode. This means that all of the persistent
74 // data (currently only cookies and local storage) will be
75 // shared in a single location as defined here.
76 CHECK(PathService::Get(DIR_CAST_HOME
, &path_
));
77 #endif // defined(OS_ANDROID)
80 base::FilePath
CastBrowserContext::GetPath() const {
84 bool CastBrowserContext::IsOffTheRecord() const {
88 net::URLRequestContextGetter
* CastBrowserContext::GetRequestContext() {
89 return GetDefaultStoragePartition(this)->GetURLRequestContext();
92 net::URLRequestContextGetter
*
93 CastBrowserContext::GetRequestContextForRenderProcess(int renderer_child_id
) {
94 return GetRequestContext();
97 net::URLRequestContextGetter
* CastBrowserContext::GetMediaRequestContext() {
98 return url_request_context_factory_
->GetMediaGetter();
101 net::URLRequestContextGetter
*
102 CastBrowserContext::GetMediaRequestContextForRenderProcess(
103 int renderer_child_id
) {
104 return GetMediaRequestContext();
107 net::URLRequestContextGetter
*
108 CastBrowserContext::GetMediaRequestContextForStoragePartition(
109 const base::FilePath
& partition_path
, bool in_memory
) {
110 return GetMediaRequestContext();
113 content::ResourceContext
* CastBrowserContext::GetResourceContext() {
114 return resource_context_
.get();
117 content::DownloadManagerDelegate
*
118 CastBrowserContext::GetDownloadManagerDelegate() {
119 return download_manager_delegate_
.get();
122 content::BrowserPluginGuestManager
* CastBrowserContext::GetGuestManager() {
127 storage::SpecialStoragePolicy
* CastBrowserContext::GetSpecialStoragePolicy() {
132 content::PushMessagingService
* CastBrowserContext::GetPushMessagingService() {
137 content::SSLHostStateDelegate
* CastBrowserContext::GetSSLHostStateDelegate() {
143 } // namespace chromecast