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