OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "ios/net/cookies/cookie_store_ios.h" | 5 #include "ios/net/cookies/cookie_store_ios.h" |
6 | 6 |
7 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
13 #include "base/ios/ios_util.h" | 13 #include "base/ios/ios_util.h" |
14 #include "base/location.h" | 14 #include "base/location.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/mac/foundation_util.h" | 16 #include "base/mac/foundation_util.h" |
17 #include "base/mac/scoped_nsobject.h" | 17 #include "base/mac/scoped_nsobject.h" |
18 #include "base/macros.h" | 18 #include "base/macros.h" |
| 19 #include "base/memory/ptr_util.h" |
19 #include "base/memory/weak_ptr.h" | 20 #include "base/memory/weak_ptr.h" |
20 #include "base/metrics/histogram.h" | 21 #include "base/metrics/histogram.h" |
21 #include "base/observer_list.h" | 22 #include "base/observer_list.h" |
22 #include "base/sequenced_task_runner.h" | 23 #include "base/sequenced_task_runner.h" |
23 #include "base/stl_util.h" | |
24 #include "base/strings/sys_string_conversions.h" | 24 #include "base/strings/sys_string_conversions.h" |
25 #include "base/task_runner_util.h" | 25 #include "base/task_runner_util.h" |
26 #include "base/threading/thread_restrictions.h" | 26 #include "base/threading/thread_restrictions.h" |
27 #include "base/threading/thread_task_runner_handle.h" | 27 #include "base/threading/thread_task_runner_handle.h" |
28 #include "ios/net/cookies/cookie_creation_time_manager.h" | 28 #include "ios/net/cookies/cookie_creation_time_manager.h" |
29 #include "ios/net/cookies/cookie_store_ios_client.h" | 29 #include "ios/net/cookies/cookie_store_ios_client.h" |
30 #include "ios/net/cookies/system_cookie_util.h" | 30 #include "ios/net/cookies/system_cookie_util.h" |
31 #import "net/base/mac/url_conversions.h" | 31 #import "net/base/mac/url_conversions.h" |
32 #include "net/cookies/cookie_util.h" | 32 #include "net/cookies/cookie_util.h" |
33 #include "net/cookies/parsed_cookie.h" | 33 #include "net/cookies/parsed_cookie.h" |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 DCHECK(system_store); | 306 DCHECK(system_store); |
307 | 307 |
308 NotificationTrampoline::GetInstance()->AddObserver(this); | 308 NotificationTrampoline::GetInstance()->AddObserver(this); |
309 | 309 |
310 cookie_monster_->SetPersistSessionCookies(true); | 310 cookie_monster_->SetPersistSessionCookies(true); |
311 cookie_monster_->SetForceKeepSessionState(); | 311 cookie_monster_->SetForceKeepSessionState(); |
312 } | 312 } |
313 | 313 |
314 CookieStoreIOS::~CookieStoreIOS() { | 314 CookieStoreIOS::~CookieStoreIOS() { |
315 NotificationTrampoline::GetInstance()->RemoveObserver(this); | 315 NotificationTrampoline::GetInstance()->RemoveObserver(this); |
316 base::STLDeleteContainerPairSecondPointers(hook_map_.begin(), | |
317 hook_map_.end()); | |
318 } | 316 } |
319 | 317 |
320 // static | 318 // static |
321 void CookieStoreIOS::SetCookiePolicy(CookiePolicy setting) { | 319 void CookieStoreIOS::SetCookiePolicy(CookiePolicy setting) { |
322 NSHTTPCookieAcceptPolicy policy = (setting == ALLOW) | 320 NSHTTPCookieAcceptPolicy policy = (setting == ALLOW) |
323 ? NSHTTPCookieAcceptPolicyAlways | 321 ? NSHTTPCookieAcceptPolicyAlways |
324 : NSHTTPCookieAcceptPolicyNever; | 322 : NSHTTPCookieAcceptPolicyNever; |
325 NSHTTPCookieStorage* store = [NSHTTPCookieStorage sharedHTTPCookieStorage]; | 323 NSHTTPCookieStorage* store = [NSHTTPCookieStorage sharedHTTPCookieStorage]; |
326 NSHTTPCookieAcceptPolicy current_policy = [store cookieAcceptPolicy]; | 324 NSHTTPCookieAcceptPolicy current_policy = [store cookieAcceptPolicy]; |
327 if (current_policy == policy) | 325 if (current_policy == policy) |
(...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
988 CookieStoreIOS::AddCallbackForCookie(const GURL& gurl, | 986 CookieStoreIOS::AddCallbackForCookie(const GURL& gurl, |
989 const std::string& name, | 987 const std::string& name, |
990 const CookieChangedCallback& callback) { | 988 const CookieChangedCallback& callback) { |
991 DCHECK(thread_checker_.CalledOnValidThread()); | 989 DCHECK(thread_checker_.CalledOnValidThread()); |
992 | 990 |
993 // Prefill cookie cache with all pertinent cookies for |url| if needed. | 991 // Prefill cookie cache with all pertinent cookies for |url| if needed. |
994 std::pair<GURL, std::string> key(gurl, name); | 992 std::pair<GURL, std::string> key(gurl, name); |
995 if (hook_map_.count(key) == 0) { | 993 if (hook_map_.count(key) == 0) { |
996 UpdateCacheForCookieFromSystem(gurl, name, nullptr, nullptr); | 994 UpdateCacheForCookieFromSystem(gurl, name, nullptr, nullptr); |
997 if (hook_map_.count(key) == 0) | 995 if (hook_map_.count(key) == 0) |
998 hook_map_[key] = new CookieChangedCallbackList; | 996 hook_map_[key] = base::MakeUnique<CookieChangedCallbackList>(); |
999 } | 997 } |
1000 | 998 |
1001 DCHECK(hook_map_.find(key) != hook_map_.end()); | 999 DCHECK(hook_map_.find(key) != hook_map_.end()); |
1002 return hook_map_[key]->Add(callback); | 1000 return hook_map_[key]->Add(callback); |
1003 } | 1001 } |
1004 | 1002 |
1005 bool CookieStoreIOS::IsEphemeral() { | 1003 bool CookieStoreIOS::IsEphemeral() { |
1006 return cookie_monster_->IsEphemeral(); | 1004 return cookie_monster_->IsEphemeral(); |
1007 } | 1005 } |
1008 | 1006 |
(...skipping 12 matching lines...) Expand all Loading... |
1021 void CookieStoreIOS::RunCallbacksForCookies( | 1019 void CookieStoreIOS::RunCallbacksForCookies( |
1022 const GURL& url, | 1020 const GURL& url, |
1023 const std::string& name, | 1021 const std::string& name, |
1024 const std::vector<net::CanonicalCookie>& cookies, | 1022 const std::vector<net::CanonicalCookie>& cookies, |
1025 bool removed) { | 1023 bool removed) { |
1026 DCHECK(thread_checker_.CalledOnValidThread()); | 1024 DCHECK(thread_checker_.CalledOnValidThread()); |
1027 if (cookies.empty()) | 1025 if (cookies.empty()) |
1028 return; | 1026 return; |
1029 | 1027 |
1030 std::pair<GURL, std::string> key(url, name); | 1028 std::pair<GURL, std::string> key(url, name); |
1031 CookieChangedCallbackList* callbacks = hook_map_[key]; | 1029 CookieChangedCallbackList* callbacks = hook_map_[key].get(); |
1032 for (const auto& cookie : cookies) { | 1030 for (const auto& cookie : cookies) { |
1033 DCHECK_EQ(name, cookie.Name()); | 1031 DCHECK_EQ(name, cookie.Name()); |
1034 callbacks->Notify(cookie, removed); | 1032 callbacks->Notify(cookie, removed); |
1035 } | 1033 } |
1036 } | 1034 } |
1037 | 1035 |
1038 bool CookieStoreIOS::GetSystemCookies( | 1036 bool CookieStoreIOS::GetSystemCookies( |
1039 const GURL& gurl, | 1037 const GURL& gurl, |
1040 const std::string& name, | 1038 const std::string& name, |
1041 std::vector<net::CanonicalCookie>* cookies) { | 1039 std::vector<net::CanonicalCookie>* cookies) { |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1156 weak_factory_.GetWeakPtr(), callback); | 1154 weak_factory_.GetWeakPtr(), callback); |
1157 } | 1155 } |
1158 | 1156 |
1159 base::Closure CookieStoreIOS::WrapClosure(const base::Closure& callback) { | 1157 base::Closure CookieStoreIOS::WrapClosure(const base::Closure& callback) { |
1160 DCHECK(thread_checker_.CalledOnValidThread()); | 1158 DCHECK(thread_checker_.CalledOnValidThread()); |
1161 return base::Bind(&CookieStoreIOS::UpdateCachesAfterClosure, | 1159 return base::Bind(&CookieStoreIOS::UpdateCachesAfterClosure, |
1162 weak_factory_.GetWeakPtr(), callback); | 1160 weak_factory_.GetWeakPtr(), callback); |
1163 } | 1161 } |
1164 | 1162 |
1165 } // namespace net | 1163 } // namespace net |
OLD | NEW |