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 "components/search_provider_logos/logo_cache.h" | 5 #include "components/search_provider_logos/logo_cache.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 | 189 |
190 std::string str; | 190 std::string str; |
191 LogoMetadataToString(*metadata_, logo_num_bytes_, &str); | 191 LogoMetadataToString(*metadata_, logo_num_bytes_, &str); |
192 base::WriteFile(GetMetadataPath(), str.data(), static_cast<int>(str.size())); | 192 base::WriteFile(GetMetadataPath(), str.data(), static_cast<int>(str.size())); |
193 } | 193 } |
194 | 194 |
195 void LogoCache::WriteLogo(scoped_refptr<base::RefCountedMemory> encoded_image) { | 195 void LogoCache::WriteLogo(scoped_refptr<base::RefCountedMemory> encoded_image) { |
196 if (!EnsureCacheDirectoryExists()) | 196 if (!EnsureCacheDirectoryExists()) |
197 return; | 197 return; |
198 | 198 |
199 if (!metadata_ || !encoded_image) { | 199 if (!metadata_ || !encoded_image.get()) { |
200 DeleteLogoAndMetadata(); | 200 DeleteLogoAndMetadata(); |
201 return; | 201 return; |
202 } | 202 } |
203 | 203 |
204 // To minimize the chances of ending up in an undetectably broken state: | 204 // To minimize the chances of ending up in an undetectably broken state: |
205 // First, delete the metadata file, then update the logo file, then update the | 205 // First, delete the metadata file, then update the logo file, then update the |
206 // metadata file. | 206 // metadata file. |
207 base::FilePath logo_path = GetLogoPath(); | 207 base::FilePath logo_path = GetLogoPath(); |
208 base::FilePath metadata_path = GetMetadataPath(); | 208 base::FilePath metadata_path = GetMetadataPath(); |
209 | 209 |
(...skipping 16 matching lines...) Expand all Loading... |
226 base::DeleteFile(GetMetadataPath(), false); | 226 base::DeleteFile(GetMetadataPath(), false); |
227 } | 227 } |
228 | 228 |
229 bool LogoCache::EnsureCacheDirectoryExists() { | 229 bool LogoCache::EnsureCacheDirectoryExists() { |
230 if (base::DirectoryExists(cache_directory_)) | 230 if (base::DirectoryExists(cache_directory_)) |
231 return true; | 231 return true; |
232 return base::CreateDirectory(cache_directory_); | 232 return base::CreateDirectory(cache_directory_); |
233 } | 233 } |
234 | 234 |
235 } // namespace search_provider_logos | 235 } // namespace search_provider_logos |
OLD | NEW |