| 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/extensions/install_signer.h" | 5 #include "chrome/browser/extensions/install_signer.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/base64.h" | 11 #include "base/base64.h" |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/json/json_reader.h" | 14 #include "base/json/json_reader.h" |
| 15 #include "base/json/json_writer.h" | 15 #include "base/json/json_writer.h" |
| 16 #include "base/lazy_instance.h" | 16 #include "base/lazy_instance.h" |
| 17 #include "base/macros.h" | 17 #include "base/macros.h" |
| 18 #include "base/memory/ptr_util.h" |
| 18 #include "base/message_loop/message_loop.h" | 19 #include "base/message_loop/message_loop.h" |
| 19 #include "base/metrics/histogram_macros.h" | 20 #include "base/metrics/histogram_macros.h" |
| 20 #include "base/process/process_info.h" | 21 #include "base/process/process_info.h" |
| 21 #include "base/stl_util.h" | 22 #include "base/stl_util.h" |
| 22 #include "base/strings/string_number_conversions.h" | 23 #include "base/strings/string_number_conversions.h" |
| 23 #include "base/strings/string_split.h" | 24 #include "base/strings/string_split.h" |
| 24 #include "base/strings/string_util.h" | 25 #include "base/strings/string_util.h" |
| 25 #include "base/time/time.h" | 26 #include "base/time/time.h" |
| 26 #include "base/values.h" | 27 #include "base/values.h" |
| 27 #include "build/build_config.h" | 28 #include "build/build_config.h" |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 } | 119 } |
| 119 } | 120 } |
| 120 return true; | 121 return true; |
| 121 } | 122 } |
| 122 | 123 |
| 123 // Sets the value of |key| in |dictionary| to be a list with the contents of | 124 // Sets the value of |key| in |dictionary| to be a list with the contents of |
| 124 // |ids|. | 125 // |ids|. |
| 125 void SetExtensionIdSet(base::DictionaryValue* dictionary, | 126 void SetExtensionIdSet(base::DictionaryValue* dictionary, |
| 126 const char* key, | 127 const char* key, |
| 127 const ExtensionIdSet& ids) { | 128 const ExtensionIdSet& ids) { |
| 128 base::ListValue* id_list = new base::ListValue(); | 129 auto id_list = base::MakeUnique<base::ListValue>(); |
| 129 for (ExtensionIdSet::const_iterator i = ids.begin(); i != ids.end(); ++i) | 130 for (ExtensionIdSet::const_iterator i = ids.begin(); i != ids.end(); ++i) |
| 130 id_list->AppendString(*i); | 131 id_list->AppendString(*i); |
| 131 dictionary->Set(key, id_list); | 132 dictionary->Set(key, std::move(id_list)); |
| 132 } | 133 } |
| 133 | 134 |
| 134 // Tries to fetch a list of strings from |dictionay| for |key|, and inserts | 135 // Tries to fetch a list of strings from |dictionay| for |key|, and inserts |
| 135 // them into |ids|. The return value indicates success/failure. Note: on | 136 // them into |ids|. The return value indicates success/failure. Note: on |
| 136 // failure, |ids| might contain partial results, for instance if some of the | 137 // failure, |ids| might contain partial results, for instance if some of the |
| 137 // members of the list were not strings. | 138 // members of the list were not strings. |
| 138 bool GetExtensionIdSet(const base::DictionaryValue& dictionary, | 139 bool GetExtensionIdSet(const base::DictionaryValue& dictionary, |
| 139 const char* key, | 140 const char* key, |
| 140 ExtensionIdSet* ids) { | 141 ExtensionIdSet* ids) { |
| 141 const base::ListValue* id_list = NULL; | 142 const base::ListValue* id_list = NULL; |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 // "hash": "<base64-encoded hash value here>", | 384 // "hash": "<base64-encoded hash value here>", |
| 384 // "ids": [ "<id1>", "id2" ] | 385 // "ids": [ "<id1>", "id2" ] |
| 385 // } | 386 // } |
| 386 base::DictionaryValue dictionary; | 387 base::DictionaryValue dictionary; |
| 387 dictionary.SetInteger(kProtocolVersionKey, 1); | 388 dictionary.SetInteger(kProtocolVersionKey, 1); |
| 388 dictionary.SetString(kHashKey, hash_base64); | 389 dictionary.SetString(kHashKey, hash_base64); |
| 389 std::unique_ptr<base::ListValue> id_list(new base::ListValue); | 390 std::unique_ptr<base::ListValue> id_list(new base::ListValue); |
| 390 for (ExtensionIdSet::const_iterator i = ids_.begin(); i != ids_.end(); ++i) { | 391 for (ExtensionIdSet::const_iterator i = ids_.begin(); i != ids_.end(); ++i) { |
| 391 id_list->AppendString(*i); | 392 id_list->AppendString(*i); |
| 392 } | 393 } |
| 393 dictionary.Set(kIdsKey, id_list.release()); | 394 dictionary.Set(kIdsKey, std::move(id_list)); |
| 394 std::string json; | 395 std::string json; |
| 395 base::JSONWriter::Write(dictionary, &json); | 396 base::JSONWriter::Write(dictionary, &json); |
| 396 if (json.empty()) { | 397 if (json.empty()) { |
| 397 ReportErrorViaCallback(); | 398 ReportErrorViaCallback(); |
| 398 return; | 399 return; |
| 399 } | 400 } |
| 400 url_fetcher_->SetUploadData("application/json", json); | 401 url_fetcher_->SetUploadData("application/json", json); |
| 401 LogRequestStartHistograms(); | 402 LogRequestStartHistograms(); |
| 402 request_start_time_ = base::Time::Now(); | 403 request_start_time_ = base::Time::Now(); |
| 403 VLOG(1) << "Sending request: " << json; | 404 VLOG(1) << "Sending request: " << json; |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 if (!verified) | 506 if (!verified) |
| 506 result.reset(); | 507 result.reset(); |
| 507 } | 508 } |
| 508 | 509 |
| 509 if (!callback_.is_null()) | 510 if (!callback_.is_null()) |
| 510 callback_.Run(std::move(result)); | 511 callback_.Run(std::move(result)); |
| 511 } | 512 } |
| 512 | 513 |
| 513 | 514 |
| 514 } // namespace extensions | 515 } // namespace extensions |
| OLD | NEW |