Chromium Code Reviews| 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> { | |
|
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.
| |
| 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. | |
|
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.
| |
| 47 virtual void StartDownloadTimer(size_t interval_seconds); | |
| 48 | |
| 49 // Timer callback indicating it's time to download whitelist from server. | |
| 50 void TriggerDownload(); | |
| 51 | |
| 52 const std::vector<std::string>& url_prefixes() const { | |
| 53 return url_prefixes_; | |
| 54 } | |
| 55 | |
| 56 void set_callback_is_pending(bool callback_is_pending) { | |
| 57 callback_is_pending_ = callback_is_pending; | |
| 58 } | |
| 59 | |
| 60 bool callback_is_pending() const { | |
| 61 return callback_is_pending_; | |
| 62 } | |
|
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.
| |
| 63 | |
| 64 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
| |
| 65 return download_timer_; | |
| 66 } | |
|
Ilya Sherman
2013/01/28 23:21:39
nit: Include a blank line after this one.
benquan
2013/01/29 03:28:30
Done.
| |
| 67 private: | |
| 68 // Implements net::URLFetcherDelegate. | |
| 69 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | |
| 70 | |
| 71 // Parse whitelist data and build whitelist. | |
| 72 void BuildWhitelist(const std::string& data); | |
| 73 | |
| 74 // A list of whitelisted url prefixes. | |
| 75 std::vector<std::string> url_prefixes_; | |
| 76 | |
| 77 base::OneShotTimer<WhitelistManager> download_timer_; | |
| 78 | |
| 79 // Indicates that the last triggered download hasn't resolved yet. | |
| 80 bool callback_is_pending_; | |
| 81 | |
| 82 // The context for the request. | |
| 83 net::URLRequestContextGetter* const context_getter_; // WEAK | |
| 84 | |
| 85 // State of the kEnableExperimentalFormFilling flag. | |
| 86 const bool experimental_form_filling_enabled_; | |
| 87 | |
| 88 // The request object. | |
| 89 scoped_ptr<net::URLFetcher> request_; | |
| 90 | |
| 91 DISALLOW_COPY_AND_ASSIGN(WhitelistManager); | |
| 92 }; | |
| 93 | |
| 94 } // namespace autocheckout | |
| 95 } // namespace autofill | |
| 96 | |
| 97 #endif // CHROME_BROWSER_AUTOFILL_AUTOCHECKOUT_WHITELIST_MANAGER_H_ | |
| 98 | |
| OLD | NEW |