Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(523)

Side by Side Diff: components/quirks/quirks_manager.h

Issue 1528963002: Quirks Client for downloading and providing display profiles (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Minor review fixes, delay download until after login Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/memory/weak_ptr.h"
14 #include "base/time/time.h"
15 #include "components/quirks/quirks_client.h"
16 #include "components/quirks/quirks_export.h"
17
18 class GURL;
19 class PrefRegistrySimple;
20 class PrefService;
21
22 namespace base {
23 class SequencedWorkerPool;
24 class SingleThreadTaskRunner;
25 }
26
27 namespace net {
28 class URLFetcher;
29 class URLFetcherDelegate;
30 class URLRequestContextGetter;
31 }
32
33 namespace quirks {
34
35 // Format int as hex string for filename.
36 QUIRKS_EXPORT std::string IdToHexString(int64_t product_id);
37
38 // Append ".icc" to hex string in filename.
39 QUIRKS_EXPORT std::string IdToFileName(int64_t product_id);
40
41 // Finds icc file, if it exists; creates and starts QuirksClient if it doesn't.
42 // In all cases, sends results to provided callback.
43 QUIRKS_EXPORT void RequestIccProfilePath(
44 int64_t product_id,
45 const RequestFinishedCallback& on_request_finished);
46
47 // Handles needed components from browser (local preferences, url context
48 // getter, blocking pool, etc).
49 class QUIRKS_EXPORT QuirksManager {
50 public:
51 using FakeQuirksFetcherCreator =
52 base::Callback<scoped_ptr<net::URLFetcher>(const GURL&,
53 net::URLFetcherDelegate*)>;
54
55 using DaysSinceOobeCallback = base::Callback<void(int)>;
56
57 // Delegate class, so implementation can access browser functionality.
58 class Delegate {
59 public:
60 virtual ~Delegate() = default;
61
62 // Provides Chrome API key for quirks server.
63 virtual std::string GetApiKey() const = 0;
64
65 // Returns the read-only directory where icc files were added before the
66 // Quirks Client provided them.
67 virtual base::FilePath GetBuiltInDisplayProfileDirectory() const = 0;
68
69 // Returns the path to the writable display profile directory.
70 // This directory must already exist.
71 virtual base::FilePath GetDownloadDisplayProfileDirectory() const = 0;
72
73 // Gets days since first login, returns via callback.
74 virtual void GetDaysSinceOobe(DaysSinceOobeCallback callback) const = 0;
75
76 private:
77 DISALLOW_ASSIGN(Delegate);
78 };
79
80 static void Initialize(
81 scoped_ptr<Delegate> delegate,
82 scoped_refptr<base::SequencedWorkerPool> blocking_pool,
83 PrefService* local_state,
84 scoped_refptr<net::URLRequestContextGetter> url_context_getter);
85 static void Shutdown();
86 static void OnLoginCompleted(); // Start queued downloads after login.
stevenjb 2016/03/10 19:29:31 I think this would be a little more clear as a mem
Greg Levin 2016/03/15 18:12:57 Done. Also made RequestIccProfilePath() a member.
87 static QuirksManager* Get();
88
89 static void RegisterPrefs(PrefRegistrySimple* registry);
90
91 // Entry point into manager. Finds or downloads icc file.
92 void RequestIccFilePath(int64_t product_id,
93 const RequestFinishedCallback& on_request_finished);
94
95 void ClientFinished(QuirksClient* client);
96
97 // UMA stats for server check reason and results.
98 void RecordReasonUmaStat(QuirksClient::RequestReason reason);
99 void RecordFileFoundUmaStat(bool success);
100
101 // Creates a real URLFetcher for OS, and a fake one for tests.
102 scoped_ptr<net::URLFetcher> CreateURLFetcher(
103 const std::string& url,
104 net::URLFetcherDelegate* delegate);
105
106 Delegate* delegate() const { return delegate_.get(); }
107 base::SequencedWorkerPool* blocking_pool() const {
108 return blocking_pool_.get();
109 }
110
111 net::URLRequestContextGetter* url_context_getter() const {
112 return url_context_getter_.get();
113 }
114
115 protected:
116 friend class QuirksBrowserTest;
117
118 void SetFakeQuirksFetcherCreatorForTests(
119 const FakeQuirksFetcherCreator& creator) {
120 fake_quirks_fetcher_creator_ = creator;
121 }
122
123 private:
124 QuirksManager(scoped_ptr<Delegate> delegate,
125 scoped_refptr<base::SequencedWorkerPool> blocking_pool,
126 PrefService* local_state,
127 scoped_refptr<net::URLRequestContextGetter> url_context_getter);
128 ~QuirksManager();
129
130 // Callback after checking for existing icc file; proceed if not found.
131 void OnIccFilePathRequestCompleted(
132 int64_t product_id,
133 const RequestFinishedCallback& on_request_finished,
134 base::FilePath path);
135
136 // Callback after checking OOBE date; launch client if appropriate.
137 void OnDaysSinceOobeReceived(
138 int64_t product_id,
139 const RequestFinishedCallback& on_request_finished,
140 int days_since_oobe);
141
142 // Create and start a client to download file.
143 void CreateClient(int64_t product_id,
144 const RequestFinishedCallback& on_request_finished);
145
146 // Records time of most recent server check.
147 void SetLastServerCheck(int64_t product_id, const base::Time& last_check);
148
149 std::set<scoped_ptr<QuirksClient>> clients_;
150 bool waiting_for_login_; // Don't start downloads before first session login.
151
152 // These objects provide resources from the browser.
153 scoped_ptr<Delegate> delegate_; // Impl runs from chrome/browser.
154 scoped_refptr<base::SequencedWorkerPool> blocking_pool_;
155 PrefService* local_state_; // For local prefs.
156 scoped_refptr<net::URLRequestContextGetter> url_context_getter_;
157
158 FakeQuirksFetcherCreator fake_quirks_fetcher_creator_; // For tests.
159
160 // Factory for callbacks.
161 base::WeakPtrFactory<QuirksManager> weak_ptr_factory_;
162
163 DISALLOW_COPY_AND_ASSIGN(QuirksManager);
164 };
165
166 } // namespace quirks
167
168 #endif // COMPONENTS_QUIRKS_QUIRKS_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698