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

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

Issue 1775023002: Enterprise policy to prevent queries to the Quirks Server (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix display unit test Created 4 years, 8 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
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 #include "components/quirks/quirks_manager.h" 5 #include "components/quirks/quirks_manager.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 25 matching lines...) Expand all
36 // Check if file exists, VLOG results. 36 // Check if file exists, VLOG results.
37 bool CheckAndLogFile(const base::FilePath& path) { 37 bool CheckAndLogFile(const base::FilePath& path) {
38 const bool exists = base::PathExists(path); 38 const bool exists = base::PathExists(path);
39 VLOG(1) << (exists ? "File" : "No File") << " found at " << path.value(); 39 VLOG(1) << (exists ? "File" : "No File") << " found at " << path.value();
40 // TODO(glevin): If file exists, do we want to implement a hash to verify that 40 // TODO(glevin): If file exists, do we want to implement a hash to verify that
41 // the file hasn't been corrupted or tampered with? 41 // the file hasn't been corrupted or tampered with?
42 return exists; 42 return exists;
43 } 43 }
44 44
45 base::FilePath CheckForIccFile(base::FilePath built_in_path, 45 base::FilePath CheckForIccFile(base::FilePath built_in_path,
46 base::FilePath download_path) { 46 base::FilePath download_path,
47 bool quirks_enabled) {
47 // First, look for icc file in old read-only location. If there, we don't use 48 // First, look for icc file in old read-only location. If there, we don't use
48 // the Quirks server. 49 // the Quirks server.
49 // TODO(glevin): Awaiting final decision on how to handle old read-only files. 50 // TODO(glevin): Awaiting final decision on how to handle old read-only files.
50 if (CheckAndLogFile(built_in_path)) 51 if (CheckAndLogFile(built_in_path))
51 return built_in_path; 52 return built_in_path;
52 53
53 // If experimental Quirks flag isn't set, no other icc file is available. 54 // If experimental Quirks flag isn't set, no other icc file is available.
54 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( 55 if (!quirks_enabled) {
55 switches::kEnableQuirksClient)) {
56 VLOG(1) << "Quirks Client disabled, no built-in icc file available."; 56 VLOG(1) << "Quirks Client disabled, no built-in icc file available.";
57 return base::FilePath(); 57 return base::FilePath();
58 } 58 }
59 59
60 // Check if QuirksClient has already downloaded icc file from server. 60 // Check if QuirksClient has already downloaded icc file from server.
61 if (CheckAndLogFile(download_path)) 61 if (CheckAndLogFile(download_path))
62 return download_path; 62 return download_path;
63 63
64 return base::FilePath(); 64 return base::FilePath();
65 } 65 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 void QuirksManager::RegisterPrefs(PrefRegistrySimple* registry) { 119 void QuirksManager::RegisterPrefs(PrefRegistrySimple* registry) {
120 registry->RegisterDictionaryPref(prefs::kQuirksClientLastServerCheck); 120 registry->RegisterDictionaryPref(prefs::kQuirksClientLastServerCheck);
121 } 121 }
122 122
123 // Delay downloads until after login, to ensure that device policy has been set. 123 // Delay downloads until after login, to ensure that device policy has been set.
124 void QuirksManager::OnLoginCompleted() { 124 void QuirksManager::OnLoginCompleted() {
125 if (!waiting_for_login_) 125 if (!waiting_for_login_)
126 return; 126 return;
127 127
128 waiting_for_login_ = false; 128 waiting_for_login_ = false;
129 if (!QuirksEnabled()) {
130 VLOG(1) << "Quirks Client disabled by device policy.";
131 return;
132 }
133
129 for (const scoped_ptr<QuirksClient>& client : clients_) 134 for (const scoped_ptr<QuirksClient>& client : clients_)
130 client->StartDownload(); 135 client->StartDownload();
131 } 136 }
132 137
133 void QuirksManager::RequestIccProfilePath( 138 void QuirksManager::RequestIccProfilePath(
134 int64_t product_id, 139 int64_t product_id,
135 const RequestFinishedCallback& on_request_finished) { 140 const RequestFinishedCallback& on_request_finished) {
136 DCHECK(thread_checker_.CalledOnValidThread()); 141 DCHECK(thread_checker_.CalledOnValidThread());
137 142
138 std::string name = IdToFileName(product_id); 143 std::string name = IdToFileName(product_id);
139 base::PostTaskAndReplyWithResult( 144 base::PostTaskAndReplyWithResult(
140 blocking_pool_.get(), FROM_HERE, 145 blocking_pool_.get(), FROM_HERE,
141 base::Bind(&CheckForIccFile, 146 base::Bind(&CheckForIccFile,
142 delegate_->GetBuiltInDisplayProfileDirectory().Append(name), 147 delegate_->GetBuiltInDisplayProfileDirectory().Append(name),
143 delegate_->GetDownloadDisplayProfileDirectory().Append(name)), 148 delegate_->GetDownloadDisplayProfileDirectory().Append(name),
149 QuirksEnabled()),
144 base::Bind(&QuirksManager::OnIccFilePathRequestCompleted, 150 base::Bind(&QuirksManager::OnIccFilePathRequestCompleted,
145 weak_ptr_factory_.GetWeakPtr(), product_id, 151 weak_ptr_factory_.GetWeakPtr(), product_id,
146 on_request_finished)); 152 on_request_finished));
147 } 153 }
148 154
149 void QuirksManager::ClientFinished(QuirksClient* client) { 155 void QuirksManager::ClientFinished(QuirksClient* client) {
150 DCHECK(thread_checker_.CalledOnValidThread()); 156 DCHECK(thread_checker_.CalledOnValidThread());
151 SetLastServerCheck(client->product_id(), base::Time::Now()); 157 SetLastServerCheck(client->product_id(), base::Time::Now());
152 auto it = std::find_if(clients_.begin(), clients_.end(), 158 auto it = std::find_if(clients_.begin(), clients_.end(),
153 [client](const scoped_ptr<QuirksClient>& c) { 159 [client](const scoped_ptr<QuirksClient>& c) {
(...skipping 12 matching lines...) Expand all
166 return net::URLFetcher::Create(url, net::URLFetcher::GET, delegate); 172 return net::URLFetcher::Create(url, net::URLFetcher::GET, delegate);
167 } 173 }
168 174
169 void QuirksManager::OnIccFilePathRequestCompleted( 175 void QuirksManager::OnIccFilePathRequestCompleted(
170 int64_t product_id, 176 int64_t product_id,
171 const RequestFinishedCallback& on_request_finished, 177 const RequestFinishedCallback& on_request_finished,
172 base::FilePath path) { 178 base::FilePath path) {
173 DCHECK(thread_checker_.CalledOnValidThread()); 179 DCHECK(thread_checker_.CalledOnValidThread());
174 180
175 // If we found a file or client is disabled, inform requester. 181 // If we found a file or client is disabled, inform requester.
176 if (!path.empty() || 182 if (!path.empty() || !QuirksEnabled()) {
177 !base::CommandLine::ForCurrentProcess()->HasSwitch(
178 switches::kEnableQuirksClient)) {
179 on_request_finished.Run(path, false); 183 on_request_finished.Run(path, false);
180 // TODO(glevin): If Quirks files are ever modified on the server, we'll need 184 // TODO(glevin): If Quirks files are ever modified on the server, we'll need
181 // to modify this logic to check for updates. See crbug.com/595024. 185 // to modify this logic to check for updates. See crbug.com/595024.
182 return; 186 return;
183 } 187 }
184 188
185 double last_check = 0.0; 189 double last_check = 0.0;
186 local_state_->GetDictionary(prefs::kQuirksClientLastServerCheck) 190 local_state_->GetDictionary(prefs::kQuirksClientLastServerCheck)
187 ->GetDouble(IdToHexString(product_id), &last_check); 191 ->GetDouble(IdToHexString(product_id), &last_check);
188 192
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 DCHECK(thread_checker_.CalledOnValidThread()); 244 DCHECK(thread_checker_.CalledOnValidThread());
241 QuirksClient* client = 245 QuirksClient* client =
242 new QuirksClient(product_id, on_request_finished, this); 246 new QuirksClient(product_id, on_request_finished, this);
243 clients_.insert(make_scoped_ptr(client)); 247 clients_.insert(make_scoped_ptr(client));
244 if (!waiting_for_login_) 248 if (!waiting_for_login_)
245 client->StartDownload(); 249 client->StartDownload();
246 else 250 else
247 VLOG(2) << "Quirks Client created; waiting for login to begin download."; 251 VLOG(2) << "Quirks Client created; waiting for login to begin download.";
248 } 252 }
249 253
254 bool QuirksManager::QuirksEnabled() {
255 return base::CommandLine::ForCurrentProcess()->HasSwitch(
256 switches::kEnableQuirksClient) &&
257 delegate_->DevicePolicyEnabled();
258 }
259
250 void QuirksManager::SetLastServerCheck(int64_t product_id, 260 void QuirksManager::SetLastServerCheck(int64_t product_id,
251 const base::Time& last_check) { 261 const base::Time& last_check) {
252 DCHECK(thread_checker_.CalledOnValidThread()); 262 DCHECK(thread_checker_.CalledOnValidThread());
253 DictionaryPrefUpdate dict(local_state_, prefs::kQuirksClientLastServerCheck); 263 DictionaryPrefUpdate dict(local_state_, prefs::kQuirksClientLastServerCheck);
254 dict->SetDouble(IdToHexString(product_id), last_check.ToDoubleT()); 264 dict->SetDouble(IdToHexString(product_id), last_check.ToDoubleT());
255 } 265 }
256 266
257 } // namespace quirks 267 } // namespace quirks
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698