OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 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 #ifndef CHROME_BROWSER_AUTOFILL_AUTOCHECKOUT_WHITELIST_MANAGER_H_ |
| 6 #define CHROME_BROWSER_AUTOFILL_AUTOCHECKOUT_WHITELIST_MANAGER_H_ |
| 7 |
| 8 #include <string> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/time.h" |
| 12 #include "base/timer.h" |
| 13 #include "net/url_request/url_fetcher_delegate.h" |
| 14 |
| 15 class GURL; |
| 16 |
| 17 namespace content { |
| 18 class BrowserContext; |
| 19 } |
| 20 |
| 21 namespace net { |
| 22 class URLRequestContextGetter; |
| 23 class URLFetcher; |
| 24 } |
| 25 |
| 26 namespace autofill { |
| 27 namespace autocheckout { |
| 28 |
| 29 // WhitelistManager is responsible for download and caching Autocheckout |
| 30 // whitelist from the server. |
| 31 class WhitelistManager : public net::URLFetcherDelegate, |
| 32 public base::RefCounted<WhitelistManager> { |
| 33 public: |
| 34 static WhitelistManager* GetForBrowserContext( |
| 35 content::BrowserContext* context); |
| 36 |
| 37 // Checks if the given url is whitelisted. |
| 38 bool IsAutocheckoutEnabled(const GURL& url); |
| 39 |
| 40 protected: |
| 41 explicit WhitelistManager(net::URLRequestContextGetter* context_getter); |
| 42 |
| 43 // Schedules a future call to TriggerDownload if one isn't already pending. |
| 44 virtual void ScheduleDownload(size_t interval_seconds); |
| 45 |
| 46 // Start the download timer. It is called by ScheduleDownload(), and exposed |
| 47 // as a separate method for mocking out in tests. |
| 48 virtual void StartDownloadTimer(size_t interval_seconds); |
| 49 |
| 50 // Timer callback indicating it's time to download whitelist from server. |
| 51 void TriggerDownload(); |
| 52 |
| 53 const std::vector<std::string>& url_prefixes() const { |
| 54 return url_prefixes_; |
| 55 } |
| 56 |
| 57 bool callback_is_pending() const { return callback_is_pending_; } |
| 58 |
| 59 void set_callback_is_pending(bool callback_is_pending) { |
| 60 callback_is_pending_ = callback_is_pending; |
| 61 } |
| 62 |
| 63 // Used by tests only. |
| 64 void StopDownloadTimer(); |
| 65 |
| 66 private: |
| 67 // Implements net::URLFetcherDelegate. |
| 68 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
| 69 |
| 70 // Parse whitelist data and build whitelist. |
| 71 void BuildWhitelist(const std::string& data); |
| 72 |
| 73 // A list of whitelisted url prefixes. |
| 74 std::vector<std::string> url_prefixes_; |
| 75 |
| 76 base::OneShotTimer<WhitelistManager> download_timer_; |
| 77 |
| 78 // Indicates that the last triggered download hasn't resolved yet. |
| 79 bool callback_is_pending_; |
| 80 |
| 81 // The context for the request. |
| 82 net::URLRequestContextGetter* const context_getter_; // WEAK |
| 83 |
| 84 // State of the kEnableExperimentalFormFilling flag. |
| 85 const bool experimental_form_filling_enabled_; |
| 86 |
| 87 // The request object. |
| 88 scoped_ptr<net::URLFetcher> request_; |
| 89 |
| 90 DISALLOW_COPY_AND_ASSIGN(WhitelistManager); |
| 91 }; |
| 92 |
| 93 } // namespace autocheckout |
| 94 } // namespace autofill |
| 95 |
| 96 #endif // CHROME_BROWSER_AUTOFILL_AUTOCHECKOUT_WHITELIST_MANAGER_H_ |
| 97 |
OLD | NEW |