Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(183)

Side by Side Diff: ios/web/browser_state.cc

Issue 1043243003: Upstream most of ios/web/net (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove accidentally-added clients Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ios/net/request_tracker.mm ('k') | ios/web/ios_web.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "ios/web/public/browser_state.h" 5 #include "ios/web/public/browser_state.h"
6 6
7 #include "base/memory/ref_counted.h"
8 #include "ios/web/public/certificate_policy_cache.h"
9 #include "ios/web/public/web_thread.h"
10
7 namespace web { 11 namespace web {
8 namespace { 12 namespace {
9 // Private key used for safe conversion of base::SupportsUserData to 13 // Private key used for safe conversion of base::SupportsUserData to
10 // web::BrowserState in web::BrowserState::FromSupportsUserData. 14 // web::BrowserState in web::BrowserState::FromSupportsUserData.
11 const char kBrowserStateIdentifierKey[] = "BrowserStateIdentifierKey"; 15 const char kBrowserStateIdentifierKey[] = "BrowserStateIdentifierKey";
16 // Data key names.
17 const char kCertificatePolicyCacheKeyName[] = "cert_policy_cache";
18
19 // Wraps a CertificatePolicyCache as a SupportsUserData::Data; this is necessary
20 // since reference counted objects can't be user data.
21 struct CertificatePolicyCacheHandle : public base::SupportsUserData::Data {
22 explicit CertificatePolicyCacheHandle(CertificatePolicyCache* cache)
23 : policy_cache(cache) {}
24
25 scoped_refptr<CertificatePolicyCache> policy_cache;
26 };
27 }
28
29 // static
30 scoped_refptr<CertificatePolicyCache> BrowserState::GetCertificatePolicyCache(
31 BrowserState* browser_state) {
32 DCHECK_CURRENTLY_ON_WEB_THREAD(WebThread::UI);
33 if (!browser_state->GetUserData(kCertificatePolicyCacheKeyName)) {
34 CertificatePolicyCacheHandle* cert_cache_service_handle =
35 new CertificatePolicyCacheHandle(new CertificatePolicyCache());
36
37 browser_state->SetUserData(kCertificatePolicyCacheKeyName,
38 cert_cache_service_handle);
39 }
40
41 CertificatePolicyCacheHandle* handle =
42 static_cast<CertificatePolicyCacheHandle*>(
43 browser_state->GetUserData(kCertificatePolicyCacheKeyName));
44 return handle->policy_cache;
12 } 45 }
13 46
14 BrowserState::BrowserState() { 47 BrowserState::BrowserState() {
15 // (Refcounted)?BrowserStateKeyedServiceFactories needs to be able to convert 48 // (Refcounted)?BrowserStateKeyedServiceFactories needs to be able to convert
16 // a base::SupportsUserData to a BrowserState. Moreover, since the factories 49 // a base::SupportsUserData to a BrowserState. Moreover, since the factories
17 // may be passed a content::BrowserContext instead of a BrowserState, attach 50 // may be passed a content::BrowserContext instead of a BrowserState, attach
18 // an empty object to this via a private key. 51 // an empty object to this via a private key.
19 SetUserData(kBrowserStateIdentifierKey, new SupportsUserData::Data); 52 SetUserData(kBrowserStateIdentifierKey, new SupportsUserData::Data);
20 } 53 }
21 54
22 BrowserState::~BrowserState() { 55 BrowserState::~BrowserState() {
23 } 56 }
24 57
25 // static 58 // static
26 BrowserState* BrowserState::FromSupportsUserData( 59 BrowserState* BrowserState::FromSupportsUserData(
27 base::SupportsUserData* supports_user_data) { 60 base::SupportsUserData* supports_user_data) {
28 if (!supports_user_data || 61 if (!supports_user_data ||
29 !supports_user_data->GetUserData(kBrowserStateIdentifierKey)) { 62 !supports_user_data->GetUserData(kBrowserStateIdentifierKey)) {
30 return nullptr; 63 return nullptr;
31 } 64 }
32 return static_cast<BrowserState*>(supports_user_data); 65 return static_cast<BrowserState*>(supports_user_data);
33 } 66 }
34 } // namespace web 67 } // namespace web
OLDNEW
« no previous file with comments | « ios/net/request_tracker.mm ('k') | ios/web/ios_web.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698