| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/feedback/system_logs/system_logs_fetcher.h" | 5 #include "chrome/browser/feedback/system_logs/system_logs_fetcher.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
| 13 | 13 |
| 14 using content::BrowserThread; | 14 using content::BrowserThread; |
| 15 | 15 |
| 16 namespace system_logs { | 16 namespace system_logs { |
| 17 | 17 |
| 18 namespace { |
| 19 |
| 20 // List of keys in the SystemLogsResponse map whose corresponding values will |
| 21 // not be anonymized. |
| 22 constexpr const char* const kWhitelistedKeysOfUUIDs[] = { |
| 23 "CHROMEOS_BOARD_APPID", |
| 24 "CHROMEOS_CANARY_APPID", |
| 25 "CHROMEOS_RELEASE_APPID", |
| 26 "CLIENT_ID", |
| 27 }; |
| 28 |
| 29 // Returns true if the given |key| is anonymizer-whitelisted and whose |
| 30 // corresponding value should not be anonymized. |
| 31 bool IsKeyWhitelisted(const std::string& key) { |
| 32 for (auto* const whitelisted_key : kWhitelistedKeysOfUUIDs) { |
| 33 if (key == whitelisted_key) |
| 34 return true; |
| 35 } |
| 36 return false; |
| 37 } |
| 38 |
| 39 } // namespace |
| 40 |
| 18 SystemLogsSource::SystemLogsSource(const std::string& source_name) | 41 SystemLogsSource::SystemLogsSource(const std::string& source_name) |
| 19 : source_name_(source_name) {} | 42 : source_name_(source_name) {} |
| 20 | 43 |
| 21 SystemLogsSource::~SystemLogsSource() {} | 44 SystemLogsSource::~SystemLogsSource() {} |
| 22 | 45 |
| 23 SystemLogsFetcher::SystemLogsFetcher(bool scrub_data) | 46 SystemLogsFetcher::SystemLogsFetcher(bool scrub_data) |
| 24 : response_(base::MakeUnique<SystemLogsResponse>()), | 47 : response_(base::MakeUnique<SystemLogsResponse>()), |
| 25 num_pending_requests_(0), | 48 num_pending_requests_(0), |
| 26 weak_ptr_factory_(this) { | 49 weak_ptr_factory_(this) { |
| 27 if (scrub_data) | 50 if (scrub_data) |
| (...skipping 21 matching lines...) Expand all Loading... |
| 49 } | 72 } |
| 50 } | 73 } |
| 51 | 74 |
| 52 void SystemLogsFetcher::OnFetched(const std::string& source_name, | 75 void SystemLogsFetcher::OnFetched(const std::string& source_name, |
| 53 SystemLogsResponse* response) { | 76 SystemLogsResponse* response) { |
| 54 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 77 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 55 | 78 |
| 56 VLOG(1) << "Received SystemLogSource: " << source_name; | 79 VLOG(1) << "Received SystemLogSource: " << source_name; |
| 57 | 80 |
| 58 if (anonymizer_) { | 81 if (anonymizer_) { |
| 59 for (auto& element : *response) | 82 for (auto& element : *response) { |
| 60 element.second = anonymizer_->Anonymize(element.second); | 83 if (!IsKeyWhitelisted(element.first)) |
| 84 element.second = anonymizer_->Anonymize(element.second); |
| 85 } |
| 61 } | 86 } |
| 62 AddResponse(source_name, response); | 87 AddResponse(source_name, response); |
| 63 } | 88 } |
| 64 | 89 |
| 65 void SystemLogsFetcher::AddResponse(const std::string& source_name, | 90 void SystemLogsFetcher::AddResponse(const std::string& source_name, |
| 66 SystemLogsResponse* response) { | 91 SystemLogsResponse* response) { |
| 67 for (const auto& it : *response) { | 92 for (const auto& it : *response) { |
| 68 // An element with a duplicate key would not be successfully inserted. | 93 // An element with a duplicate key would not be successfully inserted. |
| 69 bool ok = response_->emplace(it).second; | 94 bool ok = response_->emplace(it).second; |
| 70 DCHECK(ok) << "Duplicate key found: " << it.first; | 95 DCHECK(ok) << "Duplicate key found: " << it.first; |
| 71 } | 96 } |
| 72 | 97 |
| 73 --num_pending_requests_; | 98 --num_pending_requests_; |
| 74 if (num_pending_requests_ > 0) | 99 if (num_pending_requests_ > 0) |
| 75 return; | 100 return; |
| 76 | 101 |
| 77 callback_.Run(std::move(response_)); | 102 callback_.Run(std::move(response_)); |
| 78 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this); | 103 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this); |
| 79 } | 104 } |
| 80 | 105 |
| 81 } // namespace system_logs | 106 } // namespace system_logs |
| OLD | NEW |