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

Side by Side Diff: android_webview/browser/net/aw_cookie_store_wrapper.h

Issue 2937963003: Shift cookie system callbacks to OnceCallback to impedance match mojo. (Closed)
Patch Set: Finish Merge Created 3 years, 6 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #ifndef ANDROID_WEBVIEW_BROWSER_NET_AW_COOKIE_STORE_WRAPPER_H_ 5 #ifndef ANDROID_WEBVIEW_BROWSER_NET_AW_COOKIE_STORE_WRAPPER_H_
6 #define ANDROID_WEBVIEW_BROWSER_NET_AW_COOKIE_STORE_WRAPPER_H_ 6 #define ANDROID_WEBVIEW_BROWSER_NET_AW_COOKIE_STORE_WRAPPER_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 26 matching lines...) Expand all
37 // The CookieManager must outlive the AwCookieStoreWrapper. 37 // The CookieManager must outlive the AwCookieStoreWrapper.
38 class AwCookieStoreWrapper : public net::CookieStore { 38 class AwCookieStoreWrapper : public net::CookieStore {
39 public: 39 public:
40 AwCookieStoreWrapper(); 40 AwCookieStoreWrapper();
41 ~AwCookieStoreWrapper() override; 41 ~AwCookieStoreWrapper() override;
42 42
43 // CookieStore implementation: 43 // CookieStore implementation:
44 void SetCookieWithOptionsAsync(const GURL& url, 44 void SetCookieWithOptionsAsync(const GURL& url,
45 const std::string& cookie_line, 45 const std::string& cookie_line,
46 const net::CookieOptions& options, 46 const net::CookieOptions& options,
47 const SetCookiesCallback& callback) override; 47 SetCookiesCallback callback) override;
48 void SetCookieWithDetailsAsync(const GURL& url, 48 void SetCookieWithDetailsAsync(const GURL& url,
49 const std::string& name, 49 const std::string& name,
50 const std::string& value, 50 const std::string& value,
51 const std::string& domain, 51 const std::string& domain,
52 const std::string& path, 52 const std::string& path,
53 base::Time creation_time, 53 base::Time creation_time,
54 base::Time expiration_time, 54 base::Time expiration_time,
55 base::Time last_access_time, 55 base::Time last_access_time,
56 bool secure, 56 bool secure,
57 bool http_only, 57 bool http_only,
58 net::CookieSameSite same_site, 58 net::CookieSameSite same_site,
59 net::CookiePriority priority, 59 net::CookiePriority priority,
60 const SetCookiesCallback& callback) override; 60 SetCookiesCallback callback) override;
61 void SetCanonicalCookieAsync(std::unique_ptr<net::CanonicalCookie> cookie, 61 void SetCanonicalCookieAsync(std::unique_ptr<net::CanonicalCookie> cookie,
62 bool secure_source, 62 bool secure_source,
63 bool modify_http_only, 63 bool modify_http_only,
64 const SetCookiesCallback& callback) override; 64 SetCookiesCallback callback) override;
65 void GetCookiesWithOptionsAsync(const GURL& url, 65 void GetCookiesWithOptionsAsync(const GURL& url,
66 const net::CookieOptions& options, 66 const net::CookieOptions& options,
67 const GetCookiesCallback& callback) override; 67 GetCookiesCallback callback) override;
68 void GetCookieListWithOptionsAsync( 68 void GetCookieListWithOptionsAsync(const GURL& url,
69 const GURL& url, 69 const net::CookieOptions& options,
70 const net::CookieOptions& options, 70 GetCookieListCallback callback) override;
71 const GetCookieListCallback& callback) override; 71 void GetAllCookiesAsync(GetCookieListCallback callback) override;
72 void GetAllCookiesAsync(const GetCookieListCallback& callback) override;
73 void DeleteCookieAsync(const GURL& url, 72 void DeleteCookieAsync(const GURL& url,
74 const std::string& cookie_name, 73 const std::string& cookie_name,
75 const base::Closure& callback) override; 74 base::OnceClosure callback) override;
76 void DeleteCanonicalCookieAsync(const net::CanonicalCookie& cookie, 75 void DeleteCanonicalCookieAsync(const net::CanonicalCookie& cookie,
77 const DeleteCallback& callback) override; 76 DeleteCallback callback) override;
78 void DeleteAllCreatedBetweenAsync(const base::Time& delete_begin, 77 void DeleteAllCreatedBetweenAsync(const base::Time& delete_begin,
79 const base::Time& delete_end, 78 const base::Time& delete_end,
80 const DeleteCallback& callback) override; 79 DeleteCallback callback) override;
81 void DeleteAllCreatedBetweenWithPredicateAsync( 80 void DeleteAllCreatedBetweenWithPredicateAsync(
82 const base::Time& delete_begin, 81 const base::Time& delete_begin,
83 const base::Time& delete_end, 82 const base::Time& delete_end,
84 const CookiePredicate& predicate, 83 const CookiePredicate& predicate,
85 const DeleteCallback& callback) override; 84 DeleteCallback callback) override;
86 void DeleteSessionCookiesAsync(const DeleteCallback& callback) override; 85 void DeleteSessionCookiesAsync(DeleteCallback callback) override;
87 void FlushStore(const base::Closure& callback) override; 86 void FlushStore(base::OnceClosure callback) override;
88 void SetForceKeepSessionState() override; 87 void SetForceKeepSessionState() override;
89 std::unique_ptr<CookieChangedSubscription> AddCallbackForCookie( 88 std::unique_ptr<CookieChangedSubscription> AddCallbackForCookie(
90 const GURL& url, 89 const GURL& url,
91 const std::string& name, 90 const std::string& name,
92 const CookieChangedCallback& callback) override; 91 const CookieChangedCallback& callback) override;
93 bool IsEphemeral() override; 92 bool IsEphemeral() override;
94 93
95 private: 94 private:
96 // Used by CreateWrappedCallback below. Takes an arugment of Type and posts 95 // Used by CreateWrappedCallback below. Takes an argument of Type and posts
97 // a task to |task_runner| to invoke |callback| with that argument. If 96 // a task to |task_runner| to invoke |callback| with that argument. If
98 // |weak_cookie_store| is deleted before the task is run, the task will not 97 // |weak_cookie_store| is deleted before the task is run, the task will not
99 // be run. 98 // be run.
100 template <class Type> 99 template <class Type>
101 static void RunCallbackOnClientThread( 100 static void RunCallbackOnClientThread(
102 base::TaskRunner* task_runner, 101 base::TaskRunner* task_runner,
103 base::WeakPtr<AwCookieStoreWrapper> weak_cookie_store, 102 base::WeakPtr<AwCookieStoreWrapper> weak_cookie_store,
104 base::Callback<void(Type)> callback, 103 base::OnceCallback<void(Type)> callback,
105 Type argument) { 104 Type argument) {
106 task_runner->PostTask( 105 task_runner->PostTask(
107 FROM_HERE, 106 FROM_HERE,
108 base::Bind(&AwCookieStoreWrapper::RunClosureCallback, weak_cookie_store, 107 base::BindOnce(&AwCookieStoreWrapper::RunClosureCallback,
109 base::Bind(callback, argument))); 108 weak_cookie_store,
109 base::BindOnce(std::move(callback), argument)));
110 } 110 }
111 111
112 // Returns a base::Callback that takes an argument of Type and posts a task to 112 // Returns a base::Callback that takes an argument of Type and posts a task to
113 // the |client_task_runner_| to invoke |callback| with that argument. 113 // the |client_task_runner_| to invoke |callback| with that argument.
114 template <class Type> 114 template <class Type>
115 base::Callback<void(Type)> CreateWrappedCallback( 115 base::OnceCallback<void(Type)> CreateWrappedCallback(
116 base::Callback<void(Type)> callback) { 116 base::OnceCallback<void(Type)> callback) {
117 if (callback.is_null()) 117 if (callback.is_null())
118 return callback; 118 return std::move(callback);
119 return base::Bind(&AwCookieStoreWrapper::RunCallbackOnClientThread<Type>, 119 return base::BindOnce(
120 base::RetainedRef(client_task_runner_), 120 &AwCookieStoreWrapper::RunCallbackOnClientThread<Type>,
121 weak_factory_.GetWeakPtr(), callback); 121 base::RetainedRef(client_task_runner_), weak_factory_.GetWeakPtr(),
122 std::move(callback));
122 } 123 }
123 124
124 // Returns a base::Closure that posts a task to the |client_task_runner_| to 125 // Returns a base::OnceClosure that posts a task to the |client_task_runner_|
125 // invoke |callback|. 126 // to invoke |callback|.
126 base::Closure CreateWrappedClosureCallback(const base::Closure& callback); 127 base::OnceClosure CreateWrappedClosureCallback(base::OnceClosure callback);
127 128
128 // Runs |callback|. Used to prevent callbacks from being invoked after the 129 // Runs |callback|. Used to prevent callbacks from being invoked after the
129 // AwCookieStoreWrapper has been destroyed. 130 // AwCookieStoreWrapper has been destroyed.
130 void RunClosureCallback(const base::Closure& callback); 131 void RunClosureCallback(base::OnceClosure callback);
131 132
132 scoped_refptr<base::SingleThreadTaskRunner> client_task_runner_; 133 scoped_refptr<base::SingleThreadTaskRunner> client_task_runner_;
133 134
134 base::WeakPtrFactory<AwCookieStoreWrapper> weak_factory_; 135 base::WeakPtrFactory<AwCookieStoreWrapper> weak_factory_;
135 }; 136 };
136 137
137 } // namespace android_webview 138 } // namespace android_webview
138 139
139 #endif // ANDROID_WEBVIEW_BROWSER_NET_AW_COOKIE_STORE_WRAPPER_H_ 140 #endif // ANDROID_WEBVIEW_BROWSER_NET_AW_COOKIE_STORE_WRAPPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698