| 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 // Portions of this code based on Mozilla: | 5 // Portions of this code based on Mozilla: |
| 6 // (netwerk/cookie/src/nsCookieService.cpp) | 6 // (netwerk/cookie/src/nsCookieService.cpp) |
| 7 /* ***** BEGIN LICENSE BLOCK ***** | 7 /* ***** BEGIN LICENSE BLOCK ***** |
| 8 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | 8 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
| 9 * | 9 * |
| 10 * The contents of this file are subject to the Mozilla Public License Version | 10 * The contents of this file are subject to the Mozilla Public License Version |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 public: | 375 public: |
| 376 SetCookieWithDetailsTask(CookieMonster* cookie_monster, | 376 SetCookieWithDetailsTask(CookieMonster* cookie_monster, |
| 377 const GURL& url, | 377 const GURL& url, |
| 378 const std::string& name, | 378 const std::string& name, |
| 379 const std::string& value, | 379 const std::string& value, |
| 380 const std::string& domain, | 380 const std::string& domain, |
| 381 const std::string& path, | 381 const std::string& path, |
| 382 const base::Time& expiration_time, | 382 const base::Time& expiration_time, |
| 383 bool secure, | 383 bool secure, |
| 384 bool http_only, | 384 bool http_only, |
| 385 CookiePriority priority, |
| 385 const CookieMonster::SetCookiesCallback& callback) | 386 const CookieMonster::SetCookiesCallback& callback) |
| 386 : CookieMonsterTask(cookie_monster), | 387 : CookieMonsterTask(cookie_monster), |
| 387 url_(url), | 388 url_(url), |
| 388 name_(name), | 389 name_(name), |
| 389 value_(value), | 390 value_(value), |
| 390 domain_(domain), | 391 domain_(domain), |
| 391 path_(path), | 392 path_(path), |
| 392 expiration_time_(expiration_time), | 393 expiration_time_(expiration_time), |
| 393 secure_(secure), | 394 secure_(secure), |
| 394 http_only_(http_only), | 395 http_only_(http_only), |
| 396 priority_(priority), |
| 395 callback_(callback) { | 397 callback_(callback) { |
| 396 } | 398 } |
| 397 | 399 |
| 398 // CookieMonster::CookieMonsterTask: | 400 // CookieMonster::CookieMonsterTask: |
| 399 virtual void Run() OVERRIDE; | 401 virtual void Run() OVERRIDE; |
| 400 | 402 |
| 401 protected: | 403 protected: |
| 402 virtual ~SetCookieWithDetailsTask() {} | 404 virtual ~SetCookieWithDetailsTask() {} |
| 403 | 405 |
| 404 private: | 406 private: |
| 405 GURL url_; | 407 GURL url_; |
| 406 std::string name_; | 408 std::string name_; |
| 407 std::string value_; | 409 std::string value_; |
| 408 std::string domain_; | 410 std::string domain_; |
| 409 std::string path_; | 411 std::string path_; |
| 410 base::Time expiration_time_; | 412 base::Time expiration_time_; |
| 411 bool secure_; | 413 bool secure_; |
| 412 bool http_only_; | 414 bool http_only_; |
| 415 CookiePriority priority_; |
| 413 CookieMonster::SetCookiesCallback callback_; | 416 CookieMonster::SetCookiesCallback callback_; |
| 414 | 417 |
| 415 DISALLOW_COPY_AND_ASSIGN(SetCookieWithDetailsTask); | 418 DISALLOW_COPY_AND_ASSIGN(SetCookieWithDetailsTask); |
| 416 }; | 419 }; |
| 417 | 420 |
| 418 void CookieMonster::SetCookieWithDetailsTask::Run() { | 421 void CookieMonster::SetCookieWithDetailsTask::Run() { |
| 419 bool success = this->cookie_monster()-> | 422 bool success = this->cookie_monster()-> |
| 420 SetCookieWithDetails(url_, name_, value_, domain_, path_, | 423 SetCookieWithDetails(url_, name_, value_, domain_, path_, |
| 421 expiration_time_, secure_, http_only_); | 424 expiration_time_, secure_, http_only_, priority_); |
| 422 if (!callback_.is_null()) { | 425 if (!callback_.is_null()) { |
| 423 this->InvokeCallback(base::Bind(&CookieMonster::SetCookiesCallback::Run, | 426 this->InvokeCallback(base::Bind(&CookieMonster::SetCookiesCallback::Run, |
| 424 base::Unretained(&callback_), success)); | 427 base::Unretained(&callback_), success)); |
| 425 } | 428 } |
| 426 } | 429 } |
| 427 | 430 |
| 428 // Task class for GetAllCookies call. | 431 // Task class for GetAllCookies call. |
| 429 class CookieMonster::GetAllCookiesTask | 432 class CookieMonster::GetAllCookiesTask |
| 430 : public CookieMonster::CookieMonsterTask { | 433 : public CookieMonster::CookieMonsterTask { |
| 431 public: | 434 public: |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 769 | 772 |
| 770 void CookieMonster::SetCookieWithDetailsAsync( | 773 void CookieMonster::SetCookieWithDetailsAsync( |
| 771 const GURL& url, | 774 const GURL& url, |
| 772 const std::string& name, | 775 const std::string& name, |
| 773 const std::string& value, | 776 const std::string& value, |
| 774 const std::string& domain, | 777 const std::string& domain, |
| 775 const std::string& path, | 778 const std::string& path, |
| 776 const base::Time& expiration_time, | 779 const base::Time& expiration_time, |
| 777 bool secure, | 780 bool secure, |
| 778 bool http_only, | 781 bool http_only, |
| 782 CookiePriority priority, |
| 779 const SetCookiesCallback& callback) { | 783 const SetCookiesCallback& callback) { |
| 780 scoped_refptr<SetCookieWithDetailsTask> task = | 784 scoped_refptr<SetCookieWithDetailsTask> task = |
| 781 new SetCookieWithDetailsTask(this, url, name, value, domain, path, | 785 new SetCookieWithDetailsTask(this, url, name, value, domain, path, |
| 782 expiration_time, secure, http_only, | 786 expiration_time, secure, http_only, priority, |
| 783 callback); | 787 callback); |
| 784 | 788 |
| 785 DoCookieTaskForURL(task, url); | 789 DoCookieTaskForURL(task, url); |
| 786 } | 790 } |
| 787 | 791 |
| 788 void CookieMonster::GetAllCookiesAsync(const GetCookieListCallback& callback) { | 792 void CookieMonster::GetAllCookiesAsync(const GetCookieListCallback& callback) { |
| 789 scoped_refptr<GetAllCookiesTask> task = | 793 scoped_refptr<GetAllCookiesTask> task = |
| 790 new GetAllCookiesTask(this, callback); | 794 new GetAllCookiesTask(this, callback); |
| 791 | 795 |
| 792 DoCookieTask(task); | 796 DoCookieTask(task); |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 928 task_item->Run(); | 932 task_item->Run(); |
| 929 } | 933 } |
| 930 | 934 |
| 931 bool CookieMonster::SetCookieWithDetails(const GURL& url, | 935 bool CookieMonster::SetCookieWithDetails(const GURL& url, |
| 932 const std::string& name, | 936 const std::string& name, |
| 933 const std::string& value, | 937 const std::string& value, |
| 934 const std::string& domain, | 938 const std::string& domain, |
| 935 const std::string& path, | 939 const std::string& path, |
| 936 const base::Time& expiration_time, | 940 const base::Time& expiration_time, |
| 937 bool secure, | 941 bool secure, |
| 938 bool http_only) { | 942 bool http_only, |
| 943 CookiePriority priority) { |
| 939 base::AutoLock autolock(lock_); | 944 base::AutoLock autolock(lock_); |
| 940 | 945 |
| 941 if (!HasCookieableScheme(url)) | 946 if (!HasCookieableScheme(url)) |
| 942 return false; | 947 return false; |
| 943 | 948 |
| 944 Time creation_time = CurrentTime(); | 949 Time creation_time = CurrentTime(); |
| 945 last_time_seen_ = creation_time; | 950 last_time_seen_ = creation_time; |
| 946 | 951 |
| 947 scoped_ptr<CanonicalCookie> cc; | 952 scoped_ptr<CanonicalCookie> cc; |
| 948 cc.reset(CanonicalCookie::Create( | 953 cc.reset(CanonicalCookie::Create(url, name, value, domain, path, |
| 949 url, name, value, domain, path, | 954 creation_time, expiration_time, |
| 950 creation_time, expiration_time, | 955 secure, http_only, priority)); |
| 951 secure, http_only)); | |
| 952 | 956 |
| 953 if (!cc.get()) | 957 if (!cc.get()) |
| 954 return false; | 958 return false; |
| 955 | 959 |
| 956 CookieOptions options; | 960 CookieOptions options; |
| 957 options.set_include_httponly(); | 961 options.set_include_httponly(); |
| 958 return SetCanonicalCookie(&cc, creation_time, options); | 962 return SetCanonicalCookie(&cc, creation_time, options); |
| 959 } | 963 } |
| 960 | 964 |
| 961 bool CookieMonster::InitializeFrom(const CookieList& list) { | 965 bool CookieMonster::InitializeFrom(const CookieList& list) { |
| (...skipping 1049 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2011 | 2015 |
| 2012 // The system resolution is not high enough, so we can have multiple | 2016 // The system resolution is not high enough, so we can have multiple |
| 2013 // set cookies that result in the same system time. When this happens, we | 2017 // set cookies that result in the same system time. When this happens, we |
| 2014 // increment by one Time unit. Let's hope computers don't get too fast. | 2018 // increment by one Time unit. Let's hope computers don't get too fast. |
| 2015 Time CookieMonster::CurrentTime() { | 2019 Time CookieMonster::CurrentTime() { |
| 2016 return std::max(Time::Now(), | 2020 return std::max(Time::Now(), |
| 2017 Time::FromInternalValue(last_time_seen_.ToInternalValue() + 1)); | 2021 Time::FromInternalValue(last_time_seen_.ToInternalValue() + 1)); |
| 2018 } | 2022 } |
| 2019 | 2023 |
| 2020 } // namespace net | 2024 } // namespace net |
| OLD | NEW |