OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "net/cookies/cookie_store_test_helpers.h" | 5 #include "net/cookies/cookie_store_test_helpers.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 10 #include "base/strings/string_util.h" |
10 #include "base/thread_task_runner_handle.h" | 11 #include "base/thread_task_runner_handle.h" |
| 12 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| 13 |
| 14 using net::registry_controlled_domains::GetDomainAndRegistry; |
| 15 using net::registry_controlled_domains::GetRegistryLength; |
| 16 using net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES; |
| 17 using net::registry_controlled_domains::INCLUDE_UNKNOWN_REGISTRIES; |
| 18 |
| 19 namespace { |
| 20 |
| 21 std::string GetRegistry(const GURL& url) { |
| 22 size_t registry_length = GetRegistryLength(url, INCLUDE_UNKNOWN_REGISTRIES, |
| 23 INCLUDE_PRIVATE_REGISTRIES); |
| 24 if (registry_length == 0) |
| 25 return std::string(); |
| 26 return std::string(url.host(), url.host().length() - registry_length, |
| 27 registry_length); |
| 28 } |
| 29 |
| 30 } // namespace |
11 | 31 |
12 namespace net { | 32 namespace net { |
13 | 33 |
14 const int kDelayedTime = 0; | 34 const int kDelayedTime = 0; |
15 | 35 |
16 DelayedCookieMonster::DelayedCookieMonster() | 36 DelayedCookieMonster::DelayedCookieMonster() |
17 : cookie_monster_(new CookieMonster(NULL, NULL)), | 37 : cookie_monster_(new CookieMonster(NULL, NULL)), |
18 did_run_(false), | 38 did_run_(false), |
19 result_(false) { | 39 result_(false) { |
20 } | 40 } |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 | 156 |
137 scoped_ptr<CookieStore::CookieChangedSubscription> | 157 scoped_ptr<CookieStore::CookieChangedSubscription> |
138 DelayedCookieMonster::AddCallbackForCookie( | 158 DelayedCookieMonster::AddCallbackForCookie( |
139 const GURL& url, | 159 const GURL& url, |
140 const std::string& name, | 160 const std::string& name, |
141 const CookieChangedCallback& callback) { | 161 const CookieChangedCallback& callback) { |
142 ADD_FAILURE(); | 162 ADD_FAILURE(); |
143 return scoped_ptr<CookieStore::CookieChangedSubscription>(); | 163 return scoped_ptr<CookieStore::CookieChangedSubscription>(); |
144 } | 164 } |
145 | 165 |
| 166 // |
| 167 // CookieURLHelper |
| 168 // |
| 169 CookieURLHelper::CookieURLHelper(const std::string& url_string) |
| 170 : url_(url_string), |
| 171 registry_(GetRegistry(url_)), |
| 172 domain_and_registry_( |
| 173 GetDomainAndRegistry(url_, INCLUDE_PRIVATE_REGISTRIES)) {} |
| 174 |
| 175 const GURL CookieURLHelper::AppendPath(const std::string& path) const { |
| 176 return GURL(url_.spec() + path); |
| 177 } |
| 178 |
| 179 std::string CookieURLHelper::Format(const std::string& format_string) const { |
| 180 std::string new_string = format_string; |
| 181 base::ReplaceSubstringsAfterOffset(&new_string, 0, "%D", |
| 182 domain_and_registry_); |
| 183 base::ReplaceSubstringsAfterOffset(&new_string, 0, "%R", registry_); |
| 184 return new_string; |
| 185 } |
| 186 |
146 } // namespace net | 187 } // namespace net |
OLD | NEW |