OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_QUIRKS_QUIRKS_MANAGER_H_ | 5 #ifndef COMPONENTS_QUIRKS_QUIRKS_MANAGER_H_ |
6 #define COMPONENTS_QUIRKS_QUIRKS_MANAGER_H_ | 6 #define COMPONENTS_QUIRKS_QUIRKS_MANAGER_H_ |
7 | 7 |
| 8 #include <memory> |
8 #include <set> | 9 #include <set> |
9 | 10 |
10 #include "base/callback.h" | 11 #include "base/callback.h" |
11 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
12 #include "base/macros.h" | 13 #include "base/macros.h" |
13 #include "base/memory/scoped_ptr.h" | |
14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
15 #include "base/threading/thread_checker.h" | 15 #include "base/threading/thread_checker.h" |
16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
17 #include "components/quirks/quirks_export.h" | 17 #include "components/quirks/quirks_export.h" |
18 | 18 |
19 class GURL; | 19 class GURL; |
20 class PrefRegistrySimple; | 20 class PrefRegistrySimple; |
21 class PrefService; | 21 class PrefService; |
22 | 22 |
23 namespace base { | 23 namespace base { |
(...skipping 23 matching lines...) Expand all Loading... |
47 QUIRKS_EXPORT std::string IdToFileName(int64_t product_id); | 47 QUIRKS_EXPORT std::string IdToFileName(int64_t product_id); |
48 | 48 |
49 // Manages downloads of and requests for hardware calibration and configuration | 49 // Manages downloads of and requests for hardware calibration and configuration |
50 // files ("Quirks"). The manager presents an external Quirks API, handles | 50 // files ("Quirks"). The manager presents an external Quirks API, handles |
51 // needed components from browser (local preferences, url context getter, | 51 // needed components from browser (local preferences, url context getter, |
52 // blocking pool, etc), and owns clients and manages their life cycles. | 52 // blocking pool, etc), and owns clients and manages their life cycles. |
53 class QUIRKS_EXPORT QuirksManager { | 53 class QUIRKS_EXPORT QuirksManager { |
54 public: | 54 public: |
55 // Passed function to create a URLFetcher for tests. | 55 // Passed function to create a URLFetcher for tests. |
56 // Same parameters as URLFetcher::Create(). | 56 // Same parameters as URLFetcher::Create(). |
57 using FakeQuirksFetcherCreator = | 57 using FakeQuirksFetcherCreator = base::Callback< |
58 base::Callback<scoped_ptr<net::URLFetcher>(const GURL&, | 58 std::unique_ptr<net::URLFetcher>(const GURL&, net::URLFetcherDelegate*)>; |
59 net::URLFetcherDelegate*)>; | |
60 | 59 |
61 // Callback after getting days since OOBE on blocking pool. | 60 // Callback after getting days since OOBE on blocking pool. |
62 // Parameter is returned number of days. | 61 // Parameter is returned number of days. |
63 using DaysSinceOobeCallback = base::Callback<void(int)>; | 62 using DaysSinceOobeCallback = base::Callback<void(int)>; |
64 | 63 |
65 // Delegate class, so implementation can access browser functionality. | 64 // Delegate class, so implementation can access browser functionality. |
66 class Delegate { | 65 class Delegate { |
67 public: | 66 public: |
68 virtual ~Delegate() = default; | 67 virtual ~Delegate() = default; |
69 | 68 |
(...skipping 12 matching lines...) Expand all Loading... |
82 virtual bool DevicePolicyEnabled() const = 0; | 81 virtual bool DevicePolicyEnabled() const = 0; |
83 | 82 |
84 // Gets days since first login, returned via callback. | 83 // Gets days since first login, returned via callback. |
85 virtual void GetDaysSinceOobe(DaysSinceOobeCallback callback) const = 0; | 84 virtual void GetDaysSinceOobe(DaysSinceOobeCallback callback) const = 0; |
86 | 85 |
87 private: | 86 private: |
88 DISALLOW_ASSIGN(Delegate); | 87 DISALLOW_ASSIGN(Delegate); |
89 }; | 88 }; |
90 | 89 |
91 static void Initialize( | 90 static void Initialize( |
92 scoped_ptr<Delegate> delegate, | 91 std::unique_ptr<Delegate> delegate, |
93 scoped_refptr<base::SequencedWorkerPool> blocking_pool, | 92 scoped_refptr<base::SequencedWorkerPool> blocking_pool, |
94 PrefService* local_state, | 93 PrefService* local_state, |
95 scoped_refptr<net::URLRequestContextGetter> url_context_getter); | 94 scoped_refptr<net::URLRequestContextGetter> url_context_getter); |
96 static void Shutdown(); | 95 static void Shutdown(); |
97 static QuirksManager* Get(); | 96 static QuirksManager* Get(); |
98 | 97 |
99 static void RegisterPrefs(PrefRegistrySimple* registry); | 98 static void RegisterPrefs(PrefRegistrySimple* registry); |
100 | 99 |
101 // Signal to start queued downloads after login. | 100 // Signal to start queued downloads after login. |
102 void OnLoginCompleted(); | 101 void OnLoginCompleted(); |
103 | 102 |
104 // Entry point into manager. Finds or downloads icc file. | 103 // Entry point into manager. Finds or downloads icc file. |
105 void RequestIccProfilePath( | 104 void RequestIccProfilePath( |
106 int64_t product_id, | 105 int64_t product_id, |
107 const RequestFinishedCallback& on_request_finished); | 106 const RequestFinishedCallback& on_request_finished); |
108 | 107 |
109 void ClientFinished(QuirksClient* client); | 108 void ClientFinished(QuirksClient* client); |
110 | 109 |
111 // Creates a real URLFetcher for OS, and a fake one for tests. | 110 // Creates a real URLFetcher for OS, and a fake one for tests. |
112 scoped_ptr<net::URLFetcher> CreateURLFetcher( | 111 std::unique_ptr<net::URLFetcher> CreateURLFetcher( |
113 const GURL& url, | 112 const GURL& url, |
114 net::URLFetcherDelegate* delegate); | 113 net::URLFetcherDelegate* delegate); |
115 | 114 |
116 Delegate* delegate() { return delegate_.get(); } | 115 Delegate* delegate() { return delegate_.get(); } |
117 base::SequencedWorkerPool* blocking_pool() { return blocking_pool_.get(); } | 116 base::SequencedWorkerPool* blocking_pool() { return blocking_pool_.get(); } |
118 net::URLRequestContextGetter* url_context_getter() { | 117 net::URLRequestContextGetter* url_context_getter() { |
119 return url_context_getter_.get(); | 118 return url_context_getter_.get(); |
120 } | 119 } |
121 | 120 |
122 protected: | 121 protected: |
123 friend class QuirksBrowserTest; | 122 friend class QuirksBrowserTest; |
124 | 123 |
125 void SetFakeQuirksFetcherCreatorForTests( | 124 void SetFakeQuirksFetcherCreatorForTests( |
126 const FakeQuirksFetcherCreator& creator) { | 125 const FakeQuirksFetcherCreator& creator) { |
127 fake_quirks_fetcher_creator_ = creator; | 126 fake_quirks_fetcher_creator_ = creator; |
128 } | 127 } |
129 | 128 |
130 private: | 129 private: |
131 QuirksManager(scoped_ptr<Delegate> delegate, | 130 QuirksManager(std::unique_ptr<Delegate> delegate, |
132 scoped_refptr<base::SequencedWorkerPool> blocking_pool, | 131 scoped_refptr<base::SequencedWorkerPool> blocking_pool, |
133 PrefService* local_state, | 132 PrefService* local_state, |
134 scoped_refptr<net::URLRequestContextGetter> url_context_getter); | 133 scoped_refptr<net::URLRequestContextGetter> url_context_getter); |
135 ~QuirksManager(); | 134 ~QuirksManager(); |
136 | 135 |
137 // Callback after checking for existing icc file; proceed if not found. | 136 // Callback after checking for existing icc file; proceed if not found. |
138 void OnIccFilePathRequestCompleted( | 137 void OnIccFilePathRequestCompleted( |
139 int64_t product_id, | 138 int64_t product_id, |
140 const RequestFinishedCallback& on_request_finished, | 139 const RequestFinishedCallback& on_request_finished, |
141 base::FilePath path); | 140 base::FilePath path); |
142 | 141 |
143 // Callback after checking OOBE date; launch client if appropriate. | 142 // Callback after checking OOBE date; launch client if appropriate. |
144 void OnDaysSinceOobeReceived( | 143 void OnDaysSinceOobeReceived( |
145 int64_t product_id, | 144 int64_t product_id, |
146 const RequestFinishedCallback& on_request_finished, | 145 const RequestFinishedCallback& on_request_finished, |
147 int days_since_oobe); | 146 int days_since_oobe); |
148 | 147 |
149 // Create and start a client to download file. | 148 // Create and start a client to download file. |
150 void CreateClient(int64_t product_id, | 149 void CreateClient(int64_t product_id, |
151 const RequestFinishedCallback& on_request_finished); | 150 const RequestFinishedCallback& on_request_finished); |
152 | 151 |
153 // Whether downloads allowed by cmd line flag and device policy. | 152 // Whether downloads allowed by cmd line flag and device policy. |
154 bool QuirksEnabled(); | 153 bool QuirksEnabled(); |
155 | 154 |
156 // Records time of most recent server check. | 155 // Records time of most recent server check. |
157 void SetLastServerCheck(int64_t product_id, const base::Time& last_check); | 156 void SetLastServerCheck(int64_t product_id, const base::Time& last_check); |
158 | 157 |
159 // Set of active clients, each created to download a different Quirks file. | 158 // Set of active clients, each created to download a different Quirks file. |
160 std::set<scoped_ptr<QuirksClient>> clients_; | 159 std::set<std::unique_ptr<QuirksClient>> clients_; |
161 | 160 |
162 // Don't start downloads before first session login. | 161 // Don't start downloads before first session login. |
163 bool waiting_for_login_; | 162 bool waiting_for_login_; |
164 | 163 |
165 // Ensure this class runs on a single thread. | 164 // Ensure this class runs on a single thread. |
166 base::ThreadChecker thread_checker_; | 165 base::ThreadChecker thread_checker_; |
167 | 166 |
168 // These objects provide resources from the browser. | 167 // These objects provide resources from the browser. |
169 scoped_ptr<Delegate> delegate_; // Impl runs from chrome/browser. | 168 std::unique_ptr<Delegate> delegate_; // Impl runs from chrome/browser. |
170 scoped_refptr<base::SequencedWorkerPool> blocking_pool_; | 169 scoped_refptr<base::SequencedWorkerPool> blocking_pool_; |
171 PrefService* local_state_; // For local prefs. | 170 PrefService* local_state_; // For local prefs. |
172 scoped_refptr<net::URLRequestContextGetter> url_context_getter_; | 171 scoped_refptr<net::URLRequestContextGetter> url_context_getter_; |
173 | 172 |
174 FakeQuirksFetcherCreator fake_quirks_fetcher_creator_; // For tests. | 173 FakeQuirksFetcherCreator fake_quirks_fetcher_creator_; // For tests. |
175 | 174 |
176 // Factory for callbacks. | 175 // Factory for callbacks. |
177 base::WeakPtrFactory<QuirksManager> weak_ptr_factory_; | 176 base::WeakPtrFactory<QuirksManager> weak_ptr_factory_; |
178 | 177 |
179 DISALLOW_COPY_AND_ASSIGN(QuirksManager); | 178 DISALLOW_COPY_AND_ASSIGN(QuirksManager); |
180 }; | 179 }; |
181 | 180 |
182 } // namespace quirks | 181 } // namespace quirks |
183 | 182 |
184 #endif // COMPONENTS_QUIRKS_QUIRKS_MANAGER_H_ | 183 #endif // COMPONENTS_QUIRKS_QUIRKS_MANAGER_H_ |
OLD | NEW |