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/supports_user_data.h" |
| 12 #include "base/time.h" |
| 13 #include "base/timer.h" |
| 14 #include "net/url_request/url_fetcher_delegate.h" |
| 15 |
| 16 class GURL; |
| 17 |
| 18 namespace content { |
| 19 class BrowserContext; |
| 20 } |
| 21 |
| 22 namespace net { |
| 23 class URLRequestContextGetter; |
| 24 class URLFetcher; |
| 25 } |
| 26 |
| 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::SupportsUserData::Data { |
| 33 public: |
| 34 |
| 35 static WhitelistManager* GetForBrowserContext( |
| 36 content::BrowserContext* context); |
| 37 |
| 38 // Checks if the given url is whitelisted. |
| 39 bool IsAutocheckoutEnabled(const GURL& url); |
| 40 |
| 41 // Schedules a future call to TriggerDownload if one isn't already pending. |
| 42 // Returns true if a new download activity is scheduled. |
| 43 bool ScheduleDownload(int interval_seconds); |
| 44 |
| 45 private: |
| 46 explicit WhitelistManager(net::URLRequestContextGetter* context_getter); |
| 47 |
| 48 // Timer callback indicating it's time to download whitelist from server. |
| 49 void TriggerDownload(); |
| 50 |
| 51 // Implements net::URLFetcherDelegate. |
| 52 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
| 53 |
| 54 // Parse whitelist data and build whitelist |
| 55 void BuildWhitelist(const std::string& data); |
| 56 |
| 57 // The context for the request. |
| 58 // The pointer value is const, so this can only be set in the constructor. |
| 59 // Must not be null. |
| 60 net::URLRequestContextGetter* const context_getter_; // WEAK |
| 61 |
| 62 // Indicates that the last triggered download hasn't resolved yet. |
| 63 bool callback_pending_; |
| 64 |
| 65 // State of the kEnableExperimentalFormFilling flag. |
| 66 const bool experimental_form_filling_enabled_; |
| 67 |
| 68 // The request object. |
| 69 scoped_ptr<net::URLFetcher> request_; |
| 70 |
| 71 // A list of whitelisted url prefixes. |
| 72 std::vector<std::string> url_prefixes_; |
| 73 |
| 74 base::OneShotTimer<WhitelistManager> download_timer_; |
| 75 |
| 76 friend class WhitelistManagerTest; |
| 77 |
| 78 DISALLOW_COPY_AND_ASSIGN(WhitelistManager); |
| 79 }; |
| 80 |
| 81 } // namespace autocheckout |
| 82 |
| 83 #endif // CHROME_BROWSER_AUTOFILL_AUTOCHECKOUT_WHITELIST_MANAGER_H_ |
| 84 |
OLD | NEW |