| 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 #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/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 VLOG(2) << clients_.size() << " client(s) deleted."; | 107 VLOG(2) << clients_.size() << " client(s) deleted."; |
| 108 clients_.clear(); | 108 clients_.clear(); |
| 109 } | 109 } |
| 110 | 110 |
| 111 for (const std::unique_ptr<QuirksClient>& client : clients_) | 111 for (const std::unique_ptr<QuirksClient>& client : clients_) |
| 112 client->StartDownload(); | 112 client->StartDownload(); |
| 113 } | 113 } |
| 114 | 114 |
| 115 void QuirksManager::RequestIccProfilePath( | 115 void QuirksManager::RequestIccProfilePath( |
| 116 int64_t product_id, | 116 int64_t product_id, |
| 117 const std::string& display_name, |
| 117 const RequestFinishedCallback& on_request_finished) { | 118 const RequestFinishedCallback& on_request_finished) { |
| 118 DCHECK(thread_checker_.CalledOnValidThread()); | 119 DCHECK(thread_checker_.CalledOnValidThread()); |
| 119 | 120 |
| 120 if (!QuirksEnabled()) { | 121 if (!QuirksEnabled()) { |
| 121 VLOG(1) << "Quirks Client disabled."; | 122 VLOG(1) << "Quirks Client disabled."; |
| 122 on_request_finished.Run(base::FilePath(), false); | 123 on_request_finished.Run(base::FilePath(), false); |
| 123 return; | 124 return; |
| 124 } | 125 } |
| 125 | 126 |
| 126 if (!product_id) { | 127 if (!product_id) { |
| 127 VLOG(1) << "Could not determine display information (product id = 0)"; | 128 VLOG(1) << "Could not determine display information (product id = 0)"; |
| 128 on_request_finished.Run(base::FilePath(), false); | 129 on_request_finished.Run(base::FilePath(), false); |
| 129 return; | 130 return; |
| 130 } | 131 } |
| 131 | 132 |
| 132 std::string name = IdToFileName(product_id); | 133 std::string name = IdToFileName(product_id); |
| 133 base::PostTaskAndReplyWithResult( | 134 base::PostTaskAndReplyWithResult( |
| 134 blocking_pool_.get(), FROM_HERE, | 135 blocking_pool_.get(), FROM_HERE, |
| 135 base::Bind(&CheckForIccFile, | 136 base::Bind(&CheckForIccFile, |
| 136 delegate_->GetDisplayProfileDirectory().Append(name)), | 137 delegate_->GetDisplayProfileDirectory().Append(name)), |
| 137 base::Bind(&QuirksManager::OnIccFilePathRequestCompleted, | 138 base::Bind(&QuirksManager::OnIccFilePathRequestCompleted, |
| 138 weak_ptr_factory_.GetWeakPtr(), product_id, | 139 weak_ptr_factory_.GetWeakPtr(), product_id, display_name, |
| 139 on_request_finished)); | 140 on_request_finished)); |
| 140 } | 141 } |
| 141 | 142 |
| 142 void QuirksManager::ClientFinished(QuirksClient* client) { | 143 void QuirksManager::ClientFinished(QuirksClient* client) { |
| 143 DCHECK(thread_checker_.CalledOnValidThread()); | 144 DCHECK(thread_checker_.CalledOnValidThread()); |
| 144 SetLastServerCheck(client->product_id(), base::Time::Now()); | 145 SetLastServerCheck(client->product_id(), base::Time::Now()); |
| 145 auto it = std::find_if(clients_.begin(), clients_.end(), | 146 auto it = std::find_if(clients_.begin(), clients_.end(), |
| 146 [client](const std::unique_ptr<QuirksClient>& c) { | 147 [client](const std::unique_ptr<QuirksClient>& c) { |
| 147 return c.get() == client; | 148 return c.get() == client; |
| 148 }); | 149 }); |
| 149 CHECK(it != clients_.end()); | 150 CHECK(it != clients_.end()); |
| 150 clients_.erase(it); | 151 clients_.erase(it); |
| 151 } | 152 } |
| 152 | 153 |
| 153 std::unique_ptr<net::URLFetcher> QuirksManager::CreateURLFetcher( | 154 std::unique_ptr<net::URLFetcher> QuirksManager::CreateURLFetcher( |
| 154 const GURL& url, | 155 const GURL& url, |
| 155 net::URLFetcherDelegate* delegate) { | 156 net::URLFetcherDelegate* delegate) { |
| 156 if (!fake_quirks_fetcher_creator_.is_null()) | 157 if (!fake_quirks_fetcher_creator_.is_null()) |
| 157 return fake_quirks_fetcher_creator_.Run(url, delegate); | 158 return fake_quirks_fetcher_creator_.Run(url, delegate); |
| 158 | 159 |
| 159 return net::URLFetcher::Create(url, net::URLFetcher::GET, delegate); | 160 return net::URLFetcher::Create(url, net::URLFetcher::GET, delegate); |
| 160 } | 161 } |
| 161 | 162 |
| 162 void QuirksManager::OnIccFilePathRequestCompleted( | 163 void QuirksManager::OnIccFilePathRequestCompleted( |
| 163 int64_t product_id, | 164 int64_t product_id, |
| 165 const std::string& display_name, |
| 164 const RequestFinishedCallback& on_request_finished, | 166 const RequestFinishedCallback& on_request_finished, |
| 165 base::FilePath path) { | 167 base::FilePath path) { |
| 166 DCHECK(thread_checker_.CalledOnValidThread()); | 168 DCHECK(thread_checker_.CalledOnValidThread()); |
| 167 | 169 |
| 168 // If we found a file, just inform requester. | 170 // If we found a file, just inform requester. |
| 169 if (!path.empty()) { | 171 if (!path.empty()) { |
| 170 on_request_finished.Run(path, false); | 172 on_request_finished.Run(path, false); |
| 171 // TODO(glevin): If Quirks files are ever modified on the server, we'll need | 173 // TODO(glevin): If Quirks files are ever modified on the server, we'll need |
| 172 // to modify this logic to check for updates. See crbug.com/595024. | 174 // to modify this logic to check for updates. See crbug.com/595024. |
| 173 return; | 175 return; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 184 if (time_since < base::TimeDelta::FromDays(kDaysBetweenServerChecks)) { | 186 if (time_since < base::TimeDelta::FromDays(kDaysBetweenServerChecks)) { |
| 185 VLOG(2) << time_since.InDays() | 187 VLOG(2) << time_since.InDays() |
| 186 << " days since last Quirks Server check for display " | 188 << " days since last Quirks Server check for display " |
| 187 << IdToHexString(product_id); | 189 << IdToHexString(product_id); |
| 188 on_request_finished.Run(base::FilePath(), false); | 190 on_request_finished.Run(base::FilePath(), false); |
| 189 return; | 191 return; |
| 190 } | 192 } |
| 191 | 193 |
| 192 // Create and start a client to download file. | 194 // Create and start a client to download file. |
| 193 QuirksClient* client = | 195 QuirksClient* client = |
| 194 new QuirksClient(product_id, on_request_finished, this); | 196 new QuirksClient(product_id, display_name, on_request_finished, this); |
| 195 clients_.insert(base::WrapUnique(client)); | 197 clients_.insert(base::WrapUnique(client)); |
| 196 if (!waiting_for_login_) | 198 if (!waiting_for_login_) |
| 197 client->StartDownload(); | 199 client->StartDownload(); |
| 198 else | 200 else |
| 199 VLOG(2) << "Quirks Client created; waiting for login to begin download."; | 201 VLOG(2) << "Quirks Client created; waiting for login to begin download."; |
| 200 } | 202 } |
| 201 | 203 |
| 202 bool QuirksManager::QuirksEnabled() { | 204 bool QuirksManager::QuirksEnabled() { |
| 203 if (!delegate_->DevicePolicyEnabled()) { | 205 if (!delegate_->DevicePolicyEnabled()) { |
| 204 VLOG(2) << "Quirks Client disabled by device policy."; | 206 VLOG(2) << "Quirks Client disabled by device policy."; |
| 205 return false; | 207 return false; |
| 206 } | 208 } |
| 207 return true; | 209 return true; |
| 208 } | 210 } |
| 209 | 211 |
| 210 void QuirksManager::SetLastServerCheck(int64_t product_id, | 212 void QuirksManager::SetLastServerCheck(int64_t product_id, |
| 211 const base::Time& last_check) { | 213 const base::Time& last_check) { |
| 212 DCHECK(thread_checker_.CalledOnValidThread()); | 214 DCHECK(thread_checker_.CalledOnValidThread()); |
| 213 DictionaryPrefUpdate dict(local_state_, prefs::kQuirksClientLastServerCheck); | 215 DictionaryPrefUpdate dict(local_state_, prefs::kQuirksClientLastServerCheck); |
| 214 dict->SetDouble(IdToHexString(product_id), last_check.ToDoubleT()); | 216 dict->SetDouble(IdToHexString(product_id), last_check.ToDoubleT()); |
| 215 } | 217 } |
| 216 | 218 |
| 217 } // namespace quirks | 219 } // namespace quirks |
| OLD | NEW |