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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 bool shouldVerifyAnyPathsResult) { | 191 bool shouldVerifyAnyPathsResult) { |
181 if (shouldVerifyAnyPathsResult) | 192 if (shouldVerifyAnyPathsResult) |
182 delegate_->VerifyFailed(extension_id, ContentVerifyJob::MISSING_ALL_HASHES); | 193 delegate_->VerifyFailed(extension_id, ContentVerifyJob::MISSING_ALL_HASHES); |
183 } | 194 } |
184 | 195 |
185 void ContentVerifier::OnFetchComplete( | 196 void ContentVerifier::OnFetchComplete( |
186 const std::string& extension_id, | 197 const std::string& extension_id, |
187 bool success, | 198 bool success, |
188 bool was_force_check, | 199 bool was_force_check, |
189 const std::set<base::FilePath>& hash_mismatch_paths) { | 200 const std::set<base::FilePath>& hash_mismatch_paths) { |
| 201 if (g_test_observer) |
| 202 g_test_observer->OnFetchComplete(extension_id, success); |
| 203 |
190 if (shutdown_) | 204 if (shutdown_) |
191 return; | 205 return; |
192 | 206 |
193 VLOG(1) << "OnFetchComplete " << extension_id << " success:" << success; | 207 VLOG(1) << "OnFetchComplete " << extension_id << " success:" << success; |
194 | 208 |
195 ExtensionRegistry* registry = ExtensionRegistry::Get(context_); | 209 ExtensionRegistry* registry = ExtensionRegistry::Get(context_); |
196 const Extension* extension = | 210 const Extension* extension = |
197 registry->GetExtensionById(extension_id, ExtensionRegistry::EVERYTHING); | 211 registry->GetExtensionById(extension_id, ExtensionRegistry::EVERYTHING); |
198 if (!delegate_ || !extension) | 212 if (!delegate_ || !extension) |
199 return; | 213 return; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 !extension_l10n_util::ShouldSkipValidation( | 275 !extension_l10n_util::ShouldSkipValidation( |
262 locales_dir, full_path.DirName(), *all_locales)) | 276 locales_dir, full_path.DirName(), *all_locales)) |
263 continue; | 277 continue; |
264 } | 278 } |
265 return true; | 279 return true; |
266 } | 280 } |
267 return false; | 281 return false; |
268 } | 282 } |
269 | 283 |
270 } // namespace extensions | 284 } // namespace extensions |
OLD | NEW |