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

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

Issue 12546016: Remove the Extensions URLRequestContext (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: android webview init fix merged in. Created 7 years, 3 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
(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 #include "content/public/common/content_constants.h"
22 #include "extensions/common/constants.h"
23
24 using content::BrowserThread;
25
26 namespace {
27
28 class ChromeCookieMonsterDelegate : public net::CookieMonsterDelegate {
29 public:
30 explicit ChromeCookieMonsterDelegate(Profile* profile)
31 : profile_getter_(
32 base::Bind(&GetProfileOnUI, g_browser_process->profile_manager(),
33 profile)) {
34 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
35 DCHECK(profile);
36 }
37
38 // net::CookieMonster::Delegate implementation.
39 virtual void OnCookieChanged(
40 const net::CanonicalCookie& cookie,
41 bool removed,
42 net::CookieMonster::Delegate::ChangeCause cause) OVERRIDE {
43 BrowserThread::PostTask(
44 BrowserThread::UI, FROM_HERE,
45 base::Bind(&ChromeCookieMonsterDelegate::OnCookieChangedAsyncHelper,
46 this, cookie, removed, cause));
47 }
48
49 private:
50 virtual ~ChromeCookieMonsterDelegate() {}
51
52 static Profile* GetProfileOnUI(ProfileManager* profile_manager,
53 Profile* profile) {
54 if (profile_manager->IsValidProfile(profile))
55 return profile;
56 return NULL;
57 }
58
59 void OnCookieChangedAsyncHelper(
60 const net::CanonicalCookie& cookie,
61 bool removed,
62 net::CookieMonster::Delegate::ChangeCause cause) {
63 Profile* profile = profile_getter_.Run();
64 if (profile) {
65 ChromeCookieDetails cookie_details(&cookie, removed, cause);
66 content::NotificationService::current()->Notify(
67 chrome::NOTIFICATION_COOKIE_CHANGED,
68 content::Source<Profile>(profile),
69 content::Details<ChromeCookieDetails>(&cookie_details));
70 }
71 }
72
73 const base::Callback<Profile*(void)> profile_getter_;
74 };
75
76 } // namespace
77
78 namespace chrome_browser_net {
79
80 bool IsCookieRecordMode() {
81 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
82 // Only allow Record Mode if we are in a Debug build or where we are running
83 // a cycle, and the user has limited control.
84 return command_line.HasSwitch(switches::kRecordMode) &&
85 (chrome::kRecordModeEnabled ||
86 command_line.HasSwitch(switches::kVisitURLs));
87 }
88
89 bool ShouldUseInMemoryCookiesAndCache() {
90 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
91 return IsCookieRecordMode() ||
92 command_line.HasSwitch(switches::kPlaybackMode);
93 }
94
95 net::CookieMonsterDelegate* CreateCookieDelegate(Profile* profile) {
96 return new EvictedDomainCookieCounter(
97 new ChromeCookieMonsterDelegate(profile));
98 }
99
100 void SetCookieStoreConfigs(
101 const base::FilePath& partition_path,
102 bool in_memory_partition,
103 bool is_default_partition,
104 content::CookieStoreConfig::SessionCookieMode session_cookie_mode,
105 quota::SpecialStoragePolicy* storage_policy,
106 net::CookieMonsterDelegate* cookie_delegate,
107 content::BrowserContext::CookieSchemeMap* configs) {
108 using content::CookieStoreConfig;
109 configs->clear();
110
111 bool in_memory = in_memory_partition ||
112 chrome_browser_net::ShouldUseInMemoryCookiesAndCache();
113
114 if (in_memory) {
115 (*configs)[content::BrowserContext::kDefaultCookieScheme] =
116 CookieStoreConfig(base::FilePath(),
117 CookieStoreConfig::EPHEMERAL_SESSION_COOKIES,
118 storage_policy,
119 cookie_delegate);
120 } else {
121 (*configs)[content::BrowserContext::kDefaultCookieScheme] =
122 CookieStoreConfig(partition_path.Append(content::kCookieFilename),
123 session_cookie_mode,
124 storage_policy,
125 cookie_delegate);
126 }
127
128 // Handle adding the extensions cookie store.
129 if (is_default_partition) {
130 if (in_memory) {
131 (*configs)[extensions::kExtensionScheme] = CookieStoreConfig();
132 } else {
133 base::FilePath cookie_path = partition_path.Append(
134 chrome::kExtensionsCookieFilename);
135 (*configs)[extensions::kExtensionScheme] =
136 CookieStoreConfig(cookie_path, session_cookie_mode, NULL, NULL);
137 }
138 }
139 }
140
141 } // namespace chrome_browser_net
OLDNEW
« no previous file with comments | « chrome/browser/net/cookie_store_util.h ('k') | chrome/browser/password_manager/password_form_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698