Upstreaming browser/ui/uikit_ui_util from iOS.
[chromium-blink-merge.git] / chromecast / browser / cast_browser_context.cc
blob51a9fc02550374a870432a5995635fda43985fb5
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/base/cast_paths.h"
12 #include "chromecast/browser/cast_download_manager_delegate.h"
13 #include "chromecast/browser/cast_permission_manager.h"
14 #include "chromecast/browser/url_request_context_factory.h"
15 #include "content/public/browser/browser_thread.h"
16 #include "content/public/browser/resource_context.h"
17 #include "content/public/browser/storage_partition.h"
18 #include "content/public/common/content_switches.h"
19 #include "net/url_request/url_request_context.h"
20 #include "net/url_request/url_request_context_getter.h"
22 namespace chromecast {
23 namespace shell {
25 class CastBrowserContext::CastResourceContext :
26 public content::ResourceContext {
27 public:
28 explicit CastResourceContext(
29 URLRequestContextFactory* url_request_context_factory) :
30 url_request_context_factory_(url_request_context_factory) {}
31 ~CastResourceContext() override {}
33 // ResourceContext implementation:
34 net::HostResolver* GetHostResolver() override {
35 return url_request_context_factory_->GetMainGetter()->
36 GetURLRequestContext()->host_resolver();
39 net::URLRequestContext* GetRequestContext() override {
40 return url_request_context_factory_->GetMainGetter()->
41 GetURLRequestContext();
44 private:
45 URLRequestContextFactory* url_request_context_factory_;
47 DISALLOW_COPY_AND_ASSIGN(CastResourceContext);
50 CastBrowserContext::CastBrowserContext(
51 URLRequestContextFactory* url_request_context_factory)
52 : url_request_context_factory_(url_request_context_factory),
53 resource_context_(new CastResourceContext(url_request_context_factory)),
54 download_manager_delegate_(new CastDownloadManagerDelegate()) {
55 InitWhileIOAllowed();
58 CastBrowserContext::~CastBrowserContext() {
59 content::BrowserThread::DeleteSoon(
60 content::BrowserThread::IO,
61 FROM_HERE,
62 resource_context_.release());
65 void CastBrowserContext::InitWhileIOAllowed() {
66 #if defined(OS_ANDROID)
67 CHECK(PathService::Get(base::DIR_ANDROID_APP_DATA, &path_));
68 path_ = path_.Append(FILE_PATH_LITERAL("cast_shell"));
70 if (!base::PathExists(path_))
71 base::CreateDirectory(path_);
72 #else
73 // Chromecast doesn't support user profiles nor does it have
74 // incognito mode. This means that all of the persistent
75 // data (currently only cookies and local storage) will be
76 // shared in a single location as defined here.
77 CHECK(PathService::Get(DIR_CAST_HOME, &path_));
78 #endif // defined(OS_ANDROID)
81 scoped_ptr<content::ZoomLevelDelegate>
82 CastBrowserContext::CreateZoomLevelDelegate(
83 const base::FilePath& partition_path) {
84 return nullptr;
87 base::FilePath CastBrowserContext::GetPath() const {
88 return path_;
91 bool CastBrowserContext::IsOffTheRecord() const {
92 return false;
95 net::URLRequestContextGetter* CastBrowserContext::GetRequestContext() {
96 return GetDefaultStoragePartition(this)->GetURLRequestContext();
99 net::URLRequestContextGetter*
100 CastBrowserContext::GetRequestContextForRenderProcess(int renderer_child_id) {
101 return GetRequestContext();
104 net::URLRequestContextGetter* CastBrowserContext::GetMediaRequestContext() {
105 return url_request_context_factory_->GetMediaGetter();
108 net::URLRequestContextGetter*
109 CastBrowserContext::GetMediaRequestContextForRenderProcess(
110 int renderer_child_id) {
111 return GetMediaRequestContext();
114 net::URLRequestContextGetter*
115 CastBrowserContext::GetMediaRequestContextForStoragePartition(
116 const base::FilePath& partition_path, bool in_memory) {
117 return GetMediaRequestContext();
120 net::URLRequestContextGetter* CastBrowserContext::GetSystemRequestContext() {
121 return url_request_context_factory_->GetSystemGetter();
124 content::ResourceContext* CastBrowserContext::GetResourceContext() {
125 return resource_context_.get();
128 content::DownloadManagerDelegate*
129 CastBrowserContext::GetDownloadManagerDelegate() {
130 return download_manager_delegate_.get();
133 content::BrowserPluginGuestManager* CastBrowserContext::GetGuestManager() {
134 return nullptr;
137 storage::SpecialStoragePolicy* CastBrowserContext::GetSpecialStoragePolicy() {
138 return nullptr;
141 content::PushMessagingService* CastBrowserContext::GetPushMessagingService() {
142 return nullptr;
145 content::SSLHostStateDelegate* CastBrowserContext::GetSSLHostStateDelegate() {
146 return nullptr;
149 content::PermissionManager* CastBrowserContext::GetPermissionManager() {
150 if (!permission_manager_.get())
151 permission_manager_.reset(new CastPermissionManager());
152 return permission_manager_.get();
155 } // namespace shell
156 } // namespace chromecast