OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "chrome/browser/net/chrome_url_request_context.h" | 5 #include "chrome/browser/net/chrome_url_request_context.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
(...skipping 12 matching lines...) Expand all Loading... | |
23 #include "net/http/http_util.h" | 23 #include "net/http/http_util.h" |
24 | 24 |
25 using content::BrowserThread; | 25 using content::BrowserThread; |
26 | 26 |
27 class ChromeURLRequestContextFactory { | 27 class ChromeURLRequestContextFactory { |
28 public: | 28 public: |
29 ChromeURLRequestContextFactory() {} | 29 ChromeURLRequestContextFactory() {} |
30 virtual ~ChromeURLRequestContextFactory() {} | 30 virtual ~ChromeURLRequestContextFactory() {} |
31 | 31 |
32 // Called to create a new instance (will only be called once). | 32 // Called to create a new instance (will only be called once). |
33 virtual scoped_refptr<ChromeURLRequestContext> Create() = 0; | 33 virtual ChromeURLRequestContext* Create() = 0; |
34 | 34 |
35 protected: | 35 protected: |
36 DISALLOW_COPY_AND_ASSIGN(ChromeURLRequestContextFactory); | 36 DISALLOW_COPY_AND_ASSIGN(ChromeURLRequestContextFactory); |
37 }; | 37 }; |
38 | 38 |
39 namespace { | 39 namespace { |
40 | 40 |
41 // ---------------------------------------------------------------------------- | 41 // ---------------------------------------------------------------------------- |
42 // Helper factories | 42 // Helper factories |
43 // ---------------------------------------------------------------------------- | 43 // ---------------------------------------------------------------------------- |
44 | 44 |
45 // Factory that creates the main ChromeURLRequestContext. | 45 // Factory that creates the main ChromeURLRequestContext. |
46 class FactoryForMain : public ChromeURLRequestContextFactory { | 46 class FactoryForMain : public ChromeURLRequestContextFactory { |
47 public: | 47 public: |
48 explicit FactoryForMain(const ProfileIOData* profile_io_data) | 48 explicit FactoryForMain(const ProfileIOData* profile_io_data) |
49 : profile_io_data_(profile_io_data) {} | 49 : profile_io_data_(profile_io_data) {} |
50 | 50 |
51 virtual scoped_refptr<ChromeURLRequestContext> Create() { | 51 virtual ChromeURLRequestContext* Create() { |
eroman
2012/05/04 04:27:02
can you add OVERRIDE?
| |
52 return profile_io_data_->GetMainRequestContext(); | 52 return profile_io_data_->GetMainRequestContext(); |
53 } | 53 } |
54 | 54 |
55 private: | 55 private: |
56 const ProfileIOData* const profile_io_data_; | 56 const ProfileIOData* const profile_io_data_; |
57 }; | 57 }; |
58 | 58 |
59 // Factory that creates the ChromeURLRequestContext for extensions. | 59 // Factory that creates the ChromeURLRequestContext for extensions. |
60 class FactoryForExtensions : public ChromeURLRequestContextFactory { | 60 class FactoryForExtensions : public ChromeURLRequestContextFactory { |
61 public: | 61 public: |
62 explicit FactoryForExtensions(const ProfileIOData* profile_io_data) | 62 explicit FactoryForExtensions(const ProfileIOData* profile_io_data) |
63 : profile_io_data_(profile_io_data) {} | 63 : profile_io_data_(profile_io_data) {} |
64 | 64 |
65 virtual scoped_refptr<ChromeURLRequestContext> Create() { | 65 virtual ChromeURLRequestContext* Create() { |
eroman
2012/05/04 04:27:02
can you add OVERRIDE?
| |
66 return profile_io_data_->GetExtensionsRequestContext(); | 66 return profile_io_data_->GetExtensionsRequestContext(); |
67 } | 67 } |
68 | 68 |
69 private: | 69 private: |
70 const ProfileIOData* const profile_io_data_; | 70 const ProfileIOData* const profile_io_data_; |
71 }; | 71 }; |
72 | 72 |
73 // Factory that creates the ChromeURLRequestContext for a given isolated app. | 73 // Factory that creates the ChromeURLRequestContext for a given isolated app. |
74 class FactoryForIsolatedApp : public ChromeURLRequestContextFactory { | 74 class FactoryForIsolatedApp : public ChromeURLRequestContextFactory { |
75 public: | 75 public: |
76 FactoryForIsolatedApp(const ProfileIOData* profile_io_data, | 76 FactoryForIsolatedApp(const ProfileIOData* profile_io_data, |
77 const std::string& app_id, | 77 const std::string& app_id, |
78 ChromeURLRequestContextGetter* main_context) | 78 ChromeURLRequestContextGetter* main_context) |
79 : profile_io_data_(profile_io_data), | 79 : profile_io_data_(profile_io_data), |
80 app_id_(app_id), | 80 app_id_(app_id), |
81 main_request_context_getter_(main_context) {} | 81 main_request_context_getter_(main_context) {} |
82 | 82 |
83 virtual scoped_refptr<ChromeURLRequestContext> Create() { | 83 virtual ChromeURLRequestContext* Create() { |
eroman
2012/05/04 04:27:02
can you add OVERRIDE?
| |
84 // We will copy most of the state from the main request context. | 84 // We will copy most of the state from the main request context. |
85 return profile_io_data_->GetIsolatedAppRequestContext( | 85 return profile_io_data_->GetIsolatedAppRequestContext( |
86 main_request_context_getter_->GetIOContext(), app_id_); | 86 main_request_context_getter_->GetIOContext(), app_id_); |
87 } | 87 } |
88 | 88 |
89 private: | 89 private: |
90 const ProfileIOData* const profile_io_data_; | 90 const ProfileIOData* const profile_io_data_; |
91 const std::string app_id_; | 91 const std::string app_id_; |
92 scoped_refptr<ChromeURLRequestContextGetter> | 92 scoped_refptr<ChromeURLRequestContextGetter> |
93 main_request_context_getter_; | 93 main_request_context_getter_; |
94 }; | 94 }; |
95 | 95 |
96 // Factory that creates the ChromeURLRequestContext for media. | 96 // Factory that creates the ChromeURLRequestContext for media. |
97 class FactoryForMedia : public ChromeURLRequestContextFactory { | 97 class FactoryForMedia : public ChromeURLRequestContextFactory { |
98 public: | 98 public: |
99 explicit FactoryForMedia(const ProfileIOData* profile_io_data) | 99 explicit FactoryForMedia(const ProfileIOData* profile_io_data) |
100 : profile_io_data_(profile_io_data) { | 100 : profile_io_data_(profile_io_data) { |
101 } | 101 } |
102 | 102 |
103 virtual scoped_refptr<ChromeURLRequestContext> Create() { | 103 virtual ChromeURLRequestContext* Create() { |
eroman
2012/05/04 04:27:02
can you add OVERRIDE?
| |
104 return profile_io_data_->GetMediaRequestContext(); | 104 return profile_io_data_->GetMediaRequestContext(); |
105 } | 105 } |
106 | 106 |
107 private: | 107 private: |
108 const ProfileIOData* const profile_io_data_; | 108 const ProfileIOData* const profile_io_data_; |
109 }; | 109 }; |
110 | 110 |
111 } // namespace | 111 } // namespace |
112 | 112 |
113 // ---------------------------------------------------------------------------- | 113 // ---------------------------------------------------------------------------- |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
308 | 308 |
309 if (cookie_monster) | 309 if (cookie_monster) |
310 cookie_monster->SetClearPersistentStoreOnExit(clear_site_data); | 310 cookie_monster->SetClearPersistentStoreOnExit(clear_site_data); |
311 } | 311 } |
312 | 312 |
313 // ---------------------------------------------------------------------------- | 313 // ---------------------------------------------------------------------------- |
314 // ChromeURLRequestContext | 314 // ChromeURLRequestContext |
315 // ---------------------------------------------------------------------------- | 315 // ---------------------------------------------------------------------------- |
316 | 316 |
317 ChromeURLRequestContext::ChromeURLRequestContext() | 317 ChromeURLRequestContext::ChromeURLRequestContext() |
318 : is_incognito_(false) { | 318 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
319 is_incognito_(false) { | |
319 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 320 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
320 } | 321 } |
321 | 322 |
323 ChromeURLRequestContext::~ChromeURLRequestContext() { | |
324 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
325 } | |
326 | |
322 void ChromeURLRequestContext::CopyFrom(ChromeURLRequestContext* other) { | 327 void ChromeURLRequestContext::CopyFrom(ChromeURLRequestContext* other) { |
323 URLRequestContext::CopyFrom(other); | 328 URLRequestContext::CopyFrom(other); |
324 | 329 |
325 // Copy ChromeURLRequestContext parameters. | 330 // Copy ChromeURLRequestContext parameters. |
326 // ChromeURLDataManagerBackend is unique per context. | 331 // ChromeURLDataManagerBackend is unique per context. |
327 set_is_incognito(other->is_incognito()); | 332 set_is_incognito(other->is_incognito()); |
328 } | 333 } |
329 | 334 |
330 ChromeURLDataManagerBackend* | 335 ChromeURLDataManagerBackend* |
331 ChromeURLRequestContext::chrome_url_data_manager_backend() const { | 336 ChromeURLRequestContext::chrome_url_data_manager_backend() const { |
332 return chrome_url_data_manager_backend_; | 337 return chrome_url_data_manager_backend_; |
333 } | 338 } |
334 | 339 |
335 void ChromeURLRequestContext::set_chrome_url_data_manager_backend( | 340 void ChromeURLRequestContext::set_chrome_url_data_manager_backend( |
336 ChromeURLDataManagerBackend* backend) { | 341 ChromeURLDataManagerBackend* backend) { |
337 DCHECK(backend); | 342 DCHECK(backend); |
338 chrome_url_data_manager_backend_ = backend; | 343 chrome_url_data_manager_backend_ = backend; |
339 } | 344 } |
340 | 345 |
341 ChromeURLRequestContext::~ChromeURLRequestContext() { | |
342 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
343 } | |
344 | |
345 const std::string& ChromeURLRequestContext::GetUserAgent( | 346 const std::string& ChromeURLRequestContext::GetUserAgent( |
346 const GURL& url) const { | 347 const GURL& url) const { |
347 return content::GetUserAgent(url); | 348 return content::GetUserAgent(url); |
348 } | 349 } |
349 | 350 |
350 void ChromeURLRequestContext::OnAcceptLanguageChange( | 351 void ChromeURLRequestContext::OnAcceptLanguageChange( |
351 const std::string& accept_language) { | 352 const std::string& accept_language) { |
352 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 353 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
353 set_accept_language( | 354 set_accept_language( |
354 net::HttpUtil::GenerateAcceptLanguageHeader(accept_language)); | 355 net::HttpUtil::GenerateAcceptLanguageHeader(accept_language)); |
355 } | 356 } |
356 | 357 |
357 void ChromeURLRequestContext::OnDefaultCharsetChange( | 358 void ChromeURLRequestContext::OnDefaultCharsetChange( |
358 const std::string& default_charset) { | 359 const std::string& default_charset) { |
359 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 360 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
360 set_referrer_charset(default_charset); | 361 set_referrer_charset(default_charset); |
361 set_accept_charset( | 362 set_accept_charset( |
362 net::HttpUtil::GenerateAcceptCharsetHeader(default_charset)); | 363 net::HttpUtil::GenerateAcceptCharsetHeader(default_charset)); |
363 } | 364 } |
OLD | NEW |