| 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/chrome/browser/net/cookie_util.h" | 5 #include "ios/chrome/browser/net/cookie_util.h" |
| 6 | 6 |
| 7 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <sys/sysctl.h> | 9 #include <sys/sysctl.h> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #import "base/mac/bind_objc_block.h" | 12 #import "base/mac/bind_objc_block.h" |
| 13 #include "base/memory/ptr_util.h" |
| 13 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 14 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 15 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
| 15 #include "ios/net/cookies/cookie_store_ios.h" | 16 #include "ios/net/cookies/cookie_store_ios.h" |
| 16 #include "ios/web/public/web_thread.h" | 17 #include "ios/web/public/web_thread.h" |
| 17 #include "net/cookies/cookie_monster.h" | 18 #include "net/cookies/cookie_monster.h" |
| 18 #include "net/cookies/cookie_store.h" | 19 #include "net/cookies/cookie_store.h" |
| 19 #include "net/extras/sqlite/sqlite_persistent_cookie_store.h" | 20 #include "net/extras/sqlite/sqlite_persistent_cookie_store.h" |
| 20 #include "net/url_request/url_request_context.h" | 21 #include "net/url_request/url_request_context.h" |
| 21 #include "net/url_request/url_request_context_getter.h" | 22 #include "net/url_request/url_request_context_getter.h" |
| 22 | 23 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 37 net::CookieCryptoDelegate* crypto_delegate) { | 38 net::CookieCryptoDelegate* crypto_delegate) { |
| 38 return scoped_refptr<net::SQLitePersistentCookieStore>( | 39 return scoped_refptr<net::SQLitePersistentCookieStore>( |
| 39 new net::SQLitePersistentCookieStore( | 40 new net::SQLitePersistentCookieStore( |
| 40 path, web::WebThread::GetTaskRunnerForThread(web::WebThread::IO), | 41 path, web::WebThread::GetTaskRunnerForThread(web::WebThread::IO), |
| 41 web::WebThread::GetBlockingPool()->GetSequencedTaskRunner( | 42 web::WebThread::GetBlockingPool()->GetSequencedTaskRunner( |
| 42 web::WebThread::GetBlockingPool()->GetSequenceToken()), | 43 web::WebThread::GetBlockingPool()->GetSequenceToken()), |
| 43 restore_old_session_cookies, crypto_delegate)); | 44 restore_old_session_cookies, crypto_delegate)); |
| 44 } | 45 } |
| 45 | 46 |
| 46 // Creates a CookieMonster configured by |config|. | 47 // Creates a CookieMonster configured by |config|. |
| 47 scoped_ptr<net::CookieMonster> CreateCookieMonster( | 48 std::unique_ptr<net::CookieMonster> CreateCookieMonster( |
| 48 const CookieStoreConfig& config) { | 49 const CookieStoreConfig& config) { |
| 49 if (config.path.empty()) { | 50 if (config.path.empty()) { |
| 50 // Empty path means in-memory store. | 51 // Empty path means in-memory store. |
| 51 return make_scoped_ptr(new net::CookieMonster(nullptr, nullptr)); | 52 return base::WrapUnique(new net::CookieMonster(nullptr, nullptr)); |
| 52 } | 53 } |
| 53 | 54 |
| 54 const bool restore_old_session_cookies = | 55 const bool restore_old_session_cookies = |
| 55 config.session_cookie_mode == CookieStoreConfig::RESTORED_SESSION_COOKIES; | 56 config.session_cookie_mode == CookieStoreConfig::RESTORED_SESSION_COOKIES; |
| 56 scoped_refptr<net::SQLitePersistentCookieStore> persistent_store = | 57 scoped_refptr<net::SQLitePersistentCookieStore> persistent_store = |
| 57 CreatePersistentCookieStore(config.path, restore_old_session_cookies, | 58 CreatePersistentCookieStore(config.path, restore_old_session_cookies, |
| 58 config.crypto_delegate); | 59 config.crypto_delegate); |
| 59 scoped_ptr<net::CookieMonster> cookie_monster( | 60 std::unique_ptr<net::CookieMonster> cookie_monster( |
| 60 new net::CookieMonster(persistent_store.get(), nullptr)); | 61 new net::CookieMonster(persistent_store.get(), nullptr)); |
| 61 if (restore_old_session_cookies) | 62 if (restore_old_session_cookies) |
| 62 cookie_monster->SetPersistSessionCookies(true); | 63 cookie_monster->SetPersistSessionCookies(true); |
| 63 return cookie_monster; | 64 return cookie_monster; |
| 64 } | 65 } |
| 65 | 66 |
| 66 } // namespace | 67 } // namespace |
| 67 | 68 |
| 68 CookieStoreConfig::CookieStoreConfig(const base::FilePath& path, | 69 CookieStoreConfig::CookieStoreConfig(const base::FilePath& path, |
| 69 SessionCookieMode session_cookie_mode, | 70 SessionCookieMode session_cookie_mode, |
| 70 CookieStoreType cookie_store_type, | 71 CookieStoreType cookie_store_type, |
| 71 net::CookieCryptoDelegate* crypto_delegate) | 72 net::CookieCryptoDelegate* crypto_delegate) |
| 72 : path(path), | 73 : path(path), |
| 73 session_cookie_mode(session_cookie_mode), | 74 session_cookie_mode(session_cookie_mode), |
| 74 cookie_store_type(cookie_store_type), | 75 cookie_store_type(cookie_store_type), |
| 75 crypto_delegate(crypto_delegate) { | 76 crypto_delegate(crypto_delegate) { |
| 76 CHECK(!path.empty() || session_cookie_mode == EPHEMERAL_SESSION_COOKIES); | 77 CHECK(!path.empty() || session_cookie_mode == EPHEMERAL_SESSION_COOKIES); |
| 77 } | 78 } |
| 78 | 79 |
| 79 CookieStoreConfig::~CookieStoreConfig() {} | 80 CookieStoreConfig::~CookieStoreConfig() {} |
| 80 | 81 |
| 81 scoped_ptr<net::CookieStore> CreateCookieStore( | 82 std::unique_ptr<net::CookieStore> CreateCookieStore( |
| 82 const CookieStoreConfig& config) { | 83 const CookieStoreConfig& config) { |
| 83 if (config.cookie_store_type == CookieStoreConfig::COOKIE_MONSTER) | 84 if (config.cookie_store_type == CookieStoreConfig::COOKIE_MONSTER) |
| 84 return CreateCookieMonster(config); | 85 return CreateCookieMonster(config); |
| 85 | 86 |
| 86 scoped_refptr<net::SQLitePersistentCookieStore> persistent_store = nullptr; | 87 scoped_refptr<net::SQLitePersistentCookieStore> persistent_store = nullptr; |
| 87 if (config.session_cookie_mode == | 88 if (config.session_cookie_mode == |
| 88 CookieStoreConfig::RESTORED_SESSION_COOKIES) { | 89 CookieStoreConfig::RESTORED_SESSION_COOKIES) { |
| 89 DCHECK(!config.path.empty()); | 90 DCHECK(!config.path.empty()); |
| 90 persistent_store = CreatePersistentCookieStore( | 91 persistent_store = CreatePersistentCookieStore( |
| 91 config.path, true /* restore_old_session_cookies */, | 92 config.path, true /* restore_old_session_cookies */, |
| 92 config.crypto_delegate); | 93 config.crypto_delegate); |
| 93 } | 94 } |
| 94 return make_scoped_ptr(new net::CookieStoreIOS(persistent_store.get())); | 95 return base::WrapUnique(new net::CookieStoreIOS(persistent_store.get())); |
| 95 } | 96 } |
| 96 | 97 |
| 97 bool ShouldClearSessionCookies() { | 98 bool ShouldClearSessionCookies() { |
| 98 NSUserDefaults* standardDefaults = [NSUserDefaults standardUserDefaults]; | 99 NSUserDefaults* standardDefaults = [NSUserDefaults standardUserDefaults]; |
| 99 struct timeval boottime; | 100 struct timeval boottime; |
| 100 int mib[2] = {CTL_KERN, KERN_BOOTTIME}; | 101 int mib[2] = {CTL_KERN, KERN_BOOTTIME}; |
| 101 size_t size = sizeof(boottime); | 102 size_t size = sizeof(boottime); |
| 102 time_t lastCookieDeletionDate = | 103 time_t lastCookieDeletionDate = |
| 103 [standardDefaults integerForKey:kLastCookieDeletionDate]; | 104 [standardDefaults integerForKey:kLastCookieDeletionDate]; |
| 104 time_t now; | 105 time_t now; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 119 browser_state->GetRequestContext(); | 120 browser_state->GetRequestContext(); |
| 120 web::WebThread::PostTask( | 121 web::WebThread::PostTask( |
| 121 web::WebThread::IO, FROM_HERE, base::BindBlock(^{ | 122 web::WebThread::IO, FROM_HERE, base::BindBlock(^{ |
| 122 getter->GetURLRequestContext() | 123 getter->GetURLRequestContext() |
| 123 ->cookie_store() | 124 ->cookie_store() |
| 124 ->DeleteSessionCookiesAsync(base::Bind(&DoNothing)); | 125 ->DeleteSessionCookiesAsync(base::Bind(&DoNothing)); |
| 125 })); | 126 })); |
| 126 } | 127 } |
| 127 | 128 |
| 128 } // namespace cookie_util | 129 } // namespace cookie_util |
| OLD | NEW |