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

Side by Side Diff: chrome/browser/sessions/session_data_deleter.cc

Issue 1666513002: Promote CookieMonster::DeleteCanonicalCookieAsync to CookieStore. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cookie_monster13
Patch Set: Rebase Created 4 years, 10 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "build/build_config.h" 11 #include "build/build_config.h"
12 #include "chrome/browser/browser_shutdown.h" 12 #include "chrome/browser/browser_shutdown.h"
13 #include "chrome/browser/prefs/session_startup_pref.h" 13 #include "chrome/browser/prefs/session_startup_pref.h"
14 #include "chrome/browser/profiles/profile_io_data.h" 14 #include "chrome/browser/profiles/profile_io_data.h"
15 #include "chrome/browser/ui/startup/startup_browser_creator.h" 15 #include "chrome/browser/ui/startup/startup_browser_creator.h"
16 #include "content/public/browser/browser_context.h" 16 #include "content/public/browser/browser_context.h"
17 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
18 #include "content/public/browser/dom_storage_context.h" 18 #include "content/public/browser/dom_storage_context.h"
19 #include "content/public/browser/local_storage_usage_info.h" 19 #include "content/public/browser/local_storage_usage_info.h"
20 #include "content/public/browser/storage_partition.h" 20 #include "content/public/browser/storage_partition.h"
21 #include "net/cookies/cookie_monster.h"
22 #include "net/cookies/cookie_store.h" 21 #include "net/cookies/cookie_store.h"
23 #include "net/cookies/cookie_util.h" 22 #include "net/cookies/cookie_util.h"
24 #include "net/url_request/url_request_context.h" 23 #include "net/url_request/url_request_context.h"
25 #include "storage/browser/quota/special_storage_policy.h" 24 #include "storage/browser/quota/special_storage_policy.h"
26 25
27 namespace { 26 namespace {
28 27
29 void CookieDeleted(bool success) { 28 void CookieDeleted(int num_cookies_deleted) {
30 DCHECK(success); 29 DCHECK_EQ(1, num_cookies_deleted);
31 } 30 }
32 31
33 class SessionDataDeleter 32 class SessionDataDeleter
34 : public base::RefCountedThreadSafe<SessionDataDeleter> { 33 : public base::RefCountedThreadSafe<SessionDataDeleter> {
35 public: 34 public:
36 SessionDataDeleter(storage::SpecialStoragePolicy* storage_policy, 35 SessionDataDeleter(storage::SpecialStoragePolicy* storage_policy,
37 bool delete_only_by_session_only_policy); 36 bool delete_only_by_session_only_policy);
38 37
39 void Run(content::StoragePartition* storage_partition, 38 void Run(content::StoragePartition* storage_partition,
40 ProfileIOData* profile_io_data); 39 ProfileIOData* profile_io_data);
(...skipping 14 matching lines...) Expand all
55 // of all remaining cookies. 54 // of all remaining cookies.
56 void DeleteSessionCookiesOnIOThread(ProfileIOData* profile_io_data); 55 void DeleteSessionCookiesOnIOThread(ProfileIOData* profile_io_data);
57 56
58 // Called when all session-only cookies have been deleted. 57 // Called when all session-only cookies have been deleted.
59 void DeleteSessionCookiesDone(int num_deleted); 58 void DeleteSessionCookiesDone(int num_deleted);
60 59
61 // Deletes the cookies in |cookies| that are for origins which are 60 // Deletes the cookies in |cookies| that are for origins which are
62 // session-only. 61 // session-only.
63 void DeleteSessionOnlyOriginCookies(const net::CookieList& cookies); 62 void DeleteSessionOnlyOriginCookies(const net::CookieList& cookies);
64 63
65 scoped_refptr<net::CookieMonster> cookie_monster_; 64 scoped_refptr<net::CookieStore> cookie_store_;
66 scoped_refptr<storage::SpecialStoragePolicy> storage_policy_; 65 scoped_refptr<storage::SpecialStoragePolicy> storage_policy_;
67 const bool delete_only_by_session_only_policy_; 66 const bool delete_only_by_session_only_policy_;
68 67
69 DISALLOW_COPY_AND_ASSIGN(SessionDataDeleter); 68 DISALLOW_COPY_AND_ASSIGN(SessionDataDeleter);
70 }; 69 };
71 70
72 SessionDataDeleter::SessionDataDeleter( 71 SessionDataDeleter::SessionDataDeleter(
73 storage::SpecialStoragePolicy* storage_policy, 72 storage::SpecialStoragePolicy* storage_policy,
74 bool delete_only_by_session_only_policy) 73 bool delete_only_by_session_only_policy)
75 : storage_policy_(storage_policy), 74 : storage_policy_(storage_policy),
(...skipping 29 matching lines...) Expand all
105 continue; 104 continue;
106 storage_partition->GetDOMStorageContext()->DeleteLocalStorage(usage.origin); 105 storage_partition->GetDOMStorageContext()->DeleteLocalStorage(usage.origin);
107 } 106 }
108 } 107 }
109 108
110 void SessionDataDeleter::DeleteSessionCookiesOnIOThread( 109 void SessionDataDeleter::DeleteSessionCookiesOnIOThread(
111 ProfileIOData* profile_io_data) { 110 ProfileIOData* profile_io_data) {
112 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 111 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
113 net::URLRequestContext* request_context = 112 net::URLRequestContext* request_context =
114 profile_io_data->GetMainRequestContext(); 113 profile_io_data->GetMainRequestContext();
115 cookie_monster_ = request_context->cookie_store()->GetCookieMonster(); 114 cookie_store_ = request_context->cookie_store();
116 if (delete_only_by_session_only_policy_) { 115 if (delete_only_by_session_only_policy_) {
117 cookie_monster_->GetAllCookiesAsync( 116 cookie_store_->GetAllCookiesAsync(
118 base::Bind(&SessionDataDeleter::DeleteSessionOnlyOriginCookies, this)); 117 base::Bind(&SessionDataDeleter::DeleteSessionOnlyOriginCookies, this));
119 } else { 118 } else {
120 cookie_monster_->DeleteSessionCookiesAsync( 119 cookie_store_->DeleteSessionCookiesAsync(
121 base::Bind(&SessionDataDeleter::DeleteSessionCookiesDone, this)); 120 base::Bind(&SessionDataDeleter::DeleteSessionCookiesDone, this));
122 } 121 }
123 } 122 }
124 123
125 void SessionDataDeleter::DeleteSessionCookiesDone(int num_deleted) { 124 void SessionDataDeleter::DeleteSessionCookiesDone(int num_deleted) {
126 cookie_monster_->GetAllCookiesAsync( 125 cookie_store_->GetAllCookiesAsync(
127 base::Bind(&SessionDataDeleter::DeleteSessionOnlyOriginCookies, this)); 126 base::Bind(&SessionDataDeleter::DeleteSessionOnlyOriginCookies, this));
128 } 127 }
129 128
130 void SessionDataDeleter::DeleteSessionOnlyOriginCookies( 129 void SessionDataDeleter::DeleteSessionOnlyOriginCookies(
131 const net::CookieList& cookies) { 130 const net::CookieList& cookies) {
132 if (!storage_policy_.get() || !storage_policy_->HasSessionOnlyOrigins()) 131 if (!storage_policy_.get() || !storage_policy_->HasSessionOnlyOrigins())
133 return; 132 return;
134 133
135 for (net::CookieList::const_iterator it = cookies.begin(); 134 for (net::CookieList::const_iterator it = cookies.begin();
136 it != cookies.end(); 135 it != cookies.end();
137 ++it) { 136 ++it) {
138 GURL url = 137 GURL url =
139 net::cookie_util::CookieOriginToURL(it->Domain(), it->IsSecure()); 138 net::cookie_util::CookieOriginToURL(it->Domain(), it->IsSecure());
140 if (!storage_policy_->IsStorageSessionOnly(url)) 139 if (!storage_policy_->IsStorageSessionOnly(url))
141 continue; 140 continue;
142 cookie_monster_->DeleteCanonicalCookieAsync(*it, base::Bind(CookieDeleted)); 141 cookie_store_->DeleteCanonicalCookieAsync(*it, base::Bind(CookieDeleted));
143 } 142 }
144 } 143 }
145 144
146 } // namespace 145 } // namespace
147 146
148 void DeleteSessionOnlyData(Profile* profile) { 147 void DeleteSessionOnlyData(Profile* profile) {
149 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 148 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
150 if (browser_shutdown::IsTryingToQuit()) 149 if (browser_shutdown::IsTryingToQuit())
151 return; 150 return;
152 151
153 // TODO: Remove Athena special casing once the AthenaSessionRestore is in 152 // TODO: Remove Athena special casing once the AthenaSessionRestore is in
154 // place. 153 // place.
155 #if defined(OS_ANDROID) 154 #if defined(OS_ANDROID)
156 SessionStartupPref::Type startup_pref_type = 155 SessionStartupPref::Type startup_pref_type =
157 SessionStartupPref::GetDefaultStartupType(); 156 SessionStartupPref::GetDefaultStartupType();
158 #else 157 #else
159 SessionStartupPref::Type startup_pref_type = 158 SessionStartupPref::Type startup_pref_type =
160 StartupBrowserCreator::GetSessionStartupPref( 159 StartupBrowserCreator::GetSessionStartupPref(
161 *base::CommandLine::ForCurrentProcess(), profile).type; 160 *base::CommandLine::ForCurrentProcess(), profile).type;
162 #endif 161 #endif
163 162
164 scoped_refptr<SessionDataDeleter> deleter( 163 scoped_refptr<SessionDataDeleter> deleter(
165 new SessionDataDeleter(profile->GetSpecialStoragePolicy(), 164 new SessionDataDeleter(profile->GetSpecialStoragePolicy(),
166 startup_pref_type == SessionStartupPref::LAST)); 165 startup_pref_type == SessionStartupPref::LAST));
167 deleter->Run( 166 deleter->Run(
168 Profile::GetDefaultStoragePartition(profile), 167 Profile::GetDefaultStoragePartition(profile),
169 ProfileIOData::FromResourceContext(profile->GetResourceContext())); 168 ProfileIOData::FromResourceContext(profile->GetResourceContext()));
170 } 169 }
OLDNEW
« no previous file with comments | « chrome/browser/browsing_data/mock_browsing_data_cookie_helper.cc ('k') | ios/net/cookies/cookie_store_ios.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698