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

Side by Side Diff: content/browser/android/cookie_getter_impl.cc

Issue 10919075: Move android mediaplayer from render process to browser process. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: adding cookie policy check and fix the threading issue for CookieGetterImpl Created 8 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) 2012 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 "content/browser/android/cookie_getter_impl.h"
6
7 #include "base/bind.h"
8 #include "content/browser/child_process_security_policy_impl.h"
9 #include "content/public/browser/browser_context.h"
10 #include "content/public/browser/browser_thread.h"
11 #include "content/public/browser/content_browser_client.h"
12 #include "content/public/common/content_client.h"
13 #include "googleurl/src/gurl.h"
14 #include "net/cookies/cookie_monster.h"
15 #include "net/cookies/cookie_store.h"
16 #include "net/url_request/url_request_context.h"
17 #include "net/url_request/url_request_context_getter.h"
18
19 namespace content {
20
21 CookieGetterTask::CookieGetterTask(
22 BrowserContext* browser_context, int renderer_id, int routing_id)
23 : context_getter_(browser_context->GetRequestContext()),
24 resource_context_(browser_context->GetResourceContext()),
25 renderer_id_(renderer_id),
26 routing_id_(routing_id),
27 finish_event_(true, false) {
28 }
29
30 CookieGetterTask::~CookieGetterTask() {}
31
32 void CookieGetterTask::RequestCookies(
33 const GURL& url, const GURL& first_party_for_cookies) {
34 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
35 ChildProcessSecurityPolicyImpl* policy =
36 ChildProcessSecurityPolicyImpl::GetInstance();
37 if (!policy->CanUseCookiesForOrigin(renderer_id_, url))
38 return;
39
40 net::CookieStore* cookie_store =
41 context_getter_->GetURLRequestContext()->cookie_store();
42 if (!cookie_store)
43 return;
44
45 net::CookieMonster* cookie_monster = cookie_store->GetCookieMonster();
46 if (cookie_monster) {
47 cookie_monster->GetAllCookiesForURLAsync(url, base::Bind(
48 &CookieGetterTask::CheckPolicyForCookies, this,
49 url, first_party_for_cookies));
50 finish_event_.Wait();
scherkus (not reviewing) 2012/09/13 10:40:14 why the blocking wait on the IO thread? is there
qinmin 2012/09/13 18:51:16 If this function finishes here, CookieGetterImpl::
scherkus (not reviewing) 2012/09/14 08:09:40 PostTaskAndReply() is handy but it only works for
51 }
52 }
53
54 void CookieGetterTask::CheckPolicyForCookies(
55 const GURL& url, const GURL& first_party_for_cookies,
56 const net::CookieList& cookie_list) {
57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
58 if (GetContentClient()->browser()->AllowGetCookie(
59 url, first_party_for_cookies, cookie_list,
60 resource_context_, renderer_id_, routing_id_)) {
61 net::CookieStore* cookie_store =
62 context_getter_->GetURLRequestContext()->cookie_store();
63 cookie_store->GetCookiesWithOptionsAsync(
64 url, net::CookieOptions(),
65 base::Bind(&CookieGetterTask::ReturnCookies, this));
66 } else {
67 finish_event_.Signal();
68 }
69 }
70
71 void CookieGetterTask::ReturnCookies(const std::string& cookies) {
72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
73 cookies_ = cookies;
74 finish_event_.Signal();
75 }
76
77 CookieGetterImpl::CookieGetterImpl(
78 BrowserContext* browser_context, int renderer_id, int routing_id)
79 : browser_context_(browser_context),
80 ALLOW_THIS_IN_INITIALIZER_LIST(weak_this_(this)),
81 renderer_id_(renderer_id),
82 routing_id_(routing_id) {
83 }
84
85 CookieGetterImpl::~CookieGetterImpl() {}
86
87 void CookieGetterImpl::GetCookies(const std::string& url,
88 const std::string& first_party_for_cookies,
89 const GetCookieCB& callback) {
90 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
91 scoped_refptr<CookieGetterTask> task = new CookieGetterTask(
92 browser_context_, renderer_id_, routing_id_);
93 BrowserThread::PostTaskAndReply(
94 BrowserThread::IO,
95 FROM_HERE,
96 base::Bind(&CookieGetterTask::RequestCookies,
97 task, GURL(url), GURL(first_party_for_cookies)),
98 base::Bind(&CookieGetterImpl::GetCookiesCallback,
99 weak_this_.GetWeakPtr(), task, callback));
100 }
101
102 void CookieGetterImpl::GetCookiesCallback(
103 scoped_refptr<CookieGetterTask> task, const GetCookieCB& callback) {
104 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
105 callback.Run(task->cookies());
106 }
107
108 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698