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

Side by Side Diff: chrome/browser/net/chrome_cookie_policy.cc

Issue 6749044: Remove async functionality from net::CookiePolicy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge Created 9 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/net/chrome_cookie_policy.h" 5 #include "chrome/browser/net/chrome_cookie_policy.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "chrome/browser/browser_list.h" 9 #include "chrome/browser/browser_list.h"
10 #include "chrome/browser/content_settings/host_content_settings_map.h" 10 #include "chrome/browser/content_settings/host_content_settings_map.h"
11 #include "chrome/common/chrome_switches.h" 11 #include "chrome/common/chrome_switches.h"
12 #include "content/browser/browser_thread.h" 12 #include "content/browser/browser_thread.h"
13 #include "net/base/net_errors.h" 13 #include "net/base/net_errors.h"
14 #include "net/base/static_cookie_policy.h" 14 #include "net/base/static_cookie_policy.h"
15 15
16 // If we queue up more than this number of completions, then switch from ASK to 16 // If we queue up more than this number of completions, then switch from ASK to
17 // BLOCK. More than this number of requests at once seems like it could be a 17 // BLOCK. More than this number of requests at once seems like it could be a
18 // sign of trouble anyways. 18 // sign of trouble anyways.
19 static const size_t kMaxCompletionsPerHost = 10000; 19 static const size_t kMaxCompletionsPerHost = 10000;
jochen (gone - plz use gerrit) 2011/03/30 08:15:32 still needed?
willchan no longer on Chromium 2011/04/04 12:29:18 Done.
20 20
21 // ---------------------------------------------------------------------------- 21 // ----------------------------------------------------------------------------
22 22
23 ChromeCookiePolicy::ChromeCookiePolicy(HostContentSettingsMap* map) 23 ChromeCookiePolicy::ChromeCookiePolicy(HostContentSettingsMap* map)
24 : host_content_settings_map_(map) { 24 : host_content_settings_map_(map),
25 strict_third_party_blocking_ = CommandLine::ForCurrentProcess()->HasSwitch( 25 strict_third_party_blocking_(
26 switches::kBlockReadingThirdPartyCookies); 26 CommandLine::ForCurrentProcess()->HasSwitch(
27 } 27 switches::kBlockReadingThirdPartyCookies)) {}
jochen (gone - plz use gerrit) 2011/03/30 08:15:32 I think the closing bracket should go on the next
willchan no longer on Chromium 2011/04/04 12:29:18 There are two varying styles in Chromium and neith
28 28
29 ChromeCookiePolicy::~ChromeCookiePolicy() { 29 ChromeCookiePolicy::~ChromeCookiePolicy() {}
30 DCHECK(host_completions_map_.empty());
31 }
32 30
33 int ChromeCookiePolicy::CanGetCookies(const GURL& url, 31 int ChromeCookiePolicy::CanGetCookies(const GURL& url,
34 const GURL& first_party, 32 const GURL& first_party) const {
35 net::CompletionCallback* callback) {
36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 33 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
37 34
38 if (host_content_settings_map_->BlockThirdPartyCookies()) { 35 if (host_content_settings_map_->BlockThirdPartyCookies()) {
39 net::StaticCookiePolicy policy(strict_third_party_blocking_ ? 36 net::StaticCookiePolicy policy(strict_third_party_blocking_ ?
40 net::StaticCookiePolicy::BLOCK_ALL_THIRD_PARTY_COOKIES : 37 net::StaticCookiePolicy::BLOCK_ALL_THIRD_PARTY_COOKIES :
41 net::StaticCookiePolicy::BLOCK_SETTING_THIRD_PARTY_COOKIES); 38 net::StaticCookiePolicy::BLOCK_SETTING_THIRD_PARTY_COOKIES);
42 int rv = policy.CanGetCookies(url, first_party, NULL); 39 int rv = policy.CanGetCookies(url, first_party);
43 if (rv != net::OK) 40 if (rv != net::OK)
jochen (gone - plz use gerrit) 2011/03/30 08:15:32 maybe also DCHECK for != ERR_IO_PENDING here?
willchan no longer on Chromium 2011/04/04 12:29:18 Done.
44 return rv; 41 return rv;
45 } 42 }
46 43
47 int policy = CheckPolicy(url); 44 int policy = CheckPolicy(url);
48 if (policy == net::OK_FOR_SESSION_ONLY) 45 if (policy == net::OK_FOR_SESSION_ONLY)
49 policy = net::OK; 46 policy = net::OK;
50 if (policy != net::ERR_IO_PENDING) 47 DCHECK_NE(net::ERR_IO_PENDING, policy);
51 return policy;
52
53 DCHECK(callback);
54
55 // If we are currently prompting the user for a 'set-cookie' matching this
56 // host, then we need to defer reading cookies.
57 HostCompletionsMap::iterator it = host_completions_map_.find(url.host());
58 if (it == host_completions_map_.end()) {
59 policy = net::OK;
60 } else if (it->second.size() >= kMaxCompletionsPerHost) {
61 LOG(ERROR) << "Would exceed kMaxCompletionsPerHost";
62 policy = net::ERR_ACCESS_DENIED;
63 } else {
64 it->second.push_back(Completion::ForGetCookies(callback));
65 policy = net::ERR_IO_PENDING;
66 }
67 return policy; 48 return policy;
68 } 49 }
69 50
70 int ChromeCookiePolicy::CanSetCookie(const GURL& url, 51 int ChromeCookiePolicy::CanSetCookie(const GURL& url,
71 const GURL& first_party, 52 const GURL& first_party,
72 const std::string& cookie_line, 53 const std::string& cookie_line) const {
73 net::CompletionCallback* callback) {
74 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 54 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
75 55
76 if (host_content_settings_map_->BlockThirdPartyCookies()) { 56 if (host_content_settings_map_->BlockThirdPartyCookies()) {
77 net::StaticCookiePolicy policy(strict_third_party_blocking_ ? 57 net::StaticCookiePolicy policy(strict_third_party_blocking_ ?
78 net::StaticCookiePolicy::BLOCK_ALL_THIRD_PARTY_COOKIES : 58 net::StaticCookiePolicy::BLOCK_ALL_THIRD_PARTY_COOKIES :
79 net::StaticCookiePolicy::BLOCK_SETTING_THIRD_PARTY_COOKIES); 59 net::StaticCookiePolicy::BLOCK_SETTING_THIRD_PARTY_COOKIES);
80 int rv = policy.CanSetCookie(url, first_party, cookie_line, NULL); 60 int rv = policy.CanSetCookie(url, first_party, cookie_line);
81 if (rv != net::OK) 61 if (rv != net::OK)
82 return rv; 62 return rv;
83 } 63 }
84 64
85 int policy = CheckPolicy(url); 65 int policy = CheckPolicy(url);
86 if (policy != net::ERR_IO_PENDING) 66 DCHECK_NE(net::ERR_IO_PENDING, policy);
87 return policy;
88
89 DCHECK(callback);
90
91 Completions& completions = host_completions_map_[url.host()];
92 if (completions.size() >= kMaxCompletionsPerHost) {
93 LOG(ERROR) << "Would exceed kMaxCompletionsPerHost";
94 policy = net::ERR_ACCESS_DENIED;
95 } else {
96 completions.push_back(Completion::ForSetCookie(callback));
97 policy = net::ERR_IO_PENDING;
98 }
99
100 return policy; 67 return policy;
101 } 68 }
102 69
103 int ChromeCookiePolicy::CheckPolicy(const GURL& url) const { 70 int ChromeCookiePolicy::CheckPolicy(const GURL& url) const {
104 ContentSetting setting = host_content_settings_map_->GetContentSetting( 71 ContentSetting setting = host_content_settings_map_->GetContentSetting(
105 url, CONTENT_SETTINGS_TYPE_COOKIES, ""); 72 url, CONTENT_SETTINGS_TYPE_COOKIES, "");
106 if (setting == CONTENT_SETTING_BLOCK) 73 if (setting == CONTENT_SETTING_BLOCK)
107 return net::ERR_ACCESS_DENIED; 74 return net::ERR_ACCESS_DENIED;
108 if (setting == CONTENT_SETTING_ALLOW) 75 if (setting == CONTENT_SETTING_ALLOW)
109 return net::OK; 76 return net::OK;
110 if (setting == CONTENT_SETTING_SESSION_ONLY) 77 if (setting == CONTENT_SETTING_SESSION_ONLY)
111 return net::OK_FOR_SESSION_ONLY; 78 return net::OK_FOR_SESSION_ONLY;
112 return net::ERR_IO_PENDING; // Need to prompt. 79 return net::ERR_IO_PENDING; // Need to prompt.
jochen (gone - plz use gerrit) 2011/03/30 08:15:32 NOTREACHED() && return ACCESS DENIED?
willchan no longer on Chromium 2011/04/04 12:29:18 Done.
113 } 80 }
114
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698