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/computed_hashes.h" | 5 #include "extensions/browser/computed_hashes.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 block_hashes->AppendString(encoded); | 149 block_hashes->AppendString(encoded); |
150 } | 150 } |
151 } | 151 } |
152 | 152 |
153 bool ComputedHashes::Writer::WriteToFile(const base::FilePath& path) { | 153 bool ComputedHashes::Writer::WriteToFile(const base::FilePath& path) { |
154 std::string json; | 154 std::string json; |
155 base::DictionaryValue top_dictionary; | 155 base::DictionaryValue top_dictionary; |
156 top_dictionary.SetInteger(kVersionKey, kVersion); | 156 top_dictionary.SetInteger(kVersionKey, kVersion); |
157 top_dictionary.Set(kFileHashesKey, file_list_.release()); | 157 top_dictionary.Set(kFileHashesKey, file_list_.release()); |
158 | 158 |
159 if (!base::JSONWriter::Write(&top_dictionary, &json)) | 159 if (!base::JSONWriter::Write(top_dictionary, &json)) |
160 return false; | 160 return false; |
161 int written = base::WriteFile(path, json.data(), json.size()); | 161 int written = base::WriteFile(path, json.data(), json.size()); |
162 if (static_cast<unsigned>(written) != json.size()) { | 162 if (static_cast<unsigned>(written) != json.size()) { |
163 LOG(ERROR) << "Error writing " << path.AsUTF8Unsafe() | 163 LOG(ERROR) << "Error writing " << path.AsUTF8Unsafe() |
164 << " ; write result:" << written << " expected:" << json.size(); | 164 << " ; write result:" << written << " expected:" << json.size(); |
165 return false; | 165 return false; |
166 } | 166 } |
167 return true; | 167 return true; |
168 } | 168 } |
169 | 169 |
(...skipping 18 matching lines...) Expand all Loading... |
188 | 188 |
189 // If |contents| is empty, then we want to just exit here. | 189 // If |contents| is empty, then we want to just exit here. |
190 if (bytes_to_read == 0) | 190 if (bytes_to_read == 0) |
191 break; | 191 break; |
192 | 192 |
193 offset += bytes_to_read; | 193 offset += bytes_to_read; |
194 } while (offset < contents.size()); | 194 } while (offset < contents.size()); |
195 } | 195 } |
196 | 196 |
197 } // namespace extensions | 197 } // namespace extensions |
OLD | NEW |