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

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, 8 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) 2011 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/content_settings/host_content_settings_map.h" 9 #include "chrome/browser/content_settings/host_content_settings_map.h"
10 #include "chrome/browser/ui/browser_list.h" 10 #include "chrome/browser/ui/browser_list.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
17 // BLOCK. More than this number of requests at once seems like it could be a
18 // sign of trouble anyways.
19 static const size_t kMaxCompletionsPerHost = 10000;
20
21 // ---------------------------------------------------------------------------- 16 // ----------------------------------------------------------------------------
22 17
23 ChromeCookiePolicy::ChromeCookiePolicy(HostContentSettingsMap* map) 18 ChromeCookiePolicy::ChromeCookiePolicy(HostContentSettingsMap* map)
24 : host_content_settings_map_(map) { 19 : host_content_settings_map_(map),
25 strict_third_party_blocking_ = CommandLine::ForCurrentProcess()->HasSwitch( 20 strict_third_party_blocking_(
26 switches::kBlockReadingThirdPartyCookies); 21 CommandLine::ForCurrentProcess()->HasSwitch(
27 } 22 switches::kBlockReadingThirdPartyCookies)) {}
28 23
29 ChromeCookiePolicy::~ChromeCookiePolicy() { 24 ChromeCookiePolicy::~ChromeCookiePolicy() {}
30 DCHECK(host_completions_map_.empty());
31 }
32 25
33 int ChromeCookiePolicy::CanGetCookies(const GURL& url, 26 int ChromeCookiePolicy::CanGetCookies(const GURL& url,
34 const GURL& first_party, 27 const GURL& first_party) const {
35 net::CompletionCallback* callback) {
36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 28 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
37 29
38 if (host_content_settings_map_->BlockThirdPartyCookies()) { 30 if (host_content_settings_map_->BlockThirdPartyCookies()) {
39 net::StaticCookiePolicy policy(strict_third_party_blocking_ ? 31 net::StaticCookiePolicy policy(strict_third_party_blocking_ ?
40 net::StaticCookiePolicy::BLOCK_ALL_THIRD_PARTY_COOKIES : 32 net::StaticCookiePolicy::BLOCK_ALL_THIRD_PARTY_COOKIES :
41 net::StaticCookiePolicy::BLOCK_SETTING_THIRD_PARTY_COOKIES); 33 net::StaticCookiePolicy::BLOCK_SETTING_THIRD_PARTY_COOKIES);
42 int rv = policy.CanGetCookies(url, first_party, NULL); 34 int rv = policy.CanGetCookies(url, first_party);
35 DCHECK_NE(net::ERR_IO_PENDING, rv);
43 if (rv != net::OK) 36 if (rv != net::OK)
44 return rv; 37 return rv;
45 } 38 }
46 39
47 int policy = CheckPolicy(url); 40 int policy = CheckPolicy(url);
48 if (policy == net::OK_FOR_SESSION_ONLY) 41 if (policy == net::OK_FOR_SESSION_ONLY)
49 policy = net::OK; 42 policy = net::OK;
50 if (policy != net::ERR_IO_PENDING) 43 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; 44 return policy;
68 } 45 }
69 46
70 int ChromeCookiePolicy::CanSetCookie(const GURL& url, 47 int ChromeCookiePolicy::CanSetCookie(const GURL& url,
71 const GURL& first_party, 48 const GURL& first_party,
72 const std::string& cookie_line, 49 const std::string& cookie_line) const {
73 net::CompletionCallback* callback) {
74 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 50 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
75 51
76 if (host_content_settings_map_->BlockThirdPartyCookies()) { 52 if (host_content_settings_map_->BlockThirdPartyCookies()) {
77 net::StaticCookiePolicy policy(strict_third_party_blocking_ ? 53 net::StaticCookiePolicy policy(strict_third_party_blocking_ ?
78 net::StaticCookiePolicy::BLOCK_ALL_THIRD_PARTY_COOKIES : 54 net::StaticCookiePolicy::BLOCK_ALL_THIRD_PARTY_COOKIES :
79 net::StaticCookiePolicy::BLOCK_SETTING_THIRD_PARTY_COOKIES); 55 net::StaticCookiePolicy::BLOCK_SETTING_THIRD_PARTY_COOKIES);
80 int rv = policy.CanSetCookie(url, first_party, cookie_line, NULL); 56 int rv = policy.CanSetCookie(url, first_party, cookie_line);
81 if (rv != net::OK) 57 if (rv != net::OK)
82 return rv; 58 return rv;
83 } 59 }
84 60
85 int policy = CheckPolicy(url); 61 int policy = CheckPolicy(url);
86 if (policy != net::ERR_IO_PENDING) 62 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; 63 return policy;
101 } 64 }
102 65
103 int ChromeCookiePolicy::CheckPolicy(const GURL& url) const { 66 int ChromeCookiePolicy::CheckPolicy(const GURL& url) const {
104 ContentSetting setting = host_content_settings_map_->GetContentSetting( 67 ContentSetting setting = host_content_settings_map_->GetContentSetting(
105 url, CONTENT_SETTINGS_TYPE_COOKIES, ""); 68 url, CONTENT_SETTINGS_TYPE_COOKIES, "");
106 if (setting == CONTENT_SETTING_BLOCK) 69 if (setting == CONTENT_SETTING_BLOCK)
107 return net::ERR_ACCESS_DENIED; 70 return net::ERR_ACCESS_DENIED;
108 if (setting == CONTENT_SETTING_ALLOW) 71 if (setting == CONTENT_SETTING_ALLOW)
109 return net::OK; 72 return net::OK;
110 if (setting == CONTENT_SETTING_SESSION_ONLY) 73 if (setting == CONTENT_SETTING_SESSION_ONLY)
111 return net::OK_FOR_SESSION_ONLY; 74 return net::OK_FOR_SESSION_ONLY;
112 return net::ERR_IO_PENDING; // Need to prompt. 75 NOTREACHED();
76 return net::ERR_ACCESS_DENIED;
113 } 77 }
114
OLDNEW
« no previous file with comments | « chrome/browser/net/chrome_cookie_policy.h ('k') | chrome/browser/net/chrome_url_request_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698