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

Unified Diff: content/browser/android/cookie_getter_impl.h

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 side-by-side diff with in-line comments
Download patch
Index: content/browser/android/cookie_getter_impl.h
diff --git a/content/browser/android/cookie_getter_impl.h b/content/browser/android/cookie_getter_impl.h
new file mode 100644
index 0000000000000000000000000000000000000000..eec4da2d396a4324c15f3714d68c3ad6955410d1
--- /dev/null
+++ b/content/browser/android/cookie_getter_impl.h
@@ -0,0 +1,108 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_BROWSER_ANDROID_COOKIE_GETTER_IMPL_H_
+#define CONTENT_BROWSER_ANDROID_COOKIE_GETTER_IMPL_H_
+
+#include <string>
+
+#include "base/memory/ref_counted.h"
+#include "base/memory/weak_ptr.h"
+#include "base/synchronization/waitable_event.h"
+#include "media/base/android/cookie_getter.h"
+#include "net/cookies/canonical_cookie.h"
+
+namespace net {
+class URLRequestContextGetter;
+}
+
+namespace content {
+
+class BrowserContext;
+class CookieGetterImpl;
+class ResourceContext;
+
+// The task object that retrieves cookie on the IO thread.
+// TODO(qinmin): refactor this class to make the code reusable by others as
+// there are lots of duplicated functionalities elsewhere.
+class CookieGetterTask :
scherkus (not reviewing) 2012/09/13 10:40:14 nit: you can fwd declare this + move to .cc as Coo
qinmin 2012/09/13 18:51:16 Done.
+ public base::RefCountedThreadSafe<CookieGetterTask> {
scherkus (not reviewing) 2012/09/13 10:40:14 : goes on this line
qinmin 2012/09/13 18:51:16 Done.
+ public:
+ CookieGetterTask(BrowserContext* browser_context,
+ int renderer_id, int routing_id);
+ virtual ~CookieGetterTask();
+
+ void RequestCookies(
+ const GURL& url, const GURL& first_party_for_cookies);
+
+ std::string cookies() { return cookies_; }
+
+ private:
+ void CheckPolicyForCookies(
+ const GURL& url, const GURL& first_party_for_cookies,
+ const net::CookieList& cookie_list);
+ void ReturnCookies(const std::string& cookies);
+
+ // Context getter used to get the CookieStore.
+ net::URLRequestContextGetter* context_getter_;
+
+ // Resource context for checking cookie policies.
+ ResourceContext* resource_context_;
+
+ // Render process id, used to check whether the process can access cookies.
+ int renderer_id_;
+
+ // Routing id for the render view, used to check tab specific cookie policy.
+ int routing_id_;
+
+ // Return value.
+ std::string cookies_;
+
+ // The CookieGetterImpl object for callback.
+ base::WeakPtr<CookieGetterImpl> cookie_getter_;
+
+ // Event when all the async tasks are finished.
+ base::WaitableEvent finish_event_;
+
+ DISALLOW_COPY_AND_ASSIGN(CookieGetterTask);
+};
+
+// This class implements media::CookieGetter to retrive cookies
+// asynchronously on the UI thread.
+class CookieGetterImpl : public media::CookieGetter {
+ public:
+ // Construct a CookieGetterImpl by passing the BrowserContext reference
+ // and renderer_id to retrieve the CookieStore later.
+ CookieGetterImpl(
+ BrowserContext* browser_context, int renderer_id, int routing_id);
+ virtual ~CookieGetterImpl();
+
+ // media::CookieGetter implementation.
+ // Must be called on the UI thread.
+ virtual void GetCookies(const std::string& url,
+ const std::string& first_party_for_cookies,
+ const GetCookieCB& callback) OVERRIDE;
+
+ private:
+ void GetCookiesCallback(
+ scoped_refptr<CookieGetterTask> task, const GetCookieCB& callback);
+
+ // BrowserContext to retrieve URLRequestContext and ResourceContext.
+ BrowserContext* browser_context_;
+
+ // Used to post tasks.
+ base::WeakPtrFactory<CookieGetterImpl> weak_this_;
+
+ // Render process id, used to check whether the process can access cookies.
+ int renderer_id_;
+
+ // Routing id for the render view, used to check tab specific cookie policy.
+ int routing_id_;
+
+ DISALLOW_COPY_AND_ASSIGN(CookieGetterImpl);
+};
+
+} // namespace content
+
+#endif // CONTENT_BROWSER_ANDROID_COOKIE_GETTER_IMPL_H_

Powered by Google App Engine
This is Rietveld 408576698