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

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

Issue 2853443002: Switch SupportsUserData uses to use unique_ptr. (Closed)
Patch Set: Created 3 years, 7 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
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/location.h" 7 #include "base/location.h"
8 #include "base/memory/ptr_util.h"
8 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
9 #include "ios/web/active_state_manager_impl.h" 10 #include "ios/web/active_state_manager_impl.h"
10 #include "ios/web/public/certificate_policy_cache.h" 11 #include "ios/web/public/certificate_policy_cache.h"
11 #include "ios/web/public/web_thread.h" 12 #include "ios/web/public/web_thread.h"
12 #include "ios/web/webui/url_data_manager_ios_backend.h" 13 #include "ios/web/webui/url_data_manager_ios_backend.h"
13 14
14 #if !defined(__has_feature) || !__has_feature(objc_arc) 15 #if !defined(__has_feature) || !__has_feature(objc_arc)
15 #error "This file requires ARC support." 16 #error "This file requires ARC support."
16 #endif 17 #endif
17 18
(...skipping 15 matching lines...) Expand all
33 34
34 scoped_refptr<CertificatePolicyCache> policy_cache; 35 scoped_refptr<CertificatePolicyCache> policy_cache;
35 }; 36 };
36 } 37 }
37 38
38 // static 39 // static
39 scoped_refptr<CertificatePolicyCache> BrowserState::GetCertificatePolicyCache( 40 scoped_refptr<CertificatePolicyCache> BrowserState::GetCertificatePolicyCache(
40 BrowserState* browser_state) { 41 BrowserState* browser_state) {
41 DCHECK_CURRENTLY_ON(WebThread::UI); 42 DCHECK_CURRENTLY_ON(WebThread::UI);
42 if (!browser_state->GetUserData(kCertificatePolicyCacheKeyName)) { 43 if (!browser_state->GetUserData(kCertificatePolicyCacheKeyName)) {
43 CertificatePolicyCacheHandle* cert_cache_service_handle =
44 new CertificatePolicyCacheHandle(new CertificatePolicyCache());
45
46 browser_state->SetUserData(kCertificatePolicyCacheKeyName, 44 browser_state->SetUserData(kCertificatePolicyCacheKeyName,
47 cert_cache_service_handle); 45 base::MakeUnique<CertificatePolicyCacheHandle>(
46 new CertificatePolicyCache()));
48 } 47 }
49 48
50 CertificatePolicyCacheHandle* handle = 49 CertificatePolicyCacheHandle* handle =
51 static_cast<CertificatePolicyCacheHandle*>( 50 static_cast<CertificatePolicyCacheHandle*>(
52 browser_state->GetUserData(kCertificatePolicyCacheKeyName)); 51 browser_state->GetUserData(kCertificatePolicyCacheKeyName));
53 return handle->policy_cache; 52 return handle->policy_cache;
54 } 53 }
55 54
56 // static 55 // static
57 bool BrowserState::HasActiveStateManager(BrowserState* browser_state) { 56 bool BrowserState::HasActiveStateManager(BrowserState* browser_state) {
58 DCHECK_CURRENTLY_ON(WebThread::UI); 57 DCHECK_CURRENTLY_ON(WebThread::UI);
59 return browser_state->GetUserData(kActiveStateManagerKeyName) != nullptr; 58 return browser_state->GetUserData(kActiveStateManagerKeyName) != nullptr;
60 } 59 }
61 60
62 // static 61 // static
63 ActiveStateManager* BrowserState::GetActiveStateManager( 62 ActiveStateManager* BrowserState::GetActiveStateManager(
64 BrowserState* browser_state) { 63 BrowserState* browser_state) {
65 DCHECK_CURRENTLY_ON(WebThread::UI); 64 DCHECK_CURRENTLY_ON(WebThread::UI);
66 DCHECK(browser_state); 65 DCHECK(browser_state);
67 66
68 ActiveStateManagerImpl* active_state_manager = 67 ActiveStateManagerImpl* active_state_manager =
69 static_cast<ActiveStateManagerImpl*>( 68 static_cast<ActiveStateManagerImpl*>(
70 browser_state->GetUserData(kActiveStateManagerKeyName)); 69 browser_state->GetUserData(kActiveStateManagerKeyName));
71 if (!active_state_manager) { 70 if (!active_state_manager) {
72 active_state_manager = new ActiveStateManagerImpl(browser_state); 71 active_state_manager = new ActiveStateManagerImpl(browser_state);
73 browser_state->SetUserData(kActiveStateManagerKeyName, 72 browser_state->SetUserData(kActiveStateManagerKeyName,
74 active_state_manager); 73 base::WrapUnique(active_state_manager));
75 } 74 }
76 return active_state_manager; 75 return active_state_manager;
77 } 76 }
78 77
79 BrowserState::BrowserState() : url_data_manager_ios_backend_(nullptr) { 78 BrowserState::BrowserState() : url_data_manager_ios_backend_(nullptr) {
80 // (Refcounted)?BrowserStateKeyedServiceFactories needs to be able to convert 79 // (Refcounted)?BrowserStateKeyedServiceFactories needs to be able to convert
81 // a base::SupportsUserData to a BrowserState. Moreover, since the factories 80 // a base::SupportsUserData to a BrowserState. Moreover, since the factories
82 // may be passed a content::BrowserContext instead of a BrowserState, attach 81 // may be passed a content::BrowserContext instead of a BrowserState, attach
83 // an empty object to this via a private key. 82 // an empty object to this via a private key.
84 SetUserData(kBrowserStateIdentifierKey, new SupportsUserData::Data); 83 SetUserData(kBrowserStateIdentifierKey,
84 base::MakeUnique<SupportsUserData::Data>());
85 } 85 }
86 86
87 BrowserState::~BrowserState() { 87 BrowserState::~BrowserState() {
88 // Delete the URLDataManagerIOSBackend instance on the IO thread if it has 88 // Delete the URLDataManagerIOSBackend instance on the IO thread if it has
89 // been created. Note that while this check can theoretically race with a 89 // been created. Note that while this check can theoretically race with a
90 // call to |GetURLDataManagerIOSBackendOnIOThread()|, if any clients of this 90 // call to |GetURLDataManagerIOSBackendOnIOThread()|, if any clients of this
91 // BrowserState are still accessing it on the IO thread at this point, 91 // BrowserState are still accessing it on the IO thread at this point,
92 // they're going to have a bad time anyway. 92 // they're going to have a bad time anyway.
93 if (url_data_manager_ios_backend_) { 93 if (url_data_manager_ios_backend_) {
94 bool posted = web::WebThread::DeleteSoon(web::WebThread::IO, FROM_HERE, 94 bool posted = web::WebThread::DeleteSoon(web::WebThread::IO, FROM_HERE,
(...skipping 14 matching lines...) Expand all
109 // static 109 // static
110 BrowserState* BrowserState::FromSupportsUserData( 110 BrowserState* BrowserState::FromSupportsUserData(
111 base::SupportsUserData* supports_user_data) { 111 base::SupportsUserData* supports_user_data) {
112 if (!supports_user_data || 112 if (!supports_user_data ||
113 !supports_user_data->GetUserData(kBrowserStateIdentifierKey)) { 113 !supports_user_data->GetUserData(kBrowserStateIdentifierKey)) {
114 return nullptr; 114 return nullptr;
115 } 115 }
116 return static_cast<BrowserState*>(supports_user_data); 116 return static_cast<BrowserState*>(supports_user_data);
117 } 117 }
118 } // namespace web 118 } // namespace web
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698