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

Side by Side Diff: components/quirks_client/quirks_client.h

Issue 1528963002: Quirks Client for downloading and providing display profiles (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Refactor manager and delegate Created 4 years, 10 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 (c) 2015 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_CLIENT_QUIRKS_CLIENT_H_
6 #define COMPONENTS_QUIRKS_CLIENT_QUIRKS_CLIENT_H_
7
8 #include "base/files/file_path.h"
9 #include "base/macros.h"
10 #include "base/time/time.h"
11 #include "base/timer/timer.h"
12 #include "components/quirks_client/quirks_client_export.h"
13 #include "net/url_request/url_fetcher_delegate.h"
14
15 class PrefRegistrySimple;
16 class PrefService;
17
18 namespace base {
19 class SequencedWorkerPool;
20 class MessageLoopForUI;
21 }
22
23 namespace net {
24 class URLRequestContextGetter;
25 }
26
27 namespace quirks_client {
28
29 // Handles providing data from icc and other display data files. This may
30 // involve downloading and storing files from the Quirks Server, or serving
31 // these files from local, writable storage.
32 class QUIRKS_CLIENT_EXPORT QuirksClient : public net::URLFetcherDelegate {
33 public:
34 typedef base::Callback<void(base::FilePath)> DownloadFinishedCallback;
35
36 enum RequestReason {
37 FIRST, // Device's first server request.
38 RETRY, // Has server file been added since last check?
39 UPDATE // Has server file been updated since last check?
40 };
41
42 QuirksClient(int64_t product_id,
43 DownloadFinishedCallback* on_download_finished);
44 ~QuirksClient() override;
45
46 // Returns path to icc file, if it exists; creates and starts QuirksServer if
47 // it doesn't.
48 static base::FilePath RequestIccProfilePath(
49 int64_t product_id,
50 DownloadFinishedCallback* on_download_finished);
51
52 // Start download.
53 void Start();
oshima 2016/01/28 20:16:31 or StartDownload() and remove comment.
Greg Levin 2016/02/01 23:17:44 Done.
54
55 // TODO(glevin): Copied from wallpaper downloader. Are they needed? TBD.
56 // This is called in tests to modify (lower) retry delay.
stevenjb 2016/01/28 21:05:58 If we don't use these yet we should remove them un
Greg Levin 2016/02/01 23:17:44 Done.
57 void set_retry_delay_for_testing(base::TimeDelta value) {
58 retry_delay_ = value;
59 }
60
61 base::TimeDelta retry_current_delay_for_testing() const {
62 return retry_current_delay_;
63 }
64
65 private:
66 // Self deletion when done.
67 void Shutdown();
68
69 // Schedules retry.
70 void Retry();
71
72 // net::URLFetcherDelegate:
73 void OnURLFetchComplete(const net::URLFetcher* source) override;
74
75 // Write |data| to |file_path|.
76 static bool WriteIccFile(const base::FilePath file_path,
77 const std::string& data);
78
79 // Callback after icc write is finished.
80 void OnWriteIccFileFinished(bool success);
81
82 // Translate json with base64-encoded data (|result|) into raw |data|.
83 bool ParseResult(const std::string& result, std::string* data);
84
85 // ID of display to request from Quirks Server.
86 const int64_t product_id_;
87
88 // Callback supplied by caller.
89 const DownloadFinishedCallback* on_download_finished_;
90
91 // Full path to icc file.
92 const base::FilePath icc_path_;
93
94 // This fetcher is used to download icc file.
95 scoped_ptr<net::URLFetcher> url_fetcher_;
96
97 // Why are we making this server call?
98 RequestReason request_reason_;
99
100 // Pending retry.
101 base::OneShotTimer request_scheduled_;
102
103 // Number of download retries (first attempt is not counted as retry).
104 size_t retries_;
105
106 // TODO(glevin): Copied from wallpaper downloader. Are they needed? TBD.
107 // Sleep between retry requests (increasing, see Retry() method for details).
108 // Non-constant value for tests.
109 base::TimeDelta retry_delay_;
110
111 // Retry delay of the last attempt. For testing only.
112 base::TimeDelta retry_current_delay_;
113
114 // Factory for callbacks.
115 base::WeakPtrFactory<QuirksClient> weak_ptr_factory_;
116
117 DISALLOW_COPY_AND_ASSIGN(QuirksClient);
118 };
119
120 // Handles needed components from browser (local preferences, url context
121 // getter, message loops).
122 class QUIRKS_CLIENT_EXPORT QuirksClientManager {
oshima 2016/01/28 20:16:31 define this in a separate file.
Greg Levin 2016/02/01 23:17:43 Done.
123 public:
124 // Delegate class, so implementation can access browser functionality.
125 class Delegate {
126 public:
127 virtual ~Delegate() {};
128 virtual std::string api_key_quirks() = 0;
oshima 2016/01/28 20:16:31 GetApiKeyQuirks()
Greg Levin 2016/02/01 23:17:44 Done.
129 virtual base::FilePath GetDisplayProfileDirectory() = 0;
130 virtual int GetDaysSinceOobe() = 0;
oshima 2016/01/28 20:16:31 can/should these be const?(just asking)
Greg Levin 2016/02/01 23:17:44 Done.
131 };
stevenjb 2016/01/28 21:05:59 + private: DISALLOW_ASSIGN
Greg Levin 2016/02/01 23:17:44 Is this needed / desirable in a pure virtual class
132
133 QuirksClientManager(Delegate* delegate,
134 base::MessageLoopForUI* message_loop_ui,
135 base::SequencedWorkerPool* blocking_pool,
136 PrefService* local_state,
137 net::URLRequestContextGetter* url_context_getter);
138 virtual ~QuirksClientManager();
139
140 static void Initialize(QuirksClientManager* manager);
141 static void Shutdown();
142 static void RegisterPrefs(PrefRegistrySimple* registry);
143
144 void RunClient(int64_t product_id,
145 QuirksClient::DownloadFinishedCallback* on_download_finished);
146
147 base::Time GetLastServerCheck(int64_t product_id);
148 void SetLastServerCheck(int64_t product_id, base::Time last_check);
oshima 2016/01/28 20:16:31 const base::Time&
Greg Levin 2016/02/01 23:17:44 Done.
149 void RecordReasonUmaStat(QuirksClient::RequestReason reason);
150 void RecordFileFoundUmaStat(bool success);
151
152 Delegate* delegate() { return delegate_; }
153 base::MessageLoopForUI* message_loop_ui() { return message_loop_ui_; }
154 base::SequencedWorkerPool* blocking_pool() { return blocking_pool_; }
155 net::URLRequestContextGetter* url_context_getter() {
156 return url_context_getter_.get();
157 }
158
159 // Check that ui thread and message loop are ready.
160 bool Validate();
161
162 private:
163 // browser/ui thread components needed for client.
164 Delegate* delegate_; // Impl runs from browser.
165 base::MessageLoopForUI* message_loop_ui_; // To run QC on ui thread.
oshima 2016/01/28 20:16:31 do you need this? can't you just use ::current() ?
Greg Levin 2016/02/01 23:17:44 Do you mean base::MessageLoop::current()? From th
166 base::SequencedWorkerPool* blocking_pool_; // For url getter and file io.
167 PrefService* local_state_; // For local prefs.
168 bool is_new_device_; // Is within 30 days of OOBE?
169 // For URLFetcher.
170 scoped_refptr<net::URLRequestContextGetter> url_context_getter_;
171
172 DISALLOW_COPY_AND_ASSIGN(QuirksClientManager);
173 };
174
175 } // namespace chromeos
176
177 #endif // COMPONENTS_QUIRKS_CLIENT_QUIRKS_CLIENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698