Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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 COMPONENTS_QUIRKS_QUIRKS_MANAGER_H_ | |
| 6 #define COMPONENTS_QUIRKS_QUIRKS_MANAGER_H_ | |
| 7 | |
| 8 #include <set> | |
| 9 | |
| 10 #include "base/callback.h" | |
| 11 #include "base/macros.h" | |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "base/time/time.h" | |
| 14 #include "components/quirks/quirks_client.h" | |
| 15 #include "components/quirks/quirks_export.h" | |
| 16 | |
| 17 class GURL; | |
| 18 class PrefRegistrySimple; | |
| 19 class PrefService; | |
| 20 | |
| 21 namespace base { | |
| 22 class SequencedWorkerPool; | |
| 23 class SingleThreadTaskRunner; | |
| 24 } | |
| 25 | |
| 26 namespace net { | |
| 27 class URLFetcher; | |
| 28 class URLFetcherDelegate; | |
| 29 class URLRequestContextGetter; | |
| 30 } | |
| 31 | |
| 32 namespace quirks { | |
| 33 | |
| 34 // Format int as hex string for filename. | |
| 35 QUIRKS_EXPORT std::string IdToHexString(int64_t product_id); | |
| 36 | |
| 37 // Returns path to icc file, if it exists; creates and starts QuirksClient if | |
| 38 // it doesn't. | |
| 39 QUIRKS_EXPORT base::FilePath RequestIccProfilePath( | |
| 40 int64_t product_id, | |
| 41 const DownloadFinishedCallback& on_download_finished); | |
| 42 | |
| 43 // Handles needed components from browser (local preferences, url context | |
| 44 // getter, message loops). | |
| 45 class QUIRKS_EXPORT QuirksManager { | |
| 46 public: | |
| 47 using FakeQuirksFetcherCreator = | |
| 48 base::Callback<scoped_ptr<net::URLFetcher>(const GURL&, | |
| 49 net::URLFetcherDelegate*)>; | |
| 50 | |
| 51 // Delegate class, so implementation can access browser functionality. | |
| 52 class Delegate { | |
| 53 public: | |
| 54 virtual ~Delegate() = default; | |
| 55 virtual std::string GetApiKey() const = 0; | |
| 56 virtual base::FilePath GetDisplayProfileDirectory() const = 0; | |
| 57 virtual int GetDaysSinceOobe() const = 0; // Must run on file thread. | |
| 58 | |
| 59 private: | |
| 60 DISALLOW_ASSIGN(Delegate); | |
| 61 }; | |
| 62 | |
| 63 static void Initialize( | |
| 64 scoped_ptr<Delegate> delegate, | |
| 65 scoped_refptr<base::SequencedWorkerPool> blocking_pool, | |
| 66 PrefService* local_state, | |
| 67 scoped_refptr<net::URLRequestContextGetter> url_context_getter); | |
| 68 static void Shutdown(); | |
| 69 static QuirksManager* Get(); | |
| 70 | |
| 71 static void RegisterPrefs(PrefRegistrySimple* registry); | |
| 72 | |
| 73 // Returns path to existing icc file, or starts client to download one. | |
| 74 base::FilePath RequestIccFilePath( | |
| 75 int64_t product_id, | |
| 76 const DownloadFinishedCallback& on_download_finished); | |
| 77 | |
| 78 void ClientFinished(QuirksClient* client); | |
| 79 | |
| 80 // Determines need to check based on previous check time and device age. | |
| 81 bool NeedToCheckServer(int64_t product_id); | |
| 82 | |
| 83 // Records time of most recent server check. | |
| 84 void SetLastServerCheck(int64_t product_id, const base::Time& last_check); | |
| 85 | |
| 86 // UMA stats for server check reason and results. | |
| 87 void RecordReasonUmaStat(QuirksClient::RequestReason reason); | |
| 88 void RecordFileFoundUmaStat(bool success); | |
| 89 | |
| 90 // Switch to fake URLFetcher creator for tests. | |
| 91 scoped_ptr<net::URLFetcher> CreateURLFetcher( | |
|
stevenjb
2016/02/16 20:07:51
ForTest?
Greg Levin
2016/02/17 23:01:51
Well, URLFetcher::Create() was moved in here from
| |
| 92 const std::string& url, | |
| 93 net::URLFetcherDelegate* delegate); | |
| 94 | |
| 95 Delegate* delegate() const { return delegate_.get(); } | |
| 96 base::SequencedWorkerPool* blocking_pool() const { | |
| 97 return blocking_pool_.get(); | |
| 98 } | |
|
stevenjb
2016/02/16 20:07:52
blank line
Greg Levin
2016/02/17 23:01:51
Done.
| |
| 99 net::URLRequestContextGetter* url_context_getter() const { | |
| 100 return url_context_getter_.get(); | |
| 101 } | |
|
stevenjb
2016/02/16 20:07:51
blank line
Greg Levin
2016/02/17 23:01:52
Done.
| |
| 102 base::SingleThreadTaskRunner* task_runner() const { | |
| 103 return task_runner_.get(); | |
| 104 } | |
|
stevenjb
2016/02/16 20:07:51
blank line
Also, do these all need to be accessib
Greg Levin
2016/02/17 23:01:51
I did this for SetFakeQuirksFetcherCreatorForTests
| |
| 105 void SetFakeQuirksFetcherCreatorForTests( | |
| 106 const FakeQuirksFetcherCreator& creator) { | |
| 107 fake_quirks_fetcher_creator_ = creator; | |
| 108 } | |
| 109 | |
| 110 private: | |
| 111 QuirksManager(Delegate* delegate, | |
| 112 scoped_refptr<base::SequencedWorkerPool> blocking_pool, | |
| 113 PrefService* local_state, | |
| 114 scoped_refptr<net::URLRequestContextGetter> url_context_getter); | |
| 115 ~QuirksManager(); | |
| 116 | |
| 117 void RunClientOnUIThread( | |
| 118 int64_t product_id, | |
| 119 const DownloadFinishedCallback& on_download_finished); | |
| 120 | |
| 121 // Check that ui thread and message loop are ready. | |
| 122 bool ValidateOnUiThread(); | |
|
stevenjb
2016/02/16 20:07:51
Replace any references to 'ui thread' with 'client
Greg Levin
2016/02/17 23:01:51
Done.
| |
| 123 | |
| 124 std::set<scoped_ptr<QuirksClient>> clients_; | |
| 125 | |
| 126 // These objects provide resources from the browser. | |
| 127 scoped_ptr<Delegate> delegate_; // Impl runs from browser. | |
| 128 // For url getter and file io. | |
| 129 scoped_refptr<base::SequencedWorkerPool> blocking_pool_; | |
| 130 PrefService* local_state_; // For local prefs. | |
| 131 scoped_refptr<net::URLRequestContextGetter> url_context_getter_; | |
| 132 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | |
| 133 | |
| 134 bool is_new_device_; // Is within 30 days of OOBE? | |
| 135 FakeQuirksFetcherCreator fake_quirks_fetcher_creator_; // For tests. | |
| 136 | |
| 137 // Factory for callbacks. | |
| 138 base::WeakPtrFactory<QuirksManager> weak_ptr_factory_; | |
| 139 | |
| 140 DISALLOW_COPY_AND_ASSIGN(QuirksManager); | |
| 141 }; | |
| 142 | |
| 143 } // namespace chromeos | |
| 144 | |
| 145 #endif // COMPONENTS_QUIRKS_QUIRKS_MANAGER_H_ | |
| OLD | NEW |