OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/content_verifier.h" | 5 #include "extensions/browser/content_verifier.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
13 #include "extensions/browser/content_hash_fetcher.h" | 13 #include "extensions/browser/content_hash_fetcher.h" |
14 #include "extensions/browser/content_hash_reader.h" | 14 #include "extensions/browser/content_hash_reader.h" |
15 #include "extensions/browser/content_verifier_delegate.h" | 15 #include "extensions/browser/content_verifier_delegate.h" |
16 #include "extensions/browser/content_verifier_io_data.h" | 16 #include "extensions/browser/content_verifier_io_data.h" |
17 #include "extensions/browser/extension_registry.h" | 17 #include "extensions/browser/extension_registry.h" |
18 #include "extensions/common/constants.h" | 18 #include "extensions/common/constants.h" |
19 #include "extensions/common/extension_l10n_util.h" | 19 #include "extensions/common/extension_l10n_util.h" |
20 | 20 |
21 namespace extensions { | 21 namespace extensions { |
22 | 22 |
| 23 namespace { |
| 24 |
| 25 ContentVerifier::TestObserver* g_test_observer = NULL; |
| 26 |
| 27 } // namespace |
| 28 |
| 29 // static |
| 30 void ContentVerifier::SetObserverForTests(TestObserver* observer) { |
| 31 g_test_observer = observer; |
| 32 } |
| 33 |
23 ContentVerifier::ContentVerifier(content::BrowserContext* context, | 34 ContentVerifier::ContentVerifier(content::BrowserContext* context, |
24 ContentVerifierDelegate* delegate) | 35 ContentVerifierDelegate* delegate) |
25 : shutdown_(false), | 36 : shutdown_(false), |
26 context_(context), | 37 context_(context), |
27 delegate_(delegate), | 38 delegate_(delegate), |
28 fetcher_(new ContentHashFetcher( | 39 fetcher_(new ContentHashFetcher( |
29 context, | 40 context, |
30 delegate, | 41 delegate, |
31 base::Bind(&ContentVerifier::OnFetchComplete, this))), | 42 base::Bind(&ContentVerifier::OnFetchComplete, this))), |
32 observer_(this), | 43 observer_(this), |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 bool shouldVerifyAnyPathsResult) { | 192 bool shouldVerifyAnyPathsResult) { |
182 if (shouldVerifyAnyPathsResult) | 193 if (shouldVerifyAnyPathsResult) |
183 delegate_->VerifyFailed(extension_id, ContentVerifyJob::MISSING_ALL_HASHES); | 194 delegate_->VerifyFailed(extension_id, ContentVerifyJob::MISSING_ALL_HASHES); |
184 } | 195 } |
185 | 196 |
186 void ContentVerifier::OnFetchComplete( | 197 void ContentVerifier::OnFetchComplete( |
187 const std::string& extension_id, | 198 const std::string& extension_id, |
188 bool success, | 199 bool success, |
189 bool was_force_check, | 200 bool was_force_check, |
190 const std::set<base::FilePath>& hash_mismatch_paths) { | 201 const std::set<base::FilePath>& hash_mismatch_paths) { |
| 202 if (g_test_observer) |
| 203 g_test_observer->OnFetchComplete(extension_id, success); |
| 204 |
191 if (shutdown_) | 205 if (shutdown_) |
192 return; | 206 return; |
193 | 207 |
194 VLOG(1) << "OnFetchComplete " << extension_id << " success:" << success; | 208 VLOG(1) << "OnFetchComplete " << extension_id << " success:" << success; |
195 | 209 |
196 ExtensionRegistry* registry = ExtensionRegistry::Get(context_); | 210 ExtensionRegistry* registry = ExtensionRegistry::Get(context_); |
197 const Extension* extension = | 211 const Extension* extension = |
198 registry->GetExtensionById(extension_id, ExtensionRegistry::EVERYTHING); | 212 registry->GetExtensionById(extension_id, ExtensionRegistry::EVERYTHING); |
199 if (!delegate_ || !extension) | 213 if (!delegate_ || !extension) |
200 return; | 214 return; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 !extension_l10n_util::ShouldSkipValidation( | 276 !extension_l10n_util::ShouldSkipValidation( |
263 locales_dir, full_path.DirName(), *all_locales)) | 277 locales_dir, full_path.DirName(), *all_locales)) |
264 continue; | 278 continue; |
265 } | 279 } |
266 return true; | 280 return true; |
267 } | 281 } |
268 return false; | 282 return false; |
269 } | 283 } |
270 | 284 |
271 } // namespace extensions | 285 } // namespace extensions |
OLD | NEW |