Chromium Code Reviews| Index: components/web_restrictions/browser/web_restrictions_client.h |
| diff --git a/components/web_restrictions/browser/web_restrictions_client.h b/components/web_restrictions/browser/web_restrictions_client.h |
| index bad0b608ef0ec9a01a761fbd8bd7de4d4b93e900..5d48efc1f5a8be1bc6dc185d55849224b5560583 100644 |
| --- a/components/web_restrictions/browser/web_restrictions_client.h |
| +++ b/components/web_restrictions/browser/web_restrictions_client.h |
| @@ -6,9 +6,10 @@ |
| #define COMPONENTS_WEB_RESTRICTION_WEB_RESTRICTIONS_CLIENT_H_ |
| #include <jni.h> |
| + |
| #include <list> |
| -#include <map> |
| #include <string> |
| +#include <unordered_map> |
| #include "base/android/jni_android.h" |
| #include "base/android/scoped_java_ref.h" |
| @@ -17,12 +18,31 @@ |
| #include "base/memory/ref_counted.h" |
| #include "base/sequenced_task_runner.h" |
| #include "base/single_thread_task_runner.h" |
| -#include "url/gurl.h" |
| +#include "base/synchronization/lock.h" |
| +#include "components/web_restrictions/browser/web_restictions_client_result.h" |
| + |
| +namespace base { |
| +class Lock; |
|
Bernhard Bauer
2016/04/18 14:48:34
You already include the header for this.
aberent
2016/05/18 20:06:51
Done.
|
| +} |
| namespace web_restrictions { |
| enum UrlAccess { ALLOW, DISALLOW, PENDING }; |
| +class WebRestrictionsCache { |
|
Bernhard Bauer
2016/04/18 14:48:35
Can't this be inside of WebRestrictionsClient?
aberent
2016/05/18 20:06:51
Done.
|
| + public: |
| + std::unique_ptr<const WebRestrictionsClientResult> GetCacheEntry( |
|
Bernhard Bauer
2016/04/18 14:48:34
The const seems a bit much. If a client gets a fre
aberent
2016/05/18 20:06:50
Done.
|
| + const std::string& url); |
| + void SetCacheEntry(const std::string& url, |
| + const WebRestrictionsClientResult& entry); |
| + void RemoveCacheEntry(const std::string& url); |
| + void Clear(); |
| + |
| + private: |
| + base::Lock lock_; |
| + std::unordered_map<std::string, WebRestrictionsClientResult> cache_data_; |
|
Bernhard Bauer
2016/04/18 14:48:35
DISALLOW_COPY_AND_ASSIGN?
aberent
2016/05/18 20:06:51
Done.
|
| +}; |
| + |
| class WebRestrictionsClient { |
| public: |
| // An instance of this class is expected to live through the lifetime of a |
| @@ -42,30 +62,29 @@ class WebRestrictionsClient { |
| // WebRestrictionsProvider: |
| UrlAccess ShouldProceed(bool is_main_frame, |
| - const GURL& url, |
| + const std::string& url, |
|
Bernhard Bauer
2016/04/18 14:48:34
Why the change to std::string? I would use a GURL
aberent
2016/05/18 20:06:50
For consistency the methods should all take the sa
|
| const base::Callback<void(bool)>& callback); |
| bool SupportsRequest() const; |
| - int GetResultColumnCount(const GURL& url) const; |
| - |
| - std::string GetResultColumnName(const GURL& url, int column) const; |
| - |
| - int GetResultIntValue(const GURL& url, int column) const; |
| - |
| - std::string GetResultStringValue(const GURL& url, int column) const; |
| - |
| - void RequestPermission(const GURL& url, |
| + void RequestPermission(const std::string& url, |
| const base::Callback<void(bool)>& callback); |
| void OnWebRestrictionsChanged(); |
| + // Get a cached WebRestrictionsResult synchronously, for use when building |
| + // error pages etc.. May be called on any thread, and will return a fresh copy |
| + // of the result (hence thread safe). |
| + std::unique_ptr<const WebRestrictionsClientResult> |
| + GetCachedWebRestrictionsResult(const std::string& url); |
| + |
| private: |
| + void SetAuthorityTask(const std::string& content_provider_authority); |
| - void RecordURLAccess(const GURL& url); |
| + void RecordURLAccess(const std::string& url); |
| void UpdateCache(std::string provider_authority, |
| - GURL url, |
| + std::string url, |
| base::android::ScopedJavaGlobalRef<jobject> result); |
| void RequestSupportKnown(std::string provider_authority, |
| @@ -74,12 +93,12 @@ class WebRestrictionsClient { |
| void ClearCache(); |
| static base::android::ScopedJavaGlobalRef<jobject> ShouldProceedTask( |
| - const GURL& url, |
| + const std::string& url, |
| const base::android::JavaRef<jobject>& java_provider); |
| void OnShouldProceedComplete( |
| std::string provider_authority, |
| - const GURL& url, |
| + const std::string& url, |
| const base::Callback<void(bool)>& callback, |
| const base::android::ScopedJavaGlobalRef<jobject>& result); |
| @@ -88,12 +107,11 @@ class WebRestrictionsClient { |
| bool supports_request_; |
| base::android::ScopedJavaGlobalRef<jobject> java_provider_; |
| std::string provider_authority_; |
| + WebRestrictionsCache cache_; |
| scoped_refptr<base::SequencedTaskRunner> background_task_runner_; |
| - scoped_refptr<base::SingleThreadTaskRunner> single_thread_task_runner_; |
| - |
| - std::map<GURL, base::android::ScopedJavaGlobalRef<jobject>> cache_; |
| - std::list<GURL> recent_urls_; |
| + scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner_; |
| + std::list<std::string> recent_urls_; |
| DISALLOW_COPY_AND_ASSIGN(WebRestrictionsClient); |
| }; |