Chromium Code Reviews| Index: chrome/browser/autofill/autocheckout/whitelist_manager.h |
| diff --git a/chrome/browser/autofill/autocheckout/whitelist_manager.h b/chrome/browser/autofill/autocheckout/whitelist_manager.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f359fed065d8d39173b6592f0a3dbc074e274068 |
| --- /dev/null |
| +++ b/chrome/browser/autofill/autocheckout/whitelist_manager.h |
| @@ -0,0 +1,98 @@ |
| +// Copyright (c) 2013 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 CHROME_BROWSER_AUTOFILL_AUTOCHECKOUT_WHITELIST_MANAGER_H_ |
| +#define CHROME_BROWSER_AUTOFILL_AUTOCHECKOUT_WHITELIST_MANAGER_H_ |
| + |
| +#include <string> |
| +#include <vector> |
| + |
| +#include "base/time.h" |
| +#include "base/timer.h" |
| +#include "net/url_request/url_fetcher_delegate.h" |
| + |
| +class GURL; |
| + |
| +namespace content { |
| +class BrowserContext; |
| +} |
| + |
| +namespace net { |
| +class URLRequestContextGetter; |
| +class URLFetcher; |
| +} |
| + |
| +namespace autofill { |
| +namespace autocheckout { |
| + |
| +// WhitelistManager is responsible for download and caching Autocheckout |
| +// whitelist from the server. |
| +class WhitelistManager : public net::URLFetcherDelegate, |
| + public base::RefCounted<WhitelistManager> { |
|
Ilya Sherman
2013/01/28 23:21:39
Why is this class reference counted? It almost ce
benquan
2013/01/29 03:28:30
UserDataAdapter requires it to be reference counte
Ilya Sherman
2013/01/29 05:56:35
Ah, I didn't realize that. In that case, let's go
Ilya Sherman
2013/01/29 06:15:09
Or possibly inherit from content::WebContentsUserD
benquan
2013/01/30 00:48:42
I want one WhitelistManager instance per WebContex
benquan
2013/01/30 00:48:42
Done.
|
| + public: |
| + static WhitelistManager* GetForBrowserContext( |
| + content::BrowserContext* context); |
| + |
| + // Checks if the given url is whitelisted. |
| + bool IsAutocheckoutEnabled(const GURL& url); |
| + |
| + protected: |
| + explicit WhitelistManager(net::URLRequestContextGetter* context_getter); |
| + |
| + // Schedules a future call to TriggerDownload if one isn't already pending. |
| + virtual void ScheduleDownload(size_t interval_seconds); |
| + |
| + // Start the download timer. |
|
Ilya Sherman
2013/01/28 23:21:39
nit: Please mention that this is called by Schedul
benquan
2013/01/29 03:28:30
Done.
|
| + virtual void StartDownloadTimer(size_t interval_seconds); |
| + |
| + // Timer callback indicating it's time to download whitelist from server. |
| + void TriggerDownload(); |
| + |
| + const std::vector<std::string>& url_prefixes() const { |
| + return url_prefixes_; |
| + } |
| + |
| + void set_callback_is_pending(bool callback_is_pending) { |
| + callback_is_pending_ = callback_is_pending; |
| + } |
| + |
| + bool callback_is_pending() const { |
| + return callback_is_pending_; |
| + } |
|
Ilya Sherman
2013/01/28 23:21:39
nit: Please write this all on one line, as:
boo
Ilya Sherman
2013/01/28 23:21:39
nit: Please move this method to be before set_call
benquan
2013/01/29 03:28:30
Done.
benquan
2013/01/29 03:28:30
Done.
|
| + |
| + base::OneShotTimer<WhitelistManager>& download_timer() { |
|
Ilya Sherman
2013/01/28 23:21:39
nit: Please return a const reference from this fun
benquan
2013/01/29 03:28:30
Added StopDownloadTimer(), and this function is no
|
| + return download_timer_; |
| + } |
|
Ilya Sherman
2013/01/28 23:21:39
nit: Include a blank line after this one.
benquan
2013/01/29 03:28:30
Done.
|
| + private: |
| + // Implements net::URLFetcherDelegate. |
| + virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
| + |
| + // Parse whitelist data and build whitelist. |
| + void BuildWhitelist(const std::string& data); |
| + |
| + // A list of whitelisted url prefixes. |
| + std::vector<std::string> url_prefixes_; |
| + |
| + base::OneShotTimer<WhitelistManager> download_timer_; |
| + |
| + // Indicates that the last triggered download hasn't resolved yet. |
| + bool callback_is_pending_; |
| + |
| + // The context for the request. |
| + net::URLRequestContextGetter* const context_getter_; // WEAK |
| + |
| + // State of the kEnableExperimentalFormFilling flag. |
| + const bool experimental_form_filling_enabled_; |
| + |
| + // The request object. |
| + scoped_ptr<net::URLFetcher> request_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(WhitelistManager); |
| +}; |
| + |
| +} // namespace autocheckout |
| +} // namespace autofill |
| + |
| +#endif // CHROME_BROWSER_AUTOFILL_AUTOCHECKOUT_WHITELIST_MANAGER_H_ |
| + |