• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "chromecast/shell/browser/cast_browser_context.h"
6 
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/common/cast_paths.h"
12 #include "chromecast/shell/browser/cast_download_manager_delegate.h"
13 #include "chromecast/shell/browser/url_request_context_factory.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"
20 
21 namespace chromecast {
22 namespace shell {
23 
24 class CastBrowserContext::CastResourceContext :
25     public content::ResourceContext {
26  public:
CastResourceContext(URLRequestContextFactory * url_request_context_factory)27   explicit CastResourceContext(
28       URLRequestContextFactory* url_request_context_factory) :
29     url_request_context_factory_(url_request_context_factory) {}
~CastResourceContext()30   virtual ~CastResourceContext() {}
31 
32   // ResourceContext implementation:
GetHostResolver()33   virtual net::HostResolver* GetHostResolver() OVERRIDE {
34     return url_request_context_factory_->GetMainGetter()->
35         GetURLRequestContext()->host_resolver();
36   }
37 
GetRequestContext()38   virtual net::URLRequestContext* GetRequestContext() OVERRIDE {
39     return url_request_context_factory_->GetMainGetter()->
40         GetURLRequestContext();
41   }
42 
43  private:
44   URLRequestContextFactory* url_request_context_factory_;
45 
46   DISALLOW_COPY_AND_ASSIGN(CastResourceContext);
47 };
48 
CastBrowserContext(URLRequestContextFactory * url_request_context_factory)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()) {
54   InitWhileIOAllowed();
55 }
56 
~CastBrowserContext()57 CastBrowserContext::~CastBrowserContext() {
58   content::BrowserThread::DeleteSoon(
59       content::BrowserThread::IO,
60       FROM_HERE,
61       resource_context_.release());
62 }
63 
InitWhileIOAllowed()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"));
68 
69   if (!base::PathExists(path_))
70     base::CreateDirectory(path_);
71 #else
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)
78 }
79 
GetPath() const80 base::FilePath CastBrowserContext::GetPath() const {
81   return path_;
82 }
83 
IsOffTheRecord() const84 bool CastBrowserContext::IsOffTheRecord() const {
85   return false;
86 }
87 
GetRequestContext()88 net::URLRequestContextGetter* CastBrowserContext::GetRequestContext() {
89   return GetDefaultStoragePartition(this)->GetURLRequestContext();
90 }
91 
92 net::URLRequestContextGetter*
GetRequestContextForRenderProcess(int renderer_child_id)93 CastBrowserContext::GetRequestContextForRenderProcess(int renderer_child_id) {
94   return GetRequestContext();
95 }
96 
GetMediaRequestContext()97 net::URLRequestContextGetter* CastBrowserContext::GetMediaRequestContext() {
98   return url_request_context_factory_->GetMediaGetter();
99 }
100 
101 net::URLRequestContextGetter*
GetMediaRequestContextForRenderProcess(int renderer_child_id)102 CastBrowserContext::GetMediaRequestContextForRenderProcess(
103     int renderer_child_id) {
104   return GetMediaRequestContext();
105 }
106 
107 net::URLRequestContextGetter*
GetMediaRequestContextForStoragePartition(const base::FilePath & partition_path,bool in_memory)108 CastBrowserContext::GetMediaRequestContextForStoragePartition(
109     const base::FilePath& partition_path, bool in_memory) {
110   return GetMediaRequestContext();
111 }
112 
GetResourceContext()113 content::ResourceContext* CastBrowserContext::GetResourceContext() {
114   return resource_context_.get();
115 }
116 
117 content::DownloadManagerDelegate*
GetDownloadManagerDelegate()118 CastBrowserContext::GetDownloadManagerDelegate() {
119   return download_manager_delegate_.get();
120 }
121 
GetGuestManager()122 content::BrowserPluginGuestManager* CastBrowserContext::GetGuestManager() {
123   NOTIMPLEMENTED();
124   return NULL;
125 }
126 
GetSpecialStoragePolicy()127 storage::SpecialStoragePolicy* CastBrowserContext::GetSpecialStoragePolicy() {
128   NOTIMPLEMENTED();
129   return NULL;
130 }
131 
GetPushMessagingService()132 content::PushMessagingService* CastBrowserContext::GetPushMessagingService() {
133   NOTIMPLEMENTED();
134   return NULL;
135 }
136 
GetSSLHostStateDelegate()137 content::SSLHostStateDelegate* CastBrowserContext::GetSSLHostStateDelegate() {
138   NOTIMPLEMENTED();
139   return NULL;
140 }
141 
142 }  // namespace shell
143 }  // namespace chromecast
144