OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_PROFILES_OFF_THE_RECORD_PROFILE_IO_DATA_H_ | 5 #ifndef CHROME_BROWSER_PROFILES_OFF_THE_RECORD_PROFILE_IO_DATA_H_ |
6 #define CHROME_BROWSER_PROFILES_OFF_THE_RECORD_PROFILE_IO_DATA_H_ | 6 #define CHROME_BROWSER_PROFILES_OFF_THE_RECORD_PROFILE_IO_DATA_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| 11 #include "base/hash_tables.h" |
11 #include "base/ref_counted.h" | 12 #include "base/ref_counted.h" |
12 #include "base/scoped_ptr.h" | 13 #include "base/scoped_ptr.h" |
13 #include "chrome/browser/profiles/profile_io_data.h" | 14 #include "chrome/browser/profiles/profile_io_data.h" |
14 | 15 |
15 class ChromeURLRequestContext; | 16 class ChromeURLRequestContext; |
16 class ChromeURLRequestContextGetter; | 17 class ChromeURLRequestContextGetter; |
| 18 class Extension; |
17 class IOThread; | 19 class IOThread; |
18 class Profile; | 20 class Profile; |
19 | 21 |
20 // OffTheRecordProfile owns a OffTheRecordProfileIOData::Handle, which holds a | 22 // OffTheRecordProfile owns a OffTheRecordProfileIOData::Handle, which holds a |
21 // reference to the OffTheRecordProfileIOData. OffTheRecordProfileIOData is | 23 // reference to the OffTheRecordProfileIOData. OffTheRecordProfileIOData is |
22 // intended to own all the objects owned by OffTheRecordProfile which live on | 24 // intended to own all the objects owned by OffTheRecordProfile which live on |
23 // the IO thread, such as, but not limited to, network objects like | 25 // the IO thread, such as, but not limited to, network objects like |
24 // CookieMonster, HttpTransactionFactory, etc. OffTheRecordProfileIOData is | 26 // CookieMonster, HttpTransactionFactory, etc. OffTheRecordProfileIOData is |
25 // owned by the OffTheRecordProfile and OffTheRecordProfileIOData's | 27 // owned by the OffTheRecordProfile and OffTheRecordProfileIOData's |
26 // ChromeURLRequestContexts. When all of them go away, then ProfileIOData will | 28 // ChromeURLRequestContexts. When all of them go away, then ProfileIOData will |
27 // be deleted. Note that the OffTheRecordProfileIOData will typically outlive | 29 // be deleted. Note that the OffTheRecordProfileIOData will typically outlive |
28 // the Profile it is "owned" by, so it's important for OffTheRecordProfileIOData | 30 // the Profile it is "owned" by, so it's important for OffTheRecordProfileIOData |
29 // not to hold any references to the Profile beyond what's used by LazyParams | 31 // not to hold any references to the Profile beyond what's used by LazyParams |
30 // (which should be deleted after lazy initialization). | 32 // (which should be deleted after lazy initialization). |
31 | 33 |
32 class OffTheRecordProfileIOData : public ProfileIOData { | 34 class OffTheRecordProfileIOData : public ProfileIOData { |
33 public: | 35 public: |
34 class Handle { | 36 class Handle { |
35 public: | 37 public: |
36 explicit Handle(Profile* profile); | 38 explicit Handle(Profile* profile); |
37 ~Handle(); | 39 ~Handle(); |
38 | 40 |
39 scoped_refptr<ChromeURLRequestContextGetter> | 41 scoped_refptr<ChromeURLRequestContextGetter> |
40 GetMainRequestContextGetter() const; | 42 GetMainRequestContextGetter() const; |
41 scoped_refptr<ChromeURLRequestContextGetter> | 43 scoped_refptr<ChromeURLRequestContextGetter> |
42 GetExtensionsRequestContextGetter() const; | 44 GetExtensionsRequestContextGetter() const; |
| 45 scoped_refptr<ChromeURLRequestContextGetter> |
| 46 GetIsolatedAppRequestContextGetter( |
| 47 const Extension* installed_app) const; |
43 | 48 |
44 private: | 49 private: |
| 50 typedef base::hash_map<std::string, |
| 51 scoped_refptr<ChromeURLRequestContextGetter> > |
| 52 ChromeURLRequestContextGetterMap; |
| 53 |
45 // Lazily initialize ProfileParams. We do this on the calls to | 54 // Lazily initialize ProfileParams. We do this on the calls to |
46 // Get*RequestContextGetter(), so we only initialize ProfileParams right | 55 // Get*RequestContextGetter(), so we only initialize ProfileParams right |
47 // before posting a task to the IO thread to start using them. This prevents | 56 // before posting a task to the IO thread to start using them. This prevents |
48 // objects that are supposed to be deleted on the IO thread, but are created | 57 // objects that are supposed to be deleted on the IO thread, but are created |
49 // on the UI thread from being unnecessarily initialized. | 58 // on the UI thread from being unnecessarily initialized. |
50 void LazyInitialize() const; | 59 void LazyInitialize() const; |
51 | 60 |
52 // Ordering is important here. Do not reorder unless you know what you're | 61 // Ordering is important here. Do not reorder unless you know what you're |
53 // doing. We need to release |io_data_| *before* the getters, because we | 62 // doing. We need to release |io_data_| *before* the getters, because we |
54 // want to make sure that the last reference for |io_data_| is on the IO | 63 // want to make sure that the last reference for |io_data_| is on the IO |
55 // thread. The getters will be deleted on the IO thread, so they will | 64 // thread. The getters will be deleted on the IO thread, so they will |
56 // release their refs to their contexts, which will release the last refs to | 65 // release their refs to their contexts, which will release the last refs to |
57 // the ProfileIOData on the IO thread. | 66 // the ProfileIOData on the IO thread. |
58 mutable scoped_refptr<ChromeURLRequestContextGetter> | 67 mutable scoped_refptr<ChromeURLRequestContextGetter> |
59 main_request_context_getter_; | 68 main_request_context_getter_; |
60 mutable scoped_refptr<ChromeURLRequestContextGetter> | 69 mutable scoped_refptr<ChromeURLRequestContextGetter> |
61 extensions_request_context_getter_; | 70 extensions_request_context_getter_; |
| 71 mutable ChromeURLRequestContextGetterMap |
| 72 app_request_context_getter_map_; |
62 const scoped_refptr<OffTheRecordProfileIOData> io_data_; | 73 const scoped_refptr<OffTheRecordProfileIOData> io_data_; |
63 | 74 |
64 Profile* const profile_; | 75 Profile* const profile_; |
65 | 76 |
66 mutable bool initialized_; | 77 mutable bool initialized_; |
67 | 78 |
68 DISALLOW_COPY_AND_ASSIGN(Handle); | 79 DISALLOW_COPY_AND_ASSIGN(Handle); |
69 }; | 80 }; |
70 | 81 |
71 private: | 82 private: |
72 friend class base::RefCountedThreadSafe<OffTheRecordProfileIOData>; | 83 friend class base::RefCountedThreadSafe<OffTheRecordProfileIOData>; |
73 | 84 |
74 struct LazyParams { | 85 struct LazyParams { |
75 LazyParams(); | 86 LazyParams(); |
76 ~LazyParams(); | 87 ~LazyParams(); |
77 | 88 |
78 IOThread* io_thread; | 89 IOThread* io_thread; |
79 ProfileParams profile_params; | 90 ProfileParams profile_params; |
80 }; | 91 }; |
81 | 92 |
| 93 typedef base::hash_map<std::string, net::HttpTransactionFactory* > |
| 94 HttpTransactionFactoryMap; |
| 95 |
82 OffTheRecordProfileIOData(); | 96 OffTheRecordProfileIOData(); |
83 ~OffTheRecordProfileIOData(); | 97 ~OffTheRecordProfileIOData(); |
84 | 98 |
85 // Lazily initializes ProfileIOData. | 99 // Lazily initializes ProfileIOData. |
86 virtual void LazyInitializeInternal() const; | 100 virtual void LazyInitializeInternal() const; |
| 101 virtual scoped_refptr<RequestContext> InitializeAppRequestContext( |
| 102 scoped_refptr<ChromeURLRequestContext> main_context, |
| 103 const Extension *installed_app) const; |
87 virtual scoped_refptr<ChromeURLRequestContext> | 104 virtual scoped_refptr<ChromeURLRequestContext> |
88 AcquireMainRequestContext() const; | 105 AcquireMainRequestContext() const; |
89 virtual scoped_refptr<ChromeURLRequestContext> | 106 virtual scoped_refptr<ChromeURLRequestContext> |
90 AcquireMediaRequestContext() const; | 107 AcquireMediaRequestContext() const; |
91 virtual scoped_refptr<ChromeURLRequestContext> | 108 virtual scoped_refptr<ChromeURLRequestContext> |
92 AcquireExtensionsRequestContext() const; | 109 AcquireExtensionsRequestContext() const; |
| 110 virtual scoped_refptr<ChromeURLRequestContext> |
| 111 AcquireIsolatedAppRequestContext( |
| 112 scoped_refptr<ChromeURLRequestContext> main_context, |
| 113 const Extension* installed_app) const; |
93 | 114 |
94 // Lazy initialization params. | 115 // Lazy initialization params. |
95 mutable scoped_ptr<LazyParams> lazy_params_; | 116 mutable scoped_ptr<LazyParams> lazy_params_; |
96 | 117 |
97 mutable bool initialized_; | 118 mutable bool initialized_; |
98 mutable scoped_refptr<RequestContext> main_request_context_; | 119 mutable scoped_refptr<RequestContext> main_request_context_; |
99 // NOTE: |media_request_context_| just points to the same context that | 120 // NOTE: |media_request_context_| just points to the same context that |
100 // |main_request_context_| points to. | 121 // |main_request_context_| points to. |
101 mutable scoped_refptr<RequestContext> media_request_context_; | 122 mutable scoped_refptr<RequestContext> media_request_context_; |
102 mutable scoped_refptr<RequestContext> extensions_request_context_; | 123 mutable scoped_refptr<RequestContext> extensions_request_context_; |
103 | 124 |
104 mutable scoped_ptr<net::NetworkDelegate> network_delegate_; | 125 mutable scoped_ptr<net::NetworkDelegate> network_delegate_; |
105 mutable scoped_ptr<net::DnsCertProvenanceChecker> dns_cert_checker_; | 126 mutable scoped_ptr<net::DnsCertProvenanceChecker> dns_cert_checker_; |
106 mutable scoped_ptr<net::HttpTransactionFactory> main_http_factory_; | 127 mutable scoped_ptr<net::HttpTransactionFactory> main_http_factory_; |
107 | 128 |
| 129 // One HttpTransactionFactory per isolated app. |
| 130 mutable HttpTransactionFactoryMap app_http_factory_map_; |
| 131 |
108 DISALLOW_COPY_AND_ASSIGN(OffTheRecordProfileIOData); | 132 DISALLOW_COPY_AND_ASSIGN(OffTheRecordProfileIOData); |
109 }; | 133 }; |
110 | 134 |
111 #endif // CHROME_BROWSER_PROFILES_OFF_THE_RECORD_PROFILE_IO_DATA_H_ | 135 #endif // CHROME_BROWSER_PROFILES_OFF_THE_RECORD_PROFILE_IO_DATA_H_ |
OLD | NEW |