| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/net/cookie_store_util.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/callback.h" |
| 9 #include "base/command_line.h" |
| 10 #include "chrome/browser/browser_process.h" |
| 11 #include "chrome/browser/chrome_notification_types.h" |
| 12 #include "chrome/browser/net/chrome_cookie_notification_details.h" |
| 13 #include "chrome/browser/net/evicted_domain_cookie_counter.h" |
| 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/profiles/profile_manager.h" |
| 16 #include "chrome/common/chrome_constants.h" |
| 17 #include "chrome/common/chrome_switches.h" |
| 18 #include "content/public/browser/browser_thread.h" |
| 19 #include "content/public/browser/cookie_store_factory.h" |
| 20 #include "content/public/browser/notification_service.h" |
| 21 |
| 22 using content::BrowserThread; |
| 23 |
| 24 namespace { |
| 25 |
| 26 class ChromeCookieMonsterDelegate : public net::CookieMonsterDelegate { |
| 27 public: |
| 28 explicit ChromeCookieMonsterDelegate(Profile* profile) |
| 29 : profile_getter_( |
| 30 base::Bind(&GetProfileOnUI, g_browser_process->profile_manager(), |
| 31 profile)) { |
| 32 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 33 DCHECK(profile); |
| 34 } |
| 35 |
| 36 // net::CookieMonster::Delegate implementation. |
| 37 virtual void OnCookieChanged( |
| 38 const net::CanonicalCookie& cookie, |
| 39 bool removed, |
| 40 net::CookieMonster::Delegate::ChangeCause cause) OVERRIDE { |
| 41 BrowserThread::PostTask( |
| 42 BrowserThread::UI, FROM_HERE, |
| 43 base::Bind(&ChromeCookieMonsterDelegate::OnCookieChangedAsyncHelper, |
| 44 this, cookie, removed, cause)); |
| 45 } |
| 46 |
| 47 private: |
| 48 virtual ~ChromeCookieMonsterDelegate() {} |
| 49 |
| 50 static Profile* GetProfileOnUI(ProfileManager* profile_manager, |
| 51 Profile* profile) { |
| 52 if (profile_manager->IsValidProfile(profile)) |
| 53 return profile; |
| 54 return NULL; |
| 55 } |
| 56 |
| 57 void OnCookieChangedAsyncHelper( |
| 58 const net::CanonicalCookie& cookie, |
| 59 bool removed, |
| 60 net::CookieMonster::Delegate::ChangeCause cause) { |
| 61 Profile* profile = profile_getter_.Run(); |
| 62 if (profile) { |
| 63 ChromeCookieDetails cookie_details(&cookie, removed, cause); |
| 64 content::NotificationService::current()->Notify( |
| 65 chrome::NOTIFICATION_COOKIE_CHANGED, |
| 66 content::Source<Profile>(profile), |
| 67 content::Details<ChromeCookieDetails>(&cookie_details)); |
| 68 } |
| 69 } |
| 70 |
| 71 const base::Callback<Profile*(void)> profile_getter_; |
| 72 }; |
| 73 |
| 74 } // namespace |
| 75 |
| 76 namespace chrome_browser_net { |
| 77 |
| 78 bool IsCookieRecordMode() { |
| 79 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 80 // Only allow Record Mode if we are in a Debug build or where we are running |
| 81 // a cycle, and the user has limited control. |
| 82 return command_line.HasSwitch(switches::kRecordMode) && |
| 83 (chrome::kRecordModeEnabled || |
| 84 command_line.HasSwitch(switches::kVisitURLs)); |
| 85 } |
| 86 |
| 87 bool ShouldUseInMemoryCookiesAndCache() { |
| 88 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 89 return IsCookieRecordMode() || |
| 90 command_line.HasSwitch(switches::kPlaybackMode); |
| 91 } |
| 92 |
| 93 net::CookieMonsterDelegate* CreateCookieDelegate(Profile* profile) { |
| 94 return new EvictedDomainCookieCounter( |
| 95 new ChromeCookieMonsterDelegate(profile)); |
| 96 } |
| 97 |
| 98 } // namespace chrome_browser_net |
| OLD | NEW |