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/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 URLFetcher; | |
23 class URLRequestContextGetter; | |
24 } | |
25 | |
26 namespace autofill { | |
27 namespace autocheckout { | |
28 | |
29 // Downloads and caches the list of URL prefixes whitelisted for use with | |
30 // Autocheckout. | |
31 class WhitelistManager : public net::URLFetcherDelegate, | |
32 public base::SupportsUserData::Data { | |
33 public: | |
34 static WhitelistManager* GetForBrowserContext( | |
35 content::BrowserContext* context); | |
36 | |
37 // Matches the url with whitelist and return the matched url prefix. | |
38 // Returns empty string when it is not matched. | |
39 std::string GetMatchedURLPrefix(const GURL& url) const; | |
40 | |
41 protected: | |
42 explicit WhitelistManager(net::URLRequestContextGetter* context_getter); | |
43 virtual ~WhitelistManager(); | |
44 | |
45 // Schedules a future call to TriggerDownload if one isn't already pending. | |
46 virtual void ScheduleDownload(size_t interval_seconds); | |
47 | |
48 // Start the download timer. It is called by ScheduleDownload(), and exposed | |
49 // as a separate method for mocking out in tests. | |
50 virtual void StartDownloadTimer(size_t interval_seconds); | |
51 | |
52 // Timer callback indicating it's time to download whitelist from server. | |
53 void TriggerDownload(); | |
54 | |
55 // Used by tests only. | |
56 void StopDownloadTimer(); | |
57 | |
58 const std::vector<std::string>& url_prefixes() const { | |
59 return url_prefixes_; | |
60 } | |
61 | |
62 private: | |
63 // Implements net::URLFetcherDelegate. | |
64 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | |
65 | |
66 // Parse whitelist data and build whitelist. | |
67 void BuildWhitelist(const std::string& data); | |
68 | |
69 // A list of whitelisted url prefixes. | |
70 std::vector<std::string> url_prefixes_; | |
71 | |
72 base::OneShotTimer<WhitelistManager> download_timer_; | |
73 | |
74 // Indicates that the last triggered download hasn't resolved yet. | |
75 bool callback_is_pending_; | |
76 | |
77 // The context for the request. | |
78 net::URLRequestContextGetter* const context_getter_; // WEAK | |
79 | |
80 // State of the kEnableExperimentalFormFilling flag. | |
81 const bool experimental_form_filling_enabled_; | |
82 | |
83 // The request object. | |
84 scoped_ptr<net::URLFetcher> request_; | |
85 | |
86 DISALLOW_COPY_AND_ASSIGN(WhitelistManager); | |
87 }; | |
88 | |
89 } // namespace autocheckout | |
90 } // namespace autofill | |
91 | |
92 #endif // CHROME_BROWSER_AUTOFILL_AUTOCHECKOUT_WHITELIST_MANAGER_H_ | |
93 | |
OLD | NEW |